three.js 1.2 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291
  1. // threejs.org/license
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.THREE = {}));
  6. }(this, (function (exports) { 'use strict';
  7. // Polyfills
  8. if (Number.EPSILON === undefined) {
  9. Number.EPSILON = Math.pow(2, -52);
  10. }
  11. if (Number.isInteger === undefined) {
  12. // Missing in IE
  13. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  14. Number.isInteger = function (value) {
  15. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  16. };
  17. } //
  18. if (Math.sign === undefined) {
  19. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  20. Math.sign = function (x) {
  21. return x < 0 ? -1 : x > 0 ? 1 : +x;
  22. };
  23. }
  24. if ('name' in Function.prototype === false) {
  25. // Missing in IE
  26. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  27. Object.defineProperty(Function.prototype, 'name', {
  28. get: function get() {
  29. return this.toString().match(/^\s*function\s*([^\(\s]*)/)[1];
  30. }
  31. });
  32. }
  33. if (Object.assign === undefined) {
  34. // Missing in IE
  35. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  36. Object.assign = function (target) {
  37. if (target === undefined || target === null) {
  38. throw new TypeError('Cannot convert undefined or null to object');
  39. }
  40. var output = Object(target);
  41. for (var index = 1; index < arguments.length; index++) {
  42. var source = arguments[index];
  43. if (source !== undefined && source !== null) {
  44. for (var nextKey in source) {
  45. if (Object.prototype.hasOwnProperty.call(source, nextKey)) {
  46. output[nextKey] = source[nextKey];
  47. }
  48. }
  49. }
  50. }
  51. return output;
  52. };
  53. }
  54. /**
  55. * Copyright (c) 2014-present, Facebook, Inc.
  56. *
  57. * This source code is licensed under the MIT license found in the
  58. * LICENSE file in the root directory of this source tree.
  59. */
  60. var runtime = function (exports) {
  61. var Op = Object.prototype;
  62. var hasOwn = Op.hasOwnProperty;
  63. var undefined$1; // More compressible than void 0.
  64. var $Symbol = typeof Symbol === "function" ? Symbol : {};
  65. var iteratorSymbol = $Symbol.iterator || "@@iterator";
  66. var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
  67. var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  68. function define(obj, key, value) {
  69. Object.defineProperty(obj, key, {
  70. value: value,
  71. enumerable: true,
  72. configurable: true,
  73. writable: true
  74. });
  75. return obj[key];
  76. }
  77. try {
  78. // IE 8 has a broken Object.defineProperty that only works on DOM objects.
  79. define({}, "");
  80. } catch (err) {
  81. define = function define(obj, key, value) {
  82. return obj[key] = value;
  83. };
  84. }
  85. function wrap(innerFn, outerFn, self, tryLocsList) {
  86. // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
  87. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
  88. var generator = Object.create(protoGenerator.prototype);
  89. var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
  90. // .throw, and .return methods.
  91. generator._invoke = makeInvokeMethod(innerFn, self, context);
  92. return generator;
  93. }
  94. exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
  95. // record like context.tryEntries[i].completion. This interface could
  96. // have been (and was previously) designed to take a closure to be
  97. // invoked without arguments, but in all the cases we care about we
  98. // already have an existing method we want to call, so there's no need
  99. // to create a new function object. We can even get away with assuming
  100. // the method takes exactly one argument, since that happens to be true
  101. // in every case, so we don't have to touch the arguments object. The
  102. // only additional allocation required is the completion record, which
  103. // has a stable shape and so hopefully should be cheap to allocate.
  104. function tryCatch(fn, obj, arg) {
  105. try {
  106. return {
  107. type: "normal",
  108. arg: fn.call(obj, arg)
  109. };
  110. } catch (err) {
  111. return {
  112. type: "throw",
  113. arg: err
  114. };
  115. }
  116. }
  117. var GenStateSuspendedStart = "suspendedStart";
  118. var GenStateSuspendedYield = "suspendedYield";
  119. var GenStateExecuting = "executing";
  120. var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
  121. // breaking out of the dispatch switch statement.
  122. var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
  123. // .constructor.prototype properties for functions that return Generator
  124. // objects. For full spec compliance, you may wish to configure your
  125. // minifier not to mangle the names of these two functions.
  126. function Generator() {}
  127. function GeneratorFunction() {}
  128. function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
  129. // don't natively support it.
  130. var IteratorPrototype = {};
  131. IteratorPrototype[iteratorSymbol] = function () {
  132. return this;
  133. };
  134. var getProto = Object.getPrototypeOf;
  135. var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  136. if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
  137. // This environment has a native %IteratorPrototype%; use it instead
  138. // of the polyfill.
  139. IteratorPrototype = NativeIteratorPrototype;
  140. }
  141. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  142. GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
  143. GeneratorFunctionPrototype.constructor = GeneratorFunction;
  144. GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
  145. // Iterator interface in terms of a single ._invoke method.
  146. function defineIteratorMethods(prototype) {
  147. ["next", "throw", "return"].forEach(function (method) {
  148. define(prototype, method, function (arg) {
  149. return this._invoke(method, arg);
  150. });
  151. });
  152. }
  153. exports.isGeneratorFunction = function (genFun) {
  154. var ctor = typeof genFun === "function" && genFun.constructor;
  155. return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
  156. // do is to check its .name property.
  157. (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
  158. };
  159. exports.mark = function (genFun) {
  160. if (Object.setPrototypeOf) {
  161. Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
  162. } else {
  163. genFun.__proto__ = GeneratorFunctionPrototype;
  164. define(genFun, toStringTagSymbol, "GeneratorFunction");
  165. }
  166. genFun.prototype = Object.create(Gp);
  167. return genFun;
  168. }; // Within the body of any async function, `await x` is transformed to
  169. // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
  170. // `hasOwn.call(value, "__await")` to determine if the yielded value is
  171. // meant to be awaited.
  172. exports.awrap = function (arg) {
  173. return {
  174. __await: arg
  175. };
  176. };
  177. function AsyncIterator(generator, PromiseImpl) {
  178. function invoke(method, arg, resolve, reject) {
  179. var record = tryCatch(generator[method], generator, arg);
  180. if (record.type === "throw") {
  181. reject(record.arg);
  182. } else {
  183. var result = record.arg;
  184. var value = result.value;
  185. if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
  186. return PromiseImpl.resolve(value.__await).then(function (value) {
  187. invoke("next", value, resolve, reject);
  188. }, function (err) {
  189. invoke("throw", err, resolve, reject);
  190. });
  191. }
  192. return PromiseImpl.resolve(value).then(function (unwrapped) {
  193. // When a yielded Promise is resolved, its final value becomes
  194. // the .value of the Promise<{value,done}> result for the
  195. // current iteration.
  196. result.value = unwrapped;
  197. resolve(result);
  198. }, function (error) {
  199. // If a rejected Promise was yielded, throw the rejection back
  200. // into the async generator function so it can be handled there.
  201. return invoke("throw", error, resolve, reject);
  202. });
  203. }
  204. }
  205. var previousPromise;
  206. function enqueue(method, arg) {
  207. function callInvokeWithMethodAndArg() {
  208. return new PromiseImpl(function (resolve, reject) {
  209. invoke(method, arg, resolve, reject);
  210. });
  211. }
  212. return previousPromise = // If enqueue has been called before, then we want to wait until
  213. // all previous Promises have been resolved before calling invoke,
  214. // so that results are always delivered in the correct order. If
  215. // enqueue has not been called before, then it is important to
  216. // call invoke immediately, without waiting on a callback to fire,
  217. // so that the async generator function has the opportunity to do
  218. // any necessary setup in a predictable way. This predictability
  219. // is why the Promise constructor synchronously invokes its
  220. // executor callback, and why async functions synchronously
  221. // execute code before the first await. Since we implement simple
  222. // async functions in terms of async generators, it is especially
  223. // important to get this right, even though it requires care.
  224. previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
  225. // invocations of the iterator.
  226. callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  227. } // Define the unified helper method that is used to implement .next,
  228. // .throw, and .return (see defineIteratorMethods).
  229. this._invoke = enqueue;
  230. }
  231. defineIteratorMethods(AsyncIterator.prototype);
  232. AsyncIterator.prototype[asyncIteratorSymbol] = function () {
  233. return this;
  234. };
  235. exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
  236. // AsyncIterator objects; they just return a Promise for the value of
  237. // the final result produced by the iterator.
  238. exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  239. if (PromiseImpl === void 0) PromiseImpl = Promise;
  240. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  241. return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
  242. : iter.next().then(function (result) {
  243. return result.done ? result.value : iter.next();
  244. });
  245. };
  246. function makeInvokeMethod(innerFn, self, context) {
  247. var state = GenStateSuspendedStart;
  248. return function invoke(method, arg) {
  249. if (state === GenStateExecuting) {
  250. throw new Error("Generator is already running");
  251. }
  252. if (state === GenStateCompleted) {
  253. if (method === "throw") {
  254. throw arg;
  255. } // Be forgiving, per 25.3.3.3.3 of the spec:
  256. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
  257. return doneResult();
  258. }
  259. context.method = method;
  260. context.arg = arg;
  261. while (true) {
  262. var delegate = context.delegate;
  263. if (delegate) {
  264. var delegateResult = maybeInvokeDelegate(delegate, context);
  265. if (delegateResult) {
  266. if (delegateResult === ContinueSentinel) continue;
  267. return delegateResult;
  268. }
  269. }
  270. if (context.method === "next") {
  271. // Setting context._sent for legacy support of Babel's
  272. // function.sent implementation.
  273. context.sent = context._sent = context.arg;
  274. } else if (context.method === "throw") {
  275. if (state === GenStateSuspendedStart) {
  276. state = GenStateCompleted;
  277. throw context.arg;
  278. }
  279. context.dispatchException(context.arg);
  280. } else if (context.method === "return") {
  281. context.abrupt("return", context.arg);
  282. }
  283. state = GenStateExecuting;
  284. var record = tryCatch(innerFn, self, context);
  285. if (record.type === "normal") {
  286. // If an exception is thrown from innerFn, we leave state ===
  287. // GenStateExecuting and loop back for another invocation.
  288. state = context.done ? GenStateCompleted : GenStateSuspendedYield;
  289. if (record.arg === ContinueSentinel) {
  290. continue;
  291. }
  292. return {
  293. value: record.arg,
  294. done: context.done
  295. };
  296. } else if (record.type === "throw") {
  297. state = GenStateCompleted; // Dispatch the exception by looping back around to the
  298. // context.dispatchException(context.arg) call above.
  299. context.method = "throw";
  300. context.arg = record.arg;
  301. }
  302. }
  303. };
  304. } // Call delegate.iterator[context.method](context.arg) and handle the
  305. // result, either by returning a { value, done } result from the
  306. // delegate iterator, or by modifying context.method and context.arg,
  307. // setting context.delegate to null, and returning the ContinueSentinel.
  308. function maybeInvokeDelegate(delegate, context) {
  309. var method = delegate.iterator[context.method];
  310. if (method === undefined$1) {
  311. // A .throw or .return when the delegate iterator has no .throw
  312. // method always terminates the yield* loop.
  313. context.delegate = null;
  314. if (context.method === "throw") {
  315. // Note: ["return"] must be used for ES3 parsing compatibility.
  316. if (delegate.iterator["return"]) {
  317. // If the delegate iterator has a return method, give it a
  318. // chance to clean up.
  319. context.method = "return";
  320. context.arg = undefined$1;
  321. maybeInvokeDelegate(delegate, context);
  322. if (context.method === "throw") {
  323. // If maybeInvokeDelegate(context) changed context.method from
  324. // "return" to "throw", let that override the TypeError below.
  325. return ContinueSentinel;
  326. }
  327. }
  328. context.method = "throw";
  329. context.arg = new TypeError("The iterator does not provide a 'throw' method");
  330. }
  331. return ContinueSentinel;
  332. }
  333. var record = tryCatch(method, delegate.iterator, context.arg);
  334. if (record.type === "throw") {
  335. context.method = "throw";
  336. context.arg = record.arg;
  337. context.delegate = null;
  338. return ContinueSentinel;
  339. }
  340. var info = record.arg;
  341. if (!info) {
  342. context.method = "throw";
  343. context.arg = new TypeError("iterator result is not an object");
  344. context.delegate = null;
  345. return ContinueSentinel;
  346. }
  347. if (info.done) {
  348. // Assign the result of the finished delegate to the temporary
  349. // variable specified by delegate.resultName (see delegateYield).
  350. context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
  351. context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
  352. // exception, let the outer generator proceed normally. If
  353. // context.method was "next", forget context.arg since it has been
  354. // "consumed" by the delegate iterator. If context.method was
  355. // "return", allow the original .return call to continue in the
  356. // outer generator.
  357. if (context.method !== "return") {
  358. context.method = "next";
  359. context.arg = undefined$1;
  360. }
  361. } else {
  362. // Re-yield the result returned by the delegate method.
  363. return info;
  364. } // The delegate iterator is finished, so forget it and continue with
  365. // the outer generator.
  366. context.delegate = null;
  367. return ContinueSentinel;
  368. } // Define Generator.prototype.{next,throw,return} in terms of the
  369. // unified ._invoke helper method.
  370. defineIteratorMethods(Gp);
  371. define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
  372. // @@iterator function is called on it. Some browsers' implementations of the
  373. // iterator prototype chain incorrectly implement this, causing the Generator
  374. // object to not be returned from this call. This ensures that doesn't happen.
  375. // See https://github.com/facebook/regenerator/issues/274 for more details.
  376. Gp[iteratorSymbol] = function () {
  377. return this;
  378. };
  379. Gp.toString = function () {
  380. return "[object Generator]";
  381. };
  382. function pushTryEntry(locs) {
  383. var entry = {
  384. tryLoc: locs[0]
  385. };
  386. if (1 in locs) {
  387. entry.catchLoc = locs[1];
  388. }
  389. if (2 in locs) {
  390. entry.finallyLoc = locs[2];
  391. entry.afterLoc = locs[3];
  392. }
  393. this.tryEntries.push(entry);
  394. }
  395. function resetTryEntry(entry) {
  396. var record = entry.completion || {};
  397. record.type = "normal";
  398. delete record.arg;
  399. entry.completion = record;
  400. }
  401. function Context(tryLocsList) {
  402. // The root entry object (effectively a try statement without a catch
  403. // or a finally block) gives us a place to store values thrown from
  404. // locations where there is no enclosing try statement.
  405. this.tryEntries = [{
  406. tryLoc: "root"
  407. }];
  408. tryLocsList.forEach(pushTryEntry, this);
  409. this.reset(true);
  410. }
  411. exports.keys = function (object) {
  412. var keys = [];
  413. for (var key in object) {
  414. keys.push(key);
  415. }
  416. keys.reverse(); // Rather than returning an object with a next method, we keep
  417. // things simple and return the next function itself.
  418. return function next() {
  419. while (keys.length) {
  420. var key = keys.pop();
  421. if (key in object) {
  422. next.value = key;
  423. next.done = false;
  424. return next;
  425. }
  426. } // To avoid creating an additional object, we just hang the .value
  427. // and .done properties off the next function object itself. This
  428. // also ensures that the minifier will not anonymize the function.
  429. next.done = true;
  430. return next;
  431. };
  432. };
  433. function values(iterable) {
  434. if (iterable) {
  435. var iteratorMethod = iterable[iteratorSymbol];
  436. if (iteratorMethod) {
  437. return iteratorMethod.call(iterable);
  438. }
  439. if (typeof iterable.next === "function") {
  440. return iterable;
  441. }
  442. if (!isNaN(iterable.length)) {
  443. var i = -1,
  444. next = function next() {
  445. while (++i < iterable.length) {
  446. if (hasOwn.call(iterable, i)) {
  447. next.value = iterable[i];
  448. next.done = false;
  449. return next;
  450. }
  451. }
  452. next.value = undefined$1;
  453. next.done = true;
  454. return next;
  455. };
  456. return next.next = next;
  457. }
  458. } // Return an iterator with no values.
  459. return {
  460. next: doneResult
  461. };
  462. }
  463. exports.values = values;
  464. function doneResult() {
  465. return {
  466. value: undefined$1,
  467. done: true
  468. };
  469. }
  470. Context.prototype = {
  471. constructor: Context,
  472. reset: function reset(skipTempReset) {
  473. this.prev = 0;
  474. this.next = 0; // Resetting context._sent for legacy support of Babel's
  475. // function.sent implementation.
  476. this.sent = this._sent = undefined$1;
  477. this.done = false;
  478. this.delegate = null;
  479. this.method = "next";
  480. this.arg = undefined$1;
  481. this.tryEntries.forEach(resetTryEntry);
  482. if (!skipTempReset) {
  483. for (var name in this) {
  484. // Not sure about the optimal order of these conditions:
  485. if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
  486. this[name] = undefined$1;
  487. }
  488. }
  489. }
  490. },
  491. stop: function stop() {
  492. this.done = true;
  493. var rootEntry = this.tryEntries[0];
  494. var rootRecord = rootEntry.completion;
  495. if (rootRecord.type === "throw") {
  496. throw rootRecord.arg;
  497. }
  498. return this.rval;
  499. },
  500. dispatchException: function dispatchException(exception) {
  501. if (this.done) {
  502. throw exception;
  503. }
  504. var context = this;
  505. function handle(loc, caught) {
  506. record.type = "throw";
  507. record.arg = exception;
  508. context.next = loc;
  509. if (caught) {
  510. // If the dispatched exception was caught by a catch block,
  511. // then let that catch block handle the exception normally.
  512. context.method = "next";
  513. context.arg = undefined$1;
  514. }
  515. return !!caught;
  516. }
  517. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  518. var entry = this.tryEntries[i];
  519. var record = entry.completion;
  520. if (entry.tryLoc === "root") {
  521. // Exception thrown outside of any try block that could handle
  522. // it, so set the completion value of the entire function to
  523. // throw the exception.
  524. return handle("end");
  525. }
  526. if (entry.tryLoc <= this.prev) {
  527. var hasCatch = hasOwn.call(entry, "catchLoc");
  528. var hasFinally = hasOwn.call(entry, "finallyLoc");
  529. if (hasCatch && hasFinally) {
  530. if (this.prev < entry.catchLoc) {
  531. return handle(entry.catchLoc, true);
  532. } else if (this.prev < entry.finallyLoc) {
  533. return handle(entry.finallyLoc);
  534. }
  535. } else if (hasCatch) {
  536. if (this.prev < entry.catchLoc) {
  537. return handle(entry.catchLoc, true);
  538. }
  539. } else if (hasFinally) {
  540. if (this.prev < entry.finallyLoc) {
  541. return handle(entry.finallyLoc);
  542. }
  543. } else {
  544. throw new Error("try statement without catch or finally");
  545. }
  546. }
  547. }
  548. },
  549. abrupt: function abrupt(type, arg) {
  550. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  551. var entry = this.tryEntries[i];
  552. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  553. var finallyEntry = entry;
  554. break;
  555. }
  556. }
  557. if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
  558. // Ignore the finally entry if control is not jumping to a
  559. // location outside the try/catch block.
  560. finallyEntry = null;
  561. }
  562. var record = finallyEntry ? finallyEntry.completion : {};
  563. record.type = type;
  564. record.arg = arg;
  565. if (finallyEntry) {
  566. this.method = "next";
  567. this.next = finallyEntry.finallyLoc;
  568. return ContinueSentinel;
  569. }
  570. return this.complete(record);
  571. },
  572. complete: function complete(record, afterLoc) {
  573. if (record.type === "throw") {
  574. throw record.arg;
  575. }
  576. if (record.type === "break" || record.type === "continue") {
  577. this.next = record.arg;
  578. } else if (record.type === "return") {
  579. this.rval = this.arg = record.arg;
  580. this.method = "return";
  581. this.next = "end";
  582. } else if (record.type === "normal" && afterLoc) {
  583. this.next = afterLoc;
  584. }
  585. return ContinueSentinel;
  586. },
  587. finish: function finish(finallyLoc) {
  588. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  589. var entry = this.tryEntries[i];
  590. if (entry.finallyLoc === finallyLoc) {
  591. this.complete(entry.completion, entry.afterLoc);
  592. resetTryEntry(entry);
  593. return ContinueSentinel;
  594. }
  595. }
  596. },
  597. "catch": function _catch(tryLoc) {
  598. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  599. var entry = this.tryEntries[i];
  600. if (entry.tryLoc === tryLoc) {
  601. var record = entry.completion;
  602. if (record.type === "throw") {
  603. var thrown = record.arg;
  604. resetTryEntry(entry);
  605. }
  606. return thrown;
  607. }
  608. } // The context.catch method must only be called with a location
  609. // argument that corresponds to a known catch block.
  610. throw new Error("illegal catch attempt");
  611. },
  612. delegateYield: function delegateYield(iterable, resultName, nextLoc) {
  613. this.delegate = {
  614. iterator: values(iterable),
  615. resultName: resultName,
  616. nextLoc: nextLoc
  617. };
  618. if (this.method === "next") {
  619. // Deliberately forget the last sent value so that we don't
  620. // accidentally pass it on to the delegate.
  621. this.arg = undefined$1;
  622. }
  623. return ContinueSentinel;
  624. }
  625. }; // Regardless of whether this script is executing as a CommonJS module
  626. // or not, return the runtime object so that we can declare the variable
  627. // regeneratorRuntime in the outer scope, which allows this module to be
  628. // injected easily by `bin/regenerator --include-runtime script.js`.
  629. return exports;
  630. }( // If this script is executing as a CommonJS module, use module.exports
  631. // as the regeneratorRuntime namespace. Otherwise create a new empty
  632. // object. Either way, the resulting object will be used to initialize
  633. // the regeneratorRuntime variable at the top of this file.
  634. typeof module === "object" ? module.exports : {});
  635. try {
  636. regeneratorRuntime = runtime;
  637. } catch (accidentalStrictMode) {
  638. // This module should not be running in strict mode, so the above
  639. // assignment should always work unless something is misconfigured. Just
  640. // in case runtime.js accidentally runs in strict mode, we can escape
  641. // strict mode using a global Function call. This could conceivably fail
  642. // if a Content Security Policy forbids using Function, but in that case
  643. // the proper solution is to fix the accidental strict mode problem. If
  644. // you've misconfigured your bundler to force strict mode and applied a
  645. // CSP to forbid Function, and you're not willing to fix either of those
  646. // problems, please detail your unique predicament in a GitHub issue.
  647. Function("r", "regeneratorRuntime = r")(runtime);
  648. }
  649. var REVISION = '126dev';
  650. var MOUSE = {
  651. LEFT: 0,
  652. MIDDLE: 1,
  653. RIGHT: 2,
  654. ROTATE: 0,
  655. DOLLY: 1,
  656. PAN: 2
  657. };
  658. var TOUCH = {
  659. ROTATE: 0,
  660. PAN: 1,
  661. DOLLY_PAN: 2,
  662. DOLLY_ROTATE: 3
  663. };
  664. var CullFaceNone = 0;
  665. var CullFaceBack = 1;
  666. var CullFaceFront = 2;
  667. var CullFaceFrontBack = 3;
  668. var BasicShadowMap = 0;
  669. var PCFShadowMap = 1;
  670. var PCFSoftShadowMap = 2;
  671. var VSMShadowMap = 3;
  672. var FrontSide = 0;
  673. var BackSide = 1;
  674. var DoubleSide = 2;
  675. var FlatShading = 1;
  676. var SmoothShading = 2;
  677. var NoBlending = 0;
  678. var NormalBlending = 1;
  679. var AdditiveBlending = 2;
  680. var SubtractiveBlending = 3;
  681. var MultiplyBlending = 4;
  682. var CustomBlending = 5;
  683. var AddEquation = 100;
  684. var SubtractEquation = 101;
  685. var ReverseSubtractEquation = 102;
  686. var MinEquation = 103;
  687. var MaxEquation = 104;
  688. var ZeroFactor = 200;
  689. var OneFactor = 201;
  690. var SrcColorFactor = 202;
  691. var OneMinusSrcColorFactor = 203;
  692. var SrcAlphaFactor = 204;
  693. var OneMinusSrcAlphaFactor = 205;
  694. var DstAlphaFactor = 206;
  695. var OneMinusDstAlphaFactor = 207;
  696. var DstColorFactor = 208;
  697. var OneMinusDstColorFactor = 209;
  698. var SrcAlphaSaturateFactor = 210;
  699. var NeverDepth = 0;
  700. var AlwaysDepth = 1;
  701. var LessDepth = 2;
  702. var LessEqualDepth = 3;
  703. var EqualDepth = 4;
  704. var GreaterEqualDepth = 5;
  705. var GreaterDepth = 6;
  706. var NotEqualDepth = 7;
  707. var MultiplyOperation = 0;
  708. var MixOperation = 1;
  709. var AddOperation = 2;
  710. var NoToneMapping = 0;
  711. var LinearToneMapping = 1;
  712. var ReinhardToneMapping = 2;
  713. var CineonToneMapping = 3;
  714. var ACESFilmicToneMapping = 4;
  715. var CustomToneMapping = 5;
  716. var UVMapping = 300;
  717. var CubeReflectionMapping = 301;
  718. var CubeRefractionMapping = 302;
  719. var EquirectangularReflectionMapping = 303;
  720. var EquirectangularRefractionMapping = 304;
  721. var CubeUVReflectionMapping = 306;
  722. var CubeUVRefractionMapping = 307;
  723. var RepeatWrapping = 1000;
  724. var ClampToEdgeWrapping = 1001;
  725. var MirroredRepeatWrapping = 1002;
  726. var NearestFilter = 1003;
  727. var NearestMipmapNearestFilter = 1004;
  728. var NearestMipMapNearestFilter = 1004;
  729. var NearestMipmapLinearFilter = 1005;
  730. var NearestMipMapLinearFilter = 1005;
  731. var LinearFilter = 1006;
  732. var LinearMipmapNearestFilter = 1007;
  733. var LinearMipMapNearestFilter = 1007;
  734. var LinearMipmapLinearFilter = 1008;
  735. var LinearMipMapLinearFilter = 1008;
  736. var UnsignedByteType = 1009;
  737. var ByteType = 1010;
  738. var ShortType = 1011;
  739. var UnsignedShortType = 1012;
  740. var IntType = 1013;
  741. var UnsignedIntType = 1014;
  742. var FloatType = 1015;
  743. var HalfFloatType = 1016;
  744. var UnsignedShort4444Type = 1017;
  745. var UnsignedShort5551Type = 1018;
  746. var UnsignedShort565Type = 1019;
  747. var UnsignedInt248Type = 1020;
  748. var AlphaFormat = 1021;
  749. var RGBFormat = 1022;
  750. var RGBAFormat = 1023;
  751. var LuminanceFormat = 1024;
  752. var LuminanceAlphaFormat = 1025;
  753. var RGBEFormat = RGBAFormat;
  754. var DepthFormat = 1026;
  755. var DepthStencilFormat = 1027;
  756. var RedFormat = 1028;
  757. var RedIntegerFormat = 1029;
  758. var RGFormat = 1030;
  759. var RGIntegerFormat = 1031;
  760. var RGBIntegerFormat = 1032;
  761. var RGBAIntegerFormat = 1033;
  762. var RGB_S3TC_DXT1_Format = 33776;
  763. var RGBA_S3TC_DXT1_Format = 33777;
  764. var RGBA_S3TC_DXT3_Format = 33778;
  765. var RGBA_S3TC_DXT5_Format = 33779;
  766. var RGB_PVRTC_4BPPV1_Format = 35840;
  767. var RGB_PVRTC_2BPPV1_Format = 35841;
  768. var RGBA_PVRTC_4BPPV1_Format = 35842;
  769. var RGBA_PVRTC_2BPPV1_Format = 35843;
  770. var RGB_ETC1_Format = 36196;
  771. var RGB_ETC2_Format = 37492;
  772. var RGBA_ETC2_EAC_Format = 37496;
  773. var RGBA_ASTC_4x4_Format = 37808;
  774. var RGBA_ASTC_5x4_Format = 37809;
  775. var RGBA_ASTC_5x5_Format = 37810;
  776. var RGBA_ASTC_6x5_Format = 37811;
  777. var RGBA_ASTC_6x6_Format = 37812;
  778. var RGBA_ASTC_8x5_Format = 37813;
  779. var RGBA_ASTC_8x6_Format = 37814;
  780. var RGBA_ASTC_8x8_Format = 37815;
  781. var RGBA_ASTC_10x5_Format = 37816;
  782. var RGBA_ASTC_10x6_Format = 37817;
  783. var RGBA_ASTC_10x8_Format = 37818;
  784. var RGBA_ASTC_10x10_Format = 37819;
  785. var RGBA_ASTC_12x10_Format = 37820;
  786. var RGBA_ASTC_12x12_Format = 37821;
  787. var RGBA_BPTC_Format = 36492;
  788. var SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  789. var SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  790. var SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  791. var SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  792. var SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  793. var SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  794. var SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  795. var SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  796. var SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  797. var SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  798. var SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  799. var SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  800. var SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  801. var SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  802. var LoopOnce = 2200;
  803. var LoopRepeat = 2201;
  804. var LoopPingPong = 2202;
  805. var InterpolateDiscrete = 2300;
  806. var InterpolateLinear = 2301;
  807. var InterpolateSmooth = 2302;
  808. var ZeroCurvatureEnding = 2400;
  809. var ZeroSlopeEnding = 2401;
  810. var WrapAroundEnding = 2402;
  811. var NormalAnimationBlendMode = 2500;
  812. var AdditiveAnimationBlendMode = 2501;
  813. var TrianglesDrawMode = 0;
  814. var TriangleStripDrawMode = 1;
  815. var TriangleFanDrawMode = 2;
  816. var LinearEncoding = 3000;
  817. var sRGBEncoding = 3001;
  818. var GammaEncoding = 3007;
  819. var RGBEEncoding = 3002;
  820. var LogLuvEncoding = 3003;
  821. var RGBM7Encoding = 3004;
  822. var RGBM16Encoding = 3005;
  823. var RGBDEncoding = 3006;
  824. var BasicDepthPacking = 3200;
  825. var RGBADepthPacking = 3201;
  826. var TangentSpaceNormalMap = 0;
  827. var ObjectSpaceNormalMap = 1;
  828. var ZeroStencilOp = 0;
  829. var KeepStencilOp = 7680;
  830. var ReplaceStencilOp = 7681;
  831. var IncrementStencilOp = 7682;
  832. var DecrementStencilOp = 7683;
  833. var IncrementWrapStencilOp = 34055;
  834. var DecrementWrapStencilOp = 34056;
  835. var InvertStencilOp = 5386;
  836. var NeverStencilFunc = 512;
  837. var LessStencilFunc = 513;
  838. var EqualStencilFunc = 514;
  839. var LessEqualStencilFunc = 515;
  840. var GreaterStencilFunc = 516;
  841. var NotEqualStencilFunc = 517;
  842. var GreaterEqualStencilFunc = 518;
  843. var AlwaysStencilFunc = 519;
  844. var StaticDrawUsage = 35044;
  845. var DynamicDrawUsage = 35048;
  846. var StreamDrawUsage = 35040;
  847. var StaticReadUsage = 35045;
  848. var DynamicReadUsage = 35049;
  849. var StreamReadUsage = 35041;
  850. var StaticCopyUsage = 35046;
  851. var DynamicCopyUsage = 35050;
  852. var StreamCopyUsage = 35042;
  853. var GLSL1 = '100';
  854. var GLSL3 = '300 es';
  855. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  856. try {
  857. var info = gen[key](arg);
  858. var value = info.value;
  859. } catch (error) {
  860. reject(error);
  861. return;
  862. }
  863. if (info.done) {
  864. resolve(value);
  865. } else {
  866. Promise.resolve(value).then(_next, _throw);
  867. }
  868. }
  869. function _asyncToGenerator(fn) {
  870. return function () {
  871. var self = this,
  872. args = arguments;
  873. return new Promise(function (resolve, reject) {
  874. var gen = fn.apply(self, args);
  875. function _next(value) {
  876. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
  877. }
  878. function _throw(err) {
  879. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
  880. }
  881. _next(undefined);
  882. });
  883. };
  884. }
  885. function _defineProperties(target, props) {
  886. for (var i = 0; i < props.length; i++) {
  887. var descriptor = props[i];
  888. descriptor.enumerable = descriptor.enumerable || false;
  889. descriptor.configurable = true;
  890. if ("value" in descriptor) descriptor.writable = true;
  891. Object.defineProperty(target, descriptor.key, descriptor);
  892. }
  893. }
  894. function _createClass(Constructor, protoProps, staticProps) {
  895. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  896. if (staticProps) _defineProperties(Constructor, staticProps);
  897. return Constructor;
  898. }
  899. function _inheritsLoose(subClass, superClass) {
  900. subClass.prototype = Object.create(superClass.prototype);
  901. subClass.prototype.constructor = subClass;
  902. _setPrototypeOf(subClass, superClass);
  903. }
  904. function _setPrototypeOf(o, p) {
  905. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  906. o.__proto__ = p;
  907. return o;
  908. };
  909. return _setPrototypeOf(o, p);
  910. }
  911. function _assertThisInitialized(self) {
  912. if (self === void 0) {
  913. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  914. }
  915. return self;
  916. }
  917. function _unsupportedIterableToArray(o, minLen) {
  918. if (!o) return;
  919. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  920. var n = Object.prototype.toString.call(o).slice(8, -1);
  921. if (n === "Object" && o.constructor) n = o.constructor.name;
  922. if (n === "Map" || n === "Set") return Array.from(o);
  923. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  924. }
  925. function _arrayLikeToArray(arr, len) {
  926. if (len == null || len > arr.length) len = arr.length;
  927. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  928. return arr2;
  929. }
  930. function _createForOfIteratorHelperLoose(o, allowArrayLike) {
  931. var it;
  932. if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
  933. if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  934. if (it) o = it;
  935. var i = 0;
  936. return function () {
  937. if (i >= o.length) return {
  938. done: true
  939. };
  940. return {
  941. done: false,
  942. value: o[i++]
  943. };
  944. };
  945. }
  946. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  947. }
  948. it = o[Symbol.iterator]();
  949. return it.next.bind(it);
  950. }
  951. /**
  952. * https://github.com/mrdoob/eventdispatcher.js/
  953. */
  954. function EventDispatcher() {}
  955. Object.assign(EventDispatcher.prototype, {
  956. addEventListener: function addEventListener(type, listener) {
  957. if (this._listeners === undefined) this._listeners = {};
  958. var listeners = this._listeners;
  959. if (listeners[type] === undefined) {
  960. listeners[type] = [];
  961. }
  962. if (listeners[type].indexOf(listener) === -1) {
  963. listeners[type].push(listener);
  964. }
  965. },
  966. hasEventListener: function hasEventListener(type, listener) {
  967. if (this._listeners === undefined) return false;
  968. var listeners = this._listeners;
  969. return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
  970. },
  971. removeEventListener: function removeEventListener(type, listener) {
  972. if (this._listeners === undefined) return;
  973. var listeners = this._listeners;
  974. var listenerArray = listeners[type];
  975. if (listenerArray !== undefined) {
  976. var index = listenerArray.indexOf(listener);
  977. if (index !== -1) {
  978. listenerArray.splice(index, 1);
  979. }
  980. }
  981. },
  982. dispatchEvent: function dispatchEvent(event) {
  983. if (this._listeners === undefined) return;
  984. var listeners = this._listeners;
  985. var listenerArray = listeners[event.type];
  986. if (listenerArray !== undefined) {
  987. event.target = this; // Make a copy, in case listeners are removed while iterating.
  988. var array = listenerArray.slice(0);
  989. for (var i = 0, l = array.length; i < l; i++) {
  990. array[i].call(this, event);
  991. }
  992. }
  993. }
  994. });
  995. var _lut = [];
  996. for (var i = 0; i < 256; i++) {
  997. _lut[i] = (i < 16 ? '0' : '') + i.toString(16);
  998. }
  999. var _seed = 1234567;
  1000. var MathUtils = {
  1001. DEG2RAD: Math.PI / 180,
  1002. RAD2DEG: 180 / Math.PI,
  1003. generateUUID: function generateUUID() {
  1004. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  1005. var d0 = Math.random() * 0xffffffff | 0;
  1006. var d1 = Math.random() * 0xffffffff | 0;
  1007. var d2 = Math.random() * 0xffffffff | 0;
  1008. var d3 = Math.random() * 0xffffffff | 0;
  1009. 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.
  1010. return uuid.toUpperCase();
  1011. },
  1012. clamp: function clamp(value, min, max) {
  1013. return Math.max(min, Math.min(max, value));
  1014. },
  1015. // compute euclidian modulo of m % n
  1016. // https://en.wikipedia.org/wiki/Modulo_operation
  1017. euclideanModulo: function euclideanModulo(n, m) {
  1018. return (n % m + m) % m;
  1019. },
  1020. // Linear mapping from range <a1, a2> to range <b1, b2>
  1021. mapLinear: function mapLinear(x, a1, a2, b1, b2) {
  1022. return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
  1023. },
  1024. // https://en.wikipedia.org/wiki/Linear_interpolation
  1025. lerp: function lerp(x, y, t) {
  1026. return (1 - t) * x + t * y;
  1027. },
  1028. // http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/
  1029. damp: function damp(x, y, lambda, dt) {
  1030. return MathUtils.lerp(x, y, 1 - Math.exp(-lambda * dt));
  1031. },
  1032. // https://www.desmos.com/calculator/vcsjnyz7x4
  1033. pingpong: function pingpong(x, length) {
  1034. if (length === void 0) {
  1035. length = 1;
  1036. }
  1037. return length - Math.abs(MathUtils.euclideanModulo(x, length * 2) - length);
  1038. },
  1039. // http://en.wikipedia.org/wiki/Smoothstep
  1040. smoothstep: function smoothstep(x, min, max) {
  1041. if (x <= min) return 0;
  1042. if (x >= max) return 1;
  1043. x = (x - min) / (max - min);
  1044. return x * x * (3 - 2 * x);
  1045. },
  1046. smootherstep: function smootherstep(x, min, max) {
  1047. if (x <= min) return 0;
  1048. if (x >= max) return 1;
  1049. x = (x - min) / (max - min);
  1050. return x * x * x * (x * (x * 6 - 15) + 10);
  1051. },
  1052. // Random integer from <low, high> interval
  1053. randInt: function randInt(low, high) {
  1054. return low + Math.floor(Math.random() * (high - low + 1));
  1055. },
  1056. // Random float from <low, high> interval
  1057. randFloat: function randFloat(low, high) {
  1058. return low + Math.random() * (high - low);
  1059. },
  1060. // Random float from <-range/2, range/2> interval
  1061. randFloatSpread: function randFloatSpread(range) {
  1062. return range * (0.5 - Math.random());
  1063. },
  1064. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  1065. seededRandom: function seededRandom(s) {
  1066. if (s !== undefined) _seed = s % 2147483647; // Park-Miller algorithm
  1067. _seed = _seed * 16807 % 2147483647;
  1068. return (_seed - 1) / 2147483646;
  1069. },
  1070. degToRad: function degToRad(degrees) {
  1071. return degrees * MathUtils.DEG2RAD;
  1072. },
  1073. radToDeg: function radToDeg(radians) {
  1074. return radians * MathUtils.RAD2DEG;
  1075. },
  1076. isPowerOfTwo: function isPowerOfTwo(value) {
  1077. return (value & value - 1) === 0 && value !== 0;
  1078. },
  1079. ceilPowerOfTwo: function ceilPowerOfTwo(value) {
  1080. return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
  1081. },
  1082. floorPowerOfTwo: function floorPowerOfTwo(value) {
  1083. return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
  1084. },
  1085. setQuaternionFromProperEuler: function setQuaternionFromProperEuler(q, a, b, c, order) {
  1086. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  1087. // rotations are applied to the axes in the order specified by 'order'
  1088. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  1089. // angles are in radians
  1090. var cos = Math.cos;
  1091. var sin = Math.sin;
  1092. var c2 = cos(b / 2);
  1093. var s2 = sin(b / 2);
  1094. var c13 = cos((a + c) / 2);
  1095. var s13 = sin((a + c) / 2);
  1096. var c1_3 = cos((a - c) / 2);
  1097. var s1_3 = sin((a - c) / 2);
  1098. var c3_1 = cos((c - a) / 2);
  1099. var s3_1 = sin((c - a) / 2);
  1100. switch (order) {
  1101. case 'XYX':
  1102. q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
  1103. break;
  1104. case 'YZY':
  1105. q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
  1106. break;
  1107. case 'ZXZ':
  1108. q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
  1109. break;
  1110. case 'XZX':
  1111. q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
  1112. break;
  1113. case 'YXY':
  1114. q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
  1115. break;
  1116. case 'ZYZ':
  1117. q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
  1118. break;
  1119. default:
  1120. console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order);
  1121. }
  1122. }
  1123. };
  1124. var Vector2 = /*#__PURE__*/function () {
  1125. function Vector2(x, y) {
  1126. if (x === void 0) {
  1127. x = 0;
  1128. }
  1129. if (y === void 0) {
  1130. y = 0;
  1131. }
  1132. this.x = x;
  1133. this.y = y;
  1134. }
  1135. var _proto = Vector2.prototype;
  1136. _proto.set = function set(x, y) {
  1137. this.x = x;
  1138. this.y = y;
  1139. return this;
  1140. };
  1141. _proto.setScalar = function setScalar(scalar) {
  1142. this.x = scalar;
  1143. this.y = scalar;
  1144. return this;
  1145. };
  1146. _proto.setX = function setX(x) {
  1147. this.x = x;
  1148. return this;
  1149. };
  1150. _proto.setY = function setY(y) {
  1151. this.y = y;
  1152. return this;
  1153. };
  1154. _proto.setComponent = function setComponent(index, value) {
  1155. switch (index) {
  1156. case 0:
  1157. this.x = value;
  1158. break;
  1159. case 1:
  1160. this.y = value;
  1161. break;
  1162. default:
  1163. throw new Error('index is out of range: ' + index);
  1164. }
  1165. return this;
  1166. };
  1167. _proto.getComponent = function getComponent(index) {
  1168. switch (index) {
  1169. case 0:
  1170. return this.x;
  1171. case 1:
  1172. return this.y;
  1173. default:
  1174. throw new Error('index is out of range: ' + index);
  1175. }
  1176. };
  1177. _proto.clone = function clone() {
  1178. return new this.constructor(this.x, this.y);
  1179. };
  1180. _proto.copy = function copy(v) {
  1181. this.x = v.x;
  1182. this.y = v.y;
  1183. return this;
  1184. };
  1185. _proto.add = function add(v, w) {
  1186. if (w !== undefined) {
  1187. console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1188. return this.addVectors(v, w);
  1189. }
  1190. this.x += v.x;
  1191. this.y += v.y;
  1192. return this;
  1193. };
  1194. _proto.addScalar = function addScalar(s) {
  1195. this.x += s;
  1196. this.y += s;
  1197. return this;
  1198. };
  1199. _proto.addVectors = function addVectors(a, b) {
  1200. this.x = a.x + b.x;
  1201. this.y = a.y + b.y;
  1202. return this;
  1203. };
  1204. _proto.addScaledVector = function addScaledVector(v, s) {
  1205. this.x += v.x * s;
  1206. this.y += v.y * s;
  1207. return this;
  1208. };
  1209. _proto.sub = function sub(v, w) {
  1210. if (w !== undefined) {
  1211. console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  1212. return this.subVectors(v, w);
  1213. }
  1214. this.x -= v.x;
  1215. this.y -= v.y;
  1216. return this;
  1217. };
  1218. _proto.subScalar = function subScalar(s) {
  1219. this.x -= s;
  1220. this.y -= s;
  1221. return this;
  1222. };
  1223. _proto.subVectors = function subVectors(a, b) {
  1224. this.x = a.x - b.x;
  1225. this.y = a.y - b.y;
  1226. return this;
  1227. };
  1228. _proto.multiply = function multiply(v) {
  1229. this.x *= v.x;
  1230. this.y *= v.y;
  1231. return this;
  1232. };
  1233. _proto.multiplyScalar = function multiplyScalar(scalar) {
  1234. this.x *= scalar;
  1235. this.y *= scalar;
  1236. return this;
  1237. };
  1238. _proto.divide = function divide(v) {
  1239. this.x /= v.x;
  1240. this.y /= v.y;
  1241. return this;
  1242. };
  1243. _proto.divideScalar = function divideScalar(scalar) {
  1244. return this.multiplyScalar(1 / scalar);
  1245. };
  1246. _proto.applyMatrix3 = function applyMatrix3(m) {
  1247. var x = this.x,
  1248. y = this.y;
  1249. var e = m.elements;
  1250. this.x = e[0] * x + e[3] * y + e[6];
  1251. this.y = e[1] * x + e[4] * y + e[7];
  1252. return this;
  1253. };
  1254. _proto.min = function min(v) {
  1255. this.x = Math.min(this.x, v.x);
  1256. this.y = Math.min(this.y, v.y);
  1257. return this;
  1258. };
  1259. _proto.max = function max(v) {
  1260. this.x = Math.max(this.x, v.x);
  1261. this.y = Math.max(this.y, v.y);
  1262. return this;
  1263. };
  1264. _proto.clamp = function clamp(min, max) {
  1265. // assumes min < max, componentwise
  1266. this.x = Math.max(min.x, Math.min(max.x, this.x));
  1267. this.y = Math.max(min.y, Math.min(max.y, this.y));
  1268. return this;
  1269. };
  1270. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  1271. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  1272. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  1273. return this;
  1274. };
  1275. _proto.clampLength = function clampLength(min, max) {
  1276. var length = this.length();
  1277. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  1278. };
  1279. _proto.floor = function floor() {
  1280. this.x = Math.floor(this.x);
  1281. this.y = Math.floor(this.y);
  1282. return this;
  1283. };
  1284. _proto.ceil = function ceil() {
  1285. this.x = Math.ceil(this.x);
  1286. this.y = Math.ceil(this.y);
  1287. return this;
  1288. };
  1289. _proto.round = function round() {
  1290. this.x = Math.round(this.x);
  1291. this.y = Math.round(this.y);
  1292. return this;
  1293. };
  1294. _proto.roundToZero = function roundToZero() {
  1295. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  1296. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  1297. return this;
  1298. };
  1299. _proto.negate = function negate() {
  1300. this.x = -this.x;
  1301. this.y = -this.y;
  1302. return this;
  1303. };
  1304. _proto.dot = function dot(v) {
  1305. return this.x * v.x + this.y * v.y;
  1306. };
  1307. _proto.cross = function cross(v) {
  1308. return this.x * v.y - this.y * v.x;
  1309. };
  1310. _proto.lengthSq = function lengthSq() {
  1311. return this.x * this.x + this.y * this.y;
  1312. };
  1313. _proto.length = function length() {
  1314. return Math.sqrt(this.x * this.x + this.y * this.y);
  1315. };
  1316. _proto.manhattanLength = function manhattanLength() {
  1317. return Math.abs(this.x) + Math.abs(this.y);
  1318. };
  1319. _proto.normalize = function normalize() {
  1320. return this.divideScalar(this.length() || 1);
  1321. };
  1322. _proto.angle = function angle() {
  1323. // computes the angle in radians with respect to the positive x-axis
  1324. var angle = Math.atan2(-this.y, -this.x) + Math.PI;
  1325. return angle;
  1326. };
  1327. _proto.distanceTo = function distanceTo(v) {
  1328. return Math.sqrt(this.distanceToSquared(v));
  1329. };
  1330. _proto.distanceToSquared = function distanceToSquared(v) {
  1331. var dx = this.x - v.x,
  1332. dy = this.y - v.y;
  1333. return dx * dx + dy * dy;
  1334. };
  1335. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  1336. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
  1337. };
  1338. _proto.setLength = function setLength(length) {
  1339. return this.normalize().multiplyScalar(length);
  1340. };
  1341. _proto.lerp = function lerp(v, alpha) {
  1342. this.x += (v.x - this.x) * alpha;
  1343. this.y += (v.y - this.y) * alpha;
  1344. return this;
  1345. };
  1346. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  1347. this.x = v1.x + (v2.x - v1.x) * alpha;
  1348. this.y = v1.y + (v2.y - v1.y) * alpha;
  1349. return this;
  1350. };
  1351. _proto.equals = function equals(v) {
  1352. return v.x === this.x && v.y === this.y;
  1353. };
  1354. _proto.fromArray = function fromArray(array, offset) {
  1355. if (offset === void 0) {
  1356. offset = 0;
  1357. }
  1358. this.x = array[offset];
  1359. this.y = array[offset + 1];
  1360. return this;
  1361. };
  1362. _proto.toArray = function toArray(array, offset) {
  1363. if (array === void 0) {
  1364. array = [];
  1365. }
  1366. if (offset === void 0) {
  1367. offset = 0;
  1368. }
  1369. array[offset] = this.x;
  1370. array[offset + 1] = this.y;
  1371. return array;
  1372. };
  1373. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  1374. if (offset !== undefined) {
  1375. console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
  1376. }
  1377. this.x = attribute.getX(index);
  1378. this.y = attribute.getY(index);
  1379. return this;
  1380. };
  1381. _proto.rotateAround = function rotateAround(center, angle) {
  1382. var c = Math.cos(angle),
  1383. s = Math.sin(angle);
  1384. var x = this.x - center.x;
  1385. var y = this.y - center.y;
  1386. this.x = x * c - y * s + center.x;
  1387. this.y = x * s + y * c + center.y;
  1388. return this;
  1389. };
  1390. _proto.random = function random() {
  1391. this.x = Math.random();
  1392. this.y = Math.random();
  1393. return this;
  1394. };
  1395. _createClass(Vector2, [{
  1396. key: "width",
  1397. get: function get() {
  1398. return this.x;
  1399. },
  1400. set: function set(value) {
  1401. this.x = value;
  1402. }
  1403. }, {
  1404. key: "height",
  1405. get: function get() {
  1406. return this.y;
  1407. },
  1408. set: function set(value) {
  1409. this.y = value;
  1410. }
  1411. }]);
  1412. return Vector2;
  1413. }();
  1414. Vector2.prototype.isVector2 = true;
  1415. var Matrix3 = /*#__PURE__*/function () {
  1416. function Matrix3() {
  1417. this.elements = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  1418. if (arguments.length > 0) {
  1419. console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');
  1420. }
  1421. }
  1422. var _proto = Matrix3.prototype;
  1423. _proto.set = function set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
  1424. var te = this.elements;
  1425. te[0] = n11;
  1426. te[1] = n21;
  1427. te[2] = n31;
  1428. te[3] = n12;
  1429. te[4] = n22;
  1430. te[5] = n32;
  1431. te[6] = n13;
  1432. te[7] = n23;
  1433. te[8] = n33;
  1434. return this;
  1435. };
  1436. _proto.identity = function identity() {
  1437. this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
  1438. return this;
  1439. };
  1440. _proto.copy = function copy(m) {
  1441. var te = this.elements;
  1442. var me = m.elements;
  1443. te[0] = me[0];
  1444. te[1] = me[1];
  1445. te[2] = me[2];
  1446. te[3] = me[3];
  1447. te[4] = me[4];
  1448. te[5] = me[5];
  1449. te[6] = me[6];
  1450. te[7] = me[7];
  1451. te[8] = me[8];
  1452. return this;
  1453. };
  1454. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  1455. xAxis.setFromMatrix3Column(this, 0);
  1456. yAxis.setFromMatrix3Column(this, 1);
  1457. zAxis.setFromMatrix3Column(this, 2);
  1458. return this;
  1459. };
  1460. _proto.setFromMatrix4 = function setFromMatrix4(m) {
  1461. var me = m.elements;
  1462. this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
  1463. return this;
  1464. };
  1465. _proto.multiply = function multiply(m) {
  1466. return this.multiplyMatrices(this, m);
  1467. };
  1468. _proto.premultiply = function premultiply(m) {
  1469. return this.multiplyMatrices(m, this);
  1470. };
  1471. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  1472. var ae = a.elements;
  1473. var be = b.elements;
  1474. var te = this.elements;
  1475. var a11 = ae[0],
  1476. a12 = ae[3],
  1477. a13 = ae[6];
  1478. var a21 = ae[1],
  1479. a22 = ae[4],
  1480. a23 = ae[7];
  1481. var a31 = ae[2],
  1482. a32 = ae[5],
  1483. a33 = ae[8];
  1484. var b11 = be[0],
  1485. b12 = be[3],
  1486. b13 = be[6];
  1487. var b21 = be[1],
  1488. b22 = be[4],
  1489. b23 = be[7];
  1490. var b31 = be[2],
  1491. b32 = be[5],
  1492. b33 = be[8];
  1493. te[0] = a11 * b11 + a12 * b21 + a13 * b31;
  1494. te[3] = a11 * b12 + a12 * b22 + a13 * b32;
  1495. te[6] = a11 * b13 + a12 * b23 + a13 * b33;
  1496. te[1] = a21 * b11 + a22 * b21 + a23 * b31;
  1497. te[4] = a21 * b12 + a22 * b22 + a23 * b32;
  1498. te[7] = a21 * b13 + a22 * b23 + a23 * b33;
  1499. te[2] = a31 * b11 + a32 * b21 + a33 * b31;
  1500. te[5] = a31 * b12 + a32 * b22 + a33 * b32;
  1501. te[8] = a31 * b13 + a32 * b23 + a33 * b33;
  1502. return this;
  1503. };
  1504. _proto.multiplyScalar = function multiplyScalar(s) {
  1505. var te = this.elements;
  1506. te[0] *= s;
  1507. te[3] *= s;
  1508. te[6] *= s;
  1509. te[1] *= s;
  1510. te[4] *= s;
  1511. te[7] *= s;
  1512. te[2] *= s;
  1513. te[5] *= s;
  1514. te[8] *= s;
  1515. return this;
  1516. };
  1517. _proto.determinant = function determinant() {
  1518. var te = this.elements;
  1519. var a = te[0],
  1520. b = te[1],
  1521. c = te[2],
  1522. d = te[3],
  1523. e = te[4],
  1524. f = te[5],
  1525. g = te[6],
  1526. h = te[7],
  1527. i = te[8];
  1528. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  1529. };
  1530. _proto.invert = function invert() {
  1531. var te = this.elements,
  1532. n11 = te[0],
  1533. n21 = te[1],
  1534. n31 = te[2],
  1535. n12 = te[3],
  1536. n22 = te[4],
  1537. n32 = te[5],
  1538. n13 = te[6],
  1539. n23 = te[7],
  1540. n33 = te[8],
  1541. t11 = n33 * n22 - n32 * n23,
  1542. t12 = n32 * n13 - n33 * n12,
  1543. t13 = n23 * n12 - n22 * n13,
  1544. det = n11 * t11 + n21 * t12 + n31 * t13;
  1545. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
  1546. var detInv = 1 / det;
  1547. te[0] = t11 * detInv;
  1548. te[1] = (n31 * n23 - n33 * n21) * detInv;
  1549. te[2] = (n32 * n21 - n31 * n22) * detInv;
  1550. te[3] = t12 * detInv;
  1551. te[4] = (n33 * n11 - n31 * n13) * detInv;
  1552. te[5] = (n31 * n12 - n32 * n11) * detInv;
  1553. te[6] = t13 * detInv;
  1554. te[7] = (n21 * n13 - n23 * n11) * detInv;
  1555. te[8] = (n22 * n11 - n21 * n12) * detInv;
  1556. return this;
  1557. };
  1558. _proto.transpose = function transpose() {
  1559. var tmp;
  1560. var m = this.elements;
  1561. tmp = m[1];
  1562. m[1] = m[3];
  1563. m[3] = tmp;
  1564. tmp = m[2];
  1565. m[2] = m[6];
  1566. m[6] = tmp;
  1567. tmp = m[5];
  1568. m[5] = m[7];
  1569. m[7] = tmp;
  1570. return this;
  1571. };
  1572. _proto.getNormalMatrix = function getNormalMatrix(matrix4) {
  1573. return this.setFromMatrix4(matrix4).copy(this).invert().transpose();
  1574. };
  1575. _proto.transposeIntoArray = function transposeIntoArray(r) {
  1576. var m = this.elements;
  1577. r[0] = m[0];
  1578. r[1] = m[3];
  1579. r[2] = m[6];
  1580. r[3] = m[1];
  1581. r[4] = m[4];
  1582. r[5] = m[7];
  1583. r[6] = m[2];
  1584. r[7] = m[5];
  1585. r[8] = m[8];
  1586. return this;
  1587. };
  1588. _proto.setUvTransform = function setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
  1589. var c = Math.cos(rotation);
  1590. var s = Math.sin(rotation);
  1591. 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);
  1592. return this;
  1593. };
  1594. _proto.scale = function scale(sx, sy) {
  1595. var te = this.elements;
  1596. te[0] *= sx;
  1597. te[3] *= sx;
  1598. te[6] *= sx;
  1599. te[1] *= sy;
  1600. te[4] *= sy;
  1601. te[7] *= sy;
  1602. return this;
  1603. };
  1604. _proto.rotate = function rotate(theta) {
  1605. var c = Math.cos(theta);
  1606. var s = Math.sin(theta);
  1607. var te = this.elements;
  1608. var a11 = te[0],
  1609. a12 = te[3],
  1610. a13 = te[6];
  1611. var a21 = te[1],
  1612. a22 = te[4],
  1613. a23 = te[7];
  1614. te[0] = c * a11 + s * a21;
  1615. te[3] = c * a12 + s * a22;
  1616. te[6] = c * a13 + s * a23;
  1617. te[1] = -s * a11 + c * a21;
  1618. te[4] = -s * a12 + c * a22;
  1619. te[7] = -s * a13 + c * a23;
  1620. return this;
  1621. };
  1622. _proto.translate = function translate(tx, ty) {
  1623. var te = this.elements;
  1624. te[0] += tx * te[2];
  1625. te[3] += tx * te[5];
  1626. te[6] += tx * te[8];
  1627. te[1] += ty * te[2];
  1628. te[4] += ty * te[5];
  1629. te[7] += ty * te[8];
  1630. return this;
  1631. };
  1632. _proto.equals = function equals(matrix) {
  1633. var te = this.elements;
  1634. var me = matrix.elements;
  1635. for (var i = 0; i < 9; i++) {
  1636. if (te[i] !== me[i]) return false;
  1637. }
  1638. return true;
  1639. };
  1640. _proto.fromArray = function fromArray(array, offset) {
  1641. if (offset === void 0) {
  1642. offset = 0;
  1643. }
  1644. for (var i = 0; i < 9; i++) {
  1645. this.elements[i] = array[i + offset];
  1646. }
  1647. return this;
  1648. };
  1649. _proto.toArray = function toArray(array, offset) {
  1650. if (array === void 0) {
  1651. array = [];
  1652. }
  1653. if (offset === void 0) {
  1654. offset = 0;
  1655. }
  1656. var te = this.elements;
  1657. array[offset] = te[0];
  1658. array[offset + 1] = te[1];
  1659. array[offset + 2] = te[2];
  1660. array[offset + 3] = te[3];
  1661. array[offset + 4] = te[4];
  1662. array[offset + 5] = te[5];
  1663. array[offset + 6] = te[6];
  1664. array[offset + 7] = te[7];
  1665. array[offset + 8] = te[8];
  1666. return array;
  1667. };
  1668. _proto.clone = function clone() {
  1669. return new this.constructor().fromArray(this.elements);
  1670. };
  1671. return Matrix3;
  1672. }();
  1673. Matrix3.prototype.isMatrix3 = true;
  1674. var _canvas;
  1675. var ImageUtils = {
  1676. getDataURL: function getDataURL(image) {
  1677. if (/^data:/i.test(image.src)) {
  1678. return image.src;
  1679. }
  1680. if (typeof HTMLCanvasElement == 'undefined') {
  1681. return image.src;
  1682. }
  1683. var canvas;
  1684. if (image instanceof HTMLCanvasElement) {
  1685. canvas = image;
  1686. } else {
  1687. if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  1688. _canvas.width = image.width;
  1689. _canvas.height = image.height;
  1690. var context = _canvas.getContext('2d');
  1691. if (image instanceof ImageData) {
  1692. context.putImageData(image, 0, 0);
  1693. } else {
  1694. context.drawImage(image, 0, 0, image.width, image.height);
  1695. }
  1696. canvas = _canvas;
  1697. }
  1698. if (canvas.width > 2048 || canvas.height > 2048) {
  1699. return canvas.toDataURL('image/jpeg', 0.6);
  1700. } else {
  1701. return canvas.toDataURL('image/png');
  1702. }
  1703. }
  1704. };
  1705. var textureId = 0;
  1706. function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  1707. if (image === void 0) {
  1708. image = Texture.DEFAULT_IMAGE;
  1709. }
  1710. if (mapping === void 0) {
  1711. mapping = Texture.DEFAULT_MAPPING;
  1712. }
  1713. if (wrapS === void 0) {
  1714. wrapS = ClampToEdgeWrapping;
  1715. }
  1716. if (wrapT === void 0) {
  1717. wrapT = ClampToEdgeWrapping;
  1718. }
  1719. if (magFilter === void 0) {
  1720. magFilter = LinearFilter;
  1721. }
  1722. if (minFilter === void 0) {
  1723. minFilter = LinearMipmapLinearFilter;
  1724. }
  1725. if (format === void 0) {
  1726. format = RGBAFormat;
  1727. }
  1728. if (type === void 0) {
  1729. type = UnsignedByteType;
  1730. }
  1731. if (anisotropy === void 0) {
  1732. anisotropy = 1;
  1733. }
  1734. if (encoding === void 0) {
  1735. encoding = LinearEncoding;
  1736. }
  1737. Object.defineProperty(this, 'id', {
  1738. value: textureId++
  1739. });
  1740. this.uuid = MathUtils.generateUUID();
  1741. this.name = '';
  1742. this.image = image;
  1743. this.mipmaps = [];
  1744. this.mapping = mapping;
  1745. this.wrapS = wrapS;
  1746. this.wrapT = wrapT;
  1747. this.magFilter = magFilter;
  1748. this.minFilter = minFilter;
  1749. this.anisotropy = anisotropy;
  1750. this.format = format;
  1751. this.internalFormat = null;
  1752. this.type = type;
  1753. this.offset = new Vector2(0, 0);
  1754. this.repeat = new Vector2(1, 1);
  1755. this.center = new Vector2(0, 0);
  1756. this.rotation = 0;
  1757. this.matrixAutoUpdate = true;
  1758. this.matrix = new Matrix3();
  1759. this.generateMipmaps = true;
  1760. this.premultiplyAlpha = false;
  1761. this.flipY = true;
  1762. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1763. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1764. //
  1765. // Also changing the encoding after already used by a Material will not automatically make the Material
  1766. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1767. this.encoding = encoding;
  1768. this.version = 0;
  1769. this.onUpdate = null;
  1770. }
  1771. Texture.DEFAULT_IMAGE = undefined;
  1772. Texture.DEFAULT_MAPPING = UVMapping;
  1773. Texture.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1774. constructor: Texture,
  1775. isTexture: true,
  1776. updateMatrix: function updateMatrix() {
  1777. this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  1778. },
  1779. clone: function clone() {
  1780. return new this.constructor().copy(this);
  1781. },
  1782. copy: function copy(source) {
  1783. this.name = source.name;
  1784. this.image = source.image;
  1785. this.mipmaps = source.mipmaps.slice(0);
  1786. this.mapping = source.mapping;
  1787. this.wrapS = source.wrapS;
  1788. this.wrapT = source.wrapT;
  1789. this.magFilter = source.magFilter;
  1790. this.minFilter = source.minFilter;
  1791. this.anisotropy = source.anisotropy;
  1792. this.format = source.format;
  1793. this.internalFormat = source.internalFormat;
  1794. this.type = source.type;
  1795. this.offset.copy(source.offset);
  1796. this.repeat.copy(source.repeat);
  1797. this.center.copy(source.center);
  1798. this.rotation = source.rotation;
  1799. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1800. this.matrix.copy(source.matrix);
  1801. this.generateMipmaps = source.generateMipmaps;
  1802. this.premultiplyAlpha = source.premultiplyAlpha;
  1803. this.flipY = source.flipY;
  1804. this.unpackAlignment = source.unpackAlignment;
  1805. this.encoding = source.encoding;
  1806. return this;
  1807. },
  1808. toJSON: function toJSON(meta) {
  1809. var isRootObject = meta === undefined || typeof meta === 'string';
  1810. if (!isRootObject && meta.textures[this.uuid] !== undefined) {
  1811. return meta.textures[this.uuid];
  1812. }
  1813. var output = {
  1814. metadata: {
  1815. version: 4.5,
  1816. type: 'Texture',
  1817. generator: 'Texture.toJSON'
  1818. },
  1819. uuid: this.uuid,
  1820. name: this.name,
  1821. mapping: this.mapping,
  1822. repeat: [this.repeat.x, this.repeat.y],
  1823. offset: [this.offset.x, this.offset.y],
  1824. center: [this.center.x, this.center.y],
  1825. rotation: this.rotation,
  1826. wrap: [this.wrapS, this.wrapT],
  1827. format: this.format,
  1828. type: this.type,
  1829. encoding: this.encoding,
  1830. minFilter: this.minFilter,
  1831. magFilter: this.magFilter,
  1832. anisotropy: this.anisotropy,
  1833. flipY: this.flipY,
  1834. premultiplyAlpha: this.premultiplyAlpha,
  1835. unpackAlignment: this.unpackAlignment
  1836. };
  1837. if (this.image !== undefined) {
  1838. // TODO: Move to THREE.Image
  1839. var image = this.image;
  1840. if (image.uuid === undefined) {
  1841. image.uuid = MathUtils.generateUUID(); // UGH
  1842. }
  1843. if (!isRootObject && meta.images[image.uuid] === undefined) {
  1844. var url;
  1845. if (Array.isArray(image)) {
  1846. // process array of images e.g. CubeTexture
  1847. url = [];
  1848. for (var i = 0, l = image.length; i < l; i++) {
  1849. // check cube texture with data textures
  1850. if (image[i].isDataTexture) {
  1851. url.push(serializeImage(image[i].image));
  1852. } else {
  1853. url.push(serializeImage(image[i]));
  1854. }
  1855. }
  1856. } else {
  1857. // process single image
  1858. url = serializeImage(image);
  1859. }
  1860. meta.images[image.uuid] = {
  1861. uuid: image.uuid,
  1862. url: url
  1863. };
  1864. }
  1865. output.image = image.uuid;
  1866. }
  1867. if (!isRootObject) {
  1868. meta.textures[this.uuid] = output;
  1869. }
  1870. return output;
  1871. },
  1872. dispose: function dispose() {
  1873. this.dispatchEvent({
  1874. type: 'dispose'
  1875. });
  1876. },
  1877. transformUv: function transformUv(uv) {
  1878. if (this.mapping !== UVMapping) return uv;
  1879. uv.applyMatrix3(this.matrix);
  1880. if (uv.x < 0 || uv.x > 1) {
  1881. switch (this.wrapS) {
  1882. case RepeatWrapping:
  1883. uv.x = uv.x - Math.floor(uv.x);
  1884. break;
  1885. case ClampToEdgeWrapping:
  1886. uv.x = uv.x < 0 ? 0 : 1;
  1887. break;
  1888. case MirroredRepeatWrapping:
  1889. if (Math.abs(Math.floor(uv.x) % 2) === 1) {
  1890. uv.x = Math.ceil(uv.x) - uv.x;
  1891. } else {
  1892. uv.x = uv.x - Math.floor(uv.x);
  1893. }
  1894. break;
  1895. }
  1896. }
  1897. if (uv.y < 0 || uv.y > 1) {
  1898. switch (this.wrapT) {
  1899. case RepeatWrapping:
  1900. uv.y = uv.y - Math.floor(uv.y);
  1901. break;
  1902. case ClampToEdgeWrapping:
  1903. uv.y = uv.y < 0 ? 0 : 1;
  1904. break;
  1905. case MirroredRepeatWrapping:
  1906. if (Math.abs(Math.floor(uv.y) % 2) === 1) {
  1907. uv.y = Math.ceil(uv.y) - uv.y;
  1908. } else {
  1909. uv.y = uv.y - Math.floor(uv.y);
  1910. }
  1911. break;
  1912. }
  1913. }
  1914. if (this.flipY) {
  1915. uv.y = 1 - uv.y;
  1916. }
  1917. return uv;
  1918. }
  1919. });
  1920. Object.defineProperty(Texture.prototype, 'needsUpdate', {
  1921. set: function set(value) {
  1922. if (value === true) this.version++;
  1923. }
  1924. });
  1925. function serializeImage(image) {
  1926. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  1927. // default images
  1928. return ImageUtils.getDataURL(image);
  1929. } else {
  1930. if (image.data) {
  1931. // images of DataTexture
  1932. return {
  1933. data: Array.prototype.slice.call(image.data),
  1934. width: image.width,
  1935. height: image.height,
  1936. type: image.data.constructor.name
  1937. };
  1938. } else {
  1939. console.warn('THREE.Texture: Unable to serialize Texture.');
  1940. return {};
  1941. }
  1942. }
  1943. }
  1944. var Vector4 = /*#__PURE__*/function () {
  1945. function Vector4(x, y, z, w) {
  1946. if (x === void 0) {
  1947. x = 0;
  1948. }
  1949. if (y === void 0) {
  1950. y = 0;
  1951. }
  1952. if (z === void 0) {
  1953. z = 0;
  1954. }
  1955. if (w === void 0) {
  1956. w = 1;
  1957. }
  1958. this.x = x;
  1959. this.y = y;
  1960. this.z = z;
  1961. this.w = w;
  1962. }
  1963. var _proto = Vector4.prototype;
  1964. _proto.set = function set(x, y, z, w) {
  1965. this.x = x;
  1966. this.y = y;
  1967. this.z = z;
  1968. this.w = w;
  1969. return this;
  1970. };
  1971. _proto.setScalar = function setScalar(scalar) {
  1972. this.x = scalar;
  1973. this.y = scalar;
  1974. this.z = scalar;
  1975. this.w = scalar;
  1976. return this;
  1977. };
  1978. _proto.setX = function setX(x) {
  1979. this.x = x;
  1980. return this;
  1981. };
  1982. _proto.setY = function setY(y) {
  1983. this.y = y;
  1984. return this;
  1985. };
  1986. _proto.setZ = function setZ(z) {
  1987. this.z = z;
  1988. return this;
  1989. };
  1990. _proto.setW = function setW(w) {
  1991. this.w = w;
  1992. return this;
  1993. };
  1994. _proto.setComponent = function setComponent(index, value) {
  1995. switch (index) {
  1996. case 0:
  1997. this.x = value;
  1998. break;
  1999. case 1:
  2000. this.y = value;
  2001. break;
  2002. case 2:
  2003. this.z = value;
  2004. break;
  2005. case 3:
  2006. this.w = value;
  2007. break;
  2008. default:
  2009. throw new Error('index is out of range: ' + index);
  2010. }
  2011. return this;
  2012. };
  2013. _proto.getComponent = function getComponent(index) {
  2014. switch (index) {
  2015. case 0:
  2016. return this.x;
  2017. case 1:
  2018. return this.y;
  2019. case 2:
  2020. return this.z;
  2021. case 3:
  2022. return this.w;
  2023. default:
  2024. throw new Error('index is out of range: ' + index);
  2025. }
  2026. };
  2027. _proto.clone = function clone() {
  2028. return new this.constructor(this.x, this.y, this.z, this.w);
  2029. };
  2030. _proto.copy = function copy(v) {
  2031. this.x = v.x;
  2032. this.y = v.y;
  2033. this.z = v.z;
  2034. this.w = v.w !== undefined ? v.w : 1;
  2035. return this;
  2036. };
  2037. _proto.add = function add(v, w) {
  2038. if (w !== undefined) {
  2039. console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2040. return this.addVectors(v, w);
  2041. }
  2042. this.x += v.x;
  2043. this.y += v.y;
  2044. this.z += v.z;
  2045. this.w += v.w;
  2046. return this;
  2047. };
  2048. _proto.addScalar = function addScalar(s) {
  2049. this.x += s;
  2050. this.y += s;
  2051. this.z += s;
  2052. this.w += s;
  2053. return this;
  2054. };
  2055. _proto.addVectors = function addVectors(a, b) {
  2056. this.x = a.x + b.x;
  2057. this.y = a.y + b.y;
  2058. this.z = a.z + b.z;
  2059. this.w = a.w + b.w;
  2060. return this;
  2061. };
  2062. _proto.addScaledVector = function addScaledVector(v, s) {
  2063. this.x += v.x * s;
  2064. this.y += v.y * s;
  2065. this.z += v.z * s;
  2066. this.w += v.w * s;
  2067. return this;
  2068. };
  2069. _proto.sub = function sub(v, w) {
  2070. if (w !== undefined) {
  2071. console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2072. return this.subVectors(v, w);
  2073. }
  2074. this.x -= v.x;
  2075. this.y -= v.y;
  2076. this.z -= v.z;
  2077. this.w -= v.w;
  2078. return this;
  2079. };
  2080. _proto.subScalar = function subScalar(s) {
  2081. this.x -= s;
  2082. this.y -= s;
  2083. this.z -= s;
  2084. this.w -= s;
  2085. return this;
  2086. };
  2087. _proto.subVectors = function subVectors(a, b) {
  2088. this.x = a.x - b.x;
  2089. this.y = a.y - b.y;
  2090. this.z = a.z - b.z;
  2091. this.w = a.w - b.w;
  2092. return this;
  2093. };
  2094. _proto.multiply = function multiply(v) {
  2095. this.x *= v.x;
  2096. this.y *= v.y;
  2097. this.z *= v.z;
  2098. this.w *= v.w;
  2099. return this;
  2100. };
  2101. _proto.multiplyScalar = function multiplyScalar(scalar) {
  2102. this.x *= scalar;
  2103. this.y *= scalar;
  2104. this.z *= scalar;
  2105. this.w *= scalar;
  2106. return this;
  2107. };
  2108. _proto.applyMatrix4 = function applyMatrix4(m) {
  2109. var x = this.x,
  2110. y = this.y,
  2111. z = this.z,
  2112. w = this.w;
  2113. var e = m.elements;
  2114. this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
  2115. this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
  2116. this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
  2117. this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
  2118. return this;
  2119. };
  2120. _proto.divideScalar = function divideScalar(scalar) {
  2121. return this.multiplyScalar(1 / scalar);
  2122. };
  2123. _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
  2124. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2125. // q is assumed to be normalized
  2126. this.w = 2 * Math.acos(q.w);
  2127. var s = Math.sqrt(1 - q.w * q.w);
  2128. if (s < 0.0001) {
  2129. this.x = 1;
  2130. this.y = 0;
  2131. this.z = 0;
  2132. } else {
  2133. this.x = q.x / s;
  2134. this.y = q.y / s;
  2135. this.z = q.z / s;
  2136. }
  2137. return this;
  2138. };
  2139. _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
  2140. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2141. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2142. var angle, x, y, z; // variables for result
  2143. var epsilon = 0.01,
  2144. // margin to allow for rounding errors
  2145. epsilon2 = 0.1,
  2146. // margin to distinguish between 0 and 180 degrees
  2147. te = m.elements,
  2148. m11 = te[0],
  2149. m12 = te[4],
  2150. m13 = te[8],
  2151. m21 = te[1],
  2152. m22 = te[5],
  2153. m23 = te[9],
  2154. m31 = te[2],
  2155. m32 = te[6],
  2156. m33 = te[10];
  2157. if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
  2158. // singularity found
  2159. // first check for identity matrix which must have +1 for all terms
  2160. // in leading diagonal and zero in other terms
  2161. if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
  2162. // this singularity is identity matrix so angle = 0
  2163. this.set(1, 0, 0, 0);
  2164. return this; // zero angle, arbitrary axis
  2165. } // otherwise this singularity is angle = 180
  2166. angle = Math.PI;
  2167. var xx = (m11 + 1) / 2;
  2168. var yy = (m22 + 1) / 2;
  2169. var zz = (m33 + 1) / 2;
  2170. var xy = (m12 + m21) / 4;
  2171. var xz = (m13 + m31) / 4;
  2172. var yz = (m23 + m32) / 4;
  2173. if (xx > yy && xx > zz) {
  2174. // m11 is the largest diagonal term
  2175. if (xx < epsilon) {
  2176. x = 0;
  2177. y = 0.707106781;
  2178. z = 0.707106781;
  2179. } else {
  2180. x = Math.sqrt(xx);
  2181. y = xy / x;
  2182. z = xz / x;
  2183. }
  2184. } else if (yy > zz) {
  2185. // m22 is the largest diagonal term
  2186. if (yy < epsilon) {
  2187. x = 0.707106781;
  2188. y = 0;
  2189. z = 0.707106781;
  2190. } else {
  2191. y = Math.sqrt(yy);
  2192. x = xy / y;
  2193. z = yz / y;
  2194. }
  2195. } else {
  2196. // m33 is the largest diagonal term so base result on this
  2197. if (zz < epsilon) {
  2198. x = 0.707106781;
  2199. y = 0.707106781;
  2200. z = 0;
  2201. } else {
  2202. z = Math.sqrt(zz);
  2203. x = xz / z;
  2204. y = yz / z;
  2205. }
  2206. }
  2207. this.set(x, y, z, angle);
  2208. return this; // return 180 deg rotation
  2209. } // as we have reached here there are no singularities so we can handle normally
  2210. var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
  2211. if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2212. // caught by singularity test above, but I've left it in just in case
  2213. this.x = (m32 - m23) / s;
  2214. this.y = (m13 - m31) / s;
  2215. this.z = (m21 - m12) / s;
  2216. this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
  2217. return this;
  2218. };
  2219. _proto.min = function min(v) {
  2220. this.x = Math.min(this.x, v.x);
  2221. this.y = Math.min(this.y, v.y);
  2222. this.z = Math.min(this.z, v.z);
  2223. this.w = Math.min(this.w, v.w);
  2224. return this;
  2225. };
  2226. _proto.max = function max(v) {
  2227. this.x = Math.max(this.x, v.x);
  2228. this.y = Math.max(this.y, v.y);
  2229. this.z = Math.max(this.z, v.z);
  2230. this.w = Math.max(this.w, v.w);
  2231. return this;
  2232. };
  2233. _proto.clamp = function clamp(min, max) {
  2234. // assumes min < max, componentwise
  2235. this.x = Math.max(min.x, Math.min(max.x, this.x));
  2236. this.y = Math.max(min.y, Math.min(max.y, this.y));
  2237. this.z = Math.max(min.z, Math.min(max.z, this.z));
  2238. this.w = Math.max(min.w, Math.min(max.w, this.w));
  2239. return this;
  2240. };
  2241. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  2242. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  2243. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  2244. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  2245. this.w = Math.max(minVal, Math.min(maxVal, this.w));
  2246. return this;
  2247. };
  2248. _proto.clampLength = function clampLength(min, max) {
  2249. var length = this.length();
  2250. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  2251. };
  2252. _proto.floor = function floor() {
  2253. this.x = Math.floor(this.x);
  2254. this.y = Math.floor(this.y);
  2255. this.z = Math.floor(this.z);
  2256. this.w = Math.floor(this.w);
  2257. return this;
  2258. };
  2259. _proto.ceil = function ceil() {
  2260. this.x = Math.ceil(this.x);
  2261. this.y = Math.ceil(this.y);
  2262. this.z = Math.ceil(this.z);
  2263. this.w = Math.ceil(this.w);
  2264. return this;
  2265. };
  2266. _proto.round = function round() {
  2267. this.x = Math.round(this.x);
  2268. this.y = Math.round(this.y);
  2269. this.z = Math.round(this.z);
  2270. this.w = Math.round(this.w);
  2271. return this;
  2272. };
  2273. _proto.roundToZero = function roundToZero() {
  2274. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  2275. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  2276. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  2277. this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
  2278. return this;
  2279. };
  2280. _proto.negate = function negate() {
  2281. this.x = -this.x;
  2282. this.y = -this.y;
  2283. this.z = -this.z;
  2284. this.w = -this.w;
  2285. return this;
  2286. };
  2287. _proto.dot = function dot(v) {
  2288. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2289. };
  2290. _proto.lengthSq = function lengthSq() {
  2291. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2292. };
  2293. _proto.length = function length() {
  2294. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  2295. };
  2296. _proto.manhattanLength = function manhattanLength() {
  2297. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  2298. };
  2299. _proto.normalize = function normalize() {
  2300. return this.divideScalar(this.length() || 1);
  2301. };
  2302. _proto.setLength = function setLength(length) {
  2303. return this.normalize().multiplyScalar(length);
  2304. };
  2305. _proto.lerp = function lerp(v, alpha) {
  2306. this.x += (v.x - this.x) * alpha;
  2307. this.y += (v.y - this.y) * alpha;
  2308. this.z += (v.z - this.z) * alpha;
  2309. this.w += (v.w - this.w) * alpha;
  2310. return this;
  2311. };
  2312. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  2313. this.x = v1.x + (v2.x - v1.x) * alpha;
  2314. this.y = v1.y + (v2.y - v1.y) * alpha;
  2315. this.z = v1.z + (v2.z - v1.z) * alpha;
  2316. this.w = v1.w + (v2.w - v1.w) * alpha;
  2317. return this;
  2318. };
  2319. _proto.equals = function equals(v) {
  2320. return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
  2321. };
  2322. _proto.fromArray = function fromArray(array, offset) {
  2323. if (offset === void 0) {
  2324. offset = 0;
  2325. }
  2326. this.x = array[offset];
  2327. this.y = array[offset + 1];
  2328. this.z = array[offset + 2];
  2329. this.w = array[offset + 3];
  2330. return this;
  2331. };
  2332. _proto.toArray = function toArray(array, offset) {
  2333. if (array === void 0) {
  2334. array = [];
  2335. }
  2336. if (offset === void 0) {
  2337. offset = 0;
  2338. }
  2339. array[offset] = this.x;
  2340. array[offset + 1] = this.y;
  2341. array[offset + 2] = this.z;
  2342. array[offset + 3] = this.w;
  2343. return array;
  2344. };
  2345. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  2346. if (offset !== undefined) {
  2347. console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
  2348. }
  2349. this.x = attribute.getX(index);
  2350. this.y = attribute.getY(index);
  2351. this.z = attribute.getZ(index);
  2352. this.w = attribute.getW(index);
  2353. return this;
  2354. };
  2355. _proto.random = function random() {
  2356. this.x = Math.random();
  2357. this.y = Math.random();
  2358. this.z = Math.random();
  2359. this.w = Math.random();
  2360. return this;
  2361. };
  2362. _createClass(Vector4, [{
  2363. key: "width",
  2364. get: function get() {
  2365. return this.z;
  2366. },
  2367. set: function set(value) {
  2368. this.z = value;
  2369. }
  2370. }, {
  2371. key: "height",
  2372. get: function get() {
  2373. return this.w;
  2374. },
  2375. set: function set(value) {
  2376. this.w = value;
  2377. }
  2378. }]);
  2379. return Vector4;
  2380. }();
  2381. Vector4.prototype.isVector4 = true;
  2382. /*
  2383. In options, we can specify:
  2384. * Texture parameters for an auto-generated target texture
  2385. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2386. */
  2387. var WebGLRenderTarget = /*#__PURE__*/function (_EventDispatcher) {
  2388. _inheritsLoose(WebGLRenderTarget, _EventDispatcher);
  2389. function WebGLRenderTarget(width, height, options) {
  2390. var _this;
  2391. _this = _EventDispatcher.call(this) || this;
  2392. _this.width = width;
  2393. _this.height = height;
  2394. _this.depth = 1;
  2395. _this.scissor = new Vector4(0, 0, width, height);
  2396. _this.scissorTest = false;
  2397. _this.viewport = new Vector4(0, 0, width, height);
  2398. options = options || {};
  2399. _this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  2400. _this.texture.image = {};
  2401. _this.texture.image.width = width;
  2402. _this.texture.image.height = height;
  2403. _this.texture.image.depth = 1;
  2404. _this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2405. _this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2406. _this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2407. _this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  2408. _this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2409. return _this;
  2410. }
  2411. var _proto = WebGLRenderTarget.prototype;
  2412. _proto.setTexture = function setTexture(texture) {
  2413. texture.image = {
  2414. width: this.width,
  2415. height: this.height,
  2416. depth: this.depth
  2417. };
  2418. this.texture = texture;
  2419. };
  2420. _proto.setSize = function setSize(width, height, depth) {
  2421. if (depth === void 0) {
  2422. depth = 1;
  2423. }
  2424. if (this.width !== width || this.height !== height || this.depth !== depth) {
  2425. this.width = width;
  2426. this.height = height;
  2427. this.depth = depth;
  2428. this.texture.image.width = width;
  2429. this.texture.image.height = height;
  2430. this.texture.image.depth = depth;
  2431. this.dispose();
  2432. }
  2433. this.viewport.set(0, 0, width, height);
  2434. this.scissor.set(0, 0, width, height);
  2435. };
  2436. _proto.clone = function clone() {
  2437. return new this.constructor().copy(this);
  2438. };
  2439. _proto.copy = function copy(source) {
  2440. this.width = source.width;
  2441. this.height = source.height;
  2442. this.depth = source.depth;
  2443. this.viewport.copy(source.viewport);
  2444. this.texture = source.texture.clone();
  2445. this.depthBuffer = source.depthBuffer;
  2446. this.stencilBuffer = source.stencilBuffer;
  2447. this.depthTexture = source.depthTexture;
  2448. return this;
  2449. };
  2450. _proto.dispose = function dispose() {
  2451. this.dispatchEvent({
  2452. type: 'dispose'
  2453. });
  2454. };
  2455. return WebGLRenderTarget;
  2456. }(EventDispatcher);
  2457. WebGLRenderTarget.prototype.isWebGLRenderTarget = true;
  2458. var WebGLMultisampleRenderTarget = /*#__PURE__*/function (_WebGLRenderTarget) {
  2459. _inheritsLoose(WebGLMultisampleRenderTarget, _WebGLRenderTarget);
  2460. function WebGLMultisampleRenderTarget(width, height, options) {
  2461. var _this;
  2462. _this = _WebGLRenderTarget.call(this, width, height, options) || this;
  2463. _this.samples = 4;
  2464. return _this;
  2465. }
  2466. var _proto = WebGLMultisampleRenderTarget.prototype;
  2467. _proto.copy = function copy(source) {
  2468. _WebGLRenderTarget.prototype.copy.call(this, source);
  2469. this.samples = source.samples;
  2470. return this;
  2471. };
  2472. return WebGLMultisampleRenderTarget;
  2473. }(WebGLRenderTarget);
  2474. WebGLMultisampleRenderTarget.prototype.isWebGLMultisampleRenderTarget = true;
  2475. var Quaternion = /*#__PURE__*/function () {
  2476. function Quaternion(x, y, z, w) {
  2477. if (x === void 0) {
  2478. x = 0;
  2479. }
  2480. if (y === void 0) {
  2481. y = 0;
  2482. }
  2483. if (z === void 0) {
  2484. z = 0;
  2485. }
  2486. if (w === void 0) {
  2487. w = 1;
  2488. }
  2489. this._x = x;
  2490. this._y = y;
  2491. this._z = z;
  2492. this._w = w;
  2493. }
  2494. Quaternion.slerp = function slerp(qa, qb, qm, t) {
  2495. return qm.copy(qa).slerp(qb, t);
  2496. };
  2497. Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
  2498. // fuzz-free, array-based Quaternion SLERP operation
  2499. var x0 = src0[srcOffset0 + 0],
  2500. y0 = src0[srcOffset0 + 1],
  2501. z0 = src0[srcOffset0 + 2],
  2502. w0 = src0[srcOffset0 + 3];
  2503. var x1 = src1[srcOffset1 + 0],
  2504. y1 = src1[srcOffset1 + 1],
  2505. z1 = src1[srcOffset1 + 2],
  2506. w1 = src1[srcOffset1 + 3];
  2507. if (t === 0) {
  2508. dst[dstOffset + 0] = x0;
  2509. dst[dstOffset + 1] = y0;
  2510. dst[dstOffset + 2] = z0;
  2511. dst[dstOffset + 3] = w0;
  2512. return;
  2513. }
  2514. if (t === 1) {
  2515. dst[dstOffset + 0] = x1;
  2516. dst[dstOffset + 1] = y1;
  2517. dst[dstOffset + 2] = z1;
  2518. dst[dstOffset + 3] = w1;
  2519. return;
  2520. }
  2521. if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
  2522. var s = 1 - t;
  2523. var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  2524. dir = cos >= 0 ? 1 : -1,
  2525. sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
  2526. if (sqrSin > Number.EPSILON) {
  2527. var sin = Math.sqrt(sqrSin),
  2528. len = Math.atan2(sin, cos * dir);
  2529. s = Math.sin(s * len) / sin;
  2530. t = Math.sin(t * len) / sin;
  2531. }
  2532. var tDir = t * dir;
  2533. x0 = x0 * s + x1 * tDir;
  2534. y0 = y0 * s + y1 * tDir;
  2535. z0 = z0 * s + z1 * tDir;
  2536. w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
  2537. if (s === 1 - t) {
  2538. var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
  2539. x0 *= f;
  2540. y0 *= f;
  2541. z0 *= f;
  2542. w0 *= f;
  2543. }
  2544. }
  2545. dst[dstOffset] = x0;
  2546. dst[dstOffset + 1] = y0;
  2547. dst[dstOffset + 2] = z0;
  2548. dst[dstOffset + 3] = w0;
  2549. };
  2550. Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
  2551. var x0 = src0[srcOffset0];
  2552. var y0 = src0[srcOffset0 + 1];
  2553. var z0 = src0[srcOffset0 + 2];
  2554. var w0 = src0[srcOffset0 + 3];
  2555. var x1 = src1[srcOffset1];
  2556. var y1 = src1[srcOffset1 + 1];
  2557. var z1 = src1[srcOffset1 + 2];
  2558. var w1 = src1[srcOffset1 + 3];
  2559. dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  2560. dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  2561. dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  2562. dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  2563. return dst;
  2564. };
  2565. var _proto = Quaternion.prototype;
  2566. _proto.set = function set(x, y, z, w) {
  2567. this._x = x;
  2568. this._y = y;
  2569. this._z = z;
  2570. this._w = w;
  2571. this._onChangeCallback();
  2572. return this;
  2573. };
  2574. _proto.clone = function clone() {
  2575. return new this.constructor(this._x, this._y, this._z, this._w);
  2576. };
  2577. _proto.copy = function copy(quaternion) {
  2578. this._x = quaternion.x;
  2579. this._y = quaternion.y;
  2580. this._z = quaternion.z;
  2581. this._w = quaternion.w;
  2582. this._onChangeCallback();
  2583. return this;
  2584. };
  2585. _proto.setFromEuler = function setFromEuler(euler, update) {
  2586. if (!(euler && euler.isEuler)) {
  2587. throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
  2588. }
  2589. var x = euler._x,
  2590. y = euler._y,
  2591. z = euler._z,
  2592. order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
  2593. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  2594. // content/SpinCalc.m
  2595. var cos = Math.cos;
  2596. var sin = Math.sin;
  2597. var c1 = cos(x / 2);
  2598. var c2 = cos(y / 2);
  2599. var c3 = cos(z / 2);
  2600. var s1 = sin(x / 2);
  2601. var s2 = sin(y / 2);
  2602. var s3 = sin(z / 2);
  2603. switch (order) {
  2604. case 'XYZ':
  2605. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2606. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2607. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2608. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2609. break;
  2610. case 'YXZ':
  2611. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2612. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2613. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2614. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2615. break;
  2616. case 'ZXY':
  2617. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2618. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2619. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2620. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2621. break;
  2622. case 'ZYX':
  2623. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2624. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2625. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2626. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2627. break;
  2628. case 'YZX':
  2629. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2630. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2631. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2632. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2633. break;
  2634. case 'XZY':
  2635. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2636. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2637. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2638. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2639. break;
  2640. default:
  2641. console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
  2642. }
  2643. if (update !== false) this._onChangeCallback();
  2644. return this;
  2645. };
  2646. _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
  2647. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  2648. // assumes axis is normalized
  2649. var halfAngle = angle / 2,
  2650. s = Math.sin(halfAngle);
  2651. this._x = axis.x * s;
  2652. this._y = axis.y * s;
  2653. this._z = axis.z * s;
  2654. this._w = Math.cos(halfAngle);
  2655. this._onChangeCallback();
  2656. return this;
  2657. };
  2658. _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
  2659. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  2660. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2661. var te = m.elements,
  2662. m11 = te[0],
  2663. m12 = te[4],
  2664. m13 = te[8],
  2665. m21 = te[1],
  2666. m22 = te[5],
  2667. m23 = te[9],
  2668. m31 = te[2],
  2669. m32 = te[6],
  2670. m33 = te[10],
  2671. trace = m11 + m22 + m33;
  2672. if (trace > 0) {
  2673. var s = 0.5 / Math.sqrt(trace + 1.0);
  2674. this._w = 0.25 / s;
  2675. this._x = (m32 - m23) * s;
  2676. this._y = (m13 - m31) * s;
  2677. this._z = (m21 - m12) * s;
  2678. } else if (m11 > m22 && m11 > m33) {
  2679. var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  2680. this._w = (m32 - m23) / _s;
  2681. this._x = 0.25 * _s;
  2682. this._y = (m12 + m21) / _s;
  2683. this._z = (m13 + m31) / _s;
  2684. } else if (m22 > m33) {
  2685. var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  2686. this._w = (m13 - m31) / _s2;
  2687. this._x = (m12 + m21) / _s2;
  2688. this._y = 0.25 * _s2;
  2689. this._z = (m23 + m32) / _s2;
  2690. } else {
  2691. var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  2692. this._w = (m21 - m12) / _s3;
  2693. this._x = (m13 + m31) / _s3;
  2694. this._y = (m23 + m32) / _s3;
  2695. this._z = 0.25 * _s3;
  2696. }
  2697. this._onChangeCallback();
  2698. return this;
  2699. };
  2700. _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
  2701. // assumes direction vectors vFrom and vTo are normalized
  2702. var EPS = 0.000001;
  2703. var r = vFrom.dot(vTo) + 1;
  2704. if (r < EPS) {
  2705. r = 0;
  2706. if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
  2707. this._x = -vFrom.y;
  2708. this._y = vFrom.x;
  2709. this._z = 0;
  2710. this._w = r;
  2711. } else {
  2712. this._x = 0;
  2713. this._y = -vFrom.z;
  2714. this._z = vFrom.y;
  2715. this._w = r;
  2716. }
  2717. } else {
  2718. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  2719. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  2720. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  2721. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  2722. this._w = r;
  2723. }
  2724. return this.normalize();
  2725. };
  2726. _proto.angleTo = function angleTo(q) {
  2727. return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
  2728. };
  2729. _proto.rotateTowards = function rotateTowards(q, step) {
  2730. var angle = this.angleTo(q);
  2731. if (angle === 0) return this;
  2732. var t = Math.min(1, step / angle);
  2733. this.slerp(q, t);
  2734. return this;
  2735. };
  2736. _proto.identity = function identity() {
  2737. return this.set(0, 0, 0, 1);
  2738. };
  2739. _proto.invert = function invert() {
  2740. // quaternion is assumed to have unit length
  2741. return this.conjugate();
  2742. };
  2743. _proto.conjugate = function conjugate() {
  2744. this._x *= -1;
  2745. this._y *= -1;
  2746. this._z *= -1;
  2747. this._onChangeCallback();
  2748. return this;
  2749. };
  2750. _proto.dot = function dot(v) {
  2751. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  2752. };
  2753. _proto.lengthSq = function lengthSq() {
  2754. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  2755. };
  2756. _proto.length = function length() {
  2757. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  2758. };
  2759. _proto.normalize = function normalize() {
  2760. var l = this.length();
  2761. if (l === 0) {
  2762. this._x = 0;
  2763. this._y = 0;
  2764. this._z = 0;
  2765. this._w = 1;
  2766. } else {
  2767. l = 1 / l;
  2768. this._x = this._x * l;
  2769. this._y = this._y * l;
  2770. this._z = this._z * l;
  2771. this._w = this._w * l;
  2772. }
  2773. this._onChangeCallback();
  2774. return this;
  2775. };
  2776. _proto.multiply = function multiply(q, p) {
  2777. if (p !== undefined) {
  2778. console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
  2779. return this.multiplyQuaternions(q, p);
  2780. }
  2781. return this.multiplyQuaternions(this, q);
  2782. };
  2783. _proto.premultiply = function premultiply(q) {
  2784. return this.multiplyQuaternions(q, this);
  2785. };
  2786. _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
  2787. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2788. var qax = a._x,
  2789. qay = a._y,
  2790. qaz = a._z,
  2791. qaw = a._w;
  2792. var qbx = b._x,
  2793. qby = b._y,
  2794. qbz = b._z,
  2795. qbw = b._w;
  2796. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2797. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2798. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2799. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2800. this._onChangeCallback();
  2801. return this;
  2802. };
  2803. _proto.slerp = function slerp(qb, t) {
  2804. if (t === 0) return this;
  2805. if (t === 1) return this.copy(qb);
  2806. var x = this._x,
  2807. y = this._y,
  2808. z = this._z,
  2809. w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2810. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2811. if (cosHalfTheta < 0) {
  2812. this._w = -qb._w;
  2813. this._x = -qb._x;
  2814. this._y = -qb._y;
  2815. this._z = -qb._z;
  2816. cosHalfTheta = -cosHalfTheta;
  2817. } else {
  2818. this.copy(qb);
  2819. }
  2820. if (cosHalfTheta >= 1.0) {
  2821. this._w = w;
  2822. this._x = x;
  2823. this._y = y;
  2824. this._z = z;
  2825. return this;
  2826. }
  2827. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2828. if (sqrSinHalfTheta <= Number.EPSILON) {
  2829. var s = 1 - t;
  2830. this._w = s * w + t * this._w;
  2831. this._x = s * x + t * this._x;
  2832. this._y = s * y + t * this._y;
  2833. this._z = s * z + t * this._z;
  2834. this.normalize();
  2835. this._onChangeCallback();
  2836. return this;
  2837. }
  2838. var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
  2839. var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
  2840. var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
  2841. ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
  2842. this._w = w * ratioA + this._w * ratioB;
  2843. this._x = x * ratioA + this._x * ratioB;
  2844. this._y = y * ratioA + this._y * ratioB;
  2845. this._z = z * ratioA + this._z * ratioB;
  2846. this._onChangeCallback();
  2847. return this;
  2848. };
  2849. _proto.equals = function equals(quaternion) {
  2850. return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
  2851. };
  2852. _proto.fromArray = function fromArray(array, offset) {
  2853. if (offset === void 0) {
  2854. offset = 0;
  2855. }
  2856. this._x = array[offset];
  2857. this._y = array[offset + 1];
  2858. this._z = array[offset + 2];
  2859. this._w = array[offset + 3];
  2860. this._onChangeCallback();
  2861. return this;
  2862. };
  2863. _proto.toArray = function toArray(array, offset) {
  2864. if (array === void 0) {
  2865. array = [];
  2866. }
  2867. if (offset === void 0) {
  2868. offset = 0;
  2869. }
  2870. array[offset] = this._x;
  2871. array[offset + 1] = this._y;
  2872. array[offset + 2] = this._z;
  2873. array[offset + 3] = this._w;
  2874. return array;
  2875. };
  2876. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  2877. this._x = attribute.getX(index);
  2878. this._y = attribute.getY(index);
  2879. this._z = attribute.getZ(index);
  2880. this._w = attribute.getW(index);
  2881. return this;
  2882. };
  2883. _proto._onChange = function _onChange(callback) {
  2884. this._onChangeCallback = callback;
  2885. return this;
  2886. };
  2887. _proto._onChangeCallback = function _onChangeCallback() {};
  2888. _createClass(Quaternion, [{
  2889. key: "x",
  2890. get: function get() {
  2891. return this._x;
  2892. },
  2893. set: function set(value) {
  2894. this._x = value;
  2895. this._onChangeCallback();
  2896. }
  2897. }, {
  2898. key: "y",
  2899. get: function get() {
  2900. return this._y;
  2901. },
  2902. set: function set(value) {
  2903. this._y = value;
  2904. this._onChangeCallback();
  2905. }
  2906. }, {
  2907. key: "z",
  2908. get: function get() {
  2909. return this._z;
  2910. },
  2911. set: function set(value) {
  2912. this._z = value;
  2913. this._onChangeCallback();
  2914. }
  2915. }, {
  2916. key: "w",
  2917. get: function get() {
  2918. return this._w;
  2919. },
  2920. set: function set(value) {
  2921. this._w = value;
  2922. this._onChangeCallback();
  2923. }
  2924. }]);
  2925. return Quaternion;
  2926. }();
  2927. Quaternion.prototype.isQuaternion = true;
  2928. var Vector3 = /*#__PURE__*/function () {
  2929. function Vector3(x, y, z) {
  2930. if (x === void 0) {
  2931. x = 0;
  2932. }
  2933. if (y === void 0) {
  2934. y = 0;
  2935. }
  2936. if (z === void 0) {
  2937. z = 0;
  2938. }
  2939. this.x = x;
  2940. this.y = y;
  2941. this.z = z;
  2942. }
  2943. var _proto = Vector3.prototype;
  2944. _proto.set = function set(x, y, z) {
  2945. if (z === undefined) z = this.z; // sprite.scale.set(x,y)
  2946. this.x = x;
  2947. this.y = y;
  2948. this.z = z;
  2949. return this;
  2950. };
  2951. _proto.setScalar = function setScalar(scalar) {
  2952. this.x = scalar;
  2953. this.y = scalar;
  2954. this.z = scalar;
  2955. return this;
  2956. };
  2957. _proto.setX = function setX(x) {
  2958. this.x = x;
  2959. return this;
  2960. };
  2961. _proto.setY = function setY(y) {
  2962. this.y = y;
  2963. return this;
  2964. };
  2965. _proto.setZ = function setZ(z) {
  2966. this.z = z;
  2967. return this;
  2968. };
  2969. _proto.setComponent = function setComponent(index, value) {
  2970. switch (index) {
  2971. case 0:
  2972. this.x = value;
  2973. break;
  2974. case 1:
  2975. this.y = value;
  2976. break;
  2977. case 2:
  2978. this.z = value;
  2979. break;
  2980. default:
  2981. throw new Error('index is out of range: ' + index);
  2982. }
  2983. return this;
  2984. };
  2985. _proto.getComponent = function getComponent(index) {
  2986. switch (index) {
  2987. case 0:
  2988. return this.x;
  2989. case 1:
  2990. return this.y;
  2991. case 2:
  2992. return this.z;
  2993. default:
  2994. throw new Error('index is out of range: ' + index);
  2995. }
  2996. };
  2997. _proto.clone = function clone() {
  2998. return new this.constructor(this.x, this.y, this.z);
  2999. };
  3000. _proto.copy = function copy(v) {
  3001. this.x = v.x;
  3002. this.y = v.y;
  3003. this.z = v.z;
  3004. return this;
  3005. };
  3006. _proto.add = function add(v, w) {
  3007. if (w !== undefined) {
  3008. console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  3009. return this.addVectors(v, w);
  3010. }
  3011. this.x += v.x;
  3012. this.y += v.y;
  3013. this.z += v.z;
  3014. return this;
  3015. };
  3016. _proto.addScalar = function addScalar(s) {
  3017. this.x += s;
  3018. this.y += s;
  3019. this.z += s;
  3020. return this;
  3021. };
  3022. _proto.addVectors = function addVectors(a, b) {
  3023. this.x = a.x + b.x;
  3024. this.y = a.y + b.y;
  3025. this.z = a.z + b.z;
  3026. return this;
  3027. };
  3028. _proto.addScaledVector = function addScaledVector(v, s) {
  3029. this.x += v.x * s;
  3030. this.y += v.y * s;
  3031. this.z += v.z * s;
  3032. return this;
  3033. };
  3034. _proto.sub = function sub(v, w) {
  3035. if (w !== undefined) {
  3036. console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  3037. return this.subVectors(v, w);
  3038. }
  3039. this.x -= v.x;
  3040. this.y -= v.y;
  3041. this.z -= v.z;
  3042. return this;
  3043. };
  3044. _proto.subScalar = function subScalar(s) {
  3045. this.x -= s;
  3046. this.y -= s;
  3047. this.z -= s;
  3048. return this;
  3049. };
  3050. _proto.subVectors = function subVectors(a, b) {
  3051. this.x = a.x - b.x;
  3052. this.y = a.y - b.y;
  3053. this.z = a.z - b.z;
  3054. return this;
  3055. };
  3056. _proto.multiply = function multiply(v, w) {
  3057. if (w !== undefined) {
  3058. console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
  3059. return this.multiplyVectors(v, w);
  3060. }
  3061. this.x *= v.x;
  3062. this.y *= v.y;
  3063. this.z *= v.z;
  3064. return this;
  3065. };
  3066. _proto.multiplyScalar = function multiplyScalar(scalar) {
  3067. this.x *= scalar;
  3068. this.y *= scalar;
  3069. this.z *= scalar;
  3070. return this;
  3071. };
  3072. _proto.multiplyVectors = function multiplyVectors(a, b) {
  3073. this.x = a.x * b.x;
  3074. this.y = a.y * b.y;
  3075. this.z = a.z * b.z;
  3076. return this;
  3077. };
  3078. _proto.applyEuler = function applyEuler(euler) {
  3079. if (!(euler && euler.isEuler)) {
  3080. console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
  3081. }
  3082. return this.applyQuaternion(_quaternion.setFromEuler(euler));
  3083. };
  3084. _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
  3085. return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
  3086. };
  3087. _proto.applyMatrix3 = function applyMatrix3(m) {
  3088. var x = this.x,
  3089. y = this.y,
  3090. z = this.z;
  3091. var e = m.elements;
  3092. this.x = e[0] * x + e[3] * y + e[6] * z;
  3093. this.y = e[1] * x + e[4] * y + e[7] * z;
  3094. this.z = e[2] * x + e[5] * y + e[8] * z;
  3095. return this;
  3096. };
  3097. _proto.applyNormalMatrix = function applyNormalMatrix(m) {
  3098. return this.applyMatrix3(m).normalize();
  3099. };
  3100. _proto.applyMatrix4 = function applyMatrix4(m) {
  3101. var x = this.x,
  3102. y = this.y,
  3103. z = this.z;
  3104. var e = m.elements;
  3105. var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
  3106. this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
  3107. this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
  3108. this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
  3109. return this;
  3110. };
  3111. _proto.applyQuaternion = function applyQuaternion(q) {
  3112. var x = this.x,
  3113. y = this.y,
  3114. z = this.z;
  3115. var qx = q.x,
  3116. qy = q.y,
  3117. qz = q.z,
  3118. qw = q.w; // calculate quat * vector
  3119. var ix = qw * x + qy * z - qz * y;
  3120. var iy = qw * y + qz * x - qx * z;
  3121. var iz = qw * z + qx * y - qy * x;
  3122. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  3123. this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  3124. this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  3125. this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  3126. return this;
  3127. };
  3128. _proto.project = function project(camera) {
  3129. return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
  3130. };
  3131. _proto.unproject = function unproject(camera) {
  3132. return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
  3133. };
  3134. _proto.transformDirection = function transformDirection(m) {
  3135. // input: THREE.Matrix4 affine matrix
  3136. // vector interpreted as a direction
  3137. var x = this.x,
  3138. y = this.y,
  3139. z = this.z;
  3140. var e = m.elements;
  3141. this.x = e[0] * x + e[4] * y + e[8] * z;
  3142. this.y = e[1] * x + e[5] * y + e[9] * z;
  3143. this.z = e[2] * x + e[6] * y + e[10] * z;
  3144. return this.normalize();
  3145. };
  3146. _proto.divide = function divide(v) {
  3147. this.x /= v.x;
  3148. this.y /= v.y;
  3149. this.z /= v.z;
  3150. return this;
  3151. };
  3152. _proto.divideScalar = function divideScalar(scalar) {
  3153. return this.multiplyScalar(1 / scalar);
  3154. };
  3155. _proto.min = function min(v) {
  3156. this.x = Math.min(this.x, v.x);
  3157. this.y = Math.min(this.y, v.y);
  3158. this.z = Math.min(this.z, v.z);
  3159. return this;
  3160. };
  3161. _proto.max = function max(v) {
  3162. this.x = Math.max(this.x, v.x);
  3163. this.y = Math.max(this.y, v.y);
  3164. this.z = Math.max(this.z, v.z);
  3165. return this;
  3166. };
  3167. _proto.clamp = function clamp(min, max) {
  3168. // assumes min < max, componentwise
  3169. this.x = Math.max(min.x, Math.min(max.x, this.x));
  3170. this.y = Math.max(min.y, Math.min(max.y, this.y));
  3171. this.z = Math.max(min.z, Math.min(max.z, this.z));
  3172. return this;
  3173. };
  3174. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  3175. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  3176. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  3177. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  3178. return this;
  3179. };
  3180. _proto.clampLength = function clampLength(min, max) {
  3181. var length = this.length();
  3182. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  3183. };
  3184. _proto.floor = function floor() {
  3185. this.x = Math.floor(this.x);
  3186. this.y = Math.floor(this.y);
  3187. this.z = Math.floor(this.z);
  3188. return this;
  3189. };
  3190. _proto.ceil = function ceil() {
  3191. this.x = Math.ceil(this.x);
  3192. this.y = Math.ceil(this.y);
  3193. this.z = Math.ceil(this.z);
  3194. return this;
  3195. };
  3196. _proto.round = function round() {
  3197. this.x = Math.round(this.x);
  3198. this.y = Math.round(this.y);
  3199. this.z = Math.round(this.z);
  3200. return this;
  3201. };
  3202. _proto.roundToZero = function roundToZero() {
  3203. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  3204. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  3205. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  3206. return this;
  3207. };
  3208. _proto.negate = function negate() {
  3209. this.x = -this.x;
  3210. this.y = -this.y;
  3211. this.z = -this.z;
  3212. return this;
  3213. };
  3214. _proto.dot = function dot(v) {
  3215. return this.x * v.x + this.y * v.y + this.z * v.z;
  3216. } // TODO lengthSquared?
  3217. ;
  3218. _proto.lengthSq = function lengthSq() {
  3219. return this.x * this.x + this.y * this.y + this.z * this.z;
  3220. };
  3221. _proto.length = function length() {
  3222. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  3223. };
  3224. _proto.manhattanLength = function manhattanLength() {
  3225. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  3226. };
  3227. _proto.normalize = function normalize() {
  3228. return this.divideScalar(this.length() || 1);
  3229. };
  3230. _proto.setLength = function setLength(length) {
  3231. return this.normalize().multiplyScalar(length);
  3232. };
  3233. _proto.lerp = function lerp(v, alpha) {
  3234. this.x += (v.x - this.x) * alpha;
  3235. this.y += (v.y - this.y) * alpha;
  3236. this.z += (v.z - this.z) * alpha;
  3237. return this;
  3238. };
  3239. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  3240. this.x = v1.x + (v2.x - v1.x) * alpha;
  3241. this.y = v1.y + (v2.y - v1.y) * alpha;
  3242. this.z = v1.z + (v2.z - v1.z) * alpha;
  3243. return this;
  3244. };
  3245. _proto.cross = function cross(v, w) {
  3246. if (w !== undefined) {
  3247. console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
  3248. return this.crossVectors(v, w);
  3249. }
  3250. return this.crossVectors(this, v);
  3251. };
  3252. _proto.crossVectors = function crossVectors(a, b) {
  3253. var ax = a.x,
  3254. ay = a.y,
  3255. az = a.z;
  3256. var bx = b.x,
  3257. by = b.y,
  3258. bz = b.z;
  3259. this.x = ay * bz - az * by;
  3260. this.y = az * bx - ax * bz;
  3261. this.z = ax * by - ay * bx;
  3262. return this;
  3263. };
  3264. _proto.projectOnVector = function projectOnVector(v) {
  3265. var denominator = v.lengthSq();
  3266. if (denominator === 0) return this.set(0, 0, 0);
  3267. var scalar = v.dot(this) / denominator;
  3268. return this.copy(v).multiplyScalar(scalar);
  3269. };
  3270. _proto.projectOnPlane = function projectOnPlane(planeNormal) {
  3271. _vector.copy(this).projectOnVector(planeNormal);
  3272. return this.sub(_vector);
  3273. };
  3274. _proto.reflect = function reflect(normal) {
  3275. // reflect incident vector off plane orthogonal to normal
  3276. // normal is assumed to have unit length
  3277. return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
  3278. };
  3279. _proto.angleTo = function angleTo(v) {
  3280. var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
  3281. if (denominator === 0) return Math.PI / 2;
  3282. var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
  3283. return Math.acos(MathUtils.clamp(theta, -1, 1));
  3284. };
  3285. _proto.distanceTo = function distanceTo(v) {
  3286. return Math.sqrt(this.distanceToSquared(v));
  3287. };
  3288. _proto.distanceToSquared = function distanceToSquared(v) {
  3289. var dx = this.x - v.x,
  3290. dy = this.y - v.y,
  3291. dz = this.z - v.z;
  3292. return dx * dx + dy * dy + dz * dz;
  3293. };
  3294. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  3295. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
  3296. };
  3297. _proto.setFromSpherical = function setFromSpherical(s) {
  3298. return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
  3299. };
  3300. _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
  3301. var sinPhiRadius = Math.sin(phi) * radius;
  3302. this.x = sinPhiRadius * Math.sin(theta);
  3303. this.y = Math.cos(phi) * radius;
  3304. this.z = sinPhiRadius * Math.cos(theta);
  3305. return this;
  3306. };
  3307. _proto.setFromCylindrical = function setFromCylindrical(c) {
  3308. return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
  3309. };
  3310. _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
  3311. this.x = radius * Math.sin(theta);
  3312. this.y = y;
  3313. this.z = radius * Math.cos(theta);
  3314. return this;
  3315. };
  3316. _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
  3317. var e = m.elements;
  3318. this.x = e[12];
  3319. this.y = e[13];
  3320. this.z = e[14];
  3321. return this;
  3322. };
  3323. _proto.setFromMatrixScale = function setFromMatrixScale(m) {
  3324. var sx = this.setFromMatrixColumn(m, 0).length();
  3325. var sy = this.setFromMatrixColumn(m, 1).length();
  3326. var sz = this.setFromMatrixColumn(m, 2).length();
  3327. this.x = sx;
  3328. this.y = sy;
  3329. this.z = sz;
  3330. return this;
  3331. };
  3332. _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
  3333. return this.fromArray(m.elements, index * 4);
  3334. };
  3335. _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
  3336. return this.fromArray(m.elements, index * 3);
  3337. };
  3338. _proto.equals = function equals(v) {
  3339. return v.x === this.x && v.y === this.y && v.z === this.z;
  3340. };
  3341. _proto.fromArray = function fromArray(array, offset) {
  3342. if (offset === void 0) {
  3343. offset = 0;
  3344. }
  3345. this.x = array[offset];
  3346. this.y = array[offset + 1];
  3347. this.z = array[offset + 2];
  3348. return this;
  3349. };
  3350. _proto.toArray = function toArray(array, offset) {
  3351. if (array === void 0) {
  3352. array = [];
  3353. }
  3354. if (offset === void 0) {
  3355. offset = 0;
  3356. }
  3357. array[offset] = this.x;
  3358. array[offset + 1] = this.y;
  3359. array[offset + 2] = this.z;
  3360. return array;
  3361. };
  3362. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  3363. if (offset !== undefined) {
  3364. console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
  3365. }
  3366. this.x = attribute.getX(index);
  3367. this.y = attribute.getY(index);
  3368. this.z = attribute.getZ(index);
  3369. return this;
  3370. };
  3371. _proto.random = function random() {
  3372. this.x = Math.random();
  3373. this.y = Math.random();
  3374. this.z = Math.random();
  3375. return this;
  3376. };
  3377. return Vector3;
  3378. }();
  3379. Vector3.prototype.isVector3 = true;
  3380. var _vector = /*@__PURE__*/new Vector3();
  3381. var _quaternion = /*@__PURE__*/new Quaternion();
  3382. var Box3 = /*#__PURE__*/function () {
  3383. function Box3(min, max) {
  3384. if (min === void 0) {
  3385. min = new Vector3(+Infinity, +Infinity, +Infinity);
  3386. }
  3387. if (max === void 0) {
  3388. max = new Vector3(-Infinity, -Infinity, -Infinity);
  3389. }
  3390. this.min = min;
  3391. this.max = max;
  3392. }
  3393. var _proto = Box3.prototype;
  3394. _proto.set = function set(min, max) {
  3395. this.min.copy(min);
  3396. this.max.copy(max);
  3397. return this;
  3398. };
  3399. _proto.setFromArray = function setFromArray(array) {
  3400. var minX = +Infinity;
  3401. var minY = +Infinity;
  3402. var minZ = +Infinity;
  3403. var maxX = -Infinity;
  3404. var maxY = -Infinity;
  3405. var maxZ = -Infinity;
  3406. for (var i = 0, l = array.length; i < l; i += 3) {
  3407. var x = array[i];
  3408. var y = array[i + 1];
  3409. var z = array[i + 2];
  3410. if (x < minX) minX = x;
  3411. if (y < minY) minY = y;
  3412. if (z < minZ) minZ = z;
  3413. if (x > maxX) maxX = x;
  3414. if (y > maxY) maxY = y;
  3415. if (z > maxZ) maxZ = z;
  3416. }
  3417. this.min.set(minX, minY, minZ);
  3418. this.max.set(maxX, maxY, maxZ);
  3419. return this;
  3420. };
  3421. _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
  3422. var minX = +Infinity;
  3423. var minY = +Infinity;
  3424. var minZ = +Infinity;
  3425. var maxX = -Infinity;
  3426. var maxY = -Infinity;
  3427. var maxZ = -Infinity;
  3428. for (var i = 0, l = attribute.count; i < l; i++) {
  3429. var x = attribute.getX(i);
  3430. var y = attribute.getY(i);
  3431. var z = attribute.getZ(i);
  3432. if (x < minX) minX = x;
  3433. if (y < minY) minY = y;
  3434. if (z < minZ) minZ = z;
  3435. if (x > maxX) maxX = x;
  3436. if (y > maxY) maxY = y;
  3437. if (z > maxZ) maxZ = z;
  3438. }
  3439. this.min.set(minX, minY, minZ);
  3440. this.max.set(maxX, maxY, maxZ);
  3441. return this;
  3442. };
  3443. _proto.setFromPoints = function setFromPoints(points) {
  3444. this.makeEmpty();
  3445. for (var i = 0, il = points.length; i < il; i++) {
  3446. this.expandByPoint(points[i]);
  3447. }
  3448. return this;
  3449. };
  3450. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  3451. var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
  3452. this.min.copy(center).sub(halfSize);
  3453. this.max.copy(center).add(halfSize);
  3454. return this;
  3455. };
  3456. _proto.setFromObject = function setFromObject(object) {
  3457. this.makeEmpty();
  3458. return this.expandByObject(object);
  3459. };
  3460. _proto.clone = function clone() {
  3461. return new this.constructor().copy(this);
  3462. };
  3463. _proto.copy = function copy(box) {
  3464. this.min.copy(box.min);
  3465. this.max.copy(box.max);
  3466. return this;
  3467. };
  3468. _proto.makeEmpty = function makeEmpty() {
  3469. this.min.x = this.min.y = this.min.z = +Infinity;
  3470. this.max.x = this.max.y = this.max.z = -Infinity;
  3471. return this;
  3472. };
  3473. _proto.isEmpty = function isEmpty() {
  3474. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3475. return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  3476. };
  3477. _proto.getCenter = function getCenter(target) {
  3478. if (target === undefined) {
  3479. console.warn('THREE.Box3: .getCenter() target is now required');
  3480. target = new Vector3();
  3481. }
  3482. return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  3483. };
  3484. _proto.getSize = function getSize(target) {
  3485. if (target === undefined) {
  3486. console.warn('THREE.Box3: .getSize() target is now required');
  3487. target = new Vector3();
  3488. }
  3489. return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
  3490. };
  3491. _proto.expandByPoint = function expandByPoint(point) {
  3492. this.min.min(point);
  3493. this.max.max(point);
  3494. return this;
  3495. };
  3496. _proto.expandByVector = function expandByVector(vector) {
  3497. this.min.sub(vector);
  3498. this.max.add(vector);
  3499. return this;
  3500. };
  3501. _proto.expandByScalar = function expandByScalar(scalar) {
  3502. this.min.addScalar(-scalar);
  3503. this.max.addScalar(scalar);
  3504. return this;
  3505. };
  3506. _proto.expandByObject = function expandByObject(object) {
  3507. // Computes the world-axis-aligned bounding box of an object (including its children),
  3508. // accounting for both the object's, and children's, world transforms
  3509. object.updateWorldMatrix(false, false);
  3510. var geometry = object.geometry;
  3511. if (geometry !== undefined) {
  3512. if (geometry.boundingBox === null) {
  3513. geometry.computeBoundingBox();
  3514. }
  3515. _box.copy(geometry.boundingBox);
  3516. _box.applyMatrix4(object.matrixWorld);
  3517. this.union(_box);
  3518. }
  3519. var children = object.children;
  3520. for (var i = 0, l = children.length; i < l; i++) {
  3521. this.expandByObject(children[i]);
  3522. }
  3523. return this;
  3524. };
  3525. _proto.containsPoint = function containsPoint(point) {
  3526. 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;
  3527. };
  3528. _proto.containsBox = function containsBox(box) {
  3529. 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;
  3530. };
  3531. _proto.getParameter = function getParameter(point, target) {
  3532. // This can potentially have a divide by zero if the box
  3533. // has a size dimension of 0.
  3534. if (target === undefined) {
  3535. console.warn('THREE.Box3: .getParameter() target is now required');
  3536. target = new Vector3();
  3537. }
  3538. 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));
  3539. };
  3540. _proto.intersectsBox = function intersectsBox(box) {
  3541. // using 6 splitting planes to rule out intersections.
  3542. 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;
  3543. };
  3544. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3545. // Find the point on the AABB closest to the sphere center.
  3546. this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
  3547. return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
  3548. };
  3549. _proto.intersectsPlane = function intersectsPlane(plane) {
  3550. // We compute the minimum and maximum dot product values. If those values
  3551. // are on the same side (back or front) of the plane, then there is no intersection.
  3552. var min, max;
  3553. if (plane.normal.x > 0) {
  3554. min = plane.normal.x * this.min.x;
  3555. max = plane.normal.x * this.max.x;
  3556. } else {
  3557. min = plane.normal.x * this.max.x;
  3558. max = plane.normal.x * this.min.x;
  3559. }
  3560. if (plane.normal.y > 0) {
  3561. min += plane.normal.y * this.min.y;
  3562. max += plane.normal.y * this.max.y;
  3563. } else {
  3564. min += plane.normal.y * this.max.y;
  3565. max += plane.normal.y * this.min.y;
  3566. }
  3567. if (plane.normal.z > 0) {
  3568. min += plane.normal.z * this.min.z;
  3569. max += plane.normal.z * this.max.z;
  3570. } else {
  3571. min += plane.normal.z * this.max.z;
  3572. max += plane.normal.z * this.min.z;
  3573. }
  3574. return min <= -plane.constant && max >= -plane.constant;
  3575. };
  3576. _proto.intersectsTriangle = function intersectsTriangle(triangle) {
  3577. if (this.isEmpty()) {
  3578. return false;
  3579. } // compute box center and extents
  3580. this.getCenter(_center);
  3581. _extents.subVectors(this.max, _center); // translate triangle to aabb origin
  3582. _v0.subVectors(triangle.a, _center);
  3583. _v1.subVectors(triangle.b, _center);
  3584. _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
  3585. _f0.subVectors(_v1, _v0);
  3586. _f1.subVectors(_v2, _v1);
  3587. _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
  3588. // 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
  3589. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3590. 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];
  3591. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  3592. return false;
  3593. } // test 3 face normals from the aabb
  3594. axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  3595. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  3596. return false;
  3597. } // finally testing the face normal of the triangle
  3598. // use already existing triangle edge vectors here
  3599. _triangleNormal.crossVectors(_f0, _f1);
  3600. axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
  3601. return satForAxes(axes, _v0, _v1, _v2, _extents);
  3602. };
  3603. _proto.clampPoint = function clampPoint(point, target) {
  3604. if (target === undefined) {
  3605. console.warn('THREE.Box3: .clampPoint() target is now required');
  3606. target = new Vector3();
  3607. }
  3608. return target.copy(point).clamp(this.min, this.max);
  3609. };
  3610. _proto.distanceToPoint = function distanceToPoint(point) {
  3611. var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
  3612. return clampedPoint.sub(point).length();
  3613. };
  3614. _proto.getBoundingSphere = function getBoundingSphere(target) {
  3615. if (target === undefined) {
  3616. console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
  3617. }
  3618. this.getCenter(target.center);
  3619. target.radius = this.getSize(_vector$1).length() * 0.5;
  3620. return target;
  3621. };
  3622. _proto.intersect = function intersect(box) {
  3623. this.min.max(box.min);
  3624. 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.
  3625. if (this.isEmpty()) this.makeEmpty();
  3626. return this;
  3627. };
  3628. _proto.union = function union(box) {
  3629. this.min.min(box.min);
  3630. this.max.max(box.max);
  3631. return this;
  3632. };
  3633. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3634. // transform of empty box is an empty box.
  3635. if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  3636. _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
  3637. _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
  3638. _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
  3639. _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
  3640. _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
  3641. _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
  3642. _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
  3643. _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
  3644. this.setFromPoints(_points);
  3645. return this;
  3646. };
  3647. _proto.translate = function translate(offset) {
  3648. this.min.add(offset);
  3649. this.max.add(offset);
  3650. return this;
  3651. };
  3652. _proto.equals = function equals(box) {
  3653. return box.min.equals(this.min) && box.max.equals(this.max);
  3654. };
  3655. return Box3;
  3656. }();
  3657. Box3.prototype.isBox3 = true;
  3658. 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()];
  3659. var _vector$1 = /*@__PURE__*/new Vector3();
  3660. var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
  3661. var _v0 = /*@__PURE__*/new Vector3();
  3662. var _v1 = /*@__PURE__*/new Vector3();
  3663. var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
  3664. var _f0 = /*@__PURE__*/new Vector3();
  3665. var _f1 = /*@__PURE__*/new Vector3();
  3666. var _f2 = /*@__PURE__*/new Vector3();
  3667. var _center = /*@__PURE__*/new Vector3();
  3668. var _extents = /*@__PURE__*/new Vector3();
  3669. var _triangleNormal = /*@__PURE__*/new Vector3();
  3670. var _testAxis = /*@__PURE__*/new Vector3();
  3671. function satForAxes(axes, v0, v1, v2, extents) {
  3672. for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
  3673. _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
  3674. 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
  3675. var p0 = v0.dot(_testAxis);
  3676. var p1 = v1.dot(_testAxis);
  3677. var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
  3678. if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
  3679. // points of the projected triangle are outside the projected half-length of the aabb
  3680. // the axis is seperating and we can exit
  3681. return false;
  3682. }
  3683. }
  3684. return true;
  3685. }
  3686. var _box$1 = /*@__PURE__*/new Box3();
  3687. var Sphere = /*#__PURE__*/function () {
  3688. function Sphere(center, radius) {
  3689. if (center === void 0) {
  3690. center = new Vector3();
  3691. }
  3692. if (radius === void 0) {
  3693. radius = -1;
  3694. }
  3695. this.center = center;
  3696. this.radius = radius;
  3697. }
  3698. var _proto = Sphere.prototype;
  3699. _proto.set = function set(center, radius) {
  3700. this.center.copy(center);
  3701. this.radius = radius;
  3702. return this;
  3703. };
  3704. _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
  3705. var center = this.center;
  3706. if (optionalCenter !== undefined) {
  3707. center.copy(optionalCenter);
  3708. } else {
  3709. _box$1.setFromPoints(points).getCenter(center);
  3710. }
  3711. var maxRadiusSq = 0;
  3712. for (var i = 0, il = points.length; i < il; i++) {
  3713. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
  3714. }
  3715. this.radius = Math.sqrt(maxRadiusSq);
  3716. return this;
  3717. };
  3718. _proto.copy = function copy(sphere) {
  3719. this.center.copy(sphere.center);
  3720. this.radius = sphere.radius;
  3721. return this;
  3722. };
  3723. _proto.isEmpty = function isEmpty() {
  3724. return this.radius < 0;
  3725. };
  3726. _proto.makeEmpty = function makeEmpty() {
  3727. this.center.set(0, 0, 0);
  3728. this.radius = -1;
  3729. return this;
  3730. };
  3731. _proto.containsPoint = function containsPoint(point) {
  3732. return point.distanceToSquared(this.center) <= this.radius * this.radius;
  3733. };
  3734. _proto.distanceToPoint = function distanceToPoint(point) {
  3735. return point.distanceTo(this.center) - this.radius;
  3736. };
  3737. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3738. var radiusSum = this.radius + sphere.radius;
  3739. return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
  3740. };
  3741. _proto.intersectsBox = function intersectsBox(box) {
  3742. return box.intersectsSphere(this);
  3743. };
  3744. _proto.intersectsPlane = function intersectsPlane(plane) {
  3745. return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
  3746. };
  3747. _proto.clampPoint = function clampPoint(point, target) {
  3748. var deltaLengthSq = this.center.distanceToSquared(point);
  3749. if (target === undefined) {
  3750. console.warn('THREE.Sphere: .clampPoint() target is now required');
  3751. target = new Vector3();
  3752. }
  3753. target.copy(point);
  3754. if (deltaLengthSq > this.radius * this.radius) {
  3755. target.sub(this.center).normalize();
  3756. target.multiplyScalar(this.radius).add(this.center);
  3757. }
  3758. return target;
  3759. };
  3760. _proto.getBoundingBox = function getBoundingBox(target) {
  3761. if (target === undefined) {
  3762. console.warn('THREE.Sphere: .getBoundingBox() target is now required');
  3763. target = new Box3();
  3764. }
  3765. if (this.isEmpty()) {
  3766. // Empty sphere produces empty bounding box
  3767. target.makeEmpty();
  3768. return target;
  3769. }
  3770. target.set(this.center, this.center);
  3771. target.expandByScalar(this.radius);
  3772. return target;
  3773. };
  3774. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3775. this.center.applyMatrix4(matrix);
  3776. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3777. return this;
  3778. };
  3779. _proto.translate = function translate(offset) {
  3780. this.center.add(offset);
  3781. return this;
  3782. };
  3783. _proto.equals = function equals(sphere) {
  3784. return sphere.center.equals(this.center) && sphere.radius === this.radius;
  3785. };
  3786. _proto.clone = function clone() {
  3787. return new this.constructor().copy(this);
  3788. };
  3789. return Sphere;
  3790. }();
  3791. var _vector$2 = /*@__PURE__*/new Vector3();
  3792. var _segCenter = /*@__PURE__*/new Vector3();
  3793. var _segDir = /*@__PURE__*/new Vector3();
  3794. var _diff = /*@__PURE__*/new Vector3();
  3795. var _edge1 = /*@__PURE__*/new Vector3();
  3796. var _edge2 = /*@__PURE__*/new Vector3();
  3797. var _normal = /*@__PURE__*/new Vector3();
  3798. var Ray = /*#__PURE__*/function () {
  3799. function Ray(origin, direction) {
  3800. if (origin === void 0) {
  3801. origin = new Vector3();
  3802. }
  3803. if (direction === void 0) {
  3804. direction = new Vector3(0, 0, -1);
  3805. }
  3806. this.origin = origin;
  3807. this.direction = direction;
  3808. }
  3809. var _proto = Ray.prototype;
  3810. _proto.set = function set(origin, direction) {
  3811. this.origin.copy(origin);
  3812. this.direction.copy(direction);
  3813. return this;
  3814. };
  3815. _proto.copy = function copy(ray) {
  3816. this.origin.copy(ray.origin);
  3817. this.direction.copy(ray.direction);
  3818. return this;
  3819. };
  3820. _proto.at = function at(t, target) {
  3821. if (target === undefined) {
  3822. console.warn('THREE.Ray: .at() target is now required');
  3823. target = new Vector3();
  3824. }
  3825. return target.copy(this.direction).multiplyScalar(t).add(this.origin);
  3826. };
  3827. _proto.lookAt = function lookAt(v) {
  3828. this.direction.copy(v).sub(this.origin).normalize();
  3829. return this;
  3830. };
  3831. _proto.recast = function recast(t) {
  3832. this.origin.copy(this.at(t, _vector$2));
  3833. return this;
  3834. };
  3835. _proto.closestPointToPoint = function closestPointToPoint(point, target) {
  3836. if (target === undefined) {
  3837. console.warn('THREE.Ray: .closestPointToPoint() target is now required');
  3838. target = new Vector3();
  3839. }
  3840. target.subVectors(point, this.origin);
  3841. var directionDistance = target.dot(this.direction);
  3842. if (directionDistance < 0) {
  3843. return target.copy(this.origin);
  3844. }
  3845. return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3846. };
  3847. _proto.distanceToPoint = function distanceToPoint(point) {
  3848. return Math.sqrt(this.distanceSqToPoint(point));
  3849. };
  3850. _proto.distanceSqToPoint = function distanceSqToPoint(point) {
  3851. var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
  3852. if (directionDistance < 0) {
  3853. return this.origin.distanceToSquared(point);
  3854. }
  3855. _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3856. return _vector$2.distanceToSquared(point);
  3857. };
  3858. _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
  3859. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3860. // It returns the min distance between the ray and the segment
  3861. // defined by v0 and v1
  3862. // It can also set two optional targets :
  3863. // - The closest point on the ray
  3864. // - The closest point on the segment
  3865. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
  3866. _segDir.copy(v1).sub(v0).normalize();
  3867. _diff.copy(this.origin).sub(_segCenter);
  3868. var segExtent = v0.distanceTo(v1) * 0.5;
  3869. var a01 = -this.direction.dot(_segDir);
  3870. var b0 = _diff.dot(this.direction);
  3871. var b1 = -_diff.dot(_segDir);
  3872. var c = _diff.lengthSq();
  3873. var det = Math.abs(1 - a01 * a01);
  3874. var s0, s1, sqrDist, extDet;
  3875. if (det > 0) {
  3876. // The ray and segment are not parallel.
  3877. s0 = a01 * b1 - b0;
  3878. s1 = a01 * b0 - b1;
  3879. extDet = segExtent * det;
  3880. if (s0 >= 0) {
  3881. if (s1 >= -extDet) {
  3882. if (s1 <= extDet) {
  3883. // region 0
  3884. // Minimum at interior points of ray and segment.
  3885. var invDet = 1 / det;
  3886. s0 *= invDet;
  3887. s1 *= invDet;
  3888. sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
  3889. } else {
  3890. // region 1
  3891. s1 = segExtent;
  3892. s0 = Math.max(0, -(a01 * s1 + b0));
  3893. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3894. }
  3895. } else {
  3896. // region 5
  3897. s1 = -segExtent;
  3898. s0 = Math.max(0, -(a01 * s1 + b0));
  3899. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3900. }
  3901. } else {
  3902. if (s1 <= -extDet) {
  3903. // region 4
  3904. s0 = Math.max(0, -(-a01 * segExtent + b0));
  3905. s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3906. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3907. } else if (s1 <= extDet) {
  3908. // region 3
  3909. s0 = 0;
  3910. s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
  3911. sqrDist = s1 * (s1 + 2 * b1) + c;
  3912. } else {
  3913. // region 2
  3914. s0 = Math.max(0, -(a01 * segExtent + b0));
  3915. s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3916. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3917. }
  3918. }
  3919. } else {
  3920. // Ray and segment are parallel.
  3921. s1 = a01 > 0 ? -segExtent : segExtent;
  3922. s0 = Math.max(0, -(a01 * s1 + b0));
  3923. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3924. }
  3925. if (optionalPointOnRay) {
  3926. optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
  3927. }
  3928. if (optionalPointOnSegment) {
  3929. optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
  3930. }
  3931. return sqrDist;
  3932. };
  3933. _proto.intersectSphere = function intersectSphere(sphere, target) {
  3934. _vector$2.subVectors(sphere.center, this.origin);
  3935. var tca = _vector$2.dot(this.direction);
  3936. var d2 = _vector$2.dot(_vector$2) - tca * tca;
  3937. var radius2 = sphere.radius * sphere.radius;
  3938. if (d2 > radius2) return null;
  3939. var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
  3940. var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
  3941. var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
  3942. if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
  3943. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3944. // in order to always return an intersect point that is in front of the ray.
  3945. 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
  3946. return this.at(t0, target);
  3947. };
  3948. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3949. return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
  3950. };
  3951. _proto.distanceToPlane = function distanceToPlane(plane) {
  3952. var denominator = plane.normal.dot(this.direction);
  3953. if (denominator === 0) {
  3954. // line is coplanar, return origin
  3955. if (plane.distanceToPoint(this.origin) === 0) {
  3956. return 0;
  3957. } // Null is preferable to undefined since undefined means.... it is undefined
  3958. return null;
  3959. }
  3960. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
  3961. return t >= 0 ? t : null;
  3962. };
  3963. _proto.intersectPlane = function intersectPlane(plane, target) {
  3964. var t = this.distanceToPlane(plane);
  3965. if (t === null) {
  3966. return null;
  3967. }
  3968. return this.at(t, target);
  3969. };
  3970. _proto.intersectsPlane = function intersectsPlane(plane) {
  3971. // check if the ray lies on the plane first
  3972. var distToPoint = plane.distanceToPoint(this.origin);
  3973. if (distToPoint === 0) {
  3974. return true;
  3975. }
  3976. var denominator = plane.normal.dot(this.direction);
  3977. if (denominator * distToPoint < 0) {
  3978. return true;
  3979. } // ray origin is behind the plane (and is pointing behind it)
  3980. return false;
  3981. };
  3982. _proto.intersectBox = function intersectBox(box, target) {
  3983. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3984. var invdirx = 1 / this.direction.x,
  3985. invdiry = 1 / this.direction.y,
  3986. invdirz = 1 / this.direction.z;
  3987. var origin = this.origin;
  3988. if (invdirx >= 0) {
  3989. tmin = (box.min.x - origin.x) * invdirx;
  3990. tmax = (box.max.x - origin.x) * invdirx;
  3991. } else {
  3992. tmin = (box.max.x - origin.x) * invdirx;
  3993. tmax = (box.min.x - origin.x) * invdirx;
  3994. }
  3995. if (invdiry >= 0) {
  3996. tymin = (box.min.y - origin.y) * invdiry;
  3997. tymax = (box.max.y - origin.y) * invdiry;
  3998. } else {
  3999. tymin = (box.max.y - origin.y) * invdiry;
  4000. tymax = (box.min.y - origin.y) * invdiry;
  4001. }
  4002. if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
  4003. // (result of 0 * Infinity). x !== x returns true if x is NaN
  4004. if (tymin > tmin || tmin !== tmin) tmin = tymin;
  4005. if (tymax < tmax || tmax !== tmax) tmax = tymax;
  4006. if (invdirz >= 0) {
  4007. tzmin = (box.min.z - origin.z) * invdirz;
  4008. tzmax = (box.max.z - origin.z) * invdirz;
  4009. } else {
  4010. tzmin = (box.max.z - origin.z) * invdirz;
  4011. tzmax = (box.min.z - origin.z) * invdirz;
  4012. }
  4013. if (tmin > tzmax || tzmin > tmax) return null;
  4014. if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
  4015. if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
  4016. if (tmax < 0) return null;
  4017. return this.at(tmin >= 0 ? tmin : tmax, target);
  4018. };
  4019. _proto.intersectsBox = function intersectsBox(box) {
  4020. return this.intersectBox(box, _vector$2) !== null;
  4021. };
  4022. _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
  4023. // Compute the offset origin, edges, and normal.
  4024. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  4025. _edge1.subVectors(b, a);
  4026. _edge2.subVectors(c, a);
  4027. _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  4028. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  4029. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  4030. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  4031. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  4032. var DdN = this.direction.dot(_normal);
  4033. var sign;
  4034. if (DdN > 0) {
  4035. if (backfaceCulling) return null;
  4036. sign = 1;
  4037. } else if (DdN < 0) {
  4038. sign = -1;
  4039. DdN = -DdN;
  4040. } else {
  4041. return null;
  4042. }
  4043. _diff.subVectors(this.origin, a);
  4044. var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
  4045. if (DdQxE2 < 0) {
  4046. return null;
  4047. }
  4048. var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
  4049. if (DdE1xQ < 0) {
  4050. return null;
  4051. } // b1+b2 > 1, no intersection
  4052. if (DdQxE2 + DdE1xQ > DdN) {
  4053. return null;
  4054. } // Line intersects triangle, check if ray does.
  4055. var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
  4056. if (QdN < 0) {
  4057. return null;
  4058. } // Ray intersects triangle.
  4059. return this.at(QdN / DdN, target);
  4060. };
  4061. _proto.applyMatrix4 = function applyMatrix4(matrix4) {
  4062. this.origin.applyMatrix4(matrix4);
  4063. this.direction.transformDirection(matrix4);
  4064. return this;
  4065. };
  4066. _proto.equals = function equals(ray) {
  4067. return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
  4068. };
  4069. _proto.clone = function clone() {
  4070. return new this.constructor().copy(this);
  4071. };
  4072. return Ray;
  4073. }();
  4074. var Matrix4 = /*#__PURE__*/function () {
  4075. function Matrix4() {
  4076. this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  4077. if (arguments.length > 0) {
  4078. console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
  4079. }
  4080. }
  4081. var _proto = Matrix4.prototype;
  4082. _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
  4083. var te = this.elements;
  4084. te[0] = n11;
  4085. te[4] = n12;
  4086. te[8] = n13;
  4087. te[12] = n14;
  4088. te[1] = n21;
  4089. te[5] = n22;
  4090. te[9] = n23;
  4091. te[13] = n24;
  4092. te[2] = n31;
  4093. te[6] = n32;
  4094. te[10] = n33;
  4095. te[14] = n34;
  4096. te[3] = n41;
  4097. te[7] = n42;
  4098. te[11] = n43;
  4099. te[15] = n44;
  4100. return this;
  4101. };
  4102. _proto.identity = function identity() {
  4103. this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4104. return this;
  4105. };
  4106. _proto.clone = function clone() {
  4107. return new Matrix4().fromArray(this.elements);
  4108. };
  4109. _proto.copy = function copy(m) {
  4110. var te = this.elements;
  4111. var me = m.elements;
  4112. te[0] = me[0];
  4113. te[1] = me[1];
  4114. te[2] = me[2];
  4115. te[3] = me[3];
  4116. te[4] = me[4];
  4117. te[5] = me[5];
  4118. te[6] = me[6];
  4119. te[7] = me[7];
  4120. te[8] = me[8];
  4121. te[9] = me[9];
  4122. te[10] = me[10];
  4123. te[11] = me[11];
  4124. te[12] = me[12];
  4125. te[13] = me[13];
  4126. te[14] = me[14];
  4127. te[15] = me[15];
  4128. return this;
  4129. };
  4130. _proto.copyPosition = function copyPosition(m) {
  4131. var te = this.elements,
  4132. me = m.elements;
  4133. te[12] = me[12];
  4134. te[13] = me[13];
  4135. te[14] = me[14];
  4136. return this;
  4137. };
  4138. _proto.setFromMatrix3 = function setFromMatrix3(m) {
  4139. var me = m.elements;
  4140. 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);
  4141. return this;
  4142. };
  4143. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  4144. xAxis.setFromMatrixColumn(this, 0);
  4145. yAxis.setFromMatrixColumn(this, 1);
  4146. zAxis.setFromMatrixColumn(this, 2);
  4147. return this;
  4148. };
  4149. _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
  4150. 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);
  4151. return this;
  4152. };
  4153. _proto.extractRotation = function extractRotation(m) {
  4154. // this method does not support reflection matrices
  4155. var te = this.elements;
  4156. var me = m.elements;
  4157. var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
  4158. var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
  4159. var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
  4160. te[0] = me[0] * scaleX;
  4161. te[1] = me[1] * scaleX;
  4162. te[2] = me[2] * scaleX;
  4163. te[3] = 0;
  4164. te[4] = me[4] * scaleY;
  4165. te[5] = me[5] * scaleY;
  4166. te[6] = me[6] * scaleY;
  4167. te[7] = 0;
  4168. te[8] = me[8] * scaleZ;
  4169. te[9] = me[9] * scaleZ;
  4170. te[10] = me[10] * scaleZ;
  4171. te[11] = 0;
  4172. te[12] = 0;
  4173. te[13] = 0;
  4174. te[14] = 0;
  4175. te[15] = 1;
  4176. return this;
  4177. };
  4178. _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
  4179. if (!(euler && euler.isEuler)) {
  4180. console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
  4181. }
  4182. var te = this.elements;
  4183. var x = euler.x,
  4184. y = euler.y,
  4185. z = euler.z;
  4186. var a = Math.cos(x),
  4187. b = Math.sin(x);
  4188. var c = Math.cos(y),
  4189. d = Math.sin(y);
  4190. var e = Math.cos(z),
  4191. f = Math.sin(z);
  4192. if (euler.order === 'XYZ') {
  4193. var ae = a * e,
  4194. af = a * f,
  4195. be = b * e,
  4196. bf = b * f;
  4197. te[0] = c * e;
  4198. te[4] = -c * f;
  4199. te[8] = d;
  4200. te[1] = af + be * d;
  4201. te[5] = ae - bf * d;
  4202. te[9] = -b * c;
  4203. te[2] = bf - ae * d;
  4204. te[6] = be + af * d;
  4205. te[10] = a * c;
  4206. } else if (euler.order === 'YXZ') {
  4207. var ce = c * e,
  4208. cf = c * f,
  4209. de = d * e,
  4210. df = d * f;
  4211. te[0] = ce + df * b;
  4212. te[4] = de * b - cf;
  4213. te[8] = a * d;
  4214. te[1] = a * f;
  4215. te[5] = a * e;
  4216. te[9] = -b;
  4217. te[2] = cf * b - de;
  4218. te[6] = df + ce * b;
  4219. te[10] = a * c;
  4220. } else if (euler.order === 'ZXY') {
  4221. var _ce = c * e,
  4222. _cf = c * f,
  4223. _de = d * e,
  4224. _df = d * f;
  4225. te[0] = _ce - _df * b;
  4226. te[4] = -a * f;
  4227. te[8] = _de + _cf * b;
  4228. te[1] = _cf + _de * b;
  4229. te[5] = a * e;
  4230. te[9] = _df - _ce * b;
  4231. te[2] = -a * d;
  4232. te[6] = b;
  4233. te[10] = a * c;
  4234. } else if (euler.order === 'ZYX') {
  4235. var _ae = a * e,
  4236. _af = a * f,
  4237. _be = b * e,
  4238. _bf = b * f;
  4239. te[0] = c * e;
  4240. te[4] = _be * d - _af;
  4241. te[8] = _ae * d + _bf;
  4242. te[1] = c * f;
  4243. te[5] = _bf * d + _ae;
  4244. te[9] = _af * d - _be;
  4245. te[2] = -d;
  4246. te[6] = b * c;
  4247. te[10] = a * c;
  4248. } else if (euler.order === 'YZX') {
  4249. var ac = a * c,
  4250. ad = a * d,
  4251. bc = b * c,
  4252. bd = b * d;
  4253. te[0] = c * e;
  4254. te[4] = bd - ac * f;
  4255. te[8] = bc * f + ad;
  4256. te[1] = f;
  4257. te[5] = a * e;
  4258. te[9] = -b * e;
  4259. te[2] = -d * e;
  4260. te[6] = ad * f + bc;
  4261. te[10] = ac - bd * f;
  4262. } else if (euler.order === 'XZY') {
  4263. var _ac = a * c,
  4264. _ad = a * d,
  4265. _bc = b * c,
  4266. _bd = b * d;
  4267. te[0] = c * e;
  4268. te[4] = -f;
  4269. te[8] = d * e;
  4270. te[1] = _ac * f + _bd;
  4271. te[5] = a * e;
  4272. te[9] = _ad * f - _bc;
  4273. te[2] = _bc * f - _ad;
  4274. te[6] = b * e;
  4275. te[10] = _bd * f + _ac;
  4276. } // bottom row
  4277. te[3] = 0;
  4278. te[7] = 0;
  4279. te[11] = 0; // last column
  4280. te[12] = 0;
  4281. te[13] = 0;
  4282. te[14] = 0;
  4283. te[15] = 1;
  4284. return this;
  4285. };
  4286. _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
  4287. return this.compose(_zero, q, _one);
  4288. };
  4289. _proto.lookAt = function lookAt(eye, target, up) {
  4290. var te = this.elements;
  4291. _z.subVectors(eye, target);
  4292. if (_z.lengthSq() === 0) {
  4293. // eye and target are in the same position
  4294. _z.z = 1;
  4295. }
  4296. _z.normalize();
  4297. _x.crossVectors(up, _z);
  4298. if (_x.lengthSq() === 0) {
  4299. // up and z are parallel
  4300. if (Math.abs(up.z) === 1) {
  4301. _z.x += 0.0001;
  4302. } else {
  4303. _z.z += 0.0001;
  4304. }
  4305. _z.normalize();
  4306. _x.crossVectors(up, _z);
  4307. }
  4308. _x.normalize();
  4309. _y.crossVectors(_z, _x);
  4310. te[0] = _x.x;
  4311. te[4] = _y.x;
  4312. te[8] = _z.x;
  4313. te[1] = _x.y;
  4314. te[5] = _y.y;
  4315. te[9] = _z.y;
  4316. te[2] = _x.z;
  4317. te[6] = _y.z;
  4318. te[10] = _z.z;
  4319. return this;
  4320. };
  4321. _proto.multiply = function multiply(m, n) {
  4322. if (n !== undefined) {
  4323. console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
  4324. return this.multiplyMatrices(m, n);
  4325. }
  4326. return this.multiplyMatrices(this, m);
  4327. };
  4328. _proto.premultiply = function premultiply(m) {
  4329. return this.multiplyMatrices(m, this);
  4330. };
  4331. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  4332. var ae = a.elements;
  4333. var be = b.elements;
  4334. var te = this.elements;
  4335. var a11 = ae[0],
  4336. a12 = ae[4],
  4337. a13 = ae[8],
  4338. a14 = ae[12];
  4339. var a21 = ae[1],
  4340. a22 = ae[5],
  4341. a23 = ae[9],
  4342. a24 = ae[13];
  4343. var a31 = ae[2],
  4344. a32 = ae[6],
  4345. a33 = ae[10],
  4346. a34 = ae[14];
  4347. var a41 = ae[3],
  4348. a42 = ae[7],
  4349. a43 = ae[11],
  4350. a44 = ae[15];
  4351. var b11 = be[0],
  4352. b12 = be[4],
  4353. b13 = be[8],
  4354. b14 = be[12];
  4355. var b21 = be[1],
  4356. b22 = be[5],
  4357. b23 = be[9],
  4358. b24 = be[13];
  4359. var b31 = be[2],
  4360. b32 = be[6],
  4361. b33 = be[10],
  4362. b34 = be[14];
  4363. var b41 = be[3],
  4364. b42 = be[7],
  4365. b43 = be[11],
  4366. b44 = be[15];
  4367. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  4368. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  4369. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  4370. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  4371. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  4372. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  4373. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  4374. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  4375. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  4376. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  4377. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  4378. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  4379. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  4380. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  4381. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  4382. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  4383. return this;
  4384. };
  4385. _proto.multiplyScalar = function multiplyScalar(s) {
  4386. var te = this.elements;
  4387. te[0] *= s;
  4388. te[4] *= s;
  4389. te[8] *= s;
  4390. te[12] *= s;
  4391. te[1] *= s;
  4392. te[5] *= s;
  4393. te[9] *= s;
  4394. te[13] *= s;
  4395. te[2] *= s;
  4396. te[6] *= s;
  4397. te[10] *= s;
  4398. te[14] *= s;
  4399. te[3] *= s;
  4400. te[7] *= s;
  4401. te[11] *= s;
  4402. te[15] *= s;
  4403. return this;
  4404. };
  4405. _proto.determinant = function determinant() {
  4406. var te = this.elements;
  4407. var n11 = te[0],
  4408. n12 = te[4],
  4409. n13 = te[8],
  4410. n14 = te[12];
  4411. var n21 = te[1],
  4412. n22 = te[5],
  4413. n23 = te[9],
  4414. n24 = te[13];
  4415. var n31 = te[2],
  4416. n32 = te[6],
  4417. n33 = te[10],
  4418. n34 = te[14];
  4419. var n41 = te[3],
  4420. n42 = te[7],
  4421. n43 = te[11],
  4422. n44 = te[15]; //TODO: make this more efficient
  4423. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  4424. 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);
  4425. };
  4426. _proto.transpose = function transpose() {
  4427. var te = this.elements;
  4428. var tmp;
  4429. tmp = te[1];
  4430. te[1] = te[4];
  4431. te[4] = tmp;
  4432. tmp = te[2];
  4433. te[2] = te[8];
  4434. te[8] = tmp;
  4435. tmp = te[6];
  4436. te[6] = te[9];
  4437. te[9] = tmp;
  4438. tmp = te[3];
  4439. te[3] = te[12];
  4440. te[12] = tmp;
  4441. tmp = te[7];
  4442. te[7] = te[13];
  4443. te[13] = tmp;
  4444. tmp = te[11];
  4445. te[11] = te[14];
  4446. te[14] = tmp;
  4447. return this;
  4448. };
  4449. _proto.setPosition = function setPosition(x, y, z) {
  4450. var te = this.elements;
  4451. if (x.isVector3) {
  4452. te[12] = x.x;
  4453. te[13] = x.y;
  4454. te[14] = x.z;
  4455. } else {
  4456. te[12] = x;
  4457. te[13] = y;
  4458. te[14] = z;
  4459. }
  4460. return this;
  4461. };
  4462. _proto.invert = function invert() {
  4463. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  4464. var te = this.elements,
  4465. n11 = te[0],
  4466. n21 = te[1],
  4467. n31 = te[2],
  4468. n41 = te[3],
  4469. n12 = te[4],
  4470. n22 = te[5],
  4471. n32 = te[6],
  4472. n42 = te[7],
  4473. n13 = te[8],
  4474. n23 = te[9],
  4475. n33 = te[10],
  4476. n43 = te[11],
  4477. n14 = te[12],
  4478. n24 = te[13],
  4479. n34 = te[14],
  4480. n44 = te[15],
  4481. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  4482. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  4483. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  4484. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  4485. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  4486. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  4487. var detInv = 1 / det;
  4488. te[0] = t11 * detInv;
  4489. te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
  4490. te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
  4491. te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
  4492. te[4] = t12 * detInv;
  4493. te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
  4494. te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
  4495. te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
  4496. te[8] = t13 * detInv;
  4497. te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
  4498. te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
  4499. te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
  4500. te[12] = t14 * detInv;
  4501. te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
  4502. te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
  4503. te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
  4504. return this;
  4505. };
  4506. _proto.scale = function scale(v) {
  4507. var te = this.elements;
  4508. var x = v.x,
  4509. y = v.y,
  4510. z = v.z;
  4511. te[0] *= x;
  4512. te[4] *= y;
  4513. te[8] *= z;
  4514. te[1] *= x;
  4515. te[5] *= y;
  4516. te[9] *= z;
  4517. te[2] *= x;
  4518. te[6] *= y;
  4519. te[10] *= z;
  4520. te[3] *= x;
  4521. te[7] *= y;
  4522. te[11] *= z;
  4523. return this;
  4524. };
  4525. _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
  4526. var te = this.elements;
  4527. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  4528. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  4529. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  4530. return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
  4531. };
  4532. _proto.makeTranslation = function makeTranslation(x, y, z) {
  4533. this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
  4534. return this;
  4535. };
  4536. _proto.makeRotationX = function makeRotationX(theta) {
  4537. var c = Math.cos(theta),
  4538. s = Math.sin(theta);
  4539. this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
  4540. return this;
  4541. };
  4542. _proto.makeRotationY = function makeRotationY(theta) {
  4543. var c = Math.cos(theta),
  4544. s = Math.sin(theta);
  4545. this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
  4546. return this;
  4547. };
  4548. _proto.makeRotationZ = function makeRotationZ(theta) {
  4549. var c = Math.cos(theta),
  4550. s = Math.sin(theta);
  4551. this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4552. return this;
  4553. };
  4554. _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
  4555. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  4556. var c = Math.cos(angle);
  4557. var s = Math.sin(angle);
  4558. var t = 1 - c;
  4559. var x = axis.x,
  4560. y = axis.y,
  4561. z = axis.z;
  4562. var tx = t * x,
  4563. ty = t * y;
  4564. 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);
  4565. return this;
  4566. };
  4567. _proto.makeScale = function makeScale(x, y, z) {
  4568. this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
  4569. return this;
  4570. };
  4571. _proto.makeShear = function makeShear(x, y, z) {
  4572. this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
  4573. return this;
  4574. };
  4575. _proto.compose = function compose(position, quaternion, scale) {
  4576. var te = this.elements;
  4577. var x = quaternion._x,
  4578. y = quaternion._y,
  4579. z = quaternion._z,
  4580. w = quaternion._w;
  4581. var x2 = x + x,
  4582. y2 = y + y,
  4583. z2 = z + z;
  4584. var xx = x * x2,
  4585. xy = x * y2,
  4586. xz = x * z2;
  4587. var yy = y * y2,
  4588. yz = y * z2,
  4589. zz = z * z2;
  4590. var wx = w * x2,
  4591. wy = w * y2,
  4592. wz = w * z2;
  4593. var sx = scale.x,
  4594. sy = scale.y,
  4595. sz = scale.z;
  4596. te[0] = (1 - (yy + zz)) * sx;
  4597. te[1] = (xy + wz) * sx;
  4598. te[2] = (xz - wy) * sx;
  4599. te[3] = 0;
  4600. te[4] = (xy - wz) * sy;
  4601. te[5] = (1 - (xx + zz)) * sy;
  4602. te[6] = (yz + wx) * sy;
  4603. te[7] = 0;
  4604. te[8] = (xz + wy) * sz;
  4605. te[9] = (yz - wx) * sz;
  4606. te[10] = (1 - (xx + yy)) * sz;
  4607. te[11] = 0;
  4608. te[12] = position.x;
  4609. te[13] = position.y;
  4610. te[14] = position.z;
  4611. te[15] = 1;
  4612. return this;
  4613. };
  4614. _proto.decompose = function decompose(position, quaternion, scale) {
  4615. var te = this.elements;
  4616. var sx = _v1$1.set(te[0], te[1], te[2]).length();
  4617. var sy = _v1$1.set(te[4], te[5], te[6]).length();
  4618. var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
  4619. var det = this.determinant();
  4620. if (det < 0) sx = -sx;
  4621. position.x = te[12];
  4622. position.y = te[13];
  4623. position.z = te[14]; // scale the rotation part
  4624. _m1.copy(this);
  4625. var invSX = 1 / sx;
  4626. var invSY = 1 / sy;
  4627. var invSZ = 1 / sz;
  4628. _m1.elements[0] *= invSX;
  4629. _m1.elements[1] *= invSX;
  4630. _m1.elements[2] *= invSX;
  4631. _m1.elements[4] *= invSY;
  4632. _m1.elements[5] *= invSY;
  4633. _m1.elements[6] *= invSY;
  4634. _m1.elements[8] *= invSZ;
  4635. _m1.elements[9] *= invSZ;
  4636. _m1.elements[10] *= invSZ;
  4637. quaternion.setFromRotationMatrix(_m1);
  4638. scale.x = sx;
  4639. scale.y = sy;
  4640. scale.z = sz;
  4641. return this;
  4642. };
  4643. _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
  4644. if (far === undefined) {
  4645. console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
  4646. }
  4647. var te = this.elements;
  4648. var x = 2 * near / (right - left);
  4649. var y = 2 * near / (top - bottom);
  4650. var a = (right + left) / (right - left);
  4651. var b = (top + bottom) / (top - bottom);
  4652. var c = -(far + near) / (far - near);
  4653. var d = -2 * far * near / (far - near);
  4654. te[0] = x;
  4655. te[4] = 0;
  4656. te[8] = a;
  4657. te[12] = 0;
  4658. te[1] = 0;
  4659. te[5] = y;
  4660. te[9] = b;
  4661. te[13] = 0;
  4662. te[2] = 0;
  4663. te[6] = 0;
  4664. te[10] = c;
  4665. te[14] = d;
  4666. te[3] = 0;
  4667. te[7] = 0;
  4668. te[11] = -1;
  4669. te[15] = 0;
  4670. return this;
  4671. };
  4672. _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
  4673. var te = this.elements;
  4674. var w = 1.0 / (right - left);
  4675. var h = 1.0 / (top - bottom);
  4676. var p = 1.0 / (far - near);
  4677. var x = (right + left) * w;
  4678. var y = (top + bottom) * h;
  4679. var z = (far + near) * p;
  4680. te[0] = 2 * w;
  4681. te[4] = 0;
  4682. te[8] = 0;
  4683. te[12] = -x;
  4684. te[1] = 0;
  4685. te[5] = 2 * h;
  4686. te[9] = 0;
  4687. te[13] = -y;
  4688. te[2] = 0;
  4689. te[6] = 0;
  4690. te[10] = -2 * p;
  4691. te[14] = -z;
  4692. te[3] = 0;
  4693. te[7] = 0;
  4694. te[11] = 0;
  4695. te[15] = 1;
  4696. return this;
  4697. };
  4698. _proto.equals = function equals(matrix) {
  4699. var te = this.elements;
  4700. var me = matrix.elements;
  4701. for (var i = 0; i < 16; i++) {
  4702. if (te[i] !== me[i]) return false;
  4703. }
  4704. return true;
  4705. };
  4706. _proto.fromArray = function fromArray(array, offset) {
  4707. if (offset === void 0) {
  4708. offset = 0;
  4709. }
  4710. for (var i = 0; i < 16; i++) {
  4711. this.elements[i] = array[i + offset];
  4712. }
  4713. return this;
  4714. };
  4715. _proto.toArray = function toArray(array, offset) {
  4716. if (array === void 0) {
  4717. array = [];
  4718. }
  4719. if (offset === void 0) {
  4720. offset = 0;
  4721. }
  4722. var te = this.elements;
  4723. array[offset] = te[0];
  4724. array[offset + 1] = te[1];
  4725. array[offset + 2] = te[2];
  4726. array[offset + 3] = te[3];
  4727. array[offset + 4] = te[4];
  4728. array[offset + 5] = te[5];
  4729. array[offset + 6] = te[6];
  4730. array[offset + 7] = te[7];
  4731. array[offset + 8] = te[8];
  4732. array[offset + 9] = te[9];
  4733. array[offset + 10] = te[10];
  4734. array[offset + 11] = te[11];
  4735. array[offset + 12] = te[12];
  4736. array[offset + 13] = te[13];
  4737. array[offset + 14] = te[14];
  4738. array[offset + 15] = te[15];
  4739. return array;
  4740. };
  4741. return Matrix4;
  4742. }();
  4743. Matrix4.prototype.isMatrix4 = true;
  4744. var _v1$1 = /*@__PURE__*/new Vector3();
  4745. var _m1 = /*@__PURE__*/new Matrix4();
  4746. var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
  4747. var _one = /*@__PURE__*/new Vector3(1, 1, 1);
  4748. var _x = /*@__PURE__*/new Vector3();
  4749. var _y = /*@__PURE__*/new Vector3();
  4750. var _z = /*@__PURE__*/new Vector3();
  4751. var _matrix = /*@__PURE__*/new Matrix4();
  4752. var _quaternion$1 = /*@__PURE__*/new Quaternion();
  4753. var Euler = /*#__PURE__*/function () {
  4754. function Euler(x, y, z, order) {
  4755. if (x === void 0) {
  4756. x = 0;
  4757. }
  4758. if (y === void 0) {
  4759. y = 0;
  4760. }
  4761. if (z === void 0) {
  4762. z = 0;
  4763. }
  4764. if (order === void 0) {
  4765. order = Euler.DefaultOrder;
  4766. }
  4767. this._x = x;
  4768. this._y = y;
  4769. this._z = z;
  4770. this._order = order;
  4771. }
  4772. var _proto = Euler.prototype;
  4773. _proto.set = function set(x, y, z, order) {
  4774. this._x = x;
  4775. this._y = y;
  4776. this._z = z;
  4777. this._order = order || this._order;
  4778. this._onChangeCallback();
  4779. return this;
  4780. };
  4781. _proto.clone = function clone() {
  4782. return new this.constructor(this._x, this._y, this._z, this._order);
  4783. };
  4784. _proto.copy = function copy(euler) {
  4785. this._x = euler._x;
  4786. this._y = euler._y;
  4787. this._z = euler._z;
  4788. this._order = euler._order;
  4789. this._onChangeCallback();
  4790. return this;
  4791. };
  4792. _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
  4793. var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4794. var te = m.elements;
  4795. var m11 = te[0],
  4796. m12 = te[4],
  4797. m13 = te[8];
  4798. var m21 = te[1],
  4799. m22 = te[5],
  4800. m23 = te[9];
  4801. var m31 = te[2],
  4802. m32 = te[6],
  4803. m33 = te[10];
  4804. order = order || this._order;
  4805. switch (order) {
  4806. case 'XYZ':
  4807. this._y = Math.asin(clamp(m13, -1, 1));
  4808. if (Math.abs(m13) < 0.9999999) {
  4809. this._x = Math.atan2(-m23, m33);
  4810. this._z = Math.atan2(-m12, m11);
  4811. } else {
  4812. this._x = Math.atan2(m32, m22);
  4813. this._z = 0;
  4814. }
  4815. break;
  4816. case 'YXZ':
  4817. this._x = Math.asin(-clamp(m23, -1, 1));
  4818. if (Math.abs(m23) < 0.9999999) {
  4819. this._y = Math.atan2(m13, m33);
  4820. this._z = Math.atan2(m21, m22);
  4821. } else {
  4822. this._y = Math.atan2(-m31, m11);
  4823. this._z = 0;
  4824. }
  4825. break;
  4826. case 'ZXY':
  4827. this._x = Math.asin(clamp(m32, -1, 1));
  4828. if (Math.abs(m32) < 0.9999999) {
  4829. this._y = Math.atan2(-m31, m33);
  4830. this._z = Math.atan2(-m12, m22);
  4831. } else {
  4832. this._y = 0;
  4833. this._z = Math.atan2(m21, m11);
  4834. }
  4835. break;
  4836. case 'ZYX':
  4837. this._y = Math.asin(-clamp(m31, -1, 1));
  4838. if (Math.abs(m31) < 0.9999999) {
  4839. this._x = Math.atan2(m32, m33);
  4840. this._z = Math.atan2(m21, m11);
  4841. } else {
  4842. this._x = 0;
  4843. this._z = Math.atan2(-m12, m22);
  4844. }
  4845. break;
  4846. case 'YZX':
  4847. this._z = Math.asin(clamp(m21, -1, 1));
  4848. if (Math.abs(m21) < 0.9999999) {
  4849. this._x = Math.atan2(-m23, m22);
  4850. this._y = Math.atan2(-m31, m11);
  4851. } else {
  4852. this._x = 0;
  4853. this._y = Math.atan2(m13, m33);
  4854. }
  4855. break;
  4856. case 'XZY':
  4857. this._z = Math.asin(-clamp(m12, -1, 1));
  4858. if (Math.abs(m12) < 0.9999999) {
  4859. this._x = Math.atan2(m32, m22);
  4860. this._y = Math.atan2(m13, m11);
  4861. } else {
  4862. this._x = Math.atan2(-m23, m33);
  4863. this._y = 0;
  4864. }
  4865. break;
  4866. default:
  4867. console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
  4868. }
  4869. this._order = order;
  4870. if (update !== false) this._onChangeCallback();
  4871. return this;
  4872. };
  4873. _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
  4874. _matrix.makeRotationFromQuaternion(q);
  4875. return this.setFromRotationMatrix(_matrix, order, update);
  4876. };
  4877. _proto.setFromVector3 = function setFromVector3(v, order) {
  4878. return this.set(v.x, v.y, v.z, order || this._order);
  4879. };
  4880. _proto.reorder = function reorder(newOrder) {
  4881. // WARNING: this discards revolution information -bhouston
  4882. _quaternion$1.setFromEuler(this);
  4883. return this.setFromQuaternion(_quaternion$1, newOrder);
  4884. };
  4885. _proto.equals = function equals(euler) {
  4886. return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
  4887. };
  4888. _proto.fromArray = function fromArray(array) {
  4889. this._x = array[0];
  4890. this._y = array[1];
  4891. this._z = array[2];
  4892. if (array[3] !== undefined) this._order = array[3];
  4893. this._onChangeCallback();
  4894. return this;
  4895. };
  4896. _proto.toArray = function toArray(array, offset) {
  4897. if (array === void 0) {
  4898. array = [];
  4899. }
  4900. if (offset === void 0) {
  4901. offset = 0;
  4902. }
  4903. array[offset] = this._x;
  4904. array[offset + 1] = this._y;
  4905. array[offset + 2] = this._z;
  4906. array[offset + 3] = this._order;
  4907. return array;
  4908. };
  4909. _proto.toVector3 = function toVector3(optionalResult) {
  4910. if (optionalResult) {
  4911. return optionalResult.set(this._x, this._y, this._z);
  4912. } else {
  4913. return new Vector3(this._x, this._y, this._z);
  4914. }
  4915. };
  4916. _proto._onChange = function _onChange(callback) {
  4917. this._onChangeCallback = callback;
  4918. return this;
  4919. };
  4920. _proto._onChangeCallback = function _onChangeCallback() {};
  4921. _createClass(Euler, [{
  4922. key: "x",
  4923. get: function get() {
  4924. return this._x;
  4925. },
  4926. set: function set(value) {
  4927. this._x = value;
  4928. this._onChangeCallback();
  4929. }
  4930. }, {
  4931. key: "y",
  4932. get: function get() {
  4933. return this._y;
  4934. },
  4935. set: function set(value) {
  4936. this._y = value;
  4937. this._onChangeCallback();
  4938. }
  4939. }, {
  4940. key: "z",
  4941. get: function get() {
  4942. return this._z;
  4943. },
  4944. set: function set(value) {
  4945. this._z = value;
  4946. this._onChangeCallback();
  4947. }
  4948. }, {
  4949. key: "order",
  4950. get: function get() {
  4951. return this._order;
  4952. },
  4953. set: function set(value) {
  4954. this._order = value;
  4955. this._onChangeCallback();
  4956. }
  4957. }]);
  4958. return Euler;
  4959. }();
  4960. Euler.prototype.isEuler = true;
  4961. Euler.DefaultOrder = 'XYZ';
  4962. Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
  4963. var Layers = /*#__PURE__*/function () {
  4964. function Layers() {
  4965. this.mask = 1 | 0;
  4966. }
  4967. var _proto = Layers.prototype;
  4968. _proto.set = function set(channel) {
  4969. this.mask = 1 << channel | 0;
  4970. };
  4971. _proto.enable = function enable(channel) {
  4972. this.mask |= 1 << channel | 0;
  4973. };
  4974. _proto.enableAll = function enableAll() {
  4975. this.mask = 0xffffffff | 0;
  4976. };
  4977. _proto.toggle = function toggle(channel) {
  4978. this.mask ^= 1 << channel | 0;
  4979. };
  4980. _proto.disable = function disable(channel) {
  4981. this.mask &= ~(1 << channel | 0);
  4982. };
  4983. _proto.disableAll = function disableAll() {
  4984. this.mask = 0;
  4985. };
  4986. _proto.test = function test(layers) {
  4987. return (this.mask & layers.mask) !== 0;
  4988. };
  4989. return Layers;
  4990. }();
  4991. var _object3DId = 0;
  4992. var _v1$2 = new Vector3();
  4993. var _q1 = new Quaternion();
  4994. var _m1$1 = new Matrix4();
  4995. var _target = new Vector3();
  4996. var _position = new Vector3();
  4997. var _scale = new Vector3();
  4998. var _quaternion$2 = new Quaternion();
  4999. var _xAxis = new Vector3(1, 0, 0);
  5000. var _yAxis = new Vector3(0, 1, 0);
  5001. var _zAxis = new Vector3(0, 0, 1);
  5002. var _addedEvent = {
  5003. type: 'added'
  5004. };
  5005. var _removedEvent = {
  5006. type: 'removed'
  5007. };
  5008. function Object3D() {
  5009. Object.defineProperty(this, 'id', {
  5010. value: _object3DId++
  5011. });
  5012. this.uuid = MathUtils.generateUUID();
  5013. this.name = '';
  5014. this.type = 'Object3D';
  5015. this.parent = null;
  5016. this.children = [];
  5017. this.up = Object3D.DefaultUp.clone();
  5018. var position = new Vector3();
  5019. var rotation = new Euler();
  5020. var quaternion = new Quaternion();
  5021. var scale = new Vector3(1, 1, 1);
  5022. function onRotationChange() {
  5023. quaternion.setFromEuler(rotation, false);
  5024. }
  5025. function onQuaternionChange() {
  5026. rotation.setFromQuaternion(quaternion, undefined, false);
  5027. }
  5028. rotation._onChange(onRotationChange);
  5029. quaternion._onChange(onQuaternionChange);
  5030. Object.defineProperties(this, {
  5031. position: {
  5032. configurable: true,
  5033. enumerable: true,
  5034. value: position
  5035. },
  5036. rotation: {
  5037. configurable: true,
  5038. enumerable: true,
  5039. value: rotation
  5040. },
  5041. quaternion: {
  5042. configurable: true,
  5043. enumerable: true,
  5044. value: quaternion
  5045. },
  5046. scale: {
  5047. configurable: true,
  5048. enumerable: true,
  5049. value: scale
  5050. },
  5051. modelViewMatrix: {
  5052. value: new Matrix4()
  5053. },
  5054. normalMatrix: {
  5055. value: new Matrix3()
  5056. }
  5057. });
  5058. this.matrix = new Matrix4();
  5059. this.matrixWorld = new Matrix4();
  5060. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  5061. this.matrixWorldNeedsUpdate = false;
  5062. this.layers = new Layers();
  5063. this.visible = true;
  5064. this.castShadow = false;
  5065. this.receiveShadow = false;
  5066. this.frustumCulled = true;
  5067. this.renderOrder = 0;
  5068. this.animations = [];
  5069. this.userData = {};
  5070. }
  5071. Object3D.DefaultUp = new Vector3(0, 1, 0);
  5072. Object3D.DefaultMatrixAutoUpdate = true;
  5073. Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5074. constructor: Object3D,
  5075. isObject3D: true,
  5076. onBeforeRender: function onBeforeRender() {},
  5077. onAfterRender: function onAfterRender() {},
  5078. applyMatrix4: function applyMatrix4(matrix) {
  5079. if (this.matrixAutoUpdate) this.updateMatrix();
  5080. this.matrix.premultiply(matrix);
  5081. this.matrix.decompose(this.position, this.quaternion, this.scale);
  5082. },
  5083. applyQuaternion: function applyQuaternion(q) {
  5084. this.quaternion.premultiply(q);
  5085. return this;
  5086. },
  5087. setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
  5088. // assumes axis is normalized
  5089. this.quaternion.setFromAxisAngle(axis, angle);
  5090. },
  5091. setRotationFromEuler: function setRotationFromEuler(euler) {
  5092. this.quaternion.setFromEuler(euler, true);
  5093. },
  5094. setRotationFromMatrix: function setRotationFromMatrix(m) {
  5095. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5096. this.quaternion.setFromRotationMatrix(m);
  5097. },
  5098. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  5099. // assumes q is normalized
  5100. this.quaternion.copy(q);
  5101. },
  5102. rotateOnAxis: function rotateOnAxis(axis, angle) {
  5103. // rotate object on axis in object space
  5104. // axis is assumed to be normalized
  5105. _q1.setFromAxisAngle(axis, angle);
  5106. this.quaternion.multiply(_q1);
  5107. return this;
  5108. },
  5109. rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
  5110. // rotate object on axis in world space
  5111. // axis is assumed to be normalized
  5112. // method assumes no rotated parent
  5113. _q1.setFromAxisAngle(axis, angle);
  5114. this.quaternion.premultiply(_q1);
  5115. return this;
  5116. },
  5117. rotateX: function rotateX(angle) {
  5118. return this.rotateOnAxis(_xAxis, angle);
  5119. },
  5120. rotateY: function rotateY(angle) {
  5121. return this.rotateOnAxis(_yAxis, angle);
  5122. },
  5123. rotateZ: function rotateZ(angle) {
  5124. return this.rotateOnAxis(_zAxis, angle);
  5125. },
  5126. translateOnAxis: function translateOnAxis(axis, distance) {
  5127. // translate object by distance along axis in object space
  5128. // axis is assumed to be normalized
  5129. _v1$2.copy(axis).applyQuaternion(this.quaternion);
  5130. this.position.add(_v1$2.multiplyScalar(distance));
  5131. return this;
  5132. },
  5133. translateX: function translateX(distance) {
  5134. return this.translateOnAxis(_xAxis, distance);
  5135. },
  5136. translateY: function translateY(distance) {
  5137. return this.translateOnAxis(_yAxis, distance);
  5138. },
  5139. translateZ: function translateZ(distance) {
  5140. return this.translateOnAxis(_zAxis, distance);
  5141. },
  5142. localToWorld: function localToWorld(vector) {
  5143. return vector.applyMatrix4(this.matrixWorld);
  5144. },
  5145. worldToLocal: function worldToLocal(vector) {
  5146. return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert());
  5147. },
  5148. lookAt: function lookAt(x, y, z) {
  5149. // This method does not support objects having non-uniformly-scaled parent(s)
  5150. if (x.isVector3) {
  5151. _target.copy(x);
  5152. } else {
  5153. _target.set(x, y, z);
  5154. }
  5155. var parent = this.parent;
  5156. this.updateWorldMatrix(true, false);
  5157. _position.setFromMatrixPosition(this.matrixWorld);
  5158. if (this.isCamera || this.isLight) {
  5159. _m1$1.lookAt(_position, _target, this.up);
  5160. } else {
  5161. _m1$1.lookAt(_target, _position, this.up);
  5162. }
  5163. this.quaternion.setFromRotationMatrix(_m1$1);
  5164. if (parent) {
  5165. _m1$1.extractRotation(parent.matrixWorld);
  5166. _q1.setFromRotationMatrix(_m1$1);
  5167. this.quaternion.premultiply(_q1.invert());
  5168. }
  5169. },
  5170. add: function add(object) {
  5171. if (arguments.length > 1) {
  5172. for (var i = 0; i < arguments.length; i++) {
  5173. this.add(arguments[i]);
  5174. }
  5175. return this;
  5176. }
  5177. if (object === this) {
  5178. console.error('THREE.Object3D.add: object can\'t be added as a child of itself.', object);
  5179. return this;
  5180. }
  5181. if (object && object.isObject3D) {
  5182. if (object.parent !== null) {
  5183. object.parent.remove(object);
  5184. }
  5185. object.parent = this;
  5186. this.children.push(object);
  5187. object.dispatchEvent(_addedEvent);
  5188. } else {
  5189. console.error('THREE.Object3D.add: object not an instance of THREE.Object3D.', object);
  5190. }
  5191. return this;
  5192. },
  5193. remove: function remove(object) {
  5194. if (arguments.length > 1) {
  5195. for (var i = 0; i < arguments.length; i++) {
  5196. this.remove(arguments[i]);
  5197. }
  5198. return this;
  5199. }
  5200. var index = this.children.indexOf(object);
  5201. if (index !== -1) {
  5202. object.parent = null;
  5203. this.children.splice(index, 1);
  5204. object.dispatchEvent(_removedEvent);
  5205. }
  5206. return this;
  5207. },
  5208. clear: function clear() {
  5209. for (var i = 0; i < this.children.length; i++) {
  5210. var object = this.children[i];
  5211. object.parent = null;
  5212. object.dispatchEvent(_removedEvent);
  5213. }
  5214. this.children.length = 0;
  5215. return this;
  5216. },
  5217. attach: function attach(object) {
  5218. // adds object as a child of this, while maintaining the object's world transform
  5219. this.updateWorldMatrix(true, false);
  5220. _m1$1.copy(this.matrixWorld).invert();
  5221. if (object.parent !== null) {
  5222. object.parent.updateWorldMatrix(true, false);
  5223. _m1$1.multiply(object.parent.matrixWorld);
  5224. }
  5225. object.applyMatrix4(_m1$1);
  5226. this.add(object);
  5227. object.updateWorldMatrix(false, true);
  5228. return this;
  5229. },
  5230. getObjectById: function getObjectById(id) {
  5231. return this.getObjectByProperty('id', id);
  5232. },
  5233. getObjectByName: function getObjectByName(name) {
  5234. return this.getObjectByProperty('name', name);
  5235. },
  5236. getObjectByProperty: function getObjectByProperty(name, value) {
  5237. if (this[name] === value) return this;
  5238. for (var i = 0, l = this.children.length; i < l; i++) {
  5239. var child = this.children[i];
  5240. var object = child.getObjectByProperty(name, value);
  5241. if (object !== undefined) {
  5242. return object;
  5243. }
  5244. }
  5245. return undefined;
  5246. },
  5247. getWorldPosition: function getWorldPosition(target) {
  5248. if (target === undefined) {
  5249. console.warn('THREE.Object3D: .getWorldPosition() target is now required');
  5250. target = new Vector3();
  5251. }
  5252. this.updateWorldMatrix(true, false);
  5253. return target.setFromMatrixPosition(this.matrixWorld);
  5254. },
  5255. getWorldQuaternion: function getWorldQuaternion(target) {
  5256. if (target === undefined) {
  5257. console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
  5258. target = new Quaternion();
  5259. }
  5260. this.updateWorldMatrix(true, false);
  5261. this.matrixWorld.decompose(_position, target, _scale);
  5262. return target;
  5263. },
  5264. getWorldScale: function getWorldScale(target) {
  5265. if (target === undefined) {
  5266. console.warn('THREE.Object3D: .getWorldScale() target is now required');
  5267. target = new Vector3();
  5268. }
  5269. this.updateWorldMatrix(true, false);
  5270. this.matrixWorld.decompose(_position, _quaternion$2, target);
  5271. return target;
  5272. },
  5273. getWorldDirection: function getWorldDirection(target) {
  5274. if (target === undefined) {
  5275. console.warn('THREE.Object3D: .getWorldDirection() target is now required');
  5276. target = new Vector3();
  5277. }
  5278. this.updateWorldMatrix(true, false);
  5279. var e = this.matrixWorld.elements;
  5280. return target.set(e[8], e[9], e[10]).normalize();
  5281. },
  5282. raycast: function raycast() {},
  5283. traverse: function traverse(callback) {
  5284. callback(this);
  5285. var children = this.children;
  5286. for (var i = 0, l = children.length; i < l; i++) {
  5287. children[i].traverse(callback);
  5288. }
  5289. },
  5290. traverseVisible: function traverseVisible(callback) {
  5291. if (this.visible === false) return;
  5292. callback(this);
  5293. var children = this.children;
  5294. for (var i = 0, l = children.length; i < l; i++) {
  5295. children[i].traverseVisible(callback);
  5296. }
  5297. },
  5298. traverseAncestors: function traverseAncestors(callback) {
  5299. var parent = this.parent;
  5300. if (parent !== null) {
  5301. callback(parent);
  5302. parent.traverseAncestors(callback);
  5303. }
  5304. },
  5305. updateMatrix: function updateMatrix() {
  5306. this.matrix.compose(this.position, this.quaternion, this.scale);
  5307. this.matrixWorldNeedsUpdate = true;
  5308. },
  5309. updateMatrixWorld: function updateMatrixWorld(force) {
  5310. if (this.matrixAutoUpdate) this.updateMatrix();
  5311. if (this.matrixWorldNeedsUpdate || force) {
  5312. if (this.parent === null) {
  5313. this.matrixWorld.copy(this.matrix);
  5314. } else {
  5315. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  5316. }
  5317. this.matrixWorldNeedsUpdate = false;
  5318. force = true;
  5319. } // update children
  5320. var children = this.children;
  5321. for (var i = 0, l = children.length; i < l; i++) {
  5322. children[i].updateMatrixWorld(force);
  5323. }
  5324. },
  5325. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  5326. var parent = this.parent;
  5327. if (updateParents === true && parent !== null) {
  5328. parent.updateWorldMatrix(true, false);
  5329. }
  5330. if (this.matrixAutoUpdate) this.updateMatrix();
  5331. if (this.parent === null) {
  5332. this.matrixWorld.copy(this.matrix);
  5333. } else {
  5334. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  5335. } // update children
  5336. if (updateChildren === true) {
  5337. var children = this.children;
  5338. for (var i = 0, l = children.length; i < l; i++) {
  5339. children[i].updateWorldMatrix(false, true);
  5340. }
  5341. }
  5342. },
  5343. toJSON: function toJSON(meta) {
  5344. // meta is a string when called from JSON.stringify
  5345. var isRootObject = meta === undefined || typeof meta === 'string';
  5346. var output = {}; // meta is a hash used to collect geometries, materials.
  5347. // not providing it implies that this is the root object
  5348. // being serialized.
  5349. if (isRootObject) {
  5350. // initialize meta obj
  5351. meta = {
  5352. geometries: {},
  5353. materials: {},
  5354. textures: {},
  5355. images: {},
  5356. shapes: {},
  5357. skeletons: {},
  5358. animations: {}
  5359. };
  5360. output.metadata = {
  5361. version: 4.5,
  5362. type: 'Object',
  5363. generator: 'Object3D.toJSON'
  5364. };
  5365. } // standard Object3D serialization
  5366. var object = {};
  5367. object.uuid = this.uuid;
  5368. object.type = this.type;
  5369. if (this.name !== '') object.name = this.name;
  5370. if (this.castShadow === true) object.castShadow = true;
  5371. if (this.receiveShadow === true) object.receiveShadow = true;
  5372. if (this.visible === false) object.visible = false;
  5373. if (this.frustumCulled === false) object.frustumCulled = false;
  5374. if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
  5375. if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
  5376. object.layers = this.layers.mask;
  5377. object.matrix = this.matrix.toArray();
  5378. if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
  5379. if (this.isInstancedMesh) {
  5380. object.type = 'InstancedMesh';
  5381. object.count = this.count;
  5382. object.instanceMatrix = this.instanceMatrix.toJSON();
  5383. } //
  5384. function serialize(library, element) {
  5385. if (library[element.uuid] === undefined) {
  5386. library[element.uuid] = element.toJSON(meta);
  5387. }
  5388. return element.uuid;
  5389. }
  5390. if (this.isMesh || this.isLine || this.isPoints) {
  5391. object.geometry = serialize(meta.geometries, this.geometry);
  5392. var parameters = this.geometry.parameters;
  5393. if (parameters !== undefined && parameters.shapes !== undefined) {
  5394. var shapes = parameters.shapes;
  5395. if (Array.isArray(shapes)) {
  5396. for (var i = 0, l = shapes.length; i < l; i++) {
  5397. var shape = shapes[i];
  5398. serialize(meta.shapes, shape);
  5399. }
  5400. } else {
  5401. serialize(meta.shapes, shapes);
  5402. }
  5403. }
  5404. }
  5405. if (this.isSkinnedMesh) {
  5406. object.bindMode = this.bindMode;
  5407. object.bindMatrix = this.bindMatrix.toArray();
  5408. if (this.skeleton !== undefined) {
  5409. serialize(meta.skeletons, this.skeleton);
  5410. object.skeleton = this.skeleton.uuid;
  5411. }
  5412. }
  5413. if (this.material !== undefined) {
  5414. if (Array.isArray(this.material)) {
  5415. var uuids = [];
  5416. for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
  5417. uuids.push(serialize(meta.materials, this.material[_i]));
  5418. }
  5419. object.material = uuids;
  5420. } else {
  5421. object.material = serialize(meta.materials, this.material);
  5422. }
  5423. } //
  5424. if (this.children.length > 0) {
  5425. object.children = [];
  5426. for (var _i2 = 0; _i2 < this.children.length; _i2++) {
  5427. object.children.push(this.children[_i2].toJSON(meta).object);
  5428. }
  5429. } //
  5430. if (this.animations.length > 0) {
  5431. object.animations = [];
  5432. for (var _i3 = 0; _i3 < this.animations.length; _i3++) {
  5433. var animation = this.animations[_i3];
  5434. object.animations.push(serialize(meta.animations, animation));
  5435. }
  5436. }
  5437. if (isRootObject) {
  5438. var geometries = extractFromCache(meta.geometries);
  5439. var materials = extractFromCache(meta.materials);
  5440. var textures = extractFromCache(meta.textures);
  5441. var images = extractFromCache(meta.images);
  5442. var _shapes = extractFromCache(meta.shapes);
  5443. var skeletons = extractFromCache(meta.skeletons);
  5444. var animations = extractFromCache(meta.animations);
  5445. if (geometries.length > 0) output.geometries = geometries;
  5446. if (materials.length > 0) output.materials = materials;
  5447. if (textures.length > 0) output.textures = textures;
  5448. if (images.length > 0) output.images = images;
  5449. if (_shapes.length > 0) output.shapes = _shapes;
  5450. if (skeletons.length > 0) output.skeletons = skeletons;
  5451. if (animations.length > 0) output.animations = animations;
  5452. }
  5453. output.object = object;
  5454. return output; // extract data from the cache hash
  5455. // remove metadata on each item
  5456. // and return as array
  5457. function extractFromCache(cache) {
  5458. var values = [];
  5459. for (var key in cache) {
  5460. var data = cache[key];
  5461. delete data.metadata;
  5462. values.push(data);
  5463. }
  5464. return values;
  5465. }
  5466. },
  5467. clone: function clone(recursive) {
  5468. return new this.constructor().copy(this, recursive);
  5469. },
  5470. copy: function copy(source, recursive) {
  5471. if (recursive === void 0) {
  5472. recursive = true;
  5473. }
  5474. this.name = source.name;
  5475. this.up.copy(source.up);
  5476. this.position.copy(source.position);
  5477. this.rotation.order = source.rotation.order;
  5478. this.quaternion.copy(source.quaternion);
  5479. this.scale.copy(source.scale);
  5480. this.matrix.copy(source.matrix);
  5481. this.matrixWorld.copy(source.matrixWorld);
  5482. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5483. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5484. this.layers.mask = source.layers.mask;
  5485. this.visible = source.visible;
  5486. this.castShadow = source.castShadow;
  5487. this.receiveShadow = source.receiveShadow;
  5488. this.frustumCulled = source.frustumCulled;
  5489. this.renderOrder = source.renderOrder;
  5490. this.userData = JSON.parse(JSON.stringify(source.userData));
  5491. if (recursive === true) {
  5492. for (var i = 0; i < source.children.length; i++) {
  5493. var child = source.children[i];
  5494. this.add(child.clone());
  5495. }
  5496. }
  5497. return this;
  5498. }
  5499. });
  5500. var _vector1 = /*@__PURE__*/new Vector3();
  5501. var _vector2 = /*@__PURE__*/new Vector3();
  5502. var _normalMatrix = /*@__PURE__*/new Matrix3();
  5503. var Plane = /*#__PURE__*/function () {
  5504. function Plane(normal, constant) {
  5505. if (normal === void 0) {
  5506. normal = new Vector3(1, 0, 0);
  5507. }
  5508. if (constant === void 0) {
  5509. constant = 0;
  5510. }
  5511. // normal is assumed to be normalized
  5512. this.normal = normal;
  5513. this.constant = constant;
  5514. }
  5515. var _proto = Plane.prototype;
  5516. _proto.set = function set(normal, constant) {
  5517. this.normal.copy(normal);
  5518. this.constant = constant;
  5519. return this;
  5520. };
  5521. _proto.setComponents = function setComponents(x, y, z, w) {
  5522. this.normal.set(x, y, z);
  5523. this.constant = w;
  5524. return this;
  5525. };
  5526. _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
  5527. this.normal.copy(normal);
  5528. this.constant = -point.dot(this.normal);
  5529. return this;
  5530. };
  5531. _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
  5532. 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)?
  5533. this.setFromNormalAndCoplanarPoint(normal, a);
  5534. return this;
  5535. };
  5536. _proto.copy = function copy(plane) {
  5537. this.normal.copy(plane.normal);
  5538. this.constant = plane.constant;
  5539. return this;
  5540. };
  5541. _proto.normalize = function normalize() {
  5542. // Note: will lead to a divide by zero if the plane is invalid.
  5543. var inverseNormalLength = 1.0 / this.normal.length();
  5544. this.normal.multiplyScalar(inverseNormalLength);
  5545. this.constant *= inverseNormalLength;
  5546. return this;
  5547. };
  5548. _proto.negate = function negate() {
  5549. this.constant *= -1;
  5550. this.normal.negate();
  5551. return this;
  5552. };
  5553. _proto.distanceToPoint = function distanceToPoint(point) {
  5554. return this.normal.dot(point) + this.constant;
  5555. };
  5556. _proto.distanceToSphere = function distanceToSphere(sphere) {
  5557. return this.distanceToPoint(sphere.center) - sphere.radius;
  5558. };
  5559. _proto.projectPoint = function projectPoint(point, target) {
  5560. if (target === undefined) {
  5561. console.warn('THREE.Plane: .projectPoint() target is now required');
  5562. target = new Vector3();
  5563. }
  5564. return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
  5565. };
  5566. _proto.intersectLine = function intersectLine(line, target) {
  5567. if (target === undefined) {
  5568. console.warn('THREE.Plane: .intersectLine() target is now required');
  5569. target = new Vector3();
  5570. }
  5571. var direction = line.delta(_vector1);
  5572. var denominator = this.normal.dot(direction);
  5573. if (denominator === 0) {
  5574. // line is coplanar, return origin
  5575. if (this.distanceToPoint(line.start) === 0) {
  5576. return target.copy(line.start);
  5577. } // Unsure if this is the correct method to handle this case.
  5578. return undefined;
  5579. }
  5580. var t = -(line.start.dot(this.normal) + this.constant) / denominator;
  5581. if (t < 0 || t > 1) {
  5582. return undefined;
  5583. }
  5584. return target.copy(direction).multiplyScalar(t).add(line.start);
  5585. };
  5586. _proto.intersectsLine = function intersectsLine(line) {
  5587. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  5588. var startSign = this.distanceToPoint(line.start);
  5589. var endSign = this.distanceToPoint(line.end);
  5590. return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
  5591. };
  5592. _proto.intersectsBox = function intersectsBox(box) {
  5593. return box.intersectsPlane(this);
  5594. };
  5595. _proto.intersectsSphere = function intersectsSphere(sphere) {
  5596. return sphere.intersectsPlane(this);
  5597. };
  5598. _proto.coplanarPoint = function coplanarPoint(target) {
  5599. if (target === undefined) {
  5600. console.warn('THREE.Plane: .coplanarPoint() target is now required');
  5601. target = new Vector3();
  5602. }
  5603. return target.copy(this.normal).multiplyScalar(-this.constant);
  5604. };
  5605. _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
  5606. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
  5607. var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
  5608. var normal = this.normal.applyMatrix3(normalMatrix).normalize();
  5609. this.constant = -referencePoint.dot(normal);
  5610. return this;
  5611. };
  5612. _proto.translate = function translate(offset) {
  5613. this.constant -= offset.dot(this.normal);
  5614. return this;
  5615. };
  5616. _proto.equals = function equals(plane) {
  5617. return plane.normal.equals(this.normal) && plane.constant === this.constant;
  5618. };
  5619. _proto.clone = function clone() {
  5620. return new this.constructor().copy(this);
  5621. };
  5622. return Plane;
  5623. }();
  5624. Plane.prototype.isPlane = true;
  5625. var _v0$1 = /*@__PURE__*/new Vector3();
  5626. var _v1$3 = /*@__PURE__*/new Vector3();
  5627. var _v2$1 = /*@__PURE__*/new Vector3();
  5628. var _v3 = /*@__PURE__*/new Vector3();
  5629. var _vab = /*@__PURE__*/new Vector3();
  5630. var _vac = /*@__PURE__*/new Vector3();
  5631. var _vbc = /*@__PURE__*/new Vector3();
  5632. var _vap = /*@__PURE__*/new Vector3();
  5633. var _vbp = /*@__PURE__*/new Vector3();
  5634. var _vcp = /*@__PURE__*/new Vector3();
  5635. var Triangle = /*#__PURE__*/function () {
  5636. function Triangle(a, b, c) {
  5637. if (a === void 0) {
  5638. a = new Vector3();
  5639. }
  5640. if (b === void 0) {
  5641. b = new Vector3();
  5642. }
  5643. if (c === void 0) {
  5644. c = new Vector3();
  5645. }
  5646. this.a = a;
  5647. this.b = b;
  5648. this.c = c;
  5649. }
  5650. Triangle.getNormal = function getNormal(a, b, c, target) {
  5651. if (target === undefined) {
  5652. console.warn('THREE.Triangle: .getNormal() target is now required');
  5653. target = new Vector3();
  5654. }
  5655. target.subVectors(c, b);
  5656. _v0$1.subVectors(a, b);
  5657. target.cross(_v0$1);
  5658. var targetLengthSq = target.lengthSq();
  5659. if (targetLengthSq > 0) {
  5660. return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
  5661. }
  5662. return target.set(0, 0, 0);
  5663. } // static/instance method to calculate barycentric coordinates
  5664. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  5665. ;
  5666. Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
  5667. _v0$1.subVectors(c, a);
  5668. _v1$3.subVectors(b, a);
  5669. _v2$1.subVectors(point, a);
  5670. var dot00 = _v0$1.dot(_v0$1);
  5671. var dot01 = _v0$1.dot(_v1$3);
  5672. var dot02 = _v0$1.dot(_v2$1);
  5673. var dot11 = _v1$3.dot(_v1$3);
  5674. var dot12 = _v1$3.dot(_v2$1);
  5675. var denom = dot00 * dot11 - dot01 * dot01;
  5676. if (target === undefined) {
  5677. console.warn('THREE.Triangle: .getBarycoord() target is now required');
  5678. target = new Vector3();
  5679. } // collinear or singular triangle
  5680. if (denom === 0) {
  5681. // arbitrary location outside of triangle?
  5682. // not sure if this is the best idea, maybe should be returning undefined
  5683. return target.set(-2, -1, -1);
  5684. }
  5685. var invDenom = 1 / denom;
  5686. var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  5687. var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
  5688. return target.set(1 - u - v, v, u);
  5689. };
  5690. Triangle.containsPoint = function containsPoint(point, a, b, c) {
  5691. this.getBarycoord(point, a, b, c, _v3);
  5692. return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
  5693. };
  5694. Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
  5695. this.getBarycoord(point, p1, p2, p3, _v3);
  5696. target.set(0, 0);
  5697. target.addScaledVector(uv1, _v3.x);
  5698. target.addScaledVector(uv2, _v3.y);
  5699. target.addScaledVector(uv3, _v3.z);
  5700. return target;
  5701. };
  5702. Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
  5703. _v0$1.subVectors(c, b);
  5704. _v1$3.subVectors(a, b); // strictly front facing
  5705. return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
  5706. };
  5707. var _proto = Triangle.prototype;
  5708. _proto.set = function set(a, b, c) {
  5709. this.a.copy(a);
  5710. this.b.copy(b);
  5711. this.c.copy(c);
  5712. return this;
  5713. };
  5714. _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
  5715. this.a.copy(points[i0]);
  5716. this.b.copy(points[i1]);
  5717. this.c.copy(points[i2]);
  5718. return this;
  5719. };
  5720. _proto.clone = function clone() {
  5721. return new this.constructor().copy(this);
  5722. };
  5723. _proto.copy = function copy(triangle) {
  5724. this.a.copy(triangle.a);
  5725. this.b.copy(triangle.b);
  5726. this.c.copy(triangle.c);
  5727. return this;
  5728. };
  5729. _proto.getArea = function getArea() {
  5730. _v0$1.subVectors(this.c, this.b);
  5731. _v1$3.subVectors(this.a, this.b);
  5732. return _v0$1.cross(_v1$3).length() * 0.5;
  5733. };
  5734. _proto.getMidpoint = function getMidpoint(target) {
  5735. if (target === undefined) {
  5736. console.warn('THREE.Triangle: .getMidpoint() target is now required');
  5737. target = new Vector3();
  5738. }
  5739. return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  5740. };
  5741. _proto.getNormal = function getNormal(target) {
  5742. return Triangle.getNormal(this.a, this.b, this.c, target);
  5743. };
  5744. _proto.getPlane = function getPlane(target) {
  5745. if (target === undefined) {
  5746. console.warn('THREE.Triangle: .getPlane() target is now required');
  5747. target = new Plane();
  5748. }
  5749. return target.setFromCoplanarPoints(this.a, this.b, this.c);
  5750. };
  5751. _proto.getBarycoord = function getBarycoord(point, target) {
  5752. return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
  5753. };
  5754. _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
  5755. return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
  5756. };
  5757. _proto.containsPoint = function containsPoint(point) {
  5758. return Triangle.containsPoint(point, this.a, this.b, this.c);
  5759. };
  5760. _proto.isFrontFacing = function isFrontFacing(direction) {
  5761. return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
  5762. };
  5763. _proto.intersectsBox = function intersectsBox(box) {
  5764. return box.intersectsTriangle(this);
  5765. };
  5766. _proto.closestPointToPoint = function closestPointToPoint(p, target) {
  5767. if (target === undefined) {
  5768. console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
  5769. target = new Vector3();
  5770. }
  5771. var a = this.a,
  5772. b = this.b,
  5773. c = this.c;
  5774. var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  5775. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  5776. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  5777. // basically, we're distinguishing which of the voronoi regions of the triangle
  5778. // the point lies in with the minimum amount of redundant computation.
  5779. _vab.subVectors(b, a);
  5780. _vac.subVectors(c, a);
  5781. _vap.subVectors(p, a);
  5782. var d1 = _vab.dot(_vap);
  5783. var d2 = _vac.dot(_vap);
  5784. if (d1 <= 0 && d2 <= 0) {
  5785. // vertex region of A; barycentric coords (1, 0, 0)
  5786. return target.copy(a);
  5787. }
  5788. _vbp.subVectors(p, b);
  5789. var d3 = _vab.dot(_vbp);
  5790. var d4 = _vac.dot(_vbp);
  5791. if (d3 >= 0 && d4 <= d3) {
  5792. // vertex region of B; barycentric coords (0, 1, 0)
  5793. return target.copy(b);
  5794. }
  5795. var vc = d1 * d4 - d3 * d2;
  5796. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  5797. v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
  5798. return target.copy(a).addScaledVector(_vab, v);
  5799. }
  5800. _vcp.subVectors(p, c);
  5801. var d5 = _vab.dot(_vcp);
  5802. var d6 = _vac.dot(_vcp);
  5803. if (d6 >= 0 && d5 <= d6) {
  5804. // vertex region of C; barycentric coords (0, 0, 1)
  5805. return target.copy(c);
  5806. }
  5807. var vb = d5 * d2 - d1 * d6;
  5808. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  5809. w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
  5810. return target.copy(a).addScaledVector(_vac, w);
  5811. }
  5812. var va = d3 * d6 - d5 * d4;
  5813. if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
  5814. _vbc.subVectors(c, b);
  5815. w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
  5816. return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
  5817. } // face region
  5818. var denom = 1 / (va + vb + vc); // u = va * denom
  5819. v = vb * denom;
  5820. w = vc * denom;
  5821. return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
  5822. };
  5823. _proto.equals = function equals(triangle) {
  5824. return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
  5825. };
  5826. return Triangle;
  5827. }();
  5828. var materialId = 0;
  5829. function Material() {
  5830. Object.defineProperty(this, 'id', {
  5831. value: materialId++
  5832. });
  5833. this.uuid = MathUtils.generateUUID();
  5834. this.name = '';
  5835. this.type = 'Material';
  5836. this.fog = true;
  5837. this.blending = NormalBlending;
  5838. this.side = FrontSide;
  5839. this.vertexColors = false;
  5840. this.opacity = 1;
  5841. this.transparent = false;
  5842. this.blendSrc = SrcAlphaFactor;
  5843. this.blendDst = OneMinusSrcAlphaFactor;
  5844. this.blendEquation = AddEquation;
  5845. this.blendSrcAlpha = null;
  5846. this.blendDstAlpha = null;
  5847. this.blendEquationAlpha = null;
  5848. this.depthFunc = LessEqualDepth;
  5849. this.depthTest = true;
  5850. this.depthWrite = true;
  5851. this.stencilWriteMask = 0xff;
  5852. this.stencilFunc = AlwaysStencilFunc;
  5853. this.stencilRef = 0;
  5854. this.stencilFuncMask = 0xff;
  5855. this.stencilFail = KeepStencilOp;
  5856. this.stencilZFail = KeepStencilOp;
  5857. this.stencilZPass = KeepStencilOp;
  5858. this.stencilWrite = false;
  5859. this.clippingPlanes = null;
  5860. this.clipIntersection = false;
  5861. this.clipShadows = false;
  5862. this.shadowSide = null;
  5863. this.colorWrite = true;
  5864. this.precision = null; // override the renderer's default precision for this material
  5865. this.polygonOffset = false;
  5866. this.polygonOffsetFactor = 0;
  5867. this.polygonOffsetUnits = 0;
  5868. this.dithering = false;
  5869. this.alphaTest = 0;
  5870. this.premultipliedAlpha = false;
  5871. this.visible = true;
  5872. this.toneMapped = true;
  5873. this.userData = {};
  5874. this.version = 0;
  5875. }
  5876. Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5877. constructor: Material,
  5878. isMaterial: true,
  5879. onBeforeCompile: function onBeforeCompile()
  5880. /* shaderobject, renderer */
  5881. {},
  5882. customProgramCacheKey: function customProgramCacheKey() {
  5883. return this.onBeforeCompile.toString();
  5884. },
  5885. setValues: function setValues(values) {
  5886. if (values === undefined) return;
  5887. for (var key in values) {
  5888. var newValue = values[key];
  5889. if (newValue === undefined) {
  5890. console.warn('THREE.Material: \'' + key + '\' parameter is undefined.');
  5891. continue;
  5892. } // for backward compatability if shading is set in the constructor
  5893. if (key === 'shading') {
  5894. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  5895. this.flatShading = newValue === FlatShading ? true : false;
  5896. continue;
  5897. }
  5898. var currentValue = this[key];
  5899. if (currentValue === undefined) {
  5900. console.warn('THREE.' + this.type + ': \'' + key + '\' is not a property of this material.');
  5901. continue;
  5902. }
  5903. if (currentValue && currentValue.isColor) {
  5904. currentValue.set(newValue);
  5905. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  5906. currentValue.copy(newValue);
  5907. } else {
  5908. this[key] = newValue;
  5909. }
  5910. }
  5911. },
  5912. toJSON: function toJSON(meta) {
  5913. var isRoot = meta === undefined || typeof meta === 'string';
  5914. if (isRoot) {
  5915. meta = {
  5916. textures: {},
  5917. images: {}
  5918. };
  5919. }
  5920. var data = {
  5921. metadata: {
  5922. version: 4.5,
  5923. type: 'Material',
  5924. generator: 'Material.toJSON'
  5925. }
  5926. }; // standard Material serialization
  5927. data.uuid = this.uuid;
  5928. data.type = this.type;
  5929. if (this.name !== '') data.name = this.name;
  5930. if (this.color && this.color.isColor) data.color = this.color.getHex();
  5931. if (this.roughness !== undefined) data.roughness = this.roughness;
  5932. if (this.metalness !== undefined) data.metalness = this.metalness;
  5933. if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
  5934. if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
  5935. if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
  5936. if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
  5937. if (this.shininess !== undefined) data.shininess = this.shininess;
  5938. if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
  5939. if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
  5940. if (this.clearcoatMap && this.clearcoatMap.isTexture) {
  5941. data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
  5942. }
  5943. if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
  5944. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
  5945. }
  5946. if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
  5947. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
  5948. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5949. }
  5950. if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
  5951. if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
  5952. if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
  5953. if (this.lightMap && this.lightMap.isTexture) {
  5954. data.lightMap = this.lightMap.toJSON(meta).uuid;
  5955. data.lightMapIntensity = this.lightMapIntensity;
  5956. }
  5957. if (this.aoMap && this.aoMap.isTexture) {
  5958. data.aoMap = this.aoMap.toJSON(meta).uuid;
  5959. data.aoMapIntensity = this.aoMapIntensity;
  5960. }
  5961. if (this.bumpMap && this.bumpMap.isTexture) {
  5962. data.bumpMap = this.bumpMap.toJSON(meta).uuid;
  5963. data.bumpScale = this.bumpScale;
  5964. }
  5965. if (this.normalMap && this.normalMap.isTexture) {
  5966. data.normalMap = this.normalMap.toJSON(meta).uuid;
  5967. data.normalMapType = this.normalMapType;
  5968. data.normalScale = this.normalScale.toArray();
  5969. }
  5970. if (this.displacementMap && this.displacementMap.isTexture) {
  5971. data.displacementMap = this.displacementMap.toJSON(meta).uuid;
  5972. data.displacementScale = this.displacementScale;
  5973. data.displacementBias = this.displacementBias;
  5974. }
  5975. if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
  5976. if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
  5977. if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
  5978. if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
  5979. if (this.envMap && this.envMap.isTexture) {
  5980. data.envMap = this.envMap.toJSON(meta).uuid;
  5981. data.reflectivity = this.reflectivity; // Scale behind envMap
  5982. data.refractionRatio = this.refractionRatio;
  5983. if (this.combine !== undefined) data.combine = this.combine;
  5984. if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
  5985. }
  5986. if (this.gradientMap && this.gradientMap.isTexture) {
  5987. data.gradientMap = this.gradientMap.toJSON(meta).uuid;
  5988. }
  5989. if (this.size !== undefined) data.size = this.size;
  5990. if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
  5991. if (this.blending !== NormalBlending) data.blending = this.blending;
  5992. if (this.side !== FrontSide) data.side = this.side;
  5993. if (this.vertexColors) data.vertexColors = true;
  5994. if (this.opacity < 1) data.opacity = this.opacity;
  5995. if (this.transparent === true) data.transparent = this.transparent;
  5996. data.depthFunc = this.depthFunc;
  5997. data.depthTest = this.depthTest;
  5998. data.depthWrite = this.depthWrite;
  5999. data.stencilWrite = this.stencilWrite;
  6000. data.stencilWriteMask = this.stencilWriteMask;
  6001. data.stencilFunc = this.stencilFunc;
  6002. data.stencilRef = this.stencilRef;
  6003. data.stencilFuncMask = this.stencilFuncMask;
  6004. data.stencilFail = this.stencilFail;
  6005. data.stencilZFail = this.stencilZFail;
  6006. data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
  6007. if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
  6008. if (this.polygonOffset === true) data.polygonOffset = true;
  6009. if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
  6010. if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
  6011. if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
  6012. if (this.dashSize !== undefined) data.dashSize = this.dashSize;
  6013. if (this.gapSize !== undefined) data.gapSize = this.gapSize;
  6014. if (this.scale !== undefined) data.scale = this.scale;
  6015. if (this.dithering === true) data.dithering = true;
  6016. if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
  6017. if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
  6018. if (this.wireframe === true) data.wireframe = this.wireframe;
  6019. if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
  6020. if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
  6021. if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
  6022. if (this.morphTargets === true) data.morphTargets = true;
  6023. if (this.morphNormals === true) data.morphNormals = true;
  6024. if (this.skinning === true) data.skinning = true;
  6025. if (this.flatShading === true) data.flatShading = this.flatShading;
  6026. if (this.visible === false) data.visible = false;
  6027. if (this.toneMapped === false) data.toneMapped = false;
  6028. if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
  6029. function extractFromCache(cache) {
  6030. var values = [];
  6031. for (var key in cache) {
  6032. var _data = cache[key];
  6033. delete _data.metadata;
  6034. values.push(_data);
  6035. }
  6036. return values;
  6037. }
  6038. if (isRoot) {
  6039. var textures = extractFromCache(meta.textures);
  6040. var images = extractFromCache(meta.images);
  6041. if (textures.length > 0) data.textures = textures;
  6042. if (images.length > 0) data.images = images;
  6043. }
  6044. return data;
  6045. },
  6046. clone: function clone() {
  6047. return new this.constructor().copy(this);
  6048. },
  6049. copy: function copy(source) {
  6050. this.name = source.name;
  6051. this.fog = source.fog;
  6052. this.blending = source.blending;
  6053. this.side = source.side;
  6054. this.vertexColors = source.vertexColors;
  6055. this.opacity = source.opacity;
  6056. this.transparent = source.transparent;
  6057. this.blendSrc = source.blendSrc;
  6058. this.blendDst = source.blendDst;
  6059. this.blendEquation = source.blendEquation;
  6060. this.blendSrcAlpha = source.blendSrcAlpha;
  6061. this.blendDstAlpha = source.blendDstAlpha;
  6062. this.blendEquationAlpha = source.blendEquationAlpha;
  6063. this.depthFunc = source.depthFunc;
  6064. this.depthTest = source.depthTest;
  6065. this.depthWrite = source.depthWrite;
  6066. this.stencilWriteMask = source.stencilWriteMask;
  6067. this.stencilFunc = source.stencilFunc;
  6068. this.stencilRef = source.stencilRef;
  6069. this.stencilFuncMask = source.stencilFuncMask;
  6070. this.stencilFail = source.stencilFail;
  6071. this.stencilZFail = source.stencilZFail;
  6072. this.stencilZPass = source.stencilZPass;
  6073. this.stencilWrite = source.stencilWrite;
  6074. var srcPlanes = source.clippingPlanes;
  6075. var dstPlanes = null;
  6076. if (srcPlanes !== null) {
  6077. var n = srcPlanes.length;
  6078. dstPlanes = new Array(n);
  6079. for (var i = 0; i !== n; ++i) {
  6080. dstPlanes[i] = srcPlanes[i].clone();
  6081. }
  6082. }
  6083. this.clippingPlanes = dstPlanes;
  6084. this.clipIntersection = source.clipIntersection;
  6085. this.clipShadows = source.clipShadows;
  6086. this.shadowSide = source.shadowSide;
  6087. this.colorWrite = source.colorWrite;
  6088. this.precision = source.precision;
  6089. this.polygonOffset = source.polygonOffset;
  6090. this.polygonOffsetFactor = source.polygonOffsetFactor;
  6091. this.polygonOffsetUnits = source.polygonOffsetUnits;
  6092. this.dithering = source.dithering;
  6093. this.alphaTest = source.alphaTest;
  6094. this.premultipliedAlpha = source.premultipliedAlpha;
  6095. this.visible = source.visible;
  6096. this.toneMapped = source.toneMapped;
  6097. this.userData = JSON.parse(JSON.stringify(source.userData));
  6098. return this;
  6099. },
  6100. dispose: function dispose() {
  6101. this.dispatchEvent({
  6102. type: 'dispose'
  6103. });
  6104. }
  6105. });
  6106. Object.defineProperty(Material.prototype, 'needsUpdate', {
  6107. set: function set(value) {
  6108. if (value === true) this.version++;
  6109. }
  6110. });
  6111. var _colorKeywords = {
  6112. 'aliceblue': 0xF0F8FF,
  6113. 'antiquewhite': 0xFAEBD7,
  6114. 'aqua': 0x00FFFF,
  6115. 'aquamarine': 0x7FFFD4,
  6116. 'azure': 0xF0FFFF,
  6117. 'beige': 0xF5F5DC,
  6118. 'bisque': 0xFFE4C4,
  6119. 'black': 0x000000,
  6120. 'blanchedalmond': 0xFFEBCD,
  6121. 'blue': 0x0000FF,
  6122. 'blueviolet': 0x8A2BE2,
  6123. 'brown': 0xA52A2A,
  6124. 'burlywood': 0xDEB887,
  6125. 'cadetblue': 0x5F9EA0,
  6126. 'chartreuse': 0x7FFF00,
  6127. 'chocolate': 0xD2691E,
  6128. 'coral': 0xFF7F50,
  6129. 'cornflowerblue': 0x6495ED,
  6130. 'cornsilk': 0xFFF8DC,
  6131. 'crimson': 0xDC143C,
  6132. 'cyan': 0x00FFFF,
  6133. 'darkblue': 0x00008B,
  6134. 'darkcyan': 0x008B8B,
  6135. 'darkgoldenrod': 0xB8860B,
  6136. 'darkgray': 0xA9A9A9,
  6137. 'darkgreen': 0x006400,
  6138. 'darkgrey': 0xA9A9A9,
  6139. 'darkkhaki': 0xBDB76B,
  6140. 'darkmagenta': 0x8B008B,
  6141. 'darkolivegreen': 0x556B2F,
  6142. 'darkorange': 0xFF8C00,
  6143. 'darkorchid': 0x9932CC,
  6144. 'darkred': 0x8B0000,
  6145. 'darksalmon': 0xE9967A,
  6146. 'darkseagreen': 0x8FBC8F,
  6147. 'darkslateblue': 0x483D8B,
  6148. 'darkslategray': 0x2F4F4F,
  6149. 'darkslategrey': 0x2F4F4F,
  6150. 'darkturquoise': 0x00CED1,
  6151. 'darkviolet': 0x9400D3,
  6152. 'deeppink': 0xFF1493,
  6153. 'deepskyblue': 0x00BFFF,
  6154. 'dimgray': 0x696969,
  6155. 'dimgrey': 0x696969,
  6156. 'dodgerblue': 0x1E90FF,
  6157. 'firebrick': 0xB22222,
  6158. 'floralwhite': 0xFFFAF0,
  6159. 'forestgreen': 0x228B22,
  6160. 'fuchsia': 0xFF00FF,
  6161. 'gainsboro': 0xDCDCDC,
  6162. 'ghostwhite': 0xF8F8FF,
  6163. 'gold': 0xFFD700,
  6164. 'goldenrod': 0xDAA520,
  6165. 'gray': 0x808080,
  6166. 'green': 0x008000,
  6167. 'greenyellow': 0xADFF2F,
  6168. 'grey': 0x808080,
  6169. 'honeydew': 0xF0FFF0,
  6170. 'hotpink': 0xFF69B4,
  6171. 'indianred': 0xCD5C5C,
  6172. 'indigo': 0x4B0082,
  6173. 'ivory': 0xFFFFF0,
  6174. 'khaki': 0xF0E68C,
  6175. 'lavender': 0xE6E6FA,
  6176. 'lavenderblush': 0xFFF0F5,
  6177. 'lawngreen': 0x7CFC00,
  6178. 'lemonchiffon': 0xFFFACD,
  6179. 'lightblue': 0xADD8E6,
  6180. 'lightcoral': 0xF08080,
  6181. 'lightcyan': 0xE0FFFF,
  6182. 'lightgoldenrodyellow': 0xFAFAD2,
  6183. 'lightgray': 0xD3D3D3,
  6184. 'lightgreen': 0x90EE90,
  6185. 'lightgrey': 0xD3D3D3,
  6186. 'lightpink': 0xFFB6C1,
  6187. 'lightsalmon': 0xFFA07A,
  6188. 'lightseagreen': 0x20B2AA,
  6189. 'lightskyblue': 0x87CEFA,
  6190. 'lightslategray': 0x778899,
  6191. 'lightslategrey': 0x778899,
  6192. 'lightsteelblue': 0xB0C4DE,
  6193. 'lightyellow': 0xFFFFE0,
  6194. 'lime': 0x00FF00,
  6195. 'limegreen': 0x32CD32,
  6196. 'linen': 0xFAF0E6,
  6197. 'magenta': 0xFF00FF,
  6198. 'maroon': 0x800000,
  6199. 'mediumaquamarine': 0x66CDAA,
  6200. 'mediumblue': 0x0000CD,
  6201. 'mediumorchid': 0xBA55D3,
  6202. 'mediumpurple': 0x9370DB,
  6203. 'mediumseagreen': 0x3CB371,
  6204. 'mediumslateblue': 0x7B68EE,
  6205. 'mediumspringgreen': 0x00FA9A,
  6206. 'mediumturquoise': 0x48D1CC,
  6207. 'mediumvioletred': 0xC71585,
  6208. 'midnightblue': 0x191970,
  6209. 'mintcream': 0xF5FFFA,
  6210. 'mistyrose': 0xFFE4E1,
  6211. 'moccasin': 0xFFE4B5,
  6212. 'navajowhite': 0xFFDEAD,
  6213. 'navy': 0x000080,
  6214. 'oldlace': 0xFDF5E6,
  6215. 'olive': 0x808000,
  6216. 'olivedrab': 0x6B8E23,
  6217. 'orange': 0xFFA500,
  6218. 'orangered': 0xFF4500,
  6219. 'orchid': 0xDA70D6,
  6220. 'palegoldenrod': 0xEEE8AA,
  6221. 'palegreen': 0x98FB98,
  6222. 'paleturquoise': 0xAFEEEE,
  6223. 'palevioletred': 0xDB7093,
  6224. 'papayawhip': 0xFFEFD5,
  6225. 'peachpuff': 0xFFDAB9,
  6226. 'peru': 0xCD853F,
  6227. 'pink': 0xFFC0CB,
  6228. 'plum': 0xDDA0DD,
  6229. 'powderblue': 0xB0E0E6,
  6230. 'purple': 0x800080,
  6231. 'rebeccapurple': 0x663399,
  6232. 'red': 0xFF0000,
  6233. 'rosybrown': 0xBC8F8F,
  6234. 'royalblue': 0x4169E1,
  6235. 'saddlebrown': 0x8B4513,
  6236. 'salmon': 0xFA8072,
  6237. 'sandybrown': 0xF4A460,
  6238. 'seagreen': 0x2E8B57,
  6239. 'seashell': 0xFFF5EE,
  6240. 'sienna': 0xA0522D,
  6241. 'silver': 0xC0C0C0,
  6242. 'skyblue': 0x87CEEB,
  6243. 'slateblue': 0x6A5ACD,
  6244. 'slategray': 0x708090,
  6245. 'slategrey': 0x708090,
  6246. 'snow': 0xFFFAFA,
  6247. 'springgreen': 0x00FF7F,
  6248. 'steelblue': 0x4682B4,
  6249. 'tan': 0xD2B48C,
  6250. 'teal': 0x008080,
  6251. 'thistle': 0xD8BFD8,
  6252. 'tomato': 0xFF6347,
  6253. 'turquoise': 0x40E0D0,
  6254. 'violet': 0xEE82EE,
  6255. 'wheat': 0xF5DEB3,
  6256. 'white': 0xFFFFFF,
  6257. 'whitesmoke': 0xF5F5F5,
  6258. 'yellow': 0xFFFF00,
  6259. 'yellowgreen': 0x9ACD32
  6260. };
  6261. var _hslA = {
  6262. h: 0,
  6263. s: 0,
  6264. l: 0
  6265. };
  6266. var _hslB = {
  6267. h: 0,
  6268. s: 0,
  6269. l: 0
  6270. };
  6271. function hue2rgb(p, q, t) {
  6272. if (t < 0) t += 1;
  6273. if (t > 1) t -= 1;
  6274. if (t < 1 / 6) return p + (q - p) * 6 * t;
  6275. if (t < 1 / 2) return q;
  6276. if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  6277. return p;
  6278. }
  6279. function SRGBToLinear(c) {
  6280. return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
  6281. }
  6282. function LinearToSRGB(c) {
  6283. return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
  6284. }
  6285. var Color = /*#__PURE__*/function () {
  6286. function Color(r, g, b) {
  6287. if (g === undefined && b === undefined) {
  6288. // r is THREE.Color, hex or string
  6289. return this.set(r);
  6290. }
  6291. return this.setRGB(r, g, b);
  6292. }
  6293. var _proto = Color.prototype;
  6294. _proto.set = function set(value) {
  6295. if (value && value.isColor) {
  6296. this.copy(value);
  6297. } else if (typeof value === 'number') {
  6298. this.setHex(value);
  6299. } else if (typeof value === 'string') {
  6300. this.setStyle(value);
  6301. }
  6302. return this;
  6303. };
  6304. _proto.setScalar = function setScalar(scalar) {
  6305. this.r = scalar;
  6306. this.g = scalar;
  6307. this.b = scalar;
  6308. return this;
  6309. };
  6310. _proto.setHex = function setHex(hex) {
  6311. hex = Math.floor(hex);
  6312. this.r = (hex >> 16 & 255) / 255;
  6313. this.g = (hex >> 8 & 255) / 255;
  6314. this.b = (hex & 255) / 255;
  6315. return this;
  6316. };
  6317. _proto.setRGB = function setRGB(r, g, b) {
  6318. this.r = r;
  6319. this.g = g;
  6320. this.b = b;
  6321. return this;
  6322. };
  6323. _proto.setHSL = function setHSL(h, s, l) {
  6324. // h,s,l ranges are in 0.0 - 1.0
  6325. h = MathUtils.euclideanModulo(h, 1);
  6326. s = MathUtils.clamp(s, 0, 1);
  6327. l = MathUtils.clamp(l, 0, 1);
  6328. if (s === 0) {
  6329. this.r = this.g = this.b = l;
  6330. } else {
  6331. var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  6332. var q = 2 * l - p;
  6333. this.r = hue2rgb(q, p, h + 1 / 3);
  6334. this.g = hue2rgb(q, p, h);
  6335. this.b = hue2rgb(q, p, h - 1 / 3);
  6336. }
  6337. return this;
  6338. };
  6339. _proto.setStyle = function setStyle(style) {
  6340. function handleAlpha(string) {
  6341. if (string === undefined) return;
  6342. if (parseFloat(string) < 1) {
  6343. console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
  6344. }
  6345. }
  6346. var m;
  6347. if (m = /^((?:rgb|hsl)a?)\(([^\)]*)\)/.exec(style)) {
  6348. // rgb / hsl
  6349. var color;
  6350. var name = m[1];
  6351. var components = m[2];
  6352. switch (name) {
  6353. case 'rgb':
  6354. case 'rgba':
  6355. if (color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6356. // rgb(255,0,0) rgba(255,0,0,0.5)
  6357. this.r = Math.min(255, parseInt(color[1], 10)) / 255;
  6358. this.g = Math.min(255, parseInt(color[2], 10)) / 255;
  6359. this.b = Math.min(255, parseInt(color[3], 10)) / 255;
  6360. handleAlpha(color[4]);
  6361. return this;
  6362. }
  6363. if (color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6364. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  6365. this.r = Math.min(100, parseInt(color[1], 10)) / 100;
  6366. this.g = Math.min(100, parseInt(color[2], 10)) / 100;
  6367. this.b = Math.min(100, parseInt(color[3], 10)) / 100;
  6368. handleAlpha(color[4]);
  6369. return this;
  6370. }
  6371. break;
  6372. case 'hsl':
  6373. case 'hsla':
  6374. if (color = /^\s*(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6375. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  6376. var h = parseFloat(color[1]) / 360;
  6377. var s = parseInt(color[2], 10) / 100;
  6378. var l = parseInt(color[3], 10) / 100;
  6379. handleAlpha(color[4]);
  6380. return this.setHSL(h, s, l);
  6381. }
  6382. break;
  6383. }
  6384. } else if (m = /^\#([A-Fa-f\d]+)$/.exec(style)) {
  6385. // hex color
  6386. var hex = m[1];
  6387. var size = hex.length;
  6388. if (size === 3) {
  6389. // #ff0
  6390. this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
  6391. this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
  6392. this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
  6393. return this;
  6394. } else if (size === 6) {
  6395. // #ff0000
  6396. this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
  6397. this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
  6398. this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
  6399. return this;
  6400. }
  6401. }
  6402. if (style && style.length > 0) {
  6403. return this.setColorName(style);
  6404. }
  6405. return this;
  6406. };
  6407. _proto.setColorName = function setColorName(style) {
  6408. // color keywords
  6409. var hex = _colorKeywords[style];
  6410. if (hex !== undefined) {
  6411. // red
  6412. this.setHex(hex);
  6413. } else {
  6414. // unknown color
  6415. console.warn('THREE.Color: Unknown color ' + style);
  6416. }
  6417. return this;
  6418. };
  6419. _proto.clone = function clone() {
  6420. return new this.constructor(this.r, this.g, this.b);
  6421. };
  6422. _proto.copy = function copy(color) {
  6423. this.r = color.r;
  6424. this.g = color.g;
  6425. this.b = color.b;
  6426. return this;
  6427. };
  6428. _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
  6429. if (gammaFactor === void 0) {
  6430. gammaFactor = 2.0;
  6431. }
  6432. this.r = Math.pow(color.r, gammaFactor);
  6433. this.g = Math.pow(color.g, gammaFactor);
  6434. this.b = Math.pow(color.b, gammaFactor);
  6435. return this;
  6436. };
  6437. _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
  6438. if (gammaFactor === void 0) {
  6439. gammaFactor = 2.0;
  6440. }
  6441. var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
  6442. this.r = Math.pow(color.r, safeInverse);
  6443. this.g = Math.pow(color.g, safeInverse);
  6444. this.b = Math.pow(color.b, safeInverse);
  6445. return this;
  6446. };
  6447. _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
  6448. this.copyGammaToLinear(this, gammaFactor);
  6449. return this;
  6450. };
  6451. _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
  6452. this.copyLinearToGamma(this, gammaFactor);
  6453. return this;
  6454. };
  6455. _proto.copySRGBToLinear = function copySRGBToLinear(color) {
  6456. this.r = SRGBToLinear(color.r);
  6457. this.g = SRGBToLinear(color.g);
  6458. this.b = SRGBToLinear(color.b);
  6459. return this;
  6460. };
  6461. _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
  6462. this.r = LinearToSRGB(color.r);
  6463. this.g = LinearToSRGB(color.g);
  6464. this.b = LinearToSRGB(color.b);
  6465. return this;
  6466. };
  6467. _proto.convertSRGBToLinear = function convertSRGBToLinear() {
  6468. this.copySRGBToLinear(this);
  6469. return this;
  6470. };
  6471. _proto.convertLinearToSRGB = function convertLinearToSRGB() {
  6472. this.copyLinearToSRGB(this);
  6473. return this;
  6474. };
  6475. _proto.getHex = function getHex() {
  6476. return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
  6477. };
  6478. _proto.getHexString = function getHexString() {
  6479. return ('000000' + this.getHex().toString(16)).slice(-6);
  6480. };
  6481. _proto.getHSL = function getHSL(target) {
  6482. // h,s,l ranges are in 0.0 - 1.0
  6483. if (target === undefined) {
  6484. console.warn('THREE.Color: .getHSL() target is now required');
  6485. target = {
  6486. h: 0,
  6487. s: 0,
  6488. l: 0
  6489. };
  6490. }
  6491. var r = this.r,
  6492. g = this.g,
  6493. b = this.b;
  6494. var max = Math.max(r, g, b);
  6495. var min = Math.min(r, g, b);
  6496. var hue, saturation;
  6497. var lightness = (min + max) / 2.0;
  6498. if (min === max) {
  6499. hue = 0;
  6500. saturation = 0;
  6501. } else {
  6502. var delta = max - min;
  6503. saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
  6504. switch (max) {
  6505. case r:
  6506. hue = (g - b) / delta + (g < b ? 6 : 0);
  6507. break;
  6508. case g:
  6509. hue = (b - r) / delta + 2;
  6510. break;
  6511. case b:
  6512. hue = (r - g) / delta + 4;
  6513. break;
  6514. }
  6515. hue /= 6;
  6516. }
  6517. target.h = hue;
  6518. target.s = saturation;
  6519. target.l = lightness;
  6520. return target;
  6521. };
  6522. _proto.getStyle = function getStyle() {
  6523. return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
  6524. };
  6525. _proto.offsetHSL = function offsetHSL(h, s, l) {
  6526. this.getHSL(_hslA);
  6527. _hslA.h += h;
  6528. _hslA.s += s;
  6529. _hslA.l += l;
  6530. this.setHSL(_hslA.h, _hslA.s, _hslA.l);
  6531. return this;
  6532. };
  6533. _proto.add = function add(color) {
  6534. this.r += color.r;
  6535. this.g += color.g;
  6536. this.b += color.b;
  6537. return this;
  6538. };
  6539. _proto.addColors = function addColors(color1, color2) {
  6540. this.r = color1.r + color2.r;
  6541. this.g = color1.g + color2.g;
  6542. this.b = color1.b + color2.b;
  6543. return this;
  6544. };
  6545. _proto.addScalar = function addScalar(s) {
  6546. this.r += s;
  6547. this.g += s;
  6548. this.b += s;
  6549. return this;
  6550. };
  6551. _proto.sub = function sub(color) {
  6552. this.r = Math.max(0, this.r - color.r);
  6553. this.g = Math.max(0, this.g - color.g);
  6554. this.b = Math.max(0, this.b - color.b);
  6555. return this;
  6556. };
  6557. _proto.multiply = function multiply(color) {
  6558. this.r *= color.r;
  6559. this.g *= color.g;
  6560. this.b *= color.b;
  6561. return this;
  6562. };
  6563. _proto.multiplyScalar = function multiplyScalar(s) {
  6564. this.r *= s;
  6565. this.g *= s;
  6566. this.b *= s;
  6567. return this;
  6568. };
  6569. _proto.lerp = function lerp(color, alpha) {
  6570. this.r += (color.r - this.r) * alpha;
  6571. this.g += (color.g - this.g) * alpha;
  6572. this.b += (color.b - this.b) * alpha;
  6573. return this;
  6574. };
  6575. _proto.lerpColors = function lerpColors(color1, color2, alpha) {
  6576. this.r = color1.r + (color2.r - color1.r) * alpha;
  6577. this.g = color1.g + (color2.g - color1.g) * alpha;
  6578. this.b = color1.b + (color2.b - color1.b) * alpha;
  6579. return this;
  6580. };
  6581. _proto.lerpHSL = function lerpHSL(color, alpha) {
  6582. this.getHSL(_hslA);
  6583. color.getHSL(_hslB);
  6584. var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
  6585. var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
  6586. var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
  6587. this.setHSL(h, s, l);
  6588. return this;
  6589. };
  6590. _proto.equals = function equals(c) {
  6591. return c.r === this.r && c.g === this.g && c.b === this.b;
  6592. };
  6593. _proto.fromArray = function fromArray(array, offset) {
  6594. if (offset === void 0) {
  6595. offset = 0;
  6596. }
  6597. this.r = array[offset];
  6598. this.g = array[offset + 1];
  6599. this.b = array[offset + 2];
  6600. return this;
  6601. };
  6602. _proto.toArray = function toArray(array, offset) {
  6603. if (array === void 0) {
  6604. array = [];
  6605. }
  6606. if (offset === void 0) {
  6607. offset = 0;
  6608. }
  6609. array[offset] = this.r;
  6610. array[offset + 1] = this.g;
  6611. array[offset + 2] = this.b;
  6612. return array;
  6613. };
  6614. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  6615. this.r = attribute.getX(index);
  6616. this.g = attribute.getY(index);
  6617. this.b = attribute.getZ(index);
  6618. if (attribute.normalized === true) {
  6619. // assuming Uint8Array
  6620. this.r /= 255;
  6621. this.g /= 255;
  6622. this.b /= 255;
  6623. }
  6624. return this;
  6625. };
  6626. _proto.toJSON = function toJSON() {
  6627. return this.getHex();
  6628. };
  6629. return Color;
  6630. }();
  6631. Color.NAMES = _colorKeywords;
  6632. Color.prototype.isColor = true;
  6633. Color.prototype.r = 1;
  6634. Color.prototype.g = 1;
  6635. Color.prototype.b = 1;
  6636. /**
  6637. * parameters = {
  6638. * color: <hex>,
  6639. * opacity: <float>,
  6640. * map: new THREE.Texture( <Image> ),
  6641. *
  6642. * lightMap: new THREE.Texture( <Image> ),
  6643. * lightMapIntensity: <float>
  6644. *
  6645. * aoMap: new THREE.Texture( <Image> ),
  6646. * aoMapIntensity: <float>
  6647. *
  6648. * specularMap: new THREE.Texture( <Image> ),
  6649. *
  6650. * alphaMap: new THREE.Texture( <Image> ),
  6651. *
  6652. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  6653. * combine: THREE.Multiply,
  6654. * reflectivity: <float>,
  6655. * refractionRatio: <float>,
  6656. *
  6657. * depthTest: <bool>,
  6658. * depthWrite: <bool>,
  6659. *
  6660. * wireframe: <boolean>,
  6661. * wireframeLinewidth: <float>,
  6662. *
  6663. * skinning: <bool>,
  6664. * morphTargets: <bool>
  6665. * }
  6666. */
  6667. var MeshBasicMaterial = /*#__PURE__*/function (_Material) {
  6668. _inheritsLoose(MeshBasicMaterial, _Material);
  6669. function MeshBasicMaterial(parameters) {
  6670. var _this;
  6671. _this = _Material.call(this) || this;
  6672. _this.type = 'MeshBasicMaterial';
  6673. _this.color = new Color(0xffffff); // emissive
  6674. _this.map = null;
  6675. _this.lightMap = null;
  6676. _this.lightMapIntensity = 1.0;
  6677. _this.aoMap = null;
  6678. _this.aoMapIntensity = 1.0;
  6679. _this.specularMap = null;
  6680. _this.alphaMap = null;
  6681. _this.envMap = null;
  6682. _this.combine = MultiplyOperation;
  6683. _this.reflectivity = 1;
  6684. _this.refractionRatio = 0.98;
  6685. _this.wireframe = false;
  6686. _this.wireframeLinewidth = 1;
  6687. _this.wireframeLinecap = 'round';
  6688. _this.wireframeLinejoin = 'round';
  6689. _this.skinning = false;
  6690. _this.morphTargets = false;
  6691. _this.setValues(parameters);
  6692. return _this;
  6693. }
  6694. var _proto = MeshBasicMaterial.prototype;
  6695. _proto.copy = function copy(source) {
  6696. _Material.prototype.copy.call(this, source);
  6697. this.color.copy(source.color);
  6698. this.map = source.map;
  6699. this.lightMap = source.lightMap;
  6700. this.lightMapIntensity = source.lightMapIntensity;
  6701. this.aoMap = source.aoMap;
  6702. this.aoMapIntensity = source.aoMapIntensity;
  6703. this.specularMap = source.specularMap;
  6704. this.alphaMap = source.alphaMap;
  6705. this.envMap = source.envMap;
  6706. this.combine = source.combine;
  6707. this.reflectivity = source.reflectivity;
  6708. this.refractionRatio = source.refractionRatio;
  6709. this.wireframe = source.wireframe;
  6710. this.wireframeLinewidth = source.wireframeLinewidth;
  6711. this.wireframeLinecap = source.wireframeLinecap;
  6712. this.wireframeLinejoin = source.wireframeLinejoin;
  6713. this.skinning = source.skinning;
  6714. this.morphTargets = source.morphTargets;
  6715. return this;
  6716. };
  6717. return MeshBasicMaterial;
  6718. }(Material);
  6719. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  6720. var _vector$3 = new Vector3();
  6721. var _vector2$1 = new Vector2();
  6722. function BufferAttribute(array, itemSize, normalized) {
  6723. if (Array.isArray(array)) {
  6724. throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
  6725. }
  6726. this.name = '';
  6727. this.array = array;
  6728. this.itemSize = itemSize;
  6729. this.count = array !== undefined ? array.length / itemSize : 0;
  6730. this.normalized = normalized === true;
  6731. this.usage = StaticDrawUsage;
  6732. this.updateRange = {
  6733. offset: 0,
  6734. count: -1
  6735. };
  6736. this.version = 0;
  6737. }
  6738. Object.defineProperty(BufferAttribute.prototype, 'needsUpdate', {
  6739. set: function set(value) {
  6740. if (value === true) this.version++;
  6741. }
  6742. });
  6743. Object.assign(BufferAttribute.prototype, {
  6744. isBufferAttribute: true,
  6745. onUploadCallback: function onUploadCallback() {},
  6746. setUsage: function setUsage(value) {
  6747. this.usage = value;
  6748. return this;
  6749. },
  6750. copy: function copy(source) {
  6751. this.name = source.name;
  6752. this.array = new source.array.constructor(source.array);
  6753. this.itemSize = source.itemSize;
  6754. this.count = source.count;
  6755. this.normalized = source.normalized;
  6756. this.usage = source.usage;
  6757. return this;
  6758. },
  6759. copyAt: function copyAt(index1, attribute, index2) {
  6760. index1 *= this.itemSize;
  6761. index2 *= attribute.itemSize;
  6762. for (var i = 0, l = this.itemSize; i < l; i++) {
  6763. this.array[index1 + i] = attribute.array[index2 + i];
  6764. }
  6765. return this;
  6766. },
  6767. copyArray: function copyArray(array) {
  6768. this.array.set(array);
  6769. return this;
  6770. },
  6771. copyColorsArray: function copyColorsArray(colors) {
  6772. var array = this.array;
  6773. var offset = 0;
  6774. for (var i = 0, l = colors.length; i < l; i++) {
  6775. var color = colors[i];
  6776. if (color === undefined) {
  6777. console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
  6778. color = new Color();
  6779. }
  6780. array[offset++] = color.r;
  6781. array[offset++] = color.g;
  6782. array[offset++] = color.b;
  6783. }
  6784. return this;
  6785. },
  6786. copyVector2sArray: function copyVector2sArray(vectors) {
  6787. var array = this.array;
  6788. var offset = 0;
  6789. for (var i = 0, l = vectors.length; i < l; i++) {
  6790. var vector = vectors[i];
  6791. if (vector === undefined) {
  6792. console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
  6793. vector = new Vector2();
  6794. }
  6795. array[offset++] = vector.x;
  6796. array[offset++] = vector.y;
  6797. }
  6798. return this;
  6799. },
  6800. copyVector3sArray: function copyVector3sArray(vectors) {
  6801. var array = this.array;
  6802. var offset = 0;
  6803. for (var i = 0, l = vectors.length; i < l; i++) {
  6804. var vector = vectors[i];
  6805. if (vector === undefined) {
  6806. console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
  6807. vector = new Vector3();
  6808. }
  6809. array[offset++] = vector.x;
  6810. array[offset++] = vector.y;
  6811. array[offset++] = vector.z;
  6812. }
  6813. return this;
  6814. },
  6815. copyVector4sArray: function copyVector4sArray(vectors) {
  6816. var array = this.array;
  6817. var offset = 0;
  6818. for (var i = 0, l = vectors.length; i < l; i++) {
  6819. var vector = vectors[i];
  6820. if (vector === undefined) {
  6821. console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
  6822. vector = new Vector4();
  6823. }
  6824. array[offset++] = vector.x;
  6825. array[offset++] = vector.y;
  6826. array[offset++] = vector.z;
  6827. array[offset++] = vector.w;
  6828. }
  6829. return this;
  6830. },
  6831. applyMatrix3: function applyMatrix3(m) {
  6832. if (this.itemSize === 2) {
  6833. for (var i = 0, l = this.count; i < l; i++) {
  6834. _vector2$1.fromBufferAttribute(this, i);
  6835. _vector2$1.applyMatrix3(m);
  6836. this.setXY(i, _vector2$1.x, _vector2$1.y);
  6837. }
  6838. } else if (this.itemSize === 3) {
  6839. for (var _i = 0, _l = this.count; _i < _l; _i++) {
  6840. _vector$3.fromBufferAttribute(this, _i);
  6841. _vector$3.applyMatrix3(m);
  6842. this.setXYZ(_i, _vector$3.x, _vector$3.y, _vector$3.z);
  6843. }
  6844. }
  6845. return this;
  6846. },
  6847. applyMatrix4: function applyMatrix4(m) {
  6848. for (var i = 0, l = this.count; i < l; i++) {
  6849. _vector$3.x = this.getX(i);
  6850. _vector$3.y = this.getY(i);
  6851. _vector$3.z = this.getZ(i);
  6852. _vector$3.applyMatrix4(m);
  6853. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6854. }
  6855. return this;
  6856. },
  6857. applyNormalMatrix: function applyNormalMatrix(m) {
  6858. for (var i = 0, l = this.count; i < l; i++) {
  6859. _vector$3.x = this.getX(i);
  6860. _vector$3.y = this.getY(i);
  6861. _vector$3.z = this.getZ(i);
  6862. _vector$3.applyNormalMatrix(m);
  6863. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6864. }
  6865. return this;
  6866. },
  6867. transformDirection: function transformDirection(m) {
  6868. for (var i = 0, l = this.count; i < l; i++) {
  6869. _vector$3.x = this.getX(i);
  6870. _vector$3.y = this.getY(i);
  6871. _vector$3.z = this.getZ(i);
  6872. _vector$3.transformDirection(m);
  6873. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6874. }
  6875. return this;
  6876. },
  6877. set: function set(value, offset) {
  6878. if (offset === void 0) {
  6879. offset = 0;
  6880. }
  6881. this.array.set(value, offset);
  6882. return this;
  6883. },
  6884. getX: function getX(index) {
  6885. return this.array[index * this.itemSize];
  6886. },
  6887. setX: function setX(index, x) {
  6888. this.array[index * this.itemSize] = x;
  6889. return this;
  6890. },
  6891. getY: function getY(index) {
  6892. return this.array[index * this.itemSize + 1];
  6893. },
  6894. setY: function setY(index, y) {
  6895. this.array[index * this.itemSize + 1] = y;
  6896. return this;
  6897. },
  6898. getZ: function getZ(index) {
  6899. return this.array[index * this.itemSize + 2];
  6900. },
  6901. setZ: function setZ(index, z) {
  6902. this.array[index * this.itemSize + 2] = z;
  6903. return this;
  6904. },
  6905. getW: function getW(index) {
  6906. return this.array[index * this.itemSize + 3];
  6907. },
  6908. setW: function setW(index, w) {
  6909. this.array[index * this.itemSize + 3] = w;
  6910. return this;
  6911. },
  6912. setXY: function setXY(index, x, y) {
  6913. index *= this.itemSize;
  6914. this.array[index + 0] = x;
  6915. this.array[index + 1] = y;
  6916. return this;
  6917. },
  6918. setXYZ: function setXYZ(index, x, y, z) {
  6919. index *= this.itemSize;
  6920. this.array[index + 0] = x;
  6921. this.array[index + 1] = y;
  6922. this.array[index + 2] = z;
  6923. return this;
  6924. },
  6925. setXYZW: function setXYZW(index, x, y, z, w) {
  6926. index *= this.itemSize;
  6927. this.array[index + 0] = x;
  6928. this.array[index + 1] = y;
  6929. this.array[index + 2] = z;
  6930. this.array[index + 3] = w;
  6931. return this;
  6932. },
  6933. onUpload: function onUpload(callback) {
  6934. this.onUploadCallback = callback;
  6935. return this;
  6936. },
  6937. clone: function clone() {
  6938. return new this.constructor(this.array, this.itemSize).copy(this);
  6939. },
  6940. toJSON: function toJSON() {
  6941. return {
  6942. itemSize: this.itemSize,
  6943. type: this.array.constructor.name,
  6944. array: Array.prototype.slice.call(this.array),
  6945. normalized: this.normalized
  6946. };
  6947. }
  6948. }); //
  6949. function Int8BufferAttribute(array, itemSize, normalized) {
  6950. BufferAttribute.call(this, new Int8Array(array), itemSize, normalized);
  6951. }
  6952. Int8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6953. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6954. function Uint8BufferAttribute(array, itemSize, normalized) {
  6955. BufferAttribute.call(this, new Uint8Array(array), itemSize, normalized);
  6956. }
  6957. Uint8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6958. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6959. function Uint8ClampedBufferAttribute(array, itemSize, normalized) {
  6960. BufferAttribute.call(this, new Uint8ClampedArray(array), itemSize, normalized);
  6961. }
  6962. Uint8ClampedBufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6963. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6964. function Int16BufferAttribute(array, itemSize, normalized) {
  6965. BufferAttribute.call(this, new Int16Array(array), itemSize, normalized);
  6966. }
  6967. Int16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6968. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6969. function Uint16BufferAttribute(array, itemSize, normalized) {
  6970. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6971. }
  6972. Uint16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6973. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6974. function Int32BufferAttribute(array, itemSize, normalized) {
  6975. BufferAttribute.call(this, new Int32Array(array), itemSize, normalized);
  6976. }
  6977. Int32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6978. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6979. function Uint32BufferAttribute(array, itemSize, normalized) {
  6980. BufferAttribute.call(this, new Uint32Array(array), itemSize, normalized);
  6981. }
  6982. Uint32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6983. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6984. function Float16BufferAttribute(array, itemSize, normalized) {
  6985. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6986. }
  6987. Float16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6988. Float16BufferAttribute.prototype.constructor = Float16BufferAttribute;
  6989. Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
  6990. function Float32BufferAttribute(array, itemSize, normalized) {
  6991. BufferAttribute.call(this, new Float32Array(array), itemSize, normalized);
  6992. }
  6993. Float32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6994. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6995. function Float64BufferAttribute(array, itemSize, normalized) {
  6996. BufferAttribute.call(this, new Float64Array(array), itemSize, normalized);
  6997. }
  6998. Float64BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6999. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; //
  7000. function arrayMax(array) {
  7001. if (array.length === 0) return -Infinity;
  7002. var max = array[0];
  7003. for (var i = 1, l = array.length; i < l; ++i) {
  7004. if (array[i] > max) max = array[i];
  7005. }
  7006. return max;
  7007. }
  7008. var TYPED_ARRAYS = {
  7009. Int8Array: Int8Array,
  7010. Uint8Array: Uint8Array,
  7011. // Workaround for IE11 pre KB2929437. See #11440
  7012. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  7013. Int16Array: Int16Array,
  7014. Uint16Array: Uint16Array,
  7015. Int32Array: Int32Array,
  7016. Uint32Array: Uint32Array,
  7017. Float32Array: Float32Array,
  7018. Float64Array: Float64Array
  7019. };
  7020. function getTypedArray(type, buffer) {
  7021. return new TYPED_ARRAYS[type](buffer);
  7022. }
  7023. var _id = 0;
  7024. var _m1$2 = new Matrix4();
  7025. var _obj = new Object3D();
  7026. var _offset = new Vector3();
  7027. var _box$2 = new Box3();
  7028. var _boxMorphTargets = new Box3();
  7029. var _vector$4 = new Vector3();
  7030. function BufferGeometry() {
  7031. Object.defineProperty(this, 'id', {
  7032. value: _id++
  7033. });
  7034. this.uuid = MathUtils.generateUUID();
  7035. this.name = '';
  7036. this.type = 'BufferGeometry';
  7037. this.index = null;
  7038. this.attributes = {};
  7039. this.morphAttributes = {};
  7040. this.morphTargetsRelative = false;
  7041. this.groups = [];
  7042. this.boundingBox = null;
  7043. this.boundingSphere = null;
  7044. this.drawRange = {
  7045. start: 0,
  7046. count: Infinity
  7047. };
  7048. this.userData = {};
  7049. }
  7050. BufferGeometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  7051. constructor: BufferGeometry,
  7052. isBufferGeometry: true,
  7053. getIndex: function getIndex() {
  7054. return this.index;
  7055. },
  7056. setIndex: function setIndex(index) {
  7057. if (Array.isArray(index)) {
  7058. this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
  7059. } else {
  7060. this.index = index;
  7061. }
  7062. return this;
  7063. },
  7064. getAttribute: function getAttribute(name) {
  7065. return this.attributes[name];
  7066. },
  7067. setAttribute: function setAttribute(name, attribute) {
  7068. this.attributes[name] = attribute;
  7069. return this;
  7070. },
  7071. deleteAttribute: function deleteAttribute(name) {
  7072. delete this.attributes[name];
  7073. return this;
  7074. },
  7075. hasAttribute: function hasAttribute(name) {
  7076. return this.attributes[name] !== undefined;
  7077. },
  7078. addGroup: function addGroup(start, count, materialIndex) {
  7079. if (materialIndex === void 0) {
  7080. materialIndex = 0;
  7081. }
  7082. this.groups.push({
  7083. start: start,
  7084. count: count,
  7085. materialIndex: materialIndex
  7086. });
  7087. },
  7088. clearGroups: function clearGroups() {
  7089. this.groups = [];
  7090. },
  7091. setDrawRange: function setDrawRange(start, count) {
  7092. this.drawRange.start = start;
  7093. this.drawRange.count = count;
  7094. },
  7095. applyMatrix4: function applyMatrix4(matrix) {
  7096. var position = this.attributes.position;
  7097. if (position !== undefined) {
  7098. position.applyMatrix4(matrix);
  7099. position.needsUpdate = true;
  7100. }
  7101. var normal = this.attributes.normal;
  7102. if (normal !== undefined) {
  7103. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  7104. normal.applyNormalMatrix(normalMatrix);
  7105. normal.needsUpdate = true;
  7106. }
  7107. var tangent = this.attributes.tangent;
  7108. if (tangent !== undefined) {
  7109. tangent.transformDirection(matrix);
  7110. tangent.needsUpdate = true;
  7111. }
  7112. if (this.boundingBox !== null) {
  7113. this.computeBoundingBox();
  7114. }
  7115. if (this.boundingSphere !== null) {
  7116. this.computeBoundingSphere();
  7117. }
  7118. return this;
  7119. },
  7120. rotateX: function rotateX(angle) {
  7121. // rotate geometry around world x-axis
  7122. _m1$2.makeRotationX(angle);
  7123. this.applyMatrix4(_m1$2);
  7124. return this;
  7125. },
  7126. rotateY: function rotateY(angle) {
  7127. // rotate geometry around world y-axis
  7128. _m1$2.makeRotationY(angle);
  7129. this.applyMatrix4(_m1$2);
  7130. return this;
  7131. },
  7132. rotateZ: function rotateZ(angle) {
  7133. // rotate geometry around world z-axis
  7134. _m1$2.makeRotationZ(angle);
  7135. this.applyMatrix4(_m1$2);
  7136. return this;
  7137. },
  7138. translate: function translate(x, y, z) {
  7139. // translate geometry
  7140. _m1$2.makeTranslation(x, y, z);
  7141. this.applyMatrix4(_m1$2);
  7142. return this;
  7143. },
  7144. scale: function scale(x, y, z) {
  7145. // scale geometry
  7146. _m1$2.makeScale(x, y, z);
  7147. this.applyMatrix4(_m1$2);
  7148. return this;
  7149. },
  7150. lookAt: function lookAt(vector) {
  7151. _obj.lookAt(vector);
  7152. _obj.updateMatrix();
  7153. this.applyMatrix4(_obj.matrix);
  7154. return this;
  7155. },
  7156. center: function center() {
  7157. this.computeBoundingBox();
  7158. this.boundingBox.getCenter(_offset).negate();
  7159. this.translate(_offset.x, _offset.y, _offset.z);
  7160. return this;
  7161. },
  7162. setFromPoints: function setFromPoints(points) {
  7163. var position = [];
  7164. for (var i = 0, l = points.length; i < l; i++) {
  7165. var point = points[i];
  7166. position.push(point.x, point.y, point.z || 0);
  7167. }
  7168. this.setAttribute('position', new Float32BufferAttribute(position, 3));
  7169. return this;
  7170. },
  7171. computeBoundingBox: function computeBoundingBox() {
  7172. if (this.boundingBox === null) {
  7173. this.boundingBox = new Box3();
  7174. }
  7175. var position = this.attributes.position;
  7176. var morphAttributesPosition = this.morphAttributes.position;
  7177. if (position && position.isGLBufferAttribute) {
  7178. console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this);
  7179. this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
  7180. return;
  7181. }
  7182. if (position !== undefined) {
  7183. this.boundingBox.setFromBufferAttribute(position); // process morph attributes if present
  7184. if (morphAttributesPosition) {
  7185. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  7186. var morphAttribute = morphAttributesPosition[i];
  7187. _box$2.setFromBufferAttribute(morphAttribute);
  7188. if (this.morphTargetsRelative) {
  7189. _vector$4.addVectors(this.boundingBox.min, _box$2.min);
  7190. this.boundingBox.expandByPoint(_vector$4);
  7191. _vector$4.addVectors(this.boundingBox.max, _box$2.max);
  7192. this.boundingBox.expandByPoint(_vector$4);
  7193. } else {
  7194. this.boundingBox.expandByPoint(_box$2.min);
  7195. this.boundingBox.expandByPoint(_box$2.max);
  7196. }
  7197. }
  7198. }
  7199. } else {
  7200. this.boundingBox.makeEmpty();
  7201. }
  7202. if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
  7203. console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
  7204. }
  7205. },
  7206. computeBoundingSphere: function computeBoundingSphere() {
  7207. if (this.boundingSphere === null) {
  7208. this.boundingSphere = new Sphere();
  7209. }
  7210. var position = this.attributes.position;
  7211. var morphAttributesPosition = this.morphAttributes.position;
  7212. if (position && position.isGLBufferAttribute) {
  7213. console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this);
  7214. this.boundingSphere.set(new Vector3(), Infinity);
  7215. return;
  7216. }
  7217. if (position) {
  7218. // first, find the center of the bounding sphere
  7219. var center = this.boundingSphere.center;
  7220. _box$2.setFromBufferAttribute(position); // process morph attributes if present
  7221. if (morphAttributesPosition) {
  7222. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  7223. var morphAttribute = morphAttributesPosition[i];
  7224. _boxMorphTargets.setFromBufferAttribute(morphAttribute);
  7225. if (this.morphTargetsRelative) {
  7226. _vector$4.addVectors(_box$2.min, _boxMorphTargets.min);
  7227. _box$2.expandByPoint(_vector$4);
  7228. _vector$4.addVectors(_box$2.max, _boxMorphTargets.max);
  7229. _box$2.expandByPoint(_vector$4);
  7230. } else {
  7231. _box$2.expandByPoint(_boxMorphTargets.min);
  7232. _box$2.expandByPoint(_boxMorphTargets.max);
  7233. }
  7234. }
  7235. }
  7236. _box$2.getCenter(center); // second, try to find a boundingSphere with a radius smaller than the
  7237. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  7238. var maxRadiusSq = 0;
  7239. for (var _i = 0, _il = position.count; _i < _il; _i++) {
  7240. _vector$4.fromBufferAttribute(position, _i);
  7241. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  7242. } // process morph attributes if present
  7243. if (morphAttributesPosition) {
  7244. for (var _i2 = 0, _il2 = morphAttributesPosition.length; _i2 < _il2; _i2++) {
  7245. var _morphAttribute = morphAttributesPosition[_i2];
  7246. var morphTargetsRelative = this.morphTargetsRelative;
  7247. for (var j = 0, jl = _morphAttribute.count; j < jl; j++) {
  7248. _vector$4.fromBufferAttribute(_morphAttribute, j);
  7249. if (morphTargetsRelative) {
  7250. _offset.fromBufferAttribute(position, j);
  7251. _vector$4.add(_offset);
  7252. }
  7253. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  7254. }
  7255. }
  7256. }
  7257. this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
  7258. if (isNaN(this.boundingSphere.radius)) {
  7259. console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
  7260. }
  7261. }
  7262. },
  7263. computeFaceNormals: function computeFaceNormals() {// backwards compatibility
  7264. },
  7265. computeTangents: function computeTangents() {
  7266. var index = this.index;
  7267. var attributes = this.attributes; // based on http://www.terathon.com/code/tangent.html
  7268. // (per vertex tangents)
  7269. if (index === null || attributes.position === undefined || attributes.normal === undefined || attributes.uv === undefined) {
  7270. console.error('THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)');
  7271. return;
  7272. }
  7273. var indices = index.array;
  7274. var positions = attributes.position.array;
  7275. var normals = attributes.normal.array;
  7276. var uvs = attributes.uv.array;
  7277. var nVertices = positions.length / 3;
  7278. if (attributes.tangent === undefined) {
  7279. this.setAttribute('tangent', new BufferAttribute(new Float32Array(4 * nVertices), 4));
  7280. }
  7281. var tangents = attributes.tangent.array;
  7282. var tan1 = [],
  7283. tan2 = [];
  7284. for (var i = 0; i < nVertices; i++) {
  7285. tan1[i] = new Vector3();
  7286. tan2[i] = new Vector3();
  7287. }
  7288. var vA = new Vector3(),
  7289. vB = new Vector3(),
  7290. vC = new Vector3(),
  7291. uvA = new Vector2(),
  7292. uvB = new Vector2(),
  7293. uvC = new Vector2(),
  7294. sdir = new Vector3(),
  7295. tdir = new Vector3();
  7296. function handleTriangle(a, b, c) {
  7297. vA.fromArray(positions, a * 3);
  7298. vB.fromArray(positions, b * 3);
  7299. vC.fromArray(positions, c * 3);
  7300. uvA.fromArray(uvs, a * 2);
  7301. uvB.fromArray(uvs, b * 2);
  7302. uvC.fromArray(uvs, c * 2);
  7303. vB.sub(vA);
  7304. vC.sub(vA);
  7305. uvB.sub(uvA);
  7306. uvC.sub(uvA);
  7307. var r = 1.0 / (uvB.x * uvC.y - uvC.x * uvB.y); // silently ignore degenerate uv triangles having coincident or colinear vertices
  7308. if (!isFinite(r)) return;
  7309. sdir.copy(vB).multiplyScalar(uvC.y).addScaledVector(vC, -uvB.y).multiplyScalar(r);
  7310. tdir.copy(vC).multiplyScalar(uvB.x).addScaledVector(vB, -uvC.x).multiplyScalar(r);
  7311. tan1[a].add(sdir);
  7312. tan1[b].add(sdir);
  7313. tan1[c].add(sdir);
  7314. tan2[a].add(tdir);
  7315. tan2[b].add(tdir);
  7316. tan2[c].add(tdir);
  7317. }
  7318. var groups = this.groups;
  7319. if (groups.length === 0) {
  7320. groups = [{
  7321. start: 0,
  7322. count: indices.length
  7323. }];
  7324. }
  7325. for (var _i3 = 0, il = groups.length; _i3 < il; ++_i3) {
  7326. var group = groups[_i3];
  7327. var start = group.start;
  7328. var count = group.count;
  7329. for (var j = start, jl = start + count; j < jl; j += 3) {
  7330. handleTriangle(indices[j + 0], indices[j + 1], indices[j + 2]);
  7331. }
  7332. }
  7333. var tmp = new Vector3(),
  7334. tmp2 = new Vector3();
  7335. var n = new Vector3(),
  7336. n2 = new Vector3();
  7337. function handleVertex(v) {
  7338. n.fromArray(normals, v * 3);
  7339. n2.copy(n);
  7340. var t = tan1[v]; // Gram-Schmidt orthogonalize
  7341. tmp.copy(t);
  7342. tmp.sub(n.multiplyScalar(n.dot(t))).normalize(); // Calculate handedness
  7343. tmp2.crossVectors(n2, t);
  7344. var test = tmp2.dot(tan2[v]);
  7345. var w = test < 0.0 ? -1.0 : 1.0;
  7346. tangents[v * 4] = tmp.x;
  7347. tangents[v * 4 + 1] = tmp.y;
  7348. tangents[v * 4 + 2] = tmp.z;
  7349. tangents[v * 4 + 3] = w;
  7350. }
  7351. for (var _i4 = 0, _il3 = groups.length; _i4 < _il3; ++_i4) {
  7352. var _group = groups[_i4];
  7353. var _start = _group.start;
  7354. var _count = _group.count;
  7355. for (var _j = _start, _jl = _start + _count; _j < _jl; _j += 3) {
  7356. handleVertex(indices[_j + 0]);
  7357. handleVertex(indices[_j + 1]);
  7358. handleVertex(indices[_j + 2]);
  7359. }
  7360. }
  7361. },
  7362. computeVertexNormals: function computeVertexNormals() {
  7363. var index = this.index;
  7364. var positionAttribute = this.getAttribute('position');
  7365. if (positionAttribute !== undefined) {
  7366. var normalAttribute = this.getAttribute('normal');
  7367. if (normalAttribute === undefined) {
  7368. normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
  7369. this.setAttribute('normal', normalAttribute);
  7370. } else {
  7371. // reset existing normals to zero
  7372. for (var i = 0, il = normalAttribute.count; i < il; i++) {
  7373. normalAttribute.setXYZ(i, 0, 0, 0);
  7374. }
  7375. }
  7376. var pA = new Vector3(),
  7377. pB = new Vector3(),
  7378. pC = new Vector3();
  7379. var nA = new Vector3(),
  7380. nB = new Vector3(),
  7381. nC = new Vector3();
  7382. var cb = new Vector3(),
  7383. ab = new Vector3(); // indexed elements
  7384. if (index) {
  7385. for (var _i5 = 0, _il4 = index.count; _i5 < _il4; _i5 += 3) {
  7386. var vA = index.getX(_i5 + 0);
  7387. var vB = index.getX(_i5 + 1);
  7388. var vC = index.getX(_i5 + 2);
  7389. pA.fromBufferAttribute(positionAttribute, vA);
  7390. pB.fromBufferAttribute(positionAttribute, vB);
  7391. pC.fromBufferAttribute(positionAttribute, vC);
  7392. cb.subVectors(pC, pB);
  7393. ab.subVectors(pA, pB);
  7394. cb.cross(ab);
  7395. nA.fromBufferAttribute(normalAttribute, vA);
  7396. nB.fromBufferAttribute(normalAttribute, vB);
  7397. nC.fromBufferAttribute(normalAttribute, vC);
  7398. nA.add(cb);
  7399. nB.add(cb);
  7400. nC.add(cb);
  7401. normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
  7402. normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
  7403. normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
  7404. }
  7405. } else {
  7406. // non-indexed elements (unconnected triangle soup)
  7407. for (var _i6 = 0, _il5 = positionAttribute.count; _i6 < _il5; _i6 += 3) {
  7408. pA.fromBufferAttribute(positionAttribute, _i6 + 0);
  7409. pB.fromBufferAttribute(positionAttribute, _i6 + 1);
  7410. pC.fromBufferAttribute(positionAttribute, _i6 + 2);
  7411. cb.subVectors(pC, pB);
  7412. ab.subVectors(pA, pB);
  7413. cb.cross(ab);
  7414. normalAttribute.setXYZ(_i6 + 0, cb.x, cb.y, cb.z);
  7415. normalAttribute.setXYZ(_i6 + 1, cb.x, cb.y, cb.z);
  7416. normalAttribute.setXYZ(_i6 + 2, cb.x, cb.y, cb.z);
  7417. }
  7418. }
  7419. this.normalizeNormals();
  7420. normalAttribute.needsUpdate = true;
  7421. }
  7422. },
  7423. merge: function merge(geometry, offset) {
  7424. if (!(geometry && geometry.isBufferGeometry)) {
  7425. console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
  7426. return;
  7427. }
  7428. if (offset === undefined) {
  7429. offset = 0;
  7430. console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');
  7431. }
  7432. var attributes = this.attributes;
  7433. for (var key in attributes) {
  7434. if (geometry.attributes[key] === undefined) continue;
  7435. var attribute1 = attributes[key];
  7436. var attributeArray1 = attribute1.array;
  7437. var attribute2 = geometry.attributes[key];
  7438. var attributeArray2 = attribute2.array;
  7439. var attributeOffset = attribute2.itemSize * offset;
  7440. var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
  7441. for (var i = 0, j = attributeOffset; i < length; i++, j++) {
  7442. attributeArray1[j] = attributeArray2[i];
  7443. }
  7444. }
  7445. return this;
  7446. },
  7447. normalizeNormals: function normalizeNormals() {
  7448. var normals = this.attributes.normal;
  7449. for (var i = 0, il = normals.count; i < il; i++) {
  7450. _vector$4.fromBufferAttribute(normals, i);
  7451. _vector$4.normalize();
  7452. normals.setXYZ(i, _vector$4.x, _vector$4.y, _vector$4.z);
  7453. }
  7454. },
  7455. toNonIndexed: function toNonIndexed() {
  7456. function convertBufferAttribute(attribute, indices) {
  7457. var array = attribute.array;
  7458. var itemSize = attribute.itemSize;
  7459. var normalized = attribute.normalized;
  7460. var array2 = new array.constructor(indices.length * itemSize);
  7461. var index = 0,
  7462. index2 = 0;
  7463. for (var i = 0, l = indices.length; i < l; i++) {
  7464. index = indices[i] * itemSize;
  7465. for (var j = 0; j < itemSize; j++) {
  7466. array2[index2++] = array[index++];
  7467. }
  7468. }
  7469. return new BufferAttribute(array2, itemSize, normalized);
  7470. } //
  7471. if (this.index === null) {
  7472. console.warn('THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.');
  7473. return this;
  7474. }
  7475. var geometry2 = new BufferGeometry();
  7476. var indices = this.index.array;
  7477. var attributes = this.attributes; // attributes
  7478. for (var name in attributes) {
  7479. var attribute = attributes[name];
  7480. var newAttribute = convertBufferAttribute(attribute, indices);
  7481. geometry2.setAttribute(name, newAttribute);
  7482. } // morph attributes
  7483. var morphAttributes = this.morphAttributes;
  7484. for (var _name in morphAttributes) {
  7485. var morphArray = [];
  7486. var morphAttribute = morphAttributes[_name]; // morphAttribute: array of Float32BufferAttributes
  7487. for (var i = 0, il = morphAttribute.length; i < il; i++) {
  7488. var _attribute = morphAttribute[i];
  7489. var _newAttribute = convertBufferAttribute(_attribute, indices);
  7490. morphArray.push(_newAttribute);
  7491. }
  7492. geometry2.morphAttributes[_name] = morphArray;
  7493. }
  7494. geometry2.morphTargetsRelative = this.morphTargetsRelative; // groups
  7495. var groups = this.groups;
  7496. for (var _i7 = 0, l = groups.length; _i7 < l; _i7++) {
  7497. var group = groups[_i7];
  7498. geometry2.addGroup(group.start, group.count, group.materialIndex);
  7499. }
  7500. return geometry2;
  7501. },
  7502. toJSON: function toJSON() {
  7503. var data = {
  7504. metadata: {
  7505. version: 4.5,
  7506. type: 'BufferGeometry',
  7507. generator: 'BufferGeometry.toJSON'
  7508. }
  7509. }; // standard BufferGeometry serialization
  7510. data.uuid = this.uuid;
  7511. data.type = this.type;
  7512. if (this.name !== '') data.name = this.name;
  7513. if (Object.keys(this.userData).length > 0) data.userData = this.userData;
  7514. if (this.parameters !== undefined) {
  7515. var parameters = this.parameters;
  7516. for (var key in parameters) {
  7517. if (parameters[key] !== undefined) data[key] = parameters[key];
  7518. }
  7519. return data;
  7520. }
  7521. data.data = {
  7522. attributes: {}
  7523. };
  7524. var index = this.index;
  7525. if (index !== null) {
  7526. data.data.index = {
  7527. type: index.array.constructor.name,
  7528. array: Array.prototype.slice.call(index.array)
  7529. };
  7530. }
  7531. var attributes = this.attributes;
  7532. for (var _key in attributes) {
  7533. var attribute = attributes[_key];
  7534. var attributeData = attribute.toJSON(data.data);
  7535. if (attribute.name !== '') attributeData.name = attribute.name;
  7536. data.data.attributes[_key] = attributeData;
  7537. }
  7538. var morphAttributes = {};
  7539. var hasMorphAttributes = false;
  7540. for (var _key2 in this.morphAttributes) {
  7541. var attributeArray = this.morphAttributes[_key2];
  7542. var array = [];
  7543. for (var i = 0, il = attributeArray.length; i < il; i++) {
  7544. var _attribute2 = attributeArray[i];
  7545. var _attributeData = _attribute2.toJSON(data.data);
  7546. if (_attribute2.name !== '') _attributeData.name = _attribute2.name;
  7547. array.push(_attributeData);
  7548. }
  7549. if (array.length > 0) {
  7550. morphAttributes[_key2] = array;
  7551. hasMorphAttributes = true;
  7552. }
  7553. }
  7554. if (hasMorphAttributes) {
  7555. data.data.morphAttributes = morphAttributes;
  7556. data.data.morphTargetsRelative = this.morphTargetsRelative;
  7557. }
  7558. var groups = this.groups;
  7559. if (groups.length > 0) {
  7560. data.data.groups = JSON.parse(JSON.stringify(groups));
  7561. }
  7562. var boundingSphere = this.boundingSphere;
  7563. if (boundingSphere !== null) {
  7564. data.data.boundingSphere = {
  7565. center: boundingSphere.center.toArray(),
  7566. radius: boundingSphere.radius
  7567. };
  7568. }
  7569. return data;
  7570. },
  7571. clone: function clone() {
  7572. /*
  7573. // Handle primitives
  7574. const parameters = this.parameters;
  7575. if ( parameters !== undefined ) {
  7576. const values = [];
  7577. for ( const key in parameters ) {
  7578. values.push( parameters[ key ] );
  7579. }
  7580. const geometry = Object.create( this.constructor.prototype );
  7581. this.constructor.apply( geometry, values );
  7582. return geometry;
  7583. }
  7584. return new this.constructor().copy( this );
  7585. */
  7586. return new BufferGeometry().copy(this);
  7587. },
  7588. copy: function copy(source) {
  7589. // reset
  7590. this.index = null;
  7591. this.attributes = {};
  7592. this.morphAttributes = {};
  7593. this.groups = [];
  7594. this.boundingBox = null;
  7595. this.boundingSphere = null; // used for storing cloned, shared data
  7596. var data = {}; // name
  7597. this.name = source.name; // index
  7598. var index = source.index;
  7599. if (index !== null) {
  7600. this.setIndex(index.clone(data));
  7601. } // attributes
  7602. var attributes = source.attributes;
  7603. for (var name in attributes) {
  7604. var attribute = attributes[name];
  7605. this.setAttribute(name, attribute.clone(data));
  7606. } // morph attributes
  7607. var morphAttributes = source.morphAttributes;
  7608. for (var _name2 in morphAttributes) {
  7609. var array = [];
  7610. var morphAttribute = morphAttributes[_name2]; // morphAttribute: array of Float32BufferAttributes
  7611. for (var i = 0, l = morphAttribute.length; i < l; i++) {
  7612. array.push(morphAttribute[i].clone(data));
  7613. }
  7614. this.morphAttributes[_name2] = array;
  7615. }
  7616. this.morphTargetsRelative = source.morphTargetsRelative; // groups
  7617. var groups = source.groups;
  7618. for (var _i8 = 0, _l = groups.length; _i8 < _l; _i8++) {
  7619. var group = groups[_i8];
  7620. this.addGroup(group.start, group.count, group.materialIndex);
  7621. } // bounding box
  7622. var boundingBox = source.boundingBox;
  7623. if (boundingBox !== null) {
  7624. this.boundingBox = boundingBox.clone();
  7625. } // bounding sphere
  7626. var boundingSphere = source.boundingSphere;
  7627. if (boundingSphere !== null) {
  7628. this.boundingSphere = boundingSphere.clone();
  7629. } // draw range
  7630. this.drawRange.start = source.drawRange.start;
  7631. this.drawRange.count = source.drawRange.count; // user data
  7632. this.userData = source.userData;
  7633. return this;
  7634. },
  7635. dispose: function dispose() {
  7636. this.dispatchEvent({
  7637. type: 'dispose'
  7638. });
  7639. }
  7640. });
  7641. var _inverseMatrix = new Matrix4();
  7642. var _ray = new Ray();
  7643. var _sphere = new Sphere();
  7644. var _vA = new Vector3();
  7645. var _vB = new Vector3();
  7646. var _vC = new Vector3();
  7647. var _tempA = new Vector3();
  7648. var _tempB = new Vector3();
  7649. var _tempC = new Vector3();
  7650. var _morphA = new Vector3();
  7651. var _morphB = new Vector3();
  7652. var _morphC = new Vector3();
  7653. var _uvA = new Vector2();
  7654. var _uvB = new Vector2();
  7655. var _uvC = new Vector2();
  7656. var _intersectionPoint = new Vector3();
  7657. var _intersectionPointWorld = new Vector3();
  7658. function Mesh(geometry, material) {
  7659. if (geometry === void 0) {
  7660. geometry = new BufferGeometry();
  7661. }
  7662. if (material === void 0) {
  7663. material = new MeshBasicMaterial();
  7664. }
  7665. Object3D.call(this);
  7666. this.type = 'Mesh';
  7667. this.geometry = geometry;
  7668. this.material = material;
  7669. this.updateMorphTargets();
  7670. }
  7671. Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
  7672. constructor: Mesh,
  7673. isMesh: true,
  7674. copy: function copy(source) {
  7675. Object3D.prototype.copy.call(this, source);
  7676. if (source.morphTargetInfluences !== undefined) {
  7677. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  7678. }
  7679. if (source.morphTargetDictionary !== undefined) {
  7680. this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
  7681. }
  7682. this.material = source.material;
  7683. this.geometry = source.geometry;
  7684. return this;
  7685. },
  7686. updateMorphTargets: function updateMorphTargets() {
  7687. var geometry = this.geometry;
  7688. if (geometry.isBufferGeometry) {
  7689. var morphAttributes = geometry.morphAttributes;
  7690. var keys = Object.keys(morphAttributes);
  7691. if (keys.length > 0) {
  7692. var morphAttribute = morphAttributes[keys[0]];
  7693. if (morphAttribute !== undefined) {
  7694. this.morphTargetInfluences = [];
  7695. this.morphTargetDictionary = {};
  7696. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  7697. var name = morphAttribute[m].name || String(m);
  7698. this.morphTargetInfluences.push(0);
  7699. this.morphTargetDictionary[name] = m;
  7700. }
  7701. }
  7702. }
  7703. } else {
  7704. var morphTargets = geometry.morphTargets;
  7705. if (morphTargets !== undefined && morphTargets.length > 0) {
  7706. console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7707. }
  7708. }
  7709. },
  7710. raycast: function raycast(raycaster, intersects) {
  7711. var geometry = this.geometry;
  7712. var material = this.material;
  7713. var matrixWorld = this.matrixWorld;
  7714. if (material === undefined) return; // Checking boundingSphere distance to ray
  7715. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7716. _sphere.copy(geometry.boundingSphere);
  7717. _sphere.applyMatrix4(matrixWorld);
  7718. if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
  7719. _inverseMatrix.copy(matrixWorld).invert();
  7720. _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
  7721. if (geometry.boundingBox !== null) {
  7722. if (_ray.intersectsBox(geometry.boundingBox) === false) return;
  7723. }
  7724. var intersection;
  7725. if (geometry.isBufferGeometry) {
  7726. var index = geometry.index;
  7727. var position = geometry.attributes.position;
  7728. var morphPosition = geometry.morphAttributes.position;
  7729. var morphTargetsRelative = geometry.morphTargetsRelative;
  7730. var uv = geometry.attributes.uv;
  7731. var uv2 = geometry.attributes.uv2;
  7732. var groups = geometry.groups;
  7733. var drawRange = geometry.drawRange;
  7734. if (index !== null) {
  7735. // indexed buffer geometry
  7736. if (Array.isArray(material)) {
  7737. for (var i = 0, il = groups.length; i < il; i++) {
  7738. var group = groups[i];
  7739. var groupMaterial = material[group.materialIndex];
  7740. var start = Math.max(group.start, drawRange.start);
  7741. var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
  7742. for (var j = start, jl = end; j < jl; j += 3) {
  7743. var a = index.getX(j);
  7744. var b = index.getX(j + 1);
  7745. var c = index.getX(j + 2);
  7746. intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
  7747. if (intersection) {
  7748. intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
  7749. intersection.face.materialIndex = group.materialIndex;
  7750. intersects.push(intersection);
  7751. }
  7752. }
  7753. }
  7754. } else {
  7755. var _start = Math.max(0, drawRange.start);
  7756. var _end = Math.min(index.count, drawRange.start + drawRange.count);
  7757. for (var _i = _start, _il = _end; _i < _il; _i += 3) {
  7758. var _a = index.getX(_i);
  7759. var _b = index.getX(_i + 1);
  7760. var _c = index.getX(_i + 2);
  7761. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
  7762. if (intersection) {
  7763. intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
  7764. intersects.push(intersection);
  7765. }
  7766. }
  7767. }
  7768. } else if (position !== undefined) {
  7769. // non-indexed buffer geometry
  7770. if (Array.isArray(material)) {
  7771. for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
  7772. var _group = groups[_i2];
  7773. var _groupMaterial = material[_group.materialIndex];
  7774. var _start2 = Math.max(_group.start, drawRange.start);
  7775. var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
  7776. for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
  7777. var _a2 = _j;
  7778. var _b2 = _j + 1;
  7779. var _c2 = _j + 2;
  7780. intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
  7781. if (intersection) {
  7782. intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
  7783. intersection.face.materialIndex = _group.materialIndex;
  7784. intersects.push(intersection);
  7785. }
  7786. }
  7787. }
  7788. } else {
  7789. var _start3 = Math.max(0, drawRange.start);
  7790. var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
  7791. for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
  7792. var _a3 = _i3;
  7793. var _b3 = _i3 + 1;
  7794. var _c3 = _i3 + 2;
  7795. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
  7796. if (intersection) {
  7797. intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
  7798. intersects.push(intersection);
  7799. }
  7800. }
  7801. }
  7802. }
  7803. } else if (geometry.isGeometry) {
  7804. console.error('THREE.Mesh.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7805. }
  7806. }
  7807. });
  7808. function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
  7809. var intersect;
  7810. if (material.side === BackSide) {
  7811. intersect = ray.intersectTriangle(pC, pB, pA, true, point);
  7812. } else {
  7813. intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
  7814. }
  7815. if (intersect === null) return null;
  7816. _intersectionPointWorld.copy(point);
  7817. _intersectionPointWorld.applyMatrix4(object.matrixWorld);
  7818. var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
  7819. if (distance < raycaster.near || distance > raycaster.far) return null;
  7820. return {
  7821. distance: distance,
  7822. point: _intersectionPointWorld.clone(),
  7823. object: object
  7824. };
  7825. }
  7826. function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
  7827. _vA.fromBufferAttribute(position, a);
  7828. _vB.fromBufferAttribute(position, b);
  7829. _vC.fromBufferAttribute(position, c);
  7830. var morphInfluences = object.morphTargetInfluences;
  7831. if (material.morphTargets && morphPosition && morphInfluences) {
  7832. _morphA.set(0, 0, 0);
  7833. _morphB.set(0, 0, 0);
  7834. _morphC.set(0, 0, 0);
  7835. for (var i = 0, il = morphPosition.length; i < il; i++) {
  7836. var influence = morphInfluences[i];
  7837. var morphAttribute = morphPosition[i];
  7838. if (influence === 0) continue;
  7839. _tempA.fromBufferAttribute(morphAttribute, a);
  7840. _tempB.fromBufferAttribute(morphAttribute, b);
  7841. _tempC.fromBufferAttribute(morphAttribute, c);
  7842. if (morphTargetsRelative) {
  7843. _morphA.addScaledVector(_tempA, influence);
  7844. _morphB.addScaledVector(_tempB, influence);
  7845. _morphC.addScaledVector(_tempC, influence);
  7846. } else {
  7847. _morphA.addScaledVector(_tempA.sub(_vA), influence);
  7848. _morphB.addScaledVector(_tempB.sub(_vB), influence);
  7849. _morphC.addScaledVector(_tempC.sub(_vC), influence);
  7850. }
  7851. }
  7852. _vA.add(_morphA);
  7853. _vB.add(_morphB);
  7854. _vC.add(_morphC);
  7855. }
  7856. if (object.isSkinnedMesh && material.skinning) {
  7857. object.boneTransform(a, _vA);
  7858. object.boneTransform(b, _vB);
  7859. object.boneTransform(c, _vC);
  7860. }
  7861. var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
  7862. if (intersection) {
  7863. if (uv) {
  7864. _uvA.fromBufferAttribute(uv, a);
  7865. _uvB.fromBufferAttribute(uv, b);
  7866. _uvC.fromBufferAttribute(uv, c);
  7867. intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7868. }
  7869. if (uv2) {
  7870. _uvA.fromBufferAttribute(uv2, a);
  7871. _uvB.fromBufferAttribute(uv2, b);
  7872. _uvC.fromBufferAttribute(uv2, c);
  7873. intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7874. }
  7875. var face = {
  7876. a: a,
  7877. b: a,
  7878. c: c,
  7879. normal: new Vector3(),
  7880. materialIndex: 0
  7881. };
  7882. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7883. intersection.face = face;
  7884. }
  7885. return intersection;
  7886. }
  7887. var BoxGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7888. _inheritsLoose(BoxGeometry, _BufferGeometry);
  7889. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7890. var _this;
  7891. if (width === void 0) {
  7892. width = 1;
  7893. }
  7894. if (height === void 0) {
  7895. height = 1;
  7896. }
  7897. if (depth === void 0) {
  7898. depth = 1;
  7899. }
  7900. if (widthSegments === void 0) {
  7901. widthSegments = 1;
  7902. }
  7903. if (heightSegments === void 0) {
  7904. heightSegments = 1;
  7905. }
  7906. if (depthSegments === void 0) {
  7907. depthSegments = 1;
  7908. }
  7909. _this = _BufferGeometry.call(this) || this;
  7910. _this.type = 'BoxGeometry';
  7911. _this.parameters = {
  7912. width: width,
  7913. height: height,
  7914. depth: depth,
  7915. widthSegments: widthSegments,
  7916. heightSegments: heightSegments,
  7917. depthSegments: depthSegments
  7918. };
  7919. var scope = _assertThisInitialized(_this); // segments
  7920. widthSegments = Math.floor(widthSegments);
  7921. heightSegments = Math.floor(heightSegments);
  7922. depthSegments = Math.floor(depthSegments); // buffers
  7923. var indices = [];
  7924. var vertices = [];
  7925. var normals = [];
  7926. var uvs = []; // helper variables
  7927. var numberOfVertices = 0;
  7928. var groupStart = 0; // build each side of the box geometry
  7929. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7930. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7931. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7932. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7933. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7934. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7935. // build geometry
  7936. _this.setIndex(indices);
  7937. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7938. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7939. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7940. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7941. var segmentWidth = width / gridX;
  7942. var segmentHeight = height / gridY;
  7943. var widthHalf = width / 2;
  7944. var heightHalf = height / 2;
  7945. var depthHalf = depth / 2;
  7946. var gridX1 = gridX + 1;
  7947. var gridY1 = gridY + 1;
  7948. var vertexCounter = 0;
  7949. var groupCount = 0;
  7950. var vector = new Vector3(); // generate vertices, normals and uvs
  7951. for (var iy = 0; iy < gridY1; iy++) {
  7952. var y = iy * segmentHeight - heightHalf;
  7953. for (var ix = 0; ix < gridX1; ix++) {
  7954. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7955. vector[u] = x * udir;
  7956. vector[v] = y * vdir;
  7957. vector[w] = depthHalf; // now apply vector to vertex buffer
  7958. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7959. vector[u] = 0;
  7960. vector[v] = 0;
  7961. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7962. normals.push(vector.x, vector.y, vector.z); // uvs
  7963. uvs.push(ix / gridX);
  7964. uvs.push(1 - iy / gridY); // counters
  7965. vertexCounter += 1;
  7966. }
  7967. } // indices
  7968. // 1. you need three indices to draw a single face
  7969. // 2. a single segment consists of two faces
  7970. // 3. so we need to generate six (2*3) indices per segment
  7971. for (var _iy = 0; _iy < gridY; _iy++) {
  7972. for (var _ix = 0; _ix < gridX; _ix++) {
  7973. var a = numberOfVertices + _ix + gridX1 * _iy;
  7974. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7975. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7976. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7977. indices.push(a, b, d);
  7978. indices.push(b, c, d); // increase counter
  7979. groupCount += 6;
  7980. }
  7981. } // add a group to the geometry. this will ensure multi material support
  7982. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7983. groupStart += groupCount; // update total number of vertices
  7984. numberOfVertices += vertexCounter;
  7985. }
  7986. return _this;
  7987. }
  7988. return BoxGeometry;
  7989. }(BufferGeometry);
  7990. /**
  7991. * Uniform Utilities
  7992. */
  7993. function cloneUniforms(src) {
  7994. var dst = {};
  7995. for (var u in src) {
  7996. dst[u] = {};
  7997. for (var p in src[u]) {
  7998. var property = src[u][p];
  7999. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture || property.isQuaternion)) {
  8000. dst[u][p] = property.clone();
  8001. } else if (Array.isArray(property)) {
  8002. dst[u][p] = property.slice();
  8003. } else {
  8004. dst[u][p] = property;
  8005. }
  8006. }
  8007. }
  8008. return dst;
  8009. }
  8010. function mergeUniforms(uniforms) {
  8011. var merged = {};
  8012. for (var u = 0; u < uniforms.length; u++) {
  8013. var tmp = cloneUniforms(uniforms[u]);
  8014. for (var p in tmp) {
  8015. merged[p] = tmp[p];
  8016. }
  8017. }
  8018. return merged;
  8019. } // Legacy
  8020. var UniformsUtils = {
  8021. clone: cloneUniforms,
  8022. merge: mergeUniforms
  8023. };
  8024. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  8025. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  8026. /**
  8027. * parameters = {
  8028. * defines: { "label" : "value" },
  8029. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  8030. *
  8031. * fragmentShader: <string>,
  8032. * vertexShader: <string>,
  8033. *
  8034. * wireframe: <boolean>,
  8035. * wireframeLinewidth: <float>,
  8036. *
  8037. * lights: <bool>,
  8038. *
  8039. * skinning: <bool>,
  8040. * morphTargets: <bool>,
  8041. * morphNormals: <bool>
  8042. * }
  8043. */
  8044. function ShaderMaterial(parameters) {
  8045. Material.call(this);
  8046. this.type = 'ShaderMaterial';
  8047. this.defines = {};
  8048. this.uniforms = {};
  8049. this.vertexShader = default_vertex;
  8050. this.fragmentShader = default_fragment;
  8051. this.linewidth = 1;
  8052. this.wireframe = false;
  8053. this.wireframeLinewidth = 1;
  8054. this.fog = false; // set to use scene fog
  8055. this.lights = false; // set to use scene lights
  8056. this.clipping = false; // set to use user-defined clipping planes
  8057. this.skinning = false; // set to use skinning attribute streams
  8058. this.morphTargets = false; // set to use morph targets
  8059. this.morphNormals = false; // set to use morph normals
  8060. this.extensions = {
  8061. derivatives: false,
  8062. // set to use derivatives
  8063. fragDepth: false,
  8064. // set to use fragment depth values
  8065. drawBuffers: false,
  8066. // set to use draw buffers
  8067. shaderTextureLOD: false // set to use shader texture LOD
  8068. }; // When rendered geometry doesn't include these attributes but the material does,
  8069. // use these default values in WebGL. This avoids errors when buffer data is missing.
  8070. this.defaultAttributeValues = {
  8071. 'color': [1, 1, 1],
  8072. 'uv': [0, 0],
  8073. 'uv2': [0, 0]
  8074. };
  8075. this.index0AttributeName = undefined;
  8076. this.uniformsNeedUpdate = false;
  8077. this.glslVersion = null;
  8078. if (parameters !== undefined) {
  8079. if (parameters.attributes !== undefined) {
  8080. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  8081. }
  8082. this.setValues(parameters);
  8083. }
  8084. }
  8085. ShaderMaterial.prototype = Object.create(Material.prototype);
  8086. ShaderMaterial.prototype.constructor = ShaderMaterial;
  8087. ShaderMaterial.prototype.isShaderMaterial = true;
  8088. ShaderMaterial.prototype.copy = function (source) {
  8089. Material.prototype.copy.call(this, source);
  8090. this.fragmentShader = source.fragmentShader;
  8091. this.vertexShader = source.vertexShader;
  8092. this.uniforms = cloneUniforms(source.uniforms);
  8093. this.defines = Object.assign({}, source.defines);
  8094. this.wireframe = source.wireframe;
  8095. this.wireframeLinewidth = source.wireframeLinewidth;
  8096. this.lights = source.lights;
  8097. this.clipping = source.clipping;
  8098. this.skinning = source.skinning;
  8099. this.morphTargets = source.morphTargets;
  8100. this.morphNormals = source.morphNormals;
  8101. this.extensions = Object.assign({}, source.extensions);
  8102. this.glslVersion = source.glslVersion;
  8103. return this;
  8104. };
  8105. ShaderMaterial.prototype.toJSON = function (meta) {
  8106. var data = Material.prototype.toJSON.call(this, meta);
  8107. data.glslVersion = this.glslVersion;
  8108. data.uniforms = {};
  8109. for (var name in this.uniforms) {
  8110. var uniform = this.uniforms[name];
  8111. var value = uniform.value;
  8112. if (value && value.isTexture) {
  8113. data.uniforms[name] = {
  8114. type: 't',
  8115. value: value.toJSON(meta).uuid
  8116. };
  8117. } else if (value && value.isColor) {
  8118. data.uniforms[name] = {
  8119. type: 'c',
  8120. value: value.getHex()
  8121. };
  8122. } else if (value && value.isVector2) {
  8123. data.uniforms[name] = {
  8124. type: 'v2',
  8125. value: value.toArray()
  8126. };
  8127. } else if (value && value.isVector3) {
  8128. data.uniforms[name] = {
  8129. type: 'v3',
  8130. value: value.toArray()
  8131. };
  8132. } else if (value && value.isVector4) {
  8133. data.uniforms[name] = {
  8134. type: 'v4',
  8135. value: value.toArray()
  8136. };
  8137. } else if (value && value.isMatrix3) {
  8138. data.uniforms[name] = {
  8139. type: 'm3',
  8140. value: value.toArray()
  8141. };
  8142. } else if (value && value.isMatrix4) {
  8143. data.uniforms[name] = {
  8144. type: 'm4',
  8145. value: value.toArray()
  8146. };
  8147. } else {
  8148. data.uniforms[name] = {
  8149. value: value
  8150. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  8151. }
  8152. }
  8153. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  8154. data.vertexShader = this.vertexShader;
  8155. data.fragmentShader = this.fragmentShader;
  8156. var extensions = {};
  8157. for (var key in this.extensions) {
  8158. if (this.extensions[key] === true) extensions[key] = true;
  8159. }
  8160. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  8161. return data;
  8162. };
  8163. function Camera() {
  8164. Object3D.call(this);
  8165. this.type = 'Camera';
  8166. this.matrixWorldInverse = new Matrix4();
  8167. this.projectionMatrix = new Matrix4();
  8168. this.projectionMatrixInverse = new Matrix4();
  8169. }
  8170. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  8171. constructor: Camera,
  8172. isCamera: true,
  8173. copy: function copy(source, recursive) {
  8174. Object3D.prototype.copy.call(this, source, recursive);
  8175. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  8176. this.projectionMatrix.copy(source.projectionMatrix);
  8177. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  8178. return this;
  8179. },
  8180. getWorldDirection: function getWorldDirection(target) {
  8181. if (target === undefined) {
  8182. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  8183. target = new Vector3();
  8184. }
  8185. this.updateWorldMatrix(true, false);
  8186. var e = this.matrixWorld.elements;
  8187. return target.set(-e[8], -e[9], -e[10]).normalize();
  8188. },
  8189. updateMatrixWorld: function updateMatrixWorld(force) {
  8190. Object3D.prototype.updateMatrixWorld.call(this, force);
  8191. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  8192. },
  8193. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  8194. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  8195. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  8196. },
  8197. clone: function clone() {
  8198. return new this.constructor().copy(this);
  8199. }
  8200. });
  8201. function PerspectiveCamera(fov, aspect, near, far) {
  8202. if (fov === void 0) {
  8203. fov = 50;
  8204. }
  8205. if (aspect === void 0) {
  8206. aspect = 1;
  8207. }
  8208. if (near === void 0) {
  8209. near = 0.1;
  8210. }
  8211. if (far === void 0) {
  8212. far = 2000;
  8213. }
  8214. Camera.call(this);
  8215. this.type = 'PerspectiveCamera';
  8216. this.fov = fov;
  8217. this.zoom = 1;
  8218. this.near = near;
  8219. this.far = far;
  8220. this.focus = 10;
  8221. this.aspect = aspect;
  8222. this.view = null;
  8223. this.filmGauge = 35; // width of the film (default in millimeters)
  8224. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  8225. this.updateProjectionMatrix();
  8226. }
  8227. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  8228. constructor: PerspectiveCamera,
  8229. isPerspectiveCamera: true,
  8230. copy: function copy(source, recursive) {
  8231. Camera.prototype.copy.call(this, source, recursive);
  8232. this.fov = source.fov;
  8233. this.zoom = source.zoom;
  8234. this.near = source.near;
  8235. this.far = source.far;
  8236. this.focus = source.focus;
  8237. this.aspect = source.aspect;
  8238. this.view = source.view === null ? null : Object.assign({}, source.view);
  8239. this.filmGauge = source.filmGauge;
  8240. this.filmOffset = source.filmOffset;
  8241. return this;
  8242. },
  8243. /**
  8244. * Sets the FOV by focal length in respect to the current .filmGauge.
  8245. *
  8246. * The default film gauge is 35, so that the focal length can be specified for
  8247. * a 35mm (full frame) camera.
  8248. *
  8249. * Values for focal length and film gauge must have the same unit.
  8250. */
  8251. setFocalLength: function setFocalLength(focalLength) {
  8252. /** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
  8253. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  8254. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  8255. this.updateProjectionMatrix();
  8256. },
  8257. /**
  8258. * Calculates the focal length from the current .fov and .filmGauge.
  8259. */
  8260. getFocalLength: function getFocalLength() {
  8261. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  8262. return 0.5 * this.getFilmHeight() / vExtentSlope;
  8263. },
  8264. getEffectiveFOV: function getEffectiveFOV() {
  8265. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  8266. },
  8267. getFilmWidth: function getFilmWidth() {
  8268. // film not completely covered in portrait format (aspect < 1)
  8269. return this.filmGauge * Math.min(this.aspect, 1);
  8270. },
  8271. getFilmHeight: function getFilmHeight() {
  8272. // film not completely covered in landscape format (aspect > 1)
  8273. return this.filmGauge / Math.max(this.aspect, 1);
  8274. },
  8275. /**
  8276. * Sets an offset in a larger frustum. This is useful for multi-window or
  8277. * multi-monitor/multi-machine setups.
  8278. *
  8279. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  8280. * the monitors are in grid like this
  8281. *
  8282. * +---+---+---+
  8283. * | A | B | C |
  8284. * +---+---+---+
  8285. * | D | E | F |
  8286. * +---+---+---+
  8287. *
  8288. * then for each monitor you would call it like this
  8289. *
  8290. * const w = 1920;
  8291. * const h = 1080;
  8292. * const fullWidth = w * 3;
  8293. * const fullHeight = h * 2;
  8294. *
  8295. * --A--
  8296. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8297. * --B--
  8298. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8299. * --C--
  8300. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8301. * --D--
  8302. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8303. * --E--
  8304. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8305. * --F--
  8306. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8307. *
  8308. * Note there is no reason monitors have to be the same size or in a grid.
  8309. */
  8310. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  8311. this.aspect = fullWidth / fullHeight;
  8312. if (this.view === null) {
  8313. this.view = {
  8314. enabled: true,
  8315. fullWidth: 1,
  8316. fullHeight: 1,
  8317. offsetX: 0,
  8318. offsetY: 0,
  8319. width: 1,
  8320. height: 1
  8321. };
  8322. }
  8323. this.view.enabled = true;
  8324. this.view.fullWidth = fullWidth;
  8325. this.view.fullHeight = fullHeight;
  8326. this.view.offsetX = x;
  8327. this.view.offsetY = y;
  8328. this.view.width = width;
  8329. this.view.height = height;
  8330. this.updateProjectionMatrix();
  8331. },
  8332. clearViewOffset: function clearViewOffset() {
  8333. if (this.view !== null) {
  8334. this.view.enabled = false;
  8335. }
  8336. this.updateProjectionMatrix();
  8337. },
  8338. updateProjectionMatrix: function updateProjectionMatrix() {
  8339. var near = this.near;
  8340. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  8341. var height = 2 * top;
  8342. var width = this.aspect * height;
  8343. var left = -0.5 * width;
  8344. var view = this.view;
  8345. if (this.view !== null && this.view.enabled) {
  8346. var fullWidth = view.fullWidth,
  8347. fullHeight = view.fullHeight;
  8348. left += view.offsetX * width / fullWidth;
  8349. top -= view.offsetY * height / fullHeight;
  8350. width *= view.width / fullWidth;
  8351. height *= view.height / fullHeight;
  8352. }
  8353. var skew = this.filmOffset;
  8354. if (skew !== 0) left += near * skew / this.getFilmWidth();
  8355. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  8356. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  8357. },
  8358. toJSON: function toJSON(meta) {
  8359. var data = Object3D.prototype.toJSON.call(this, meta);
  8360. data.object.fov = this.fov;
  8361. data.object.zoom = this.zoom;
  8362. data.object.near = this.near;
  8363. data.object.far = this.far;
  8364. data.object.focus = this.focus;
  8365. data.object.aspect = this.aspect;
  8366. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  8367. data.object.filmGauge = this.filmGauge;
  8368. data.object.filmOffset = this.filmOffset;
  8369. return data;
  8370. }
  8371. });
  8372. var fov = 90,
  8373. aspect = 1;
  8374. var CubeCamera = /*#__PURE__*/function (_Object3D) {
  8375. _inheritsLoose(CubeCamera, _Object3D);
  8376. function CubeCamera(near, far, renderTarget) {
  8377. var _this;
  8378. _this = _Object3D.call(this) || this;
  8379. _this.type = 'CubeCamera';
  8380. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  8381. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  8382. return _assertThisInitialized(_this);
  8383. }
  8384. _this.renderTarget = renderTarget;
  8385. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  8386. cameraPX.layers = _this.layers;
  8387. cameraPX.up.set(0, -1, 0);
  8388. cameraPX.lookAt(new Vector3(1, 0, 0));
  8389. _this.add(cameraPX);
  8390. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  8391. cameraNX.layers = _this.layers;
  8392. cameraNX.up.set(0, -1, 0);
  8393. cameraNX.lookAt(new Vector3(-1, 0, 0));
  8394. _this.add(cameraNX);
  8395. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  8396. cameraPY.layers = _this.layers;
  8397. cameraPY.up.set(0, 0, 1);
  8398. cameraPY.lookAt(new Vector3(0, 1, 0));
  8399. _this.add(cameraPY);
  8400. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  8401. cameraNY.layers = _this.layers;
  8402. cameraNY.up.set(0, 0, -1);
  8403. cameraNY.lookAt(new Vector3(0, -1, 0));
  8404. _this.add(cameraNY);
  8405. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  8406. cameraPZ.layers = _this.layers;
  8407. cameraPZ.up.set(0, -1, 0);
  8408. cameraPZ.lookAt(new Vector3(0, 0, 1));
  8409. _this.add(cameraPZ);
  8410. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  8411. cameraNZ.layers = _this.layers;
  8412. cameraNZ.up.set(0, -1, 0);
  8413. cameraNZ.lookAt(new Vector3(0, 0, -1));
  8414. _this.add(cameraNZ);
  8415. return _this;
  8416. }
  8417. var _proto = CubeCamera.prototype;
  8418. _proto.update = function update(renderer, scene) {
  8419. if (this.parent === null) this.updateMatrixWorld();
  8420. var renderTarget = this.renderTarget;
  8421. var cameraPX = this.children[0];
  8422. var cameraNX = this.children[1];
  8423. var cameraPY = this.children[2];
  8424. var cameraNY = this.children[3];
  8425. var cameraPZ = this.children[4];
  8426. var cameraNZ = this.children[5];
  8427. var currentXrEnabled = renderer.xr.enabled;
  8428. var currentRenderTarget = renderer.getRenderTarget();
  8429. renderer.xr.enabled = false;
  8430. var generateMipmaps = renderTarget.texture.generateMipmaps;
  8431. renderTarget.texture.generateMipmaps = false;
  8432. renderer.setRenderTarget(renderTarget, 0);
  8433. renderer.render(scene, cameraPX);
  8434. renderer.setRenderTarget(renderTarget, 1);
  8435. renderer.render(scene, cameraNX);
  8436. renderer.setRenderTarget(renderTarget, 2);
  8437. renderer.render(scene, cameraPY);
  8438. renderer.setRenderTarget(renderTarget, 3);
  8439. renderer.render(scene, cameraNY);
  8440. renderer.setRenderTarget(renderTarget, 4);
  8441. renderer.render(scene, cameraPZ);
  8442. renderTarget.texture.generateMipmaps = generateMipmaps;
  8443. renderer.setRenderTarget(renderTarget, 5);
  8444. renderer.render(scene, cameraNZ);
  8445. renderer.setRenderTarget(currentRenderTarget);
  8446. renderer.xr.enabled = currentXrEnabled;
  8447. };
  8448. return CubeCamera;
  8449. }(Object3D);
  8450. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  8451. images = images !== undefined ? images : [];
  8452. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  8453. format = format !== undefined ? format : RGBFormat;
  8454. Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8455. this.flipY = false; // Why CubeTexture._needsFlipEnvMap is necessary:
  8456. //
  8457. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  8458. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  8459. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  8460. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  8461. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  8462. // when using WebGLCubeRenderTarget.texture as a cube texture.
  8463. this._needsFlipEnvMap = true;
  8464. }
  8465. CubeTexture.prototype = Object.create(Texture.prototype);
  8466. CubeTexture.prototype.constructor = CubeTexture;
  8467. CubeTexture.prototype.isCubeTexture = true;
  8468. Object.defineProperty(CubeTexture.prototype, 'images', {
  8469. get: function get() {
  8470. return this.image;
  8471. },
  8472. set: function set(value) {
  8473. this.image = value;
  8474. }
  8475. });
  8476. var WebGLCubeRenderTarget = /*#__PURE__*/function (_WebGLRenderTarget) {
  8477. _inheritsLoose(WebGLCubeRenderTarget, _WebGLRenderTarget);
  8478. function WebGLCubeRenderTarget(size, options, dummy) {
  8479. var _this;
  8480. if (Number.isInteger(options)) {
  8481. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  8482. options = dummy;
  8483. }
  8484. _this = _WebGLRenderTarget.call(this, size, size, options) || this;
  8485. options = options || {};
  8486. _this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  8487. _this.texture._needsFlipEnvMap = false;
  8488. return _this;
  8489. }
  8490. var _proto = WebGLCubeRenderTarget.prototype;
  8491. _proto.fromEquirectangularTexture = function fromEquirectangularTexture(renderer, texture) {
  8492. this.texture.type = texture.type;
  8493. this.texture.format = RGBAFormat; // see #18859
  8494. this.texture.encoding = texture.encoding;
  8495. this.texture.generateMipmaps = texture.generateMipmaps;
  8496. this.texture.minFilter = texture.minFilter;
  8497. this.texture.magFilter = texture.magFilter;
  8498. var shader = {
  8499. uniforms: {
  8500. tEquirect: {
  8501. value: null
  8502. }
  8503. },
  8504. vertexShader:
  8505. /* glsl */
  8506. "\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",
  8507. fragmentShader:
  8508. /* glsl */
  8509. "\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"
  8510. };
  8511. var geometry = new BoxGeometry(5, 5, 5);
  8512. var material = new ShaderMaterial({
  8513. name: 'CubemapFromEquirect',
  8514. uniforms: cloneUniforms(shader.uniforms),
  8515. vertexShader: shader.vertexShader,
  8516. fragmentShader: shader.fragmentShader,
  8517. side: BackSide,
  8518. blending: NoBlending
  8519. });
  8520. material.uniforms.tEquirect.value = texture;
  8521. var mesh = new Mesh(geometry, material);
  8522. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  8523. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  8524. var camera = new CubeCamera(1, 10, this);
  8525. camera.update(renderer, mesh);
  8526. texture.minFilter = currentMinFilter;
  8527. mesh.geometry.dispose();
  8528. mesh.material.dispose();
  8529. return this;
  8530. };
  8531. _proto.clear = function clear(renderer, color, depth, stencil) {
  8532. var currentRenderTarget = renderer.getRenderTarget();
  8533. for (var i = 0; i < 6; i++) {
  8534. renderer.setRenderTarget(this, i);
  8535. renderer.clear(color, depth, stencil);
  8536. }
  8537. renderer.setRenderTarget(currentRenderTarget);
  8538. };
  8539. return WebGLCubeRenderTarget;
  8540. }(WebGLRenderTarget);
  8541. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  8542. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  8543. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8544. this.image = {
  8545. data: data || null,
  8546. width: width || 1,
  8547. height: height || 1
  8548. };
  8549. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8550. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8551. this.generateMipmaps = false;
  8552. this.flipY = false;
  8553. this.unpackAlignment = 1;
  8554. this.needsUpdate = true;
  8555. }
  8556. DataTexture.prototype = Object.create(Texture.prototype);
  8557. DataTexture.prototype.constructor = DataTexture;
  8558. DataTexture.prototype.isDataTexture = true;
  8559. var _sphere$1 = /*@__PURE__*/new Sphere();
  8560. var _vector$5 = /*@__PURE__*/new Vector3();
  8561. var Frustum = /*#__PURE__*/function () {
  8562. function Frustum(p0, p1, p2, p3, p4, p5) {
  8563. if (p0 === void 0) {
  8564. p0 = new Plane();
  8565. }
  8566. if (p1 === void 0) {
  8567. p1 = new Plane();
  8568. }
  8569. if (p2 === void 0) {
  8570. p2 = new Plane();
  8571. }
  8572. if (p3 === void 0) {
  8573. p3 = new Plane();
  8574. }
  8575. if (p4 === void 0) {
  8576. p4 = new Plane();
  8577. }
  8578. if (p5 === void 0) {
  8579. p5 = new Plane();
  8580. }
  8581. this.planes = [p0, p1, p2, p3, p4, p5];
  8582. }
  8583. var _proto = Frustum.prototype;
  8584. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  8585. var planes = this.planes;
  8586. planes[0].copy(p0);
  8587. planes[1].copy(p1);
  8588. planes[2].copy(p2);
  8589. planes[3].copy(p3);
  8590. planes[4].copy(p4);
  8591. planes[5].copy(p5);
  8592. return this;
  8593. };
  8594. _proto.copy = function copy(frustum) {
  8595. var planes = this.planes;
  8596. for (var i = 0; i < 6; i++) {
  8597. planes[i].copy(frustum.planes[i]);
  8598. }
  8599. return this;
  8600. };
  8601. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  8602. var planes = this.planes;
  8603. var me = m.elements;
  8604. var me0 = me[0],
  8605. me1 = me[1],
  8606. me2 = me[2],
  8607. me3 = me[3];
  8608. var me4 = me[4],
  8609. me5 = me[5],
  8610. me6 = me[6],
  8611. me7 = me[7];
  8612. var me8 = me[8],
  8613. me9 = me[9],
  8614. me10 = me[10],
  8615. me11 = me[11];
  8616. var me12 = me[12],
  8617. me13 = me[13],
  8618. me14 = me[14],
  8619. me15 = me[15];
  8620. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  8621. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  8622. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  8623. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  8624. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  8625. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  8626. return this;
  8627. };
  8628. _proto.intersectsObject = function intersectsObject(object) {
  8629. var geometry = object.geometry;
  8630. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  8631. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  8632. return this.intersectsSphere(_sphere$1);
  8633. };
  8634. _proto.intersectsSprite = function intersectsSprite(sprite) {
  8635. _sphere$1.center.set(0, 0, 0);
  8636. _sphere$1.radius = 0.7071067811865476;
  8637. _sphere$1.applyMatrix4(sprite.matrixWorld);
  8638. return this.intersectsSphere(_sphere$1);
  8639. };
  8640. _proto.intersectsSphere = function intersectsSphere(sphere) {
  8641. var planes = this.planes;
  8642. var center = sphere.center;
  8643. var negRadius = -sphere.radius;
  8644. for (var i = 0; i < 6; i++) {
  8645. var distance = planes[i].distanceToPoint(center);
  8646. if (distance < negRadius) {
  8647. return false;
  8648. }
  8649. }
  8650. return true;
  8651. };
  8652. _proto.intersectsBox = function intersectsBox(box) {
  8653. var planes = this.planes;
  8654. for (var i = 0; i < 6; i++) {
  8655. var plane = planes[i]; // corner at max distance
  8656. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8657. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8658. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8659. if (plane.distanceToPoint(_vector$5) < 0) {
  8660. return false;
  8661. }
  8662. }
  8663. return true;
  8664. };
  8665. _proto.containsPoint = function containsPoint(point) {
  8666. var planes = this.planes;
  8667. for (var i = 0; i < 6; i++) {
  8668. if (planes[i].distanceToPoint(point) < 0) {
  8669. return false;
  8670. }
  8671. }
  8672. return true;
  8673. };
  8674. _proto.clone = function clone() {
  8675. return new this.constructor().copy(this);
  8676. };
  8677. return Frustum;
  8678. }();
  8679. function WebGLAnimation() {
  8680. var context = null;
  8681. var isAnimating = false;
  8682. var animationLoop = null;
  8683. var requestId = null;
  8684. function onAnimationFrame(time, frame) {
  8685. animationLoop(time, frame);
  8686. requestId = context.requestAnimationFrame(onAnimationFrame);
  8687. }
  8688. return {
  8689. start: function start() {
  8690. if (isAnimating === true) return;
  8691. if (animationLoop === null) return;
  8692. requestId = context.requestAnimationFrame(onAnimationFrame);
  8693. isAnimating = true;
  8694. },
  8695. stop: function stop() {
  8696. context.cancelAnimationFrame(requestId);
  8697. isAnimating = false;
  8698. },
  8699. setAnimationLoop: function setAnimationLoop(callback) {
  8700. animationLoop = callback;
  8701. },
  8702. setContext: function setContext(value) {
  8703. context = value;
  8704. }
  8705. };
  8706. }
  8707. function WebGLAttributes(gl, capabilities) {
  8708. var isWebGL2 = capabilities.isWebGL2;
  8709. var buffers = new WeakMap();
  8710. function createBuffer(attribute, bufferType) {
  8711. var array = attribute.array;
  8712. var usage = attribute.usage;
  8713. var buffer = gl.createBuffer();
  8714. gl.bindBuffer(bufferType, buffer);
  8715. gl.bufferData(bufferType, array, usage);
  8716. attribute.onUploadCallback();
  8717. var type = 5126;
  8718. if (array instanceof Float32Array) {
  8719. type = 5126;
  8720. } else if (array instanceof Float64Array) {
  8721. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  8722. } else if (array instanceof Uint16Array) {
  8723. if (attribute.isFloat16BufferAttribute) {
  8724. if (isWebGL2) {
  8725. type = 5131;
  8726. } else {
  8727. console.warn('THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.');
  8728. }
  8729. } else {
  8730. type = 5123;
  8731. }
  8732. } else if (array instanceof Int16Array) {
  8733. type = 5122;
  8734. } else if (array instanceof Uint32Array) {
  8735. type = 5125;
  8736. } else if (array instanceof Int32Array) {
  8737. type = 5124;
  8738. } else if (array instanceof Int8Array) {
  8739. type = 5120;
  8740. } else if (array instanceof Uint8Array) {
  8741. type = 5121;
  8742. }
  8743. return {
  8744. buffer: buffer,
  8745. type: type,
  8746. bytesPerElement: array.BYTES_PER_ELEMENT,
  8747. version: attribute.version
  8748. };
  8749. }
  8750. function updateBuffer(buffer, attribute, bufferType) {
  8751. var array = attribute.array;
  8752. var updateRange = attribute.updateRange;
  8753. gl.bindBuffer(bufferType, buffer);
  8754. if (updateRange.count === -1) {
  8755. // Not using update ranges
  8756. gl.bufferSubData(bufferType, 0, array);
  8757. } else {
  8758. if (isWebGL2) {
  8759. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8760. } else {
  8761. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8762. }
  8763. updateRange.count = -1; // reset range
  8764. }
  8765. } //
  8766. function get(attribute) {
  8767. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8768. return buffers.get(attribute);
  8769. }
  8770. function remove(attribute) {
  8771. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8772. var data = buffers.get(attribute);
  8773. if (data) {
  8774. gl.deleteBuffer(data.buffer);
  8775. buffers.delete(attribute);
  8776. }
  8777. }
  8778. function update(attribute, bufferType) {
  8779. if (attribute.isGLBufferAttribute) {
  8780. var cached = buffers.get(attribute);
  8781. if (!cached || cached.version < attribute.version) {
  8782. buffers.set(attribute, {
  8783. buffer: attribute.buffer,
  8784. type: attribute.type,
  8785. bytesPerElement: attribute.elementSize,
  8786. version: attribute.version
  8787. });
  8788. }
  8789. return;
  8790. }
  8791. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8792. var data = buffers.get(attribute);
  8793. if (data === undefined) {
  8794. buffers.set(attribute, createBuffer(attribute, bufferType));
  8795. } else if (data.version < attribute.version) {
  8796. updateBuffer(data.buffer, attribute, bufferType);
  8797. data.version = attribute.version;
  8798. }
  8799. }
  8800. return {
  8801. get: get,
  8802. remove: remove,
  8803. update: update
  8804. };
  8805. }
  8806. var PlaneGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8807. _inheritsLoose(PlaneGeometry, _BufferGeometry);
  8808. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  8809. var _this;
  8810. if (width === void 0) {
  8811. width = 1;
  8812. }
  8813. if (height === void 0) {
  8814. height = 1;
  8815. }
  8816. if (widthSegments === void 0) {
  8817. widthSegments = 1;
  8818. }
  8819. if (heightSegments === void 0) {
  8820. heightSegments = 1;
  8821. }
  8822. _this = _BufferGeometry.call(this) || this;
  8823. _this.type = 'PlaneGeometry';
  8824. _this.parameters = {
  8825. width: width,
  8826. height: height,
  8827. widthSegments: widthSegments,
  8828. heightSegments: heightSegments
  8829. };
  8830. var width_half = width / 2;
  8831. var height_half = height / 2;
  8832. var gridX = Math.floor(widthSegments);
  8833. var gridY = Math.floor(heightSegments);
  8834. var gridX1 = gridX + 1;
  8835. var gridY1 = gridY + 1;
  8836. var segment_width = width / gridX;
  8837. var segment_height = height / gridY; //
  8838. var indices = [];
  8839. var vertices = [];
  8840. var normals = [];
  8841. var uvs = [];
  8842. for (var iy = 0; iy < gridY1; iy++) {
  8843. var y = iy * segment_height - height_half;
  8844. for (var ix = 0; ix < gridX1; ix++) {
  8845. var x = ix * segment_width - width_half;
  8846. vertices.push(x, -y, 0);
  8847. normals.push(0, 0, 1);
  8848. uvs.push(ix / gridX);
  8849. uvs.push(1 - iy / gridY);
  8850. }
  8851. }
  8852. for (var _iy = 0; _iy < gridY; _iy++) {
  8853. for (var _ix = 0; _ix < gridX; _ix++) {
  8854. var a = _ix + gridX1 * _iy;
  8855. var b = _ix + gridX1 * (_iy + 1);
  8856. var c = _ix + 1 + gridX1 * (_iy + 1);
  8857. var d = _ix + 1 + gridX1 * _iy;
  8858. indices.push(a, b, d);
  8859. indices.push(b, c, d);
  8860. }
  8861. }
  8862. _this.setIndex(indices);
  8863. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8864. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8865. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8866. return _this;
  8867. }
  8868. return PlaneGeometry;
  8869. }(BufferGeometry);
  8870. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8871. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8872. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8873. 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";
  8874. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8875. var begin_vertex = "vec3 transformed = vec3( position );";
  8876. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8877. 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";
  8878. var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 ) * faceDirection;\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif";
  8879. 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";
  8880. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8881. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8882. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8883. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8884. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8885. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8886. 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";
  8887. 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}";
  8888. 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";
  8889. 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";
  8890. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8891. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8892. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8893. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8894. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8895. 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}";
  8896. 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";
  8897. 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";
  8898. 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";
  8899. 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";
  8900. 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";
  8901. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8902. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8903. 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";
  8904. 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";
  8905. 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}";
  8906. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8907. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8908. 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";
  8909. 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";
  8910. 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";
  8911. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8912. 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)";
  8913. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8914. 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)";
  8915. 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";
  8916. 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}";
  8917. 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";
  8918. 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";
  8919. 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";
  8920. 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";
  8921. 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";
  8922. 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";
  8923. 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";
  8924. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8925. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8926. 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";
  8927. 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";
  8928. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8929. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8930. 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";
  8931. 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";
  8932. 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";
  8933. var normal_fragment_begin = "float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\t#ifdef USE_TANGENT\n\t\tvec3 tangent = normalize( vTangent );\n\t\tvec3 bitangent = normalize( vBitangent );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\ttangent = tangent * faceDirection;\n\t\t\tbitangent = bitangent * faceDirection;\n\t\t#endif\n\t\t#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t#endif\n\t#endif\n#endif\nvec3 geometryNormal = normal;";
  8934. var normal_fragment_maps = "#ifdef OBJECTSPACE_NORMALMAP\n\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( TANGENTSPACE_NORMALMAP )\n\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\t#ifdef USE_TANGENT\n\t\tnormal = normalize( vTBN * mapN );\n\t#else\n\t\tnormal = perturbNormal2Arb( -vViewPosition, normal, mapN, faceDirection );\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif";
  8935. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( TANGENTSPACE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP ) )\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 mapN, float faceDirection ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tvec3 N = surf_norm;\n\t\tvec3 q1perp = cross( q1, N );\n\t\tvec3 q0perp = cross( N, q0 );\n\t\tvec3 T = q1perp * st0.x + q0perp * st1.x;\n\t\tvec3 B = q1perp * st0.y + q0perp * st1.y;\n\t\tfloat det = max( dot( T, T ), dot( B, B ) );\n\t\tfloat scale = ( det == 0.0 ) ? 0.0 : faceDirection * inversesqrt( det );\n\t\treturn normalize( T * ( mapN.x * scale ) + B * ( mapN.y * scale ) + N * mapN.z );\n\t}\n#endif";
  8936. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8937. var clearcoat_normal_fragment_maps = "#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\t#ifdef USE_TANGENT\n\t\tclearcoatNormal = normalize( vTBN * clearcoatMapN );\n\t#else\n\t\tclearcoatNormal = perturbNormal2Arb( - vViewPosition, clearcoatNormal, clearcoatMapN, faceDirection );\n\t#endif\n#endif";
  8938. 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";
  8939. 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}";
  8940. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8941. 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;";
  8942. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8943. 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";
  8944. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8945. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8946. 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";
  8947. 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";
  8948. 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";
  8949. 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}";
  8950. 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";
  8951. 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";
  8952. 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";
  8953. 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";
  8954. 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";
  8955. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8956. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8957. 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; }";
  8958. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8959. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8960. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8961. 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";
  8962. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8963. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8964. 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";
  8965. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8966. 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";
  8967. 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}";
  8968. 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}";
  8969. 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}";
  8970. 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}";
  8971. 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}";
  8972. 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}";
  8973. 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}";
  8974. 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}";
  8975. 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}";
  8976. 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}";
  8977. 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}";
  8978. 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}";
  8979. 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}";
  8980. 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}";
  8981. 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}";
  8982. 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}";
  8983. 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}";
  8984. 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}";
  8985. 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}";
  8986. 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}";
  8987. 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}";
  8988. 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}";
  8989. 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}";
  8990. 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}";
  8991. 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}";
  8992. 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}";
  8993. 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}";
  8994. 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}";
  8995. 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}";
  8996. 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}";
  8997. 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}";
  8998. 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}";
  8999. var ShaderChunk = {
  9000. alphamap_fragment: alphamap_fragment,
  9001. alphamap_pars_fragment: alphamap_pars_fragment,
  9002. alphatest_fragment: alphatest_fragment,
  9003. aomap_fragment: aomap_fragment,
  9004. aomap_pars_fragment: aomap_pars_fragment,
  9005. begin_vertex: begin_vertex,
  9006. beginnormal_vertex: beginnormal_vertex,
  9007. bsdfs: bsdfs,
  9008. bumpmap_pars_fragment: bumpmap_pars_fragment,
  9009. clipping_planes_fragment: clipping_planes_fragment,
  9010. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  9011. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  9012. clipping_planes_vertex: clipping_planes_vertex,
  9013. color_fragment: color_fragment,
  9014. color_pars_fragment: color_pars_fragment,
  9015. color_pars_vertex: color_pars_vertex,
  9016. color_vertex: color_vertex,
  9017. common: common,
  9018. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  9019. defaultnormal_vertex: defaultnormal_vertex,
  9020. displacementmap_pars_vertex: displacementmap_pars_vertex,
  9021. displacementmap_vertex: displacementmap_vertex,
  9022. emissivemap_fragment: emissivemap_fragment,
  9023. emissivemap_pars_fragment: emissivemap_pars_fragment,
  9024. encodings_fragment: encodings_fragment,
  9025. encodings_pars_fragment: encodings_pars_fragment,
  9026. envmap_fragment: envmap_fragment,
  9027. envmap_common_pars_fragment: envmap_common_pars_fragment,
  9028. envmap_pars_fragment: envmap_pars_fragment,
  9029. envmap_pars_vertex: envmap_pars_vertex,
  9030. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  9031. envmap_vertex: envmap_vertex,
  9032. fog_vertex: fog_vertex,
  9033. fog_pars_vertex: fog_pars_vertex,
  9034. fog_fragment: fog_fragment,
  9035. fog_pars_fragment: fog_pars_fragment,
  9036. gradientmap_pars_fragment: gradientmap_pars_fragment,
  9037. lightmap_fragment: lightmap_fragment,
  9038. lightmap_pars_fragment: lightmap_pars_fragment,
  9039. lights_lambert_vertex: lights_lambert_vertex,
  9040. lights_pars_begin: lights_pars_begin,
  9041. lights_toon_fragment: lights_toon_fragment,
  9042. lights_toon_pars_fragment: lights_toon_pars_fragment,
  9043. lights_phong_fragment: lights_phong_fragment,
  9044. lights_phong_pars_fragment: lights_phong_pars_fragment,
  9045. lights_physical_fragment: lights_physical_fragment,
  9046. lights_physical_pars_fragment: lights_physical_pars_fragment,
  9047. lights_fragment_begin: lights_fragment_begin,
  9048. lights_fragment_maps: lights_fragment_maps,
  9049. lights_fragment_end: lights_fragment_end,
  9050. logdepthbuf_fragment: logdepthbuf_fragment,
  9051. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  9052. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  9053. logdepthbuf_vertex: logdepthbuf_vertex,
  9054. map_fragment: map_fragment,
  9055. map_pars_fragment: map_pars_fragment,
  9056. map_particle_fragment: map_particle_fragment,
  9057. map_particle_pars_fragment: map_particle_pars_fragment,
  9058. metalnessmap_fragment: metalnessmap_fragment,
  9059. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  9060. morphnormal_vertex: morphnormal_vertex,
  9061. morphtarget_pars_vertex: morphtarget_pars_vertex,
  9062. morphtarget_vertex: morphtarget_vertex,
  9063. normal_fragment_begin: normal_fragment_begin,
  9064. normal_fragment_maps: normal_fragment_maps,
  9065. normalmap_pars_fragment: normalmap_pars_fragment,
  9066. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  9067. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  9068. clearcoat_pars_fragment: clearcoat_pars_fragment,
  9069. packing: packing,
  9070. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  9071. project_vertex: project_vertex,
  9072. dithering_fragment: dithering_fragment,
  9073. dithering_pars_fragment: dithering_pars_fragment,
  9074. roughnessmap_fragment: roughnessmap_fragment,
  9075. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  9076. shadowmap_pars_fragment: shadowmap_pars_fragment,
  9077. shadowmap_pars_vertex: shadowmap_pars_vertex,
  9078. shadowmap_vertex: shadowmap_vertex,
  9079. shadowmask_pars_fragment: shadowmask_pars_fragment,
  9080. skinbase_vertex: skinbase_vertex,
  9081. skinning_pars_vertex: skinning_pars_vertex,
  9082. skinning_vertex: skinning_vertex,
  9083. skinnormal_vertex: skinnormal_vertex,
  9084. specularmap_fragment: specularmap_fragment,
  9085. specularmap_pars_fragment: specularmap_pars_fragment,
  9086. tonemapping_fragment: tonemapping_fragment,
  9087. tonemapping_pars_fragment: tonemapping_pars_fragment,
  9088. transmissionmap_fragment: transmissionmap_fragment,
  9089. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  9090. uv_pars_fragment: uv_pars_fragment,
  9091. uv_pars_vertex: uv_pars_vertex,
  9092. uv_vertex: uv_vertex,
  9093. uv2_pars_fragment: uv2_pars_fragment,
  9094. uv2_pars_vertex: uv2_pars_vertex,
  9095. uv2_vertex: uv2_vertex,
  9096. worldpos_vertex: worldpos_vertex,
  9097. background_frag: background_frag,
  9098. background_vert: background_vert,
  9099. cube_frag: cube_frag,
  9100. cube_vert: cube_vert,
  9101. depth_frag: depth_frag,
  9102. depth_vert: depth_vert,
  9103. distanceRGBA_frag: distanceRGBA_frag,
  9104. distanceRGBA_vert: distanceRGBA_vert,
  9105. equirect_frag: equirect_frag,
  9106. equirect_vert: equirect_vert,
  9107. linedashed_frag: linedashed_frag,
  9108. linedashed_vert: linedashed_vert,
  9109. meshbasic_frag: meshbasic_frag,
  9110. meshbasic_vert: meshbasic_vert,
  9111. meshlambert_frag: meshlambert_frag,
  9112. meshlambert_vert: meshlambert_vert,
  9113. meshmatcap_frag: meshmatcap_frag,
  9114. meshmatcap_vert: meshmatcap_vert,
  9115. meshtoon_frag: meshtoon_frag,
  9116. meshtoon_vert: meshtoon_vert,
  9117. meshphong_frag: meshphong_frag,
  9118. meshphong_vert: meshphong_vert,
  9119. meshphysical_frag: meshphysical_frag,
  9120. meshphysical_vert: meshphysical_vert,
  9121. normal_frag: normal_frag,
  9122. normal_vert: normal_vert,
  9123. points_frag: points_frag,
  9124. points_vert: points_vert,
  9125. shadow_frag: shadow_frag,
  9126. shadow_vert: shadow_vert,
  9127. sprite_frag: sprite_frag,
  9128. sprite_vert: sprite_vert
  9129. };
  9130. /**
  9131. * Uniforms library for shared webgl shaders
  9132. */
  9133. var UniformsLib = {
  9134. common: {
  9135. diffuse: {
  9136. value: new Color(0xeeeeee)
  9137. },
  9138. opacity: {
  9139. value: 1.0
  9140. },
  9141. map: {
  9142. value: null
  9143. },
  9144. uvTransform: {
  9145. value: new Matrix3()
  9146. },
  9147. uv2Transform: {
  9148. value: new Matrix3()
  9149. },
  9150. alphaMap: {
  9151. value: null
  9152. }
  9153. },
  9154. specularmap: {
  9155. specularMap: {
  9156. value: null
  9157. }
  9158. },
  9159. envmap: {
  9160. envMap: {
  9161. value: null
  9162. },
  9163. flipEnvMap: {
  9164. value: -1
  9165. },
  9166. reflectivity: {
  9167. value: 1.0
  9168. },
  9169. refractionRatio: {
  9170. value: 0.98
  9171. },
  9172. maxMipLevel: {
  9173. value: 0
  9174. }
  9175. },
  9176. aomap: {
  9177. aoMap: {
  9178. value: null
  9179. },
  9180. aoMapIntensity: {
  9181. value: 1
  9182. }
  9183. },
  9184. lightmap: {
  9185. lightMap: {
  9186. value: null
  9187. },
  9188. lightMapIntensity: {
  9189. value: 1
  9190. }
  9191. },
  9192. emissivemap: {
  9193. emissiveMap: {
  9194. value: null
  9195. }
  9196. },
  9197. bumpmap: {
  9198. bumpMap: {
  9199. value: null
  9200. },
  9201. bumpScale: {
  9202. value: 1
  9203. }
  9204. },
  9205. normalmap: {
  9206. normalMap: {
  9207. value: null
  9208. },
  9209. normalScale: {
  9210. value: new Vector2(1, 1)
  9211. }
  9212. },
  9213. displacementmap: {
  9214. displacementMap: {
  9215. value: null
  9216. },
  9217. displacementScale: {
  9218. value: 1
  9219. },
  9220. displacementBias: {
  9221. value: 0
  9222. }
  9223. },
  9224. roughnessmap: {
  9225. roughnessMap: {
  9226. value: null
  9227. }
  9228. },
  9229. metalnessmap: {
  9230. metalnessMap: {
  9231. value: null
  9232. }
  9233. },
  9234. gradientmap: {
  9235. gradientMap: {
  9236. value: null
  9237. }
  9238. },
  9239. fog: {
  9240. fogDensity: {
  9241. value: 0.00025
  9242. },
  9243. fogNear: {
  9244. value: 1
  9245. },
  9246. fogFar: {
  9247. value: 2000
  9248. },
  9249. fogColor: {
  9250. value: new Color(0xffffff)
  9251. }
  9252. },
  9253. lights: {
  9254. ambientLightColor: {
  9255. value: []
  9256. },
  9257. lightProbe: {
  9258. value: []
  9259. },
  9260. directionalLights: {
  9261. value: [],
  9262. properties: {
  9263. direction: {},
  9264. color: {}
  9265. }
  9266. },
  9267. directionalLightShadows: {
  9268. value: [],
  9269. properties: {
  9270. shadowBias: {},
  9271. shadowNormalBias: {},
  9272. shadowRadius: {},
  9273. shadowMapSize: {}
  9274. }
  9275. },
  9276. directionalShadowMap: {
  9277. value: []
  9278. },
  9279. directionalShadowMatrix: {
  9280. value: []
  9281. },
  9282. spotLights: {
  9283. value: [],
  9284. properties: {
  9285. color: {},
  9286. position: {},
  9287. direction: {},
  9288. distance: {},
  9289. coneCos: {},
  9290. penumbraCos: {},
  9291. decay: {}
  9292. }
  9293. },
  9294. spotLightShadows: {
  9295. value: [],
  9296. properties: {
  9297. shadowBias: {},
  9298. shadowNormalBias: {},
  9299. shadowRadius: {},
  9300. shadowMapSize: {}
  9301. }
  9302. },
  9303. spotShadowMap: {
  9304. value: []
  9305. },
  9306. spotShadowMatrix: {
  9307. value: []
  9308. },
  9309. pointLights: {
  9310. value: [],
  9311. properties: {
  9312. color: {},
  9313. position: {},
  9314. decay: {},
  9315. distance: {}
  9316. }
  9317. },
  9318. pointLightShadows: {
  9319. value: [],
  9320. properties: {
  9321. shadowBias: {},
  9322. shadowNormalBias: {},
  9323. shadowRadius: {},
  9324. shadowMapSize: {},
  9325. shadowCameraNear: {},
  9326. shadowCameraFar: {}
  9327. }
  9328. },
  9329. pointShadowMap: {
  9330. value: []
  9331. },
  9332. pointShadowMatrix: {
  9333. value: []
  9334. },
  9335. hemisphereLights: {
  9336. value: [],
  9337. properties: {
  9338. direction: {},
  9339. skyColor: {},
  9340. groundColor: {}
  9341. }
  9342. },
  9343. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  9344. rectAreaLights: {
  9345. value: [],
  9346. properties: {
  9347. color: {},
  9348. position: {},
  9349. width: {},
  9350. height: {}
  9351. }
  9352. },
  9353. ltc_1: {
  9354. value: null
  9355. },
  9356. ltc_2: {
  9357. value: null
  9358. }
  9359. },
  9360. points: {
  9361. diffuse: {
  9362. value: new Color(0xeeeeee)
  9363. },
  9364. opacity: {
  9365. value: 1.0
  9366. },
  9367. size: {
  9368. value: 1.0
  9369. },
  9370. scale: {
  9371. value: 1.0
  9372. },
  9373. map: {
  9374. value: null
  9375. },
  9376. alphaMap: {
  9377. value: null
  9378. },
  9379. uvTransform: {
  9380. value: new Matrix3()
  9381. }
  9382. },
  9383. sprite: {
  9384. diffuse: {
  9385. value: new Color(0xeeeeee)
  9386. },
  9387. opacity: {
  9388. value: 1.0
  9389. },
  9390. center: {
  9391. value: new Vector2(0.5, 0.5)
  9392. },
  9393. rotation: {
  9394. value: 0.0
  9395. },
  9396. map: {
  9397. value: null
  9398. },
  9399. alphaMap: {
  9400. value: null
  9401. },
  9402. uvTransform: {
  9403. value: new Matrix3()
  9404. }
  9405. }
  9406. };
  9407. var ShaderLib = {
  9408. basic: {
  9409. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  9410. vertexShader: ShaderChunk.meshbasic_vert,
  9411. fragmentShader: ShaderChunk.meshbasic_frag
  9412. },
  9413. lambert: {
  9414. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  9415. emissive: {
  9416. value: new Color(0x000000)
  9417. }
  9418. }]),
  9419. vertexShader: ShaderChunk.meshlambert_vert,
  9420. fragmentShader: ShaderChunk.meshlambert_frag
  9421. },
  9422. phong: {
  9423. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  9424. emissive: {
  9425. value: new Color(0x000000)
  9426. },
  9427. specular: {
  9428. value: new Color(0x111111)
  9429. },
  9430. shininess: {
  9431. value: 30
  9432. }
  9433. }]),
  9434. vertexShader: ShaderChunk.meshphong_vert,
  9435. fragmentShader: ShaderChunk.meshphong_frag
  9436. },
  9437. standard: {
  9438. 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, {
  9439. emissive: {
  9440. value: new Color(0x000000)
  9441. },
  9442. roughness: {
  9443. value: 1.0
  9444. },
  9445. metalness: {
  9446. value: 0.0
  9447. },
  9448. envMapIntensity: {
  9449. value: 1
  9450. } // temporary
  9451. }]),
  9452. vertexShader: ShaderChunk.meshphysical_vert,
  9453. fragmentShader: ShaderChunk.meshphysical_frag
  9454. },
  9455. toon: {
  9456. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  9457. emissive: {
  9458. value: new Color(0x000000)
  9459. }
  9460. }]),
  9461. vertexShader: ShaderChunk.meshtoon_vert,
  9462. fragmentShader: ShaderChunk.meshtoon_frag
  9463. },
  9464. matcap: {
  9465. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  9466. matcap: {
  9467. value: null
  9468. }
  9469. }]),
  9470. vertexShader: ShaderChunk.meshmatcap_vert,
  9471. fragmentShader: ShaderChunk.meshmatcap_frag
  9472. },
  9473. points: {
  9474. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  9475. vertexShader: ShaderChunk.points_vert,
  9476. fragmentShader: ShaderChunk.points_frag
  9477. },
  9478. dashed: {
  9479. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  9480. scale: {
  9481. value: 1
  9482. },
  9483. dashSize: {
  9484. value: 1
  9485. },
  9486. totalSize: {
  9487. value: 2
  9488. }
  9489. }]),
  9490. vertexShader: ShaderChunk.linedashed_vert,
  9491. fragmentShader: ShaderChunk.linedashed_frag
  9492. },
  9493. depth: {
  9494. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  9495. vertexShader: ShaderChunk.depth_vert,
  9496. fragmentShader: ShaderChunk.depth_frag
  9497. },
  9498. normal: {
  9499. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  9500. opacity: {
  9501. value: 1.0
  9502. }
  9503. }]),
  9504. vertexShader: ShaderChunk.normal_vert,
  9505. fragmentShader: ShaderChunk.normal_frag
  9506. },
  9507. sprite: {
  9508. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  9509. vertexShader: ShaderChunk.sprite_vert,
  9510. fragmentShader: ShaderChunk.sprite_frag
  9511. },
  9512. background: {
  9513. uniforms: {
  9514. uvTransform: {
  9515. value: new Matrix3()
  9516. },
  9517. t2D: {
  9518. value: null
  9519. }
  9520. },
  9521. vertexShader: ShaderChunk.background_vert,
  9522. fragmentShader: ShaderChunk.background_frag
  9523. },
  9524. /* -------------------------------------------------------------------------
  9525. // Cube map shader
  9526. ------------------------------------------------------------------------- */
  9527. cube: {
  9528. uniforms: mergeUniforms([UniformsLib.envmap, {
  9529. opacity: {
  9530. value: 1.0
  9531. }
  9532. }]),
  9533. vertexShader: ShaderChunk.cube_vert,
  9534. fragmentShader: ShaderChunk.cube_frag
  9535. },
  9536. equirect: {
  9537. uniforms: {
  9538. tEquirect: {
  9539. value: null
  9540. }
  9541. },
  9542. vertexShader: ShaderChunk.equirect_vert,
  9543. fragmentShader: ShaderChunk.equirect_frag
  9544. },
  9545. distanceRGBA: {
  9546. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  9547. referencePosition: {
  9548. value: new Vector3()
  9549. },
  9550. nearDistance: {
  9551. value: 1
  9552. },
  9553. farDistance: {
  9554. value: 1000
  9555. }
  9556. }]),
  9557. vertexShader: ShaderChunk.distanceRGBA_vert,
  9558. fragmentShader: ShaderChunk.distanceRGBA_frag
  9559. },
  9560. shadow: {
  9561. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  9562. color: {
  9563. value: new Color(0x00000)
  9564. },
  9565. opacity: {
  9566. value: 1.0
  9567. }
  9568. }]),
  9569. vertexShader: ShaderChunk.shadow_vert,
  9570. fragmentShader: ShaderChunk.shadow_frag
  9571. }
  9572. };
  9573. ShaderLib.physical = {
  9574. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  9575. clearcoat: {
  9576. value: 0
  9577. },
  9578. clearcoatMap: {
  9579. value: null
  9580. },
  9581. clearcoatRoughness: {
  9582. value: 0
  9583. },
  9584. clearcoatRoughnessMap: {
  9585. value: null
  9586. },
  9587. clearcoatNormalScale: {
  9588. value: new Vector2(1, 1)
  9589. },
  9590. clearcoatNormalMap: {
  9591. value: null
  9592. },
  9593. sheen: {
  9594. value: new Color(0x000000)
  9595. },
  9596. transmission: {
  9597. value: 0
  9598. },
  9599. transmissionMap: {
  9600. value: null
  9601. }
  9602. }]),
  9603. vertexShader: ShaderChunk.meshphysical_vert,
  9604. fragmentShader: ShaderChunk.meshphysical_frag
  9605. };
  9606. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  9607. var clearColor = new Color(0x000000);
  9608. var clearAlpha = 0;
  9609. var planeMesh;
  9610. var boxMesh;
  9611. var currentBackground = null;
  9612. var currentBackgroundVersion = 0;
  9613. var currentTonemapping = null;
  9614. function render(renderList, scene, camera, forceClear) {
  9615. var background = scene.isScene === true ? scene.background : null;
  9616. if (background && background.isTexture) {
  9617. background = cubemaps.get(background);
  9618. } // Ignore background in AR
  9619. // TODO: Reconsider this.
  9620. var xr = renderer.xr;
  9621. var session = xr.getSession && xr.getSession();
  9622. if (session && session.environmentBlendMode === 'additive') {
  9623. background = null;
  9624. }
  9625. if (background === null) {
  9626. setClear(clearColor, clearAlpha);
  9627. } else if (background && background.isColor) {
  9628. setClear(background, 1);
  9629. forceClear = true;
  9630. }
  9631. if (renderer.autoClear || forceClear) {
  9632. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  9633. }
  9634. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  9635. if (boxMesh === undefined) {
  9636. boxMesh = new Mesh(new BoxGeometry(1, 1, 1), new ShaderMaterial({
  9637. name: 'BackgroundCubeMaterial',
  9638. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  9639. vertexShader: ShaderLib.cube.vertexShader,
  9640. fragmentShader: ShaderLib.cube.fragmentShader,
  9641. side: BackSide,
  9642. depthTest: false,
  9643. depthWrite: false,
  9644. fog: false
  9645. }));
  9646. boxMesh.geometry.deleteAttribute('normal');
  9647. boxMesh.geometry.deleteAttribute('uv');
  9648. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  9649. this.matrixWorld.copyPosition(camera.matrixWorld);
  9650. }; // enable code injection for non-built-in material
  9651. Object.defineProperty(boxMesh.material, 'envMap', {
  9652. get: function get() {
  9653. return this.uniforms.envMap.value;
  9654. }
  9655. });
  9656. objects.update(boxMesh);
  9657. }
  9658. if (background.isWebGLCubeRenderTarget) {
  9659. // TODO Deprecate
  9660. background = background.texture;
  9661. }
  9662. boxMesh.material.uniforms.envMap.value = background;
  9663. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  9664. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9665. boxMesh.material.needsUpdate = true;
  9666. currentBackground = background;
  9667. currentBackgroundVersion = background.version;
  9668. currentTonemapping = renderer.toneMapping;
  9669. } // push to the pre-sorted opaque render list
  9670. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  9671. } else if (background && background.isTexture) {
  9672. if (planeMesh === undefined) {
  9673. planeMesh = new Mesh(new PlaneGeometry(2, 2), new ShaderMaterial({
  9674. name: 'BackgroundMaterial',
  9675. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  9676. vertexShader: ShaderLib.background.vertexShader,
  9677. fragmentShader: ShaderLib.background.fragmentShader,
  9678. side: FrontSide,
  9679. depthTest: false,
  9680. depthWrite: false,
  9681. fog: false
  9682. }));
  9683. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  9684. Object.defineProperty(planeMesh.material, 'map', {
  9685. get: function get() {
  9686. return this.uniforms.t2D.value;
  9687. }
  9688. });
  9689. objects.update(planeMesh);
  9690. }
  9691. planeMesh.material.uniforms.t2D.value = background;
  9692. if (background.matrixAutoUpdate === true) {
  9693. background.updateMatrix();
  9694. }
  9695. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  9696. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9697. planeMesh.material.needsUpdate = true;
  9698. currentBackground = background;
  9699. currentBackgroundVersion = background.version;
  9700. currentTonemapping = renderer.toneMapping;
  9701. } // push to the pre-sorted opaque render list
  9702. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  9703. }
  9704. }
  9705. function setClear(color, alpha) {
  9706. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  9707. }
  9708. return {
  9709. getClearColor: function getClearColor() {
  9710. return clearColor;
  9711. },
  9712. setClearColor: function setClearColor(color, alpha) {
  9713. if (alpha === void 0) {
  9714. alpha = 1;
  9715. }
  9716. clearColor.set(color);
  9717. clearAlpha = alpha;
  9718. setClear(clearColor, clearAlpha);
  9719. },
  9720. getClearAlpha: function getClearAlpha() {
  9721. return clearAlpha;
  9722. },
  9723. setClearAlpha: function setClearAlpha(alpha) {
  9724. clearAlpha = alpha;
  9725. setClear(clearColor, clearAlpha);
  9726. },
  9727. render: render
  9728. };
  9729. }
  9730. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  9731. var maxVertexAttributes = gl.getParameter(34921);
  9732. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  9733. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9734. var bindingStates = {};
  9735. var defaultState = createBindingState(null);
  9736. var currentState = defaultState;
  9737. function setup(object, material, program, geometry, index) {
  9738. var updateBuffers = false;
  9739. if (vaoAvailable) {
  9740. var state = getBindingState(geometry, program, material);
  9741. if (currentState !== state) {
  9742. currentState = state;
  9743. bindVertexArrayObject(currentState.object);
  9744. }
  9745. updateBuffers = needsUpdate(geometry, index);
  9746. if (updateBuffers) saveCache(geometry, index);
  9747. } else {
  9748. var wireframe = material.wireframe === true;
  9749. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9750. currentState.geometry = geometry.id;
  9751. currentState.program = program.id;
  9752. currentState.wireframe = wireframe;
  9753. updateBuffers = true;
  9754. }
  9755. }
  9756. if (object.isInstancedMesh === true) {
  9757. updateBuffers = true;
  9758. }
  9759. if (index !== null) {
  9760. attributes.update(index, 34963);
  9761. }
  9762. if (updateBuffers) {
  9763. setupVertexAttributes(object, material, program, geometry);
  9764. if (index !== null) {
  9765. gl.bindBuffer(34963, attributes.get(index).buffer);
  9766. }
  9767. }
  9768. }
  9769. function createVertexArrayObject() {
  9770. if (capabilities.isWebGL2) return gl.createVertexArray();
  9771. return extension.createVertexArrayOES();
  9772. }
  9773. function bindVertexArrayObject(vao) {
  9774. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9775. return extension.bindVertexArrayOES(vao);
  9776. }
  9777. function deleteVertexArrayObject(vao) {
  9778. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9779. return extension.deleteVertexArrayOES(vao);
  9780. }
  9781. function getBindingState(geometry, program, material) {
  9782. var wireframe = material.wireframe === true;
  9783. var programMap = bindingStates[geometry.id];
  9784. if (programMap === undefined) {
  9785. programMap = {};
  9786. bindingStates[geometry.id] = programMap;
  9787. }
  9788. var stateMap = programMap[program.id];
  9789. if (stateMap === undefined) {
  9790. stateMap = {};
  9791. programMap[program.id] = stateMap;
  9792. }
  9793. var state = stateMap[wireframe];
  9794. if (state === undefined) {
  9795. state = createBindingState(createVertexArrayObject());
  9796. stateMap[wireframe] = state;
  9797. }
  9798. return state;
  9799. }
  9800. function createBindingState(vao) {
  9801. var newAttributes = [];
  9802. var enabledAttributes = [];
  9803. var attributeDivisors = [];
  9804. for (var i = 0; i < maxVertexAttributes; i++) {
  9805. newAttributes[i] = 0;
  9806. enabledAttributes[i] = 0;
  9807. attributeDivisors[i] = 0;
  9808. }
  9809. return {
  9810. // for backward compatibility on non-VAO support browser
  9811. geometry: null,
  9812. program: null,
  9813. wireframe: false,
  9814. newAttributes: newAttributes,
  9815. enabledAttributes: enabledAttributes,
  9816. attributeDivisors: attributeDivisors,
  9817. object: vao,
  9818. attributes: {},
  9819. index: null
  9820. };
  9821. }
  9822. function needsUpdate(geometry, index) {
  9823. var cachedAttributes = currentState.attributes;
  9824. var geometryAttributes = geometry.attributes;
  9825. var attributesNum = 0;
  9826. for (var key in geometryAttributes) {
  9827. var cachedAttribute = cachedAttributes[key];
  9828. var geometryAttribute = geometryAttributes[key];
  9829. if (cachedAttribute === undefined) return true;
  9830. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9831. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9832. attributesNum++;
  9833. }
  9834. if (currentState.attributesNum !== attributesNum) return true;
  9835. if (currentState.index !== index) return true;
  9836. return false;
  9837. }
  9838. function saveCache(geometry, index) {
  9839. var cache = {};
  9840. var attributes = geometry.attributes;
  9841. var attributesNum = 0;
  9842. for (var key in attributes) {
  9843. var attribute = attributes[key];
  9844. var data = {};
  9845. data.attribute = attribute;
  9846. if (attribute.data) {
  9847. data.data = attribute.data;
  9848. }
  9849. cache[key] = data;
  9850. attributesNum++;
  9851. }
  9852. currentState.attributes = cache;
  9853. currentState.attributesNum = attributesNum;
  9854. currentState.index = index;
  9855. }
  9856. function initAttributes() {
  9857. var newAttributes = currentState.newAttributes;
  9858. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9859. newAttributes[i] = 0;
  9860. }
  9861. }
  9862. function enableAttribute(attribute) {
  9863. enableAttributeAndDivisor(attribute, 0);
  9864. }
  9865. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9866. var newAttributes = currentState.newAttributes;
  9867. var enabledAttributes = currentState.enabledAttributes;
  9868. var attributeDivisors = currentState.attributeDivisors;
  9869. newAttributes[attribute] = 1;
  9870. if (enabledAttributes[attribute] === 0) {
  9871. gl.enableVertexAttribArray(attribute);
  9872. enabledAttributes[attribute] = 1;
  9873. }
  9874. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9875. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9876. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9877. attributeDivisors[attribute] = meshPerAttribute;
  9878. }
  9879. }
  9880. function disableUnusedAttributes() {
  9881. var newAttributes = currentState.newAttributes;
  9882. var enabledAttributes = currentState.enabledAttributes;
  9883. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9884. if (enabledAttributes[i] !== newAttributes[i]) {
  9885. gl.disableVertexAttribArray(i);
  9886. enabledAttributes[i] = 0;
  9887. }
  9888. }
  9889. }
  9890. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9891. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9892. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9893. } else {
  9894. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9895. }
  9896. }
  9897. function setupVertexAttributes(object, material, program, geometry) {
  9898. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9899. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9900. }
  9901. initAttributes();
  9902. var geometryAttributes = geometry.attributes;
  9903. var programAttributes = program.getAttributes();
  9904. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9905. for (var name in programAttributes) {
  9906. var programAttribute = programAttributes[name];
  9907. if (programAttribute >= 0) {
  9908. var geometryAttribute = geometryAttributes[name];
  9909. if (geometryAttribute !== undefined) {
  9910. var normalized = geometryAttribute.normalized;
  9911. var size = geometryAttribute.itemSize;
  9912. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9913. if (attribute === undefined) continue;
  9914. var buffer = attribute.buffer;
  9915. var type = attribute.type;
  9916. var bytesPerElement = attribute.bytesPerElement;
  9917. if (geometryAttribute.isInterleavedBufferAttribute) {
  9918. var data = geometryAttribute.data;
  9919. var stride = data.stride;
  9920. var offset = geometryAttribute.offset;
  9921. if (data && data.isInstancedInterleavedBuffer) {
  9922. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9923. if (geometry._maxInstanceCount === undefined) {
  9924. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9925. }
  9926. } else {
  9927. enableAttribute(programAttribute);
  9928. }
  9929. gl.bindBuffer(34962, buffer);
  9930. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9931. } else {
  9932. if (geometryAttribute.isInstancedBufferAttribute) {
  9933. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9934. if (geometry._maxInstanceCount === undefined) {
  9935. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9936. }
  9937. } else {
  9938. enableAttribute(programAttribute);
  9939. }
  9940. gl.bindBuffer(34962, buffer);
  9941. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9942. }
  9943. } else if (name === 'instanceMatrix') {
  9944. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9945. if (_attribute === undefined) continue;
  9946. var _buffer = _attribute.buffer;
  9947. var _type = _attribute.type;
  9948. enableAttributeAndDivisor(programAttribute + 0, 1);
  9949. enableAttributeAndDivisor(programAttribute + 1, 1);
  9950. enableAttributeAndDivisor(programAttribute + 2, 1);
  9951. enableAttributeAndDivisor(programAttribute + 3, 1);
  9952. gl.bindBuffer(34962, _buffer);
  9953. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9954. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9955. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9956. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9957. } else if (name === 'instanceColor') {
  9958. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9959. if (_attribute2 === undefined) continue;
  9960. var _buffer2 = _attribute2.buffer;
  9961. var _type2 = _attribute2.type;
  9962. enableAttributeAndDivisor(programAttribute, 1);
  9963. gl.bindBuffer(34962, _buffer2);
  9964. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9965. } else if (materialDefaultAttributeValues !== undefined) {
  9966. var value = materialDefaultAttributeValues[name];
  9967. if (value !== undefined) {
  9968. switch (value.length) {
  9969. case 2:
  9970. gl.vertexAttrib2fv(programAttribute, value);
  9971. break;
  9972. case 3:
  9973. gl.vertexAttrib3fv(programAttribute, value);
  9974. break;
  9975. case 4:
  9976. gl.vertexAttrib4fv(programAttribute, value);
  9977. break;
  9978. default:
  9979. gl.vertexAttrib1fv(programAttribute, value);
  9980. }
  9981. }
  9982. }
  9983. }
  9984. }
  9985. disableUnusedAttributes();
  9986. }
  9987. function dispose() {
  9988. reset();
  9989. for (var geometryId in bindingStates) {
  9990. var programMap = bindingStates[geometryId];
  9991. for (var programId in programMap) {
  9992. var stateMap = programMap[programId];
  9993. for (var wireframe in stateMap) {
  9994. deleteVertexArrayObject(stateMap[wireframe].object);
  9995. delete stateMap[wireframe];
  9996. }
  9997. delete programMap[programId];
  9998. }
  9999. delete bindingStates[geometryId];
  10000. }
  10001. }
  10002. function releaseStatesOfGeometry(geometry) {
  10003. if (bindingStates[geometry.id] === undefined) return;
  10004. var programMap = bindingStates[geometry.id];
  10005. for (var programId in programMap) {
  10006. var stateMap = programMap[programId];
  10007. for (var wireframe in stateMap) {
  10008. deleteVertexArrayObject(stateMap[wireframe].object);
  10009. delete stateMap[wireframe];
  10010. }
  10011. delete programMap[programId];
  10012. }
  10013. delete bindingStates[geometry.id];
  10014. }
  10015. function releaseStatesOfProgram(program) {
  10016. for (var geometryId in bindingStates) {
  10017. var programMap = bindingStates[geometryId];
  10018. if (programMap[program.id] === undefined) continue;
  10019. var stateMap = programMap[program.id];
  10020. for (var wireframe in stateMap) {
  10021. deleteVertexArrayObject(stateMap[wireframe].object);
  10022. delete stateMap[wireframe];
  10023. }
  10024. delete programMap[program.id];
  10025. }
  10026. }
  10027. function reset() {
  10028. resetDefaultState();
  10029. if (currentState === defaultState) return;
  10030. currentState = defaultState;
  10031. bindVertexArrayObject(currentState.object);
  10032. } // for backward-compatilibity
  10033. function resetDefaultState() {
  10034. defaultState.geometry = null;
  10035. defaultState.program = null;
  10036. defaultState.wireframe = false;
  10037. }
  10038. return {
  10039. setup: setup,
  10040. reset: reset,
  10041. resetDefaultState: resetDefaultState,
  10042. dispose: dispose,
  10043. releaseStatesOfGeometry: releaseStatesOfGeometry,
  10044. releaseStatesOfProgram: releaseStatesOfProgram,
  10045. initAttributes: initAttributes,
  10046. enableAttribute: enableAttribute,
  10047. disableUnusedAttributes: disableUnusedAttributes
  10048. };
  10049. }
  10050. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  10051. var isWebGL2 = capabilities.isWebGL2;
  10052. var mode;
  10053. function setMode(value) {
  10054. mode = value;
  10055. }
  10056. function render(start, count) {
  10057. gl.drawArrays(mode, start, count);
  10058. info.update(count, mode, 1);
  10059. }
  10060. function renderInstances(start, count, primcount) {
  10061. if (primcount === 0) return;
  10062. var extension, methodName;
  10063. if (isWebGL2) {
  10064. extension = gl;
  10065. methodName = 'drawArraysInstanced';
  10066. } else {
  10067. extension = extensions.get('ANGLE_instanced_arrays');
  10068. methodName = 'drawArraysInstancedANGLE';
  10069. if (extension === null) {
  10070. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  10071. return;
  10072. }
  10073. }
  10074. extension[methodName](mode, start, count, primcount);
  10075. info.update(count, mode, primcount);
  10076. } //
  10077. this.setMode = setMode;
  10078. this.render = render;
  10079. this.renderInstances = renderInstances;
  10080. }
  10081. function WebGLCapabilities(gl, extensions, parameters) {
  10082. var maxAnisotropy;
  10083. function getMaxAnisotropy() {
  10084. if (maxAnisotropy !== undefined) return maxAnisotropy;
  10085. if (extensions.has('EXT_texture_filter_anisotropic') === true) {
  10086. var extension = extensions.get('EXT_texture_filter_anisotropic');
  10087. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  10088. } else {
  10089. maxAnisotropy = 0;
  10090. }
  10091. return maxAnisotropy;
  10092. }
  10093. function getMaxPrecision(precision) {
  10094. if (precision === 'highp') {
  10095. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  10096. return 'highp';
  10097. }
  10098. precision = 'mediump';
  10099. }
  10100. if (precision === 'mediump') {
  10101. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  10102. return 'mediump';
  10103. }
  10104. }
  10105. return 'lowp';
  10106. }
  10107. /* eslint-disable no-undef */
  10108. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  10109. /* eslint-enable no-undef */
  10110. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  10111. var maxPrecision = getMaxPrecision(precision);
  10112. if (maxPrecision !== precision) {
  10113. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  10114. precision = maxPrecision;
  10115. }
  10116. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  10117. var maxTextures = gl.getParameter(34930);
  10118. var maxVertexTextures = gl.getParameter(35660);
  10119. var maxTextureSize = gl.getParameter(3379);
  10120. var maxCubemapSize = gl.getParameter(34076);
  10121. var maxAttributes = gl.getParameter(34921);
  10122. var maxVertexUniforms = gl.getParameter(36347);
  10123. var maxVaryings = gl.getParameter(36348);
  10124. var maxFragmentUniforms = gl.getParameter(36349);
  10125. var vertexTextures = maxVertexTextures > 0;
  10126. var floatFragmentTextures = isWebGL2 || extensions.has('OES_texture_float');
  10127. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  10128. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  10129. return {
  10130. isWebGL2: isWebGL2,
  10131. getMaxAnisotropy: getMaxAnisotropy,
  10132. getMaxPrecision: getMaxPrecision,
  10133. precision: precision,
  10134. logarithmicDepthBuffer: logarithmicDepthBuffer,
  10135. maxTextures: maxTextures,
  10136. maxVertexTextures: maxVertexTextures,
  10137. maxTextureSize: maxTextureSize,
  10138. maxCubemapSize: maxCubemapSize,
  10139. maxAttributes: maxAttributes,
  10140. maxVertexUniforms: maxVertexUniforms,
  10141. maxVaryings: maxVaryings,
  10142. maxFragmentUniforms: maxFragmentUniforms,
  10143. vertexTextures: vertexTextures,
  10144. floatFragmentTextures: floatFragmentTextures,
  10145. floatVertexTextures: floatVertexTextures,
  10146. maxSamples: maxSamples
  10147. };
  10148. }
  10149. function WebGLClipping(properties) {
  10150. var scope = this;
  10151. var globalState = null,
  10152. numGlobalPlanes = 0,
  10153. localClippingEnabled = false,
  10154. renderingShadows = false;
  10155. var plane = new Plane(),
  10156. viewNormalMatrix = new Matrix3(),
  10157. uniform = {
  10158. value: null,
  10159. needsUpdate: false
  10160. };
  10161. this.uniform = uniform;
  10162. this.numPlanes = 0;
  10163. this.numIntersection = 0;
  10164. this.init = function (planes, enableLocalClipping, camera) {
  10165. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  10166. // run another frame in order to reset the state:
  10167. numGlobalPlanes !== 0 || localClippingEnabled;
  10168. localClippingEnabled = enableLocalClipping;
  10169. globalState = projectPlanes(planes, camera, 0);
  10170. numGlobalPlanes = planes.length;
  10171. return enabled;
  10172. };
  10173. this.beginShadows = function () {
  10174. renderingShadows = true;
  10175. projectPlanes(null);
  10176. };
  10177. this.endShadows = function () {
  10178. renderingShadows = false;
  10179. resetGlobalState();
  10180. };
  10181. this.setState = function (material, camera, useCache) {
  10182. var planes = material.clippingPlanes,
  10183. clipIntersection = material.clipIntersection,
  10184. clipShadows = material.clipShadows;
  10185. var materialProperties = properties.get(material);
  10186. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  10187. // there's no local clipping
  10188. if (renderingShadows) {
  10189. // there's no global clipping
  10190. projectPlanes(null);
  10191. } else {
  10192. resetGlobalState();
  10193. }
  10194. } else {
  10195. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  10196. lGlobal = nGlobal * 4;
  10197. var dstArray = materialProperties.clippingState || null;
  10198. uniform.value = dstArray; // ensure unique state
  10199. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  10200. for (var i = 0; i !== lGlobal; ++i) {
  10201. dstArray[i] = globalState[i];
  10202. }
  10203. materialProperties.clippingState = dstArray;
  10204. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  10205. this.numPlanes += nGlobal;
  10206. }
  10207. };
  10208. function resetGlobalState() {
  10209. if (uniform.value !== globalState) {
  10210. uniform.value = globalState;
  10211. uniform.needsUpdate = numGlobalPlanes > 0;
  10212. }
  10213. scope.numPlanes = numGlobalPlanes;
  10214. scope.numIntersection = 0;
  10215. }
  10216. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  10217. var nPlanes = planes !== null ? planes.length : 0;
  10218. var dstArray = null;
  10219. if (nPlanes !== 0) {
  10220. dstArray = uniform.value;
  10221. if (skipTransform !== true || dstArray === null) {
  10222. var flatSize = dstOffset + nPlanes * 4,
  10223. viewMatrix = camera.matrixWorldInverse;
  10224. viewNormalMatrix.getNormalMatrix(viewMatrix);
  10225. if (dstArray === null || dstArray.length < flatSize) {
  10226. dstArray = new Float32Array(flatSize);
  10227. }
  10228. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  10229. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  10230. plane.normal.toArray(dstArray, i4);
  10231. dstArray[i4 + 3] = plane.constant;
  10232. }
  10233. }
  10234. uniform.value = dstArray;
  10235. uniform.needsUpdate = true;
  10236. }
  10237. scope.numPlanes = nPlanes;
  10238. scope.numIntersection = 0;
  10239. return dstArray;
  10240. }
  10241. }
  10242. function WebGLCubeMaps(renderer) {
  10243. var cubemaps = new WeakMap();
  10244. function mapTextureMapping(texture, mapping) {
  10245. if (mapping === EquirectangularReflectionMapping) {
  10246. texture.mapping = CubeReflectionMapping;
  10247. } else if (mapping === EquirectangularRefractionMapping) {
  10248. texture.mapping = CubeRefractionMapping;
  10249. }
  10250. return texture;
  10251. }
  10252. function get(texture) {
  10253. if (texture && texture.isTexture) {
  10254. var mapping = texture.mapping;
  10255. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  10256. if (cubemaps.has(texture)) {
  10257. var cubemap = cubemaps.get(texture).texture;
  10258. return mapTextureMapping(cubemap, texture.mapping);
  10259. } else {
  10260. var image = texture.image;
  10261. if (image && image.height > 0) {
  10262. var currentRenderTarget = renderer.getRenderTarget();
  10263. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  10264. renderTarget.fromEquirectangularTexture(renderer, texture);
  10265. cubemaps.set(texture, renderTarget);
  10266. renderer.setRenderTarget(currentRenderTarget);
  10267. texture.addEventListener('dispose', onTextureDispose);
  10268. return mapTextureMapping(renderTarget.texture, texture.mapping);
  10269. } else {
  10270. // image not yet ready. try the conversion next frame
  10271. return null;
  10272. }
  10273. }
  10274. }
  10275. }
  10276. return texture;
  10277. }
  10278. function onTextureDispose(event) {
  10279. var texture = event.target;
  10280. texture.removeEventListener('dispose', onTextureDispose);
  10281. var cubemap = cubemaps.get(texture);
  10282. if (cubemap !== undefined) {
  10283. cubemaps.delete(texture);
  10284. cubemap.dispose();
  10285. }
  10286. }
  10287. function dispose() {
  10288. cubemaps = new WeakMap();
  10289. }
  10290. return {
  10291. get: get,
  10292. dispose: dispose
  10293. };
  10294. }
  10295. function WebGLExtensions(gl) {
  10296. var extensions = {};
  10297. function getExtension(name) {
  10298. if (extensions[name] !== undefined) {
  10299. return extensions[name];
  10300. }
  10301. var extension;
  10302. switch (name) {
  10303. case 'WEBGL_depth_texture':
  10304. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  10305. break;
  10306. case 'EXT_texture_filter_anisotropic':
  10307. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  10308. break;
  10309. case 'WEBGL_compressed_texture_s3tc':
  10310. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  10311. break;
  10312. case 'WEBGL_compressed_texture_pvrtc':
  10313. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  10314. break;
  10315. default:
  10316. extension = gl.getExtension(name);
  10317. }
  10318. extensions[name] = extension;
  10319. return extension;
  10320. }
  10321. return {
  10322. has: function has(name) {
  10323. return getExtension(name) !== null;
  10324. },
  10325. init: function init(capabilities) {
  10326. if (capabilities.isWebGL2) {
  10327. getExtension('EXT_color_buffer_float');
  10328. } else {
  10329. getExtension('WEBGL_depth_texture');
  10330. getExtension('OES_texture_float');
  10331. getExtension('OES_texture_half_float');
  10332. getExtension('OES_texture_half_float_linear');
  10333. getExtension('OES_standard_derivatives');
  10334. getExtension('OES_element_index_uint');
  10335. getExtension('OES_vertex_array_object');
  10336. getExtension('ANGLE_instanced_arrays');
  10337. }
  10338. getExtension('OES_texture_float_linear');
  10339. getExtension('EXT_color_buffer_half_float');
  10340. },
  10341. get: function get(name) {
  10342. var extension = getExtension(name);
  10343. if (extension === null) {
  10344. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  10345. }
  10346. return extension;
  10347. }
  10348. };
  10349. }
  10350. function WebGLGeometries(gl, attributes, info, bindingStates) {
  10351. var geometries = {};
  10352. var wireframeAttributes = new WeakMap();
  10353. function onGeometryDispose(event) {
  10354. var geometry = event.target;
  10355. if (geometry.index !== null) {
  10356. attributes.remove(geometry.index);
  10357. }
  10358. for (var name in geometry.attributes) {
  10359. attributes.remove(geometry.attributes[name]);
  10360. }
  10361. geometry.removeEventListener('dispose', onGeometryDispose);
  10362. delete geometries[geometry.id];
  10363. var attribute = wireframeAttributes.get(geometry);
  10364. if (attribute) {
  10365. attributes.remove(attribute);
  10366. wireframeAttributes.delete(geometry);
  10367. }
  10368. bindingStates.releaseStatesOfGeometry(geometry);
  10369. if (geometry.isInstancedBufferGeometry === true) {
  10370. delete geometry._maxInstanceCount;
  10371. } //
  10372. info.memory.geometries--;
  10373. }
  10374. function get(object, geometry) {
  10375. if (geometries[geometry.id] === true) return geometry;
  10376. geometry.addEventListener('dispose', onGeometryDispose);
  10377. geometries[geometry.id] = true;
  10378. info.memory.geometries++;
  10379. return geometry;
  10380. }
  10381. function update(geometry) {
  10382. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  10383. for (var name in geometryAttributes) {
  10384. attributes.update(geometryAttributes[name], 34962);
  10385. } // morph targets
  10386. var morphAttributes = geometry.morphAttributes;
  10387. for (var _name in morphAttributes) {
  10388. var array = morphAttributes[_name];
  10389. for (var i = 0, l = array.length; i < l; i++) {
  10390. attributes.update(array[i], 34962);
  10391. }
  10392. }
  10393. }
  10394. function updateWireframeAttribute(geometry) {
  10395. var indices = [];
  10396. var geometryIndex = geometry.index;
  10397. var geometryPosition = geometry.attributes.position;
  10398. var version = 0;
  10399. if (geometryIndex !== null) {
  10400. var array = geometryIndex.array;
  10401. version = geometryIndex.version;
  10402. for (var i = 0, l = array.length; i < l; i += 3) {
  10403. var a = array[i + 0];
  10404. var b = array[i + 1];
  10405. var c = array[i + 2];
  10406. indices.push(a, b, b, c, c, a);
  10407. }
  10408. } else {
  10409. var _array = geometryPosition.array;
  10410. version = geometryPosition.version;
  10411. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  10412. var _a = _i + 0;
  10413. var _b = _i + 1;
  10414. var _c = _i + 2;
  10415. indices.push(_a, _b, _b, _c, _c, _a);
  10416. }
  10417. }
  10418. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  10419. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  10420. //
  10421. var previousAttribute = wireframeAttributes.get(geometry);
  10422. if (previousAttribute) attributes.remove(previousAttribute); //
  10423. wireframeAttributes.set(geometry, attribute);
  10424. }
  10425. function getWireframeAttribute(geometry) {
  10426. var currentAttribute = wireframeAttributes.get(geometry);
  10427. if (currentAttribute) {
  10428. var geometryIndex = geometry.index;
  10429. if (geometryIndex !== null) {
  10430. // if the attribute is obsolete, create a new one
  10431. if (currentAttribute.version < geometryIndex.version) {
  10432. updateWireframeAttribute(geometry);
  10433. }
  10434. }
  10435. } else {
  10436. updateWireframeAttribute(geometry);
  10437. }
  10438. return wireframeAttributes.get(geometry);
  10439. }
  10440. return {
  10441. get: get,
  10442. update: update,
  10443. getWireframeAttribute: getWireframeAttribute
  10444. };
  10445. }
  10446. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  10447. var isWebGL2 = capabilities.isWebGL2;
  10448. var mode;
  10449. function setMode(value) {
  10450. mode = value;
  10451. }
  10452. var type, bytesPerElement;
  10453. function setIndex(value) {
  10454. type = value.type;
  10455. bytesPerElement = value.bytesPerElement;
  10456. }
  10457. function render(start, count) {
  10458. gl.drawElements(mode, count, type, start * bytesPerElement);
  10459. info.update(count, mode, 1);
  10460. }
  10461. function renderInstances(start, count, primcount) {
  10462. if (primcount === 0) return;
  10463. var extension, methodName;
  10464. if (isWebGL2) {
  10465. extension = gl;
  10466. methodName = 'drawElementsInstanced';
  10467. } else {
  10468. extension = extensions.get('ANGLE_instanced_arrays');
  10469. methodName = 'drawElementsInstancedANGLE';
  10470. if (extension === null) {
  10471. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  10472. return;
  10473. }
  10474. }
  10475. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  10476. info.update(count, mode, primcount);
  10477. } //
  10478. this.setMode = setMode;
  10479. this.setIndex = setIndex;
  10480. this.render = render;
  10481. this.renderInstances = renderInstances;
  10482. }
  10483. function WebGLInfo(gl) {
  10484. var memory = {
  10485. geometries: 0,
  10486. textures: 0
  10487. };
  10488. var render = {
  10489. frame: 0,
  10490. calls: 0,
  10491. triangles: 0,
  10492. points: 0,
  10493. lines: 0
  10494. };
  10495. function update(count, mode, instanceCount) {
  10496. render.calls++;
  10497. switch (mode) {
  10498. case 4:
  10499. render.triangles += instanceCount * (count / 3);
  10500. break;
  10501. case 1:
  10502. render.lines += instanceCount * (count / 2);
  10503. break;
  10504. case 3:
  10505. render.lines += instanceCount * (count - 1);
  10506. break;
  10507. case 2:
  10508. render.lines += instanceCount * count;
  10509. break;
  10510. case 0:
  10511. render.points += instanceCount * count;
  10512. break;
  10513. default:
  10514. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  10515. break;
  10516. }
  10517. }
  10518. function reset() {
  10519. render.frame++;
  10520. render.calls = 0;
  10521. render.triangles = 0;
  10522. render.points = 0;
  10523. render.lines = 0;
  10524. }
  10525. return {
  10526. memory: memory,
  10527. render: render,
  10528. programs: null,
  10529. autoReset: true,
  10530. reset: reset,
  10531. update: update
  10532. };
  10533. }
  10534. function numericalSort(a, b) {
  10535. return a[0] - b[0];
  10536. }
  10537. function absNumericalSort(a, b) {
  10538. return Math.abs(b[1]) - Math.abs(a[1]);
  10539. }
  10540. function WebGLMorphtargets(gl) {
  10541. var influencesList = {};
  10542. var morphInfluences = new Float32Array(8);
  10543. var workInfluences = [];
  10544. for (var i = 0; i < 8; i++) {
  10545. workInfluences[i] = [i, 0];
  10546. }
  10547. function update(object, geometry, material, program) {
  10548. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  10549. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  10550. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  10551. var influences = influencesList[geometry.id];
  10552. if (influences === undefined) {
  10553. // initialise list
  10554. influences = [];
  10555. for (var _i = 0; _i < length; _i++) {
  10556. influences[_i] = [_i, 0];
  10557. }
  10558. influencesList[geometry.id] = influences;
  10559. } // Collect influences
  10560. for (var _i2 = 0; _i2 < length; _i2++) {
  10561. var influence = influences[_i2];
  10562. influence[0] = _i2;
  10563. influence[1] = objectInfluences[_i2];
  10564. }
  10565. influences.sort(absNumericalSort);
  10566. for (var _i3 = 0; _i3 < 8; _i3++) {
  10567. if (_i3 < length && influences[_i3][1]) {
  10568. workInfluences[_i3][0] = influences[_i3][0];
  10569. workInfluences[_i3][1] = influences[_i3][1];
  10570. } else {
  10571. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  10572. workInfluences[_i3][1] = 0;
  10573. }
  10574. }
  10575. workInfluences.sort(numericalSort);
  10576. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  10577. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  10578. var morphInfluencesSum = 0;
  10579. for (var _i4 = 0; _i4 < 8; _i4++) {
  10580. var _influence = workInfluences[_i4];
  10581. var index = _influence[0];
  10582. var value = _influence[1];
  10583. if (index !== Number.MAX_SAFE_INTEGER && value) {
  10584. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  10585. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  10586. }
  10587. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  10588. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  10589. }
  10590. morphInfluences[_i4] = value;
  10591. morphInfluencesSum += value;
  10592. } else {
  10593. if (morphTargets && geometry.hasAttribute('morphTarget' + _i4) === true) {
  10594. geometry.deleteAttribute('morphTarget' + _i4);
  10595. }
  10596. if (morphNormals && geometry.hasAttribute('morphNormal' + _i4) === true) {
  10597. geometry.deleteAttribute('morphNormal' + _i4);
  10598. }
  10599. morphInfluences[_i4] = 0;
  10600. }
  10601. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  10602. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  10603. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  10604. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  10605. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  10606. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  10607. }
  10608. return {
  10609. update: update
  10610. };
  10611. }
  10612. function WebGLObjects(gl, geometries, attributes, info) {
  10613. var updateMap = new WeakMap();
  10614. function update(object) {
  10615. var frame = info.render.frame;
  10616. var geometry = object.geometry;
  10617. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  10618. if (updateMap.get(buffergeometry) !== frame) {
  10619. geometries.update(buffergeometry);
  10620. updateMap.set(buffergeometry, frame);
  10621. }
  10622. if (object.isInstancedMesh) {
  10623. if (object.hasEventListener('dispose', onInstancedMeshDispose) === false) {
  10624. object.addEventListener('dispose', onInstancedMeshDispose);
  10625. }
  10626. attributes.update(object.instanceMatrix, 34962);
  10627. if (object.instanceColor !== null) {
  10628. attributes.update(object.instanceColor, 34962);
  10629. }
  10630. }
  10631. return buffergeometry;
  10632. }
  10633. function dispose() {
  10634. updateMap = new WeakMap();
  10635. }
  10636. function onInstancedMeshDispose(event) {
  10637. var instancedMesh = event.target;
  10638. instancedMesh.removeEventListener('dispose', onInstancedMeshDispose);
  10639. attributes.remove(instancedMesh.instanceMatrix);
  10640. if (instancedMesh.instanceColor !== null) attributes.remove(instancedMesh.instanceColor);
  10641. }
  10642. return {
  10643. update: update,
  10644. dispose: dispose
  10645. };
  10646. }
  10647. function DataTexture2DArray(data, width, height, depth) {
  10648. if (data === void 0) {
  10649. data = null;
  10650. }
  10651. if (width === void 0) {
  10652. width = 1;
  10653. }
  10654. if (height === void 0) {
  10655. height = 1;
  10656. }
  10657. if (depth === void 0) {
  10658. depth = 1;
  10659. }
  10660. Texture.call(this, null);
  10661. this.image = {
  10662. data: data,
  10663. width: width,
  10664. height: height,
  10665. depth: depth
  10666. };
  10667. this.magFilter = NearestFilter;
  10668. this.minFilter = NearestFilter;
  10669. this.wrapR = ClampToEdgeWrapping;
  10670. this.generateMipmaps = false;
  10671. this.flipY = false;
  10672. this.needsUpdate = true;
  10673. }
  10674. DataTexture2DArray.prototype = Object.create(Texture.prototype);
  10675. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  10676. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  10677. function DataTexture3D(data, width, height, depth) {
  10678. if (data === void 0) {
  10679. data = null;
  10680. }
  10681. if (width === void 0) {
  10682. width = 1;
  10683. }
  10684. if (height === void 0) {
  10685. height = 1;
  10686. }
  10687. if (depth === void 0) {
  10688. depth = 1;
  10689. }
  10690. // We're going to add .setXXX() methods for setting properties later.
  10691. // Users can still set in DataTexture3D directly.
  10692. //
  10693. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  10694. // texture.anisotropy = 16;
  10695. //
  10696. // See #14839
  10697. Texture.call(this, null);
  10698. this.image = {
  10699. data: data,
  10700. width: width,
  10701. height: height,
  10702. depth: depth
  10703. };
  10704. this.magFilter = NearestFilter;
  10705. this.minFilter = NearestFilter;
  10706. this.wrapR = ClampToEdgeWrapping;
  10707. this.generateMipmaps = false;
  10708. this.flipY = false;
  10709. this.needsUpdate = true;
  10710. }
  10711. DataTexture3D.prototype = Object.create(Texture.prototype);
  10712. DataTexture3D.prototype.constructor = DataTexture3D;
  10713. DataTexture3D.prototype.isDataTexture3D = true;
  10714. /**
  10715. * Uniforms of a program.
  10716. * Those form a tree structure with a special top-level container for the root,
  10717. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10718. *
  10719. *
  10720. * Properties of inner nodes including the top-level container:
  10721. *
  10722. * .seq - array of nested uniforms
  10723. * .map - nested uniforms by name
  10724. *
  10725. *
  10726. * Methods of all nodes except the top-level container:
  10727. *
  10728. * .setValue( gl, value, [textures] )
  10729. *
  10730. * uploads a uniform value(s)
  10731. * the 'textures' parameter is needed for sampler uniforms
  10732. *
  10733. *
  10734. * Static methods of the top-level container (textures factorizations):
  10735. *
  10736. * .upload( gl, seq, values, textures )
  10737. *
  10738. * sets uniforms in 'seq' to 'values[id].value'
  10739. *
  10740. * .seqWithValue( seq, values ) : filteredSeq
  10741. *
  10742. * filters 'seq' entries with corresponding entry in values
  10743. *
  10744. *
  10745. * Methods of the top-level container (textures factorizations):
  10746. *
  10747. * .setValue( gl, name, value, textures )
  10748. *
  10749. * sets uniform with name 'name' to 'value'
  10750. *
  10751. * .setOptional( gl, obj, prop )
  10752. *
  10753. * like .set for an optional property of the object
  10754. *
  10755. */
  10756. var emptyTexture = new Texture();
  10757. var emptyTexture2dArray = new DataTexture2DArray();
  10758. var emptyTexture3d = new DataTexture3D();
  10759. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  10760. // Array Caches (provide typed arrays for temporary by size)
  10761. var arrayCacheF32 = [];
  10762. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  10763. var mat4array = new Float32Array(16);
  10764. var mat3array = new Float32Array(9);
  10765. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  10766. function flatten(array, nBlocks, blockSize) {
  10767. var firstElem = array[0];
  10768. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  10769. // see http://jacksondunstan.com/articles/983
  10770. var n = nBlocks * blockSize;
  10771. var r = arrayCacheF32[n];
  10772. if (r === undefined) {
  10773. r = new Float32Array(n);
  10774. arrayCacheF32[n] = r;
  10775. }
  10776. if (nBlocks !== 0) {
  10777. firstElem.toArray(r, 0);
  10778. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  10779. offset += blockSize;
  10780. array[i].toArray(r, offset);
  10781. }
  10782. }
  10783. return r;
  10784. }
  10785. function arraysEqual(a, b) {
  10786. if (a.length !== b.length) return false;
  10787. for (var i = 0, l = a.length; i < l; i++) {
  10788. if (a[i] !== b[i]) return false;
  10789. }
  10790. return true;
  10791. }
  10792. function copyArray(a, b) {
  10793. for (var i = 0, l = b.length; i < l; i++) {
  10794. a[i] = b[i];
  10795. }
  10796. } // Texture unit allocation
  10797. function allocTexUnits(textures, n) {
  10798. var r = arrayCacheI32[n];
  10799. if (r === undefined) {
  10800. r = new Int32Array(n);
  10801. arrayCacheI32[n] = r;
  10802. }
  10803. for (var i = 0; i !== n; ++i) {
  10804. r[i] = textures.allocateTextureUnit();
  10805. }
  10806. return r;
  10807. } // --- Setters ---
  10808. // Note: Defining these methods externally, because they come in a bunch
  10809. // and this way their names minify.
  10810. // Single scalar
  10811. function setValueV1f(gl, v) {
  10812. var cache = this.cache;
  10813. if (cache[0] === v) return;
  10814. gl.uniform1f(this.addr, v);
  10815. cache[0] = v;
  10816. } // Single float vector (from flat array or THREE.VectorN)
  10817. function setValueV2f(gl, v) {
  10818. var cache = this.cache;
  10819. if (v.x !== undefined) {
  10820. if (cache[0] !== v.x || cache[1] !== v.y) {
  10821. gl.uniform2f(this.addr, v.x, v.y);
  10822. cache[0] = v.x;
  10823. cache[1] = v.y;
  10824. }
  10825. } else {
  10826. if (arraysEqual(cache, v)) return;
  10827. gl.uniform2fv(this.addr, v);
  10828. copyArray(cache, v);
  10829. }
  10830. }
  10831. function setValueV3f(gl, v) {
  10832. var cache = this.cache;
  10833. if (v.x !== undefined) {
  10834. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10835. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10836. cache[0] = v.x;
  10837. cache[1] = v.y;
  10838. cache[2] = v.z;
  10839. }
  10840. } else if (v.r !== undefined) {
  10841. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10842. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10843. cache[0] = v.r;
  10844. cache[1] = v.g;
  10845. cache[2] = v.b;
  10846. }
  10847. } else {
  10848. if (arraysEqual(cache, v)) return;
  10849. gl.uniform3fv(this.addr, v);
  10850. copyArray(cache, v);
  10851. }
  10852. }
  10853. function setValueV4f(gl, v) {
  10854. var cache = this.cache;
  10855. if (v.x !== undefined) {
  10856. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10857. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10858. cache[0] = v.x;
  10859. cache[1] = v.y;
  10860. cache[2] = v.z;
  10861. cache[3] = v.w;
  10862. }
  10863. } else {
  10864. if (arraysEqual(cache, v)) return;
  10865. gl.uniform4fv(this.addr, v);
  10866. copyArray(cache, v);
  10867. }
  10868. } // Single matrix (from flat array or MatrixN)
  10869. function setValueM2(gl, v) {
  10870. var cache = this.cache;
  10871. var elements = v.elements;
  10872. if (elements === undefined) {
  10873. if (arraysEqual(cache, v)) return;
  10874. gl.uniformMatrix2fv(this.addr, false, v);
  10875. copyArray(cache, v);
  10876. } else {
  10877. if (arraysEqual(cache, elements)) return;
  10878. mat2array.set(elements);
  10879. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10880. copyArray(cache, elements);
  10881. }
  10882. }
  10883. function setValueM3(gl, v) {
  10884. var cache = this.cache;
  10885. var elements = v.elements;
  10886. if (elements === undefined) {
  10887. if (arraysEqual(cache, v)) return;
  10888. gl.uniformMatrix3fv(this.addr, false, v);
  10889. copyArray(cache, v);
  10890. } else {
  10891. if (arraysEqual(cache, elements)) return;
  10892. mat3array.set(elements);
  10893. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10894. copyArray(cache, elements);
  10895. }
  10896. }
  10897. function setValueM4(gl, v) {
  10898. var cache = this.cache;
  10899. var elements = v.elements;
  10900. if (elements === undefined) {
  10901. if (arraysEqual(cache, v)) return;
  10902. gl.uniformMatrix4fv(this.addr, false, v);
  10903. copyArray(cache, v);
  10904. } else {
  10905. if (arraysEqual(cache, elements)) return;
  10906. mat4array.set(elements);
  10907. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10908. copyArray(cache, elements);
  10909. }
  10910. } // Single texture (2D / Cube)
  10911. function setValueT1(gl, v, textures) {
  10912. var cache = this.cache;
  10913. var unit = textures.allocateTextureUnit();
  10914. if (cache[0] !== unit) {
  10915. gl.uniform1i(this.addr, unit);
  10916. cache[0] = unit;
  10917. }
  10918. textures.safeSetTexture2D(v || emptyTexture, unit);
  10919. }
  10920. function setValueT2DArray1(gl, v, textures) {
  10921. var cache = this.cache;
  10922. var unit = textures.allocateTextureUnit();
  10923. if (cache[0] !== unit) {
  10924. gl.uniform1i(this.addr, unit);
  10925. cache[0] = unit;
  10926. }
  10927. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10928. }
  10929. function setValueT3D1(gl, v, textures) {
  10930. var cache = this.cache;
  10931. var unit = textures.allocateTextureUnit();
  10932. if (cache[0] !== unit) {
  10933. gl.uniform1i(this.addr, unit);
  10934. cache[0] = unit;
  10935. }
  10936. textures.setTexture3D(v || emptyTexture3d, unit);
  10937. }
  10938. function setValueT6(gl, v, textures) {
  10939. var cache = this.cache;
  10940. var unit = textures.allocateTextureUnit();
  10941. if (cache[0] !== unit) {
  10942. gl.uniform1i(this.addr, unit);
  10943. cache[0] = unit;
  10944. }
  10945. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10946. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10947. function setValueV1i(gl, v) {
  10948. var cache = this.cache;
  10949. if (cache[0] === v) return;
  10950. gl.uniform1i(this.addr, v);
  10951. cache[0] = v;
  10952. }
  10953. function setValueV2i(gl, v) {
  10954. var cache = this.cache;
  10955. if (arraysEqual(cache, v)) return;
  10956. gl.uniform2iv(this.addr, v);
  10957. copyArray(cache, v);
  10958. }
  10959. function setValueV3i(gl, v) {
  10960. var cache = this.cache;
  10961. if (arraysEqual(cache, v)) return;
  10962. gl.uniform3iv(this.addr, v);
  10963. copyArray(cache, v);
  10964. }
  10965. function setValueV4i(gl, v) {
  10966. var cache = this.cache;
  10967. if (arraysEqual(cache, v)) return;
  10968. gl.uniform4iv(this.addr, v);
  10969. copyArray(cache, v);
  10970. } // uint
  10971. function setValueV1ui(gl, v) {
  10972. var cache = this.cache;
  10973. if (cache[0] === v) return;
  10974. gl.uniform1ui(this.addr, v);
  10975. cache[0] = v;
  10976. } // Helper to pick the right setter for the singular case
  10977. function getSingularSetter(type) {
  10978. switch (type) {
  10979. case 0x1406:
  10980. return setValueV1f;
  10981. // FLOAT
  10982. case 0x8b50:
  10983. return setValueV2f;
  10984. // _VEC2
  10985. case 0x8b51:
  10986. return setValueV3f;
  10987. // _VEC3
  10988. case 0x8b52:
  10989. return setValueV4f;
  10990. // _VEC4
  10991. case 0x8b5a:
  10992. return setValueM2;
  10993. // _MAT2
  10994. case 0x8b5b:
  10995. return setValueM3;
  10996. // _MAT3
  10997. case 0x8b5c:
  10998. return setValueM4;
  10999. // _MAT4
  11000. case 0x1404:
  11001. case 0x8b56:
  11002. return setValueV1i;
  11003. // INT, BOOL
  11004. case 0x8b53:
  11005. case 0x8b57:
  11006. return setValueV2i;
  11007. // _VEC2
  11008. case 0x8b54:
  11009. case 0x8b58:
  11010. return setValueV3i;
  11011. // _VEC3
  11012. case 0x8b55:
  11013. case 0x8b59:
  11014. return setValueV4i;
  11015. // _VEC4
  11016. case 0x1405:
  11017. return setValueV1ui;
  11018. // UINT
  11019. case 0x8b5e: // SAMPLER_2D
  11020. case 0x8d66: // SAMPLER_EXTERNAL_OES
  11021. case 0x8dca: // INT_SAMPLER_2D
  11022. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  11023. case 0x8b62:
  11024. // SAMPLER_2D_SHADOW
  11025. return setValueT1;
  11026. case 0x8b5f: // SAMPLER_3D
  11027. case 0x8dcb: // INT_SAMPLER_3D
  11028. case 0x8dd3:
  11029. // UNSIGNED_INT_SAMPLER_3D
  11030. return setValueT3D1;
  11031. case 0x8b60: // SAMPLER_CUBE
  11032. case 0x8dcc: // INT_SAMPLER_CUBE
  11033. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  11034. case 0x8dc5:
  11035. // SAMPLER_CUBE_SHADOW
  11036. return setValueT6;
  11037. case 0x8dc1: // SAMPLER_2D_ARRAY
  11038. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  11039. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  11040. case 0x8dc4:
  11041. // SAMPLER_2D_ARRAY_SHADOW
  11042. return setValueT2DArray1;
  11043. }
  11044. } // Array of scalars
  11045. function setValueV1fArray(gl, v) {
  11046. gl.uniform1fv(this.addr, v);
  11047. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  11048. function setValueV1iArray(gl, v) {
  11049. gl.uniform1iv(this.addr, v);
  11050. }
  11051. function setValueV2iArray(gl, v) {
  11052. gl.uniform2iv(this.addr, v);
  11053. }
  11054. function setValueV3iArray(gl, v) {
  11055. gl.uniform3iv(this.addr, v);
  11056. }
  11057. function setValueV4iArray(gl, v) {
  11058. gl.uniform4iv(this.addr, v);
  11059. } // Array of vectors (flat or from THREE classes)
  11060. function setValueV2fArray(gl, v) {
  11061. var data = flatten(v, this.size, 2);
  11062. gl.uniform2fv(this.addr, data);
  11063. }
  11064. function setValueV3fArray(gl, v) {
  11065. var data = flatten(v, this.size, 3);
  11066. gl.uniform3fv(this.addr, data);
  11067. }
  11068. function setValueV4fArray(gl, v) {
  11069. var data = flatten(v, this.size, 4);
  11070. gl.uniform4fv(this.addr, data);
  11071. } // Array of matrices (flat or from THREE clases)
  11072. function setValueM2Array(gl, v) {
  11073. var data = flatten(v, this.size, 4);
  11074. gl.uniformMatrix2fv(this.addr, false, data);
  11075. }
  11076. function setValueM3Array(gl, v) {
  11077. var data = flatten(v, this.size, 9);
  11078. gl.uniformMatrix3fv(this.addr, false, data);
  11079. }
  11080. function setValueM4Array(gl, v) {
  11081. var data = flatten(v, this.size, 16);
  11082. gl.uniformMatrix4fv(this.addr, false, data);
  11083. } // Array of textures (2D / Cube)
  11084. function setValueT1Array(gl, v, textures) {
  11085. var n = v.length;
  11086. var units = allocTexUnits(textures, n);
  11087. gl.uniform1iv(this.addr, units);
  11088. for (var i = 0; i !== n; ++i) {
  11089. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  11090. }
  11091. }
  11092. function setValueT6Array(gl, v, textures) {
  11093. var n = v.length;
  11094. var units = allocTexUnits(textures, n);
  11095. gl.uniform1iv(this.addr, units);
  11096. for (var i = 0; i !== n; ++i) {
  11097. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  11098. }
  11099. } // Helper to pick the right setter for a pure (bottom-level) array
  11100. function getPureArraySetter(type) {
  11101. switch (type) {
  11102. case 0x1406:
  11103. return setValueV1fArray;
  11104. // FLOAT
  11105. case 0x8b50:
  11106. return setValueV2fArray;
  11107. // _VEC2
  11108. case 0x8b51:
  11109. return setValueV3fArray;
  11110. // _VEC3
  11111. case 0x8b52:
  11112. return setValueV4fArray;
  11113. // _VEC4
  11114. case 0x8b5a:
  11115. return setValueM2Array;
  11116. // _MAT2
  11117. case 0x8b5b:
  11118. return setValueM3Array;
  11119. // _MAT3
  11120. case 0x8b5c:
  11121. return setValueM4Array;
  11122. // _MAT4
  11123. case 0x1404:
  11124. case 0x8b56:
  11125. return setValueV1iArray;
  11126. // INT, BOOL
  11127. case 0x8b53:
  11128. case 0x8b57:
  11129. return setValueV2iArray;
  11130. // _VEC2
  11131. case 0x8b54:
  11132. case 0x8b58:
  11133. return setValueV3iArray;
  11134. // _VEC3
  11135. case 0x8b55:
  11136. case 0x8b59:
  11137. return setValueV4iArray;
  11138. // _VEC4
  11139. case 0x8b5e: // SAMPLER_2D
  11140. case 0x8d66: // SAMPLER_EXTERNAL_OES
  11141. case 0x8dca: // INT_SAMPLER_2D
  11142. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  11143. case 0x8b62:
  11144. // SAMPLER_2D_SHADOW
  11145. return setValueT1Array;
  11146. case 0x8b60: // SAMPLER_CUBE
  11147. case 0x8dcc: // INT_SAMPLER_CUBE
  11148. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  11149. case 0x8dc5:
  11150. // SAMPLER_CUBE_SHADOW
  11151. return setValueT6Array;
  11152. }
  11153. } // --- Uniform Classes ---
  11154. function SingleUniform(id, activeInfo, addr) {
  11155. this.id = id;
  11156. this.addr = addr;
  11157. this.cache = [];
  11158. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  11159. }
  11160. function PureArrayUniform(id, activeInfo, addr) {
  11161. this.id = id;
  11162. this.addr = addr;
  11163. this.cache = [];
  11164. this.size = activeInfo.size;
  11165. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  11166. }
  11167. PureArrayUniform.prototype.updateCache = function (data) {
  11168. var cache = this.cache;
  11169. if (data instanceof Float32Array && cache.length !== data.length) {
  11170. this.cache = new Float32Array(data.length);
  11171. }
  11172. copyArray(cache, data);
  11173. };
  11174. function StructuredUniform(id) {
  11175. this.id = id;
  11176. this.seq = [];
  11177. this.map = {};
  11178. }
  11179. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  11180. var seq = this.seq;
  11181. for (var i = 0, n = seq.length; i !== n; ++i) {
  11182. var u = seq[i];
  11183. u.setValue(gl, value[u.id], textures);
  11184. }
  11185. }; // --- Top-level ---
  11186. // Parser - builds up the property tree from the path strings
  11187. var RePathPart = /(\w+)(\])?(\[|\.)?/g; // extracts
  11188. // - the identifier (member name or array index)
  11189. // - followed by an optional right bracket (found when array index)
  11190. // - followed by an optional left bracket or dot (type of subscript)
  11191. //
  11192. // Note: These portions can be read in a non-overlapping fashion and
  11193. // allow straightforward parsing of the hierarchy that WebGL encodes
  11194. // in the uniform names.
  11195. function addUniform(container, uniformObject) {
  11196. container.seq.push(uniformObject);
  11197. container.map[uniformObject.id] = uniformObject;
  11198. }
  11199. function parseUniform(activeInfo, addr, container) {
  11200. var path = activeInfo.name,
  11201. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  11202. RePathPart.lastIndex = 0;
  11203. while (true) {
  11204. var match = RePathPart.exec(path),
  11205. matchEnd = RePathPart.lastIndex;
  11206. var id = match[1];
  11207. var idIsIndex = match[2] === ']',
  11208. subscript = match[3];
  11209. if (idIsIndex) id = id | 0; // convert to integer
  11210. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  11211. // bare name or "pure" bottom-level array "[0]" suffix
  11212. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  11213. break;
  11214. } else {
  11215. // step into inner node / create it in case it doesn't exist
  11216. var map = container.map;
  11217. var next = map[id];
  11218. if (next === undefined) {
  11219. next = new StructuredUniform(id);
  11220. addUniform(container, next);
  11221. }
  11222. container = next;
  11223. }
  11224. }
  11225. } // Root Container
  11226. function WebGLUniforms(gl, program) {
  11227. this.seq = [];
  11228. this.map = {};
  11229. var n = gl.getProgramParameter(program, 35718);
  11230. for (var i = 0; i < n; ++i) {
  11231. var info = gl.getActiveUniform(program, i),
  11232. addr = gl.getUniformLocation(program, info.name);
  11233. parseUniform(info, addr, this);
  11234. }
  11235. }
  11236. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  11237. var u = this.map[name];
  11238. if (u !== undefined) u.setValue(gl, value, textures);
  11239. };
  11240. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  11241. var v = object[name];
  11242. if (v !== undefined) this.setValue(gl, name, v);
  11243. }; // Static interface
  11244. WebGLUniforms.upload = function (gl, seq, values, textures) {
  11245. for (var i = 0, n = seq.length; i !== n; ++i) {
  11246. var u = seq[i],
  11247. v = values[u.id];
  11248. if (v.needsUpdate !== false) {
  11249. // note: always updating when .needsUpdate is undefined
  11250. u.setValue(gl, v.value, textures);
  11251. }
  11252. }
  11253. };
  11254. WebGLUniforms.seqWithValue = function (seq, values) {
  11255. var r = [];
  11256. for (var i = 0, n = seq.length; i !== n; ++i) {
  11257. var u = seq[i];
  11258. if (u.id in values) r.push(u);
  11259. }
  11260. return r;
  11261. };
  11262. function WebGLShader(gl, type, string) {
  11263. var shader = gl.createShader(type);
  11264. gl.shaderSource(shader, string);
  11265. gl.compileShader(shader);
  11266. return shader;
  11267. }
  11268. var programIdCount = 0;
  11269. function addLineNumbers(string) {
  11270. var lines = string.split('\n');
  11271. for (var i = 0; i < lines.length; i++) {
  11272. lines[i] = i + 1 + ': ' + lines[i];
  11273. }
  11274. return lines.join('\n');
  11275. }
  11276. function getEncodingComponents(encoding) {
  11277. switch (encoding) {
  11278. case LinearEncoding:
  11279. return ['Linear', '( value )'];
  11280. case sRGBEncoding:
  11281. return ['sRGB', '( value )'];
  11282. case RGBEEncoding:
  11283. return ['RGBE', '( value )'];
  11284. case RGBM7Encoding:
  11285. return ['RGBM', '( value, 7.0 )'];
  11286. case RGBM16Encoding:
  11287. return ['RGBM', '( value, 16.0 )'];
  11288. case RGBDEncoding:
  11289. return ['RGBD', '( value, 256.0 )'];
  11290. case GammaEncoding:
  11291. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  11292. case LogLuvEncoding:
  11293. return ['LogLuv', '( value )'];
  11294. default:
  11295. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  11296. return ['Linear', '( value )'];
  11297. }
  11298. }
  11299. function getShaderErrors(gl, shader, type) {
  11300. var status = gl.getShaderParameter(shader, 35713);
  11301. var log = gl.getShaderInfoLog(shader).trim();
  11302. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  11303. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  11304. var source = gl.getShaderSource(shader);
  11305. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  11306. }
  11307. function getTexelDecodingFunction(functionName, encoding) {
  11308. var components = getEncodingComponents(encoding);
  11309. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  11310. }
  11311. function getTexelEncodingFunction(functionName, encoding) {
  11312. var components = getEncodingComponents(encoding);
  11313. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  11314. }
  11315. function getToneMappingFunction(functionName, toneMapping) {
  11316. var toneMappingName;
  11317. switch (toneMapping) {
  11318. case LinearToneMapping:
  11319. toneMappingName = 'Linear';
  11320. break;
  11321. case ReinhardToneMapping:
  11322. toneMappingName = 'Reinhard';
  11323. break;
  11324. case CineonToneMapping:
  11325. toneMappingName = 'OptimizedCineon';
  11326. break;
  11327. case ACESFilmicToneMapping:
  11328. toneMappingName = 'ACESFilmic';
  11329. break;
  11330. case CustomToneMapping:
  11331. toneMappingName = 'Custom';
  11332. break;
  11333. default:
  11334. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  11335. toneMappingName = 'Linear';
  11336. }
  11337. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  11338. }
  11339. function generateExtensions(parameters) {
  11340. 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' : ''];
  11341. return chunks.filter(filterEmptyLine).join('\n');
  11342. }
  11343. function generateDefines(defines) {
  11344. var chunks = [];
  11345. for (var name in defines) {
  11346. var value = defines[name];
  11347. if (value === false) continue;
  11348. chunks.push('#define ' + name + ' ' + value);
  11349. }
  11350. return chunks.join('\n');
  11351. }
  11352. function fetchAttributeLocations(gl, program) {
  11353. var attributes = {};
  11354. var n = gl.getProgramParameter(program, 35721);
  11355. for (var i = 0; i < n; i++) {
  11356. var info = gl.getActiveAttrib(program, i);
  11357. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  11358. attributes[name] = gl.getAttribLocation(program, name);
  11359. }
  11360. return attributes;
  11361. }
  11362. function filterEmptyLine(string) {
  11363. return string !== '';
  11364. }
  11365. function replaceLightNums(string, parameters) {
  11366. 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);
  11367. }
  11368. function replaceClippingPlaneNums(string, parameters) {
  11369. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  11370. } // Resolve Includes
  11371. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  11372. function resolveIncludes(string) {
  11373. return string.replace(includePattern, includeReplacer);
  11374. }
  11375. function includeReplacer(match, include) {
  11376. var string = ShaderChunk[include];
  11377. if (string === undefined) {
  11378. throw new Error('Can not resolve #include <' + include + '>');
  11379. }
  11380. return resolveIncludes(string);
  11381. } // Unroll Loops
  11382. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  11383. 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;
  11384. function unrollLoops(string) {
  11385. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  11386. }
  11387. function deprecatedLoopReplacer(match, start, end, snippet) {
  11388. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  11389. return loopReplacer(match, start, end, snippet);
  11390. }
  11391. function loopReplacer(match, start, end, snippet) {
  11392. var string = '';
  11393. for (var i = parseInt(start); i < parseInt(end); i++) {
  11394. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  11395. }
  11396. return string;
  11397. } //
  11398. function generatePrecision(parameters) {
  11399. var precisionstring = 'precision ' + parameters.precision + ' float;\nprecision ' + parameters.precision + ' int;';
  11400. if (parameters.precision === 'highp') {
  11401. precisionstring += '\n#define HIGH_PRECISION';
  11402. } else if (parameters.precision === 'mediump') {
  11403. precisionstring += '\n#define MEDIUM_PRECISION';
  11404. } else if (parameters.precision === 'lowp') {
  11405. precisionstring += '\n#define LOW_PRECISION';
  11406. }
  11407. return precisionstring;
  11408. }
  11409. function generateShadowMapTypeDefine(parameters) {
  11410. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  11411. if (parameters.shadowMapType === PCFShadowMap) {
  11412. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  11413. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  11414. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  11415. } else if (parameters.shadowMapType === VSMShadowMap) {
  11416. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  11417. }
  11418. return shadowMapTypeDefine;
  11419. }
  11420. function generateEnvMapTypeDefine(parameters) {
  11421. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11422. if (parameters.envMap) {
  11423. switch (parameters.envMapMode) {
  11424. case CubeReflectionMapping:
  11425. case CubeRefractionMapping:
  11426. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11427. break;
  11428. case CubeUVReflectionMapping:
  11429. case CubeUVRefractionMapping:
  11430. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  11431. break;
  11432. }
  11433. }
  11434. return envMapTypeDefine;
  11435. }
  11436. function generateEnvMapModeDefine(parameters) {
  11437. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  11438. if (parameters.envMap) {
  11439. switch (parameters.envMapMode) {
  11440. case CubeRefractionMapping:
  11441. case CubeUVRefractionMapping:
  11442. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  11443. break;
  11444. }
  11445. }
  11446. return envMapModeDefine;
  11447. }
  11448. function generateEnvMapBlendingDefine(parameters) {
  11449. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  11450. if (parameters.envMap) {
  11451. switch (parameters.combine) {
  11452. case MultiplyOperation:
  11453. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  11454. break;
  11455. case MixOperation:
  11456. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  11457. break;
  11458. case AddOperation:
  11459. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  11460. break;
  11461. }
  11462. }
  11463. return envMapBlendingDefine;
  11464. }
  11465. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  11466. var gl = renderer.getContext();
  11467. var defines = parameters.defines;
  11468. var vertexShader = parameters.vertexShader;
  11469. var fragmentShader = parameters.fragmentShader;
  11470. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  11471. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  11472. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  11473. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  11474. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  11475. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  11476. var customDefines = generateDefines(defines);
  11477. var program = gl.createProgram();
  11478. var prefixVertex, prefixFragment;
  11479. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : '';
  11480. if (parameters.isRawShaderMaterial) {
  11481. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  11482. if (prefixVertex.length > 0) {
  11483. prefixVertex += '\n';
  11484. }
  11485. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  11486. if (prefixFragment.length > 0) {
  11487. prefixFragment += '\n';
  11488. }
  11489. } else {
  11490. 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');
  11491. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  11492. '#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
  11493. 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
  11494. 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');
  11495. }
  11496. vertexShader = resolveIncludes(vertexShader);
  11497. vertexShader = replaceLightNums(vertexShader, parameters);
  11498. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  11499. fragmentShader = resolveIncludes(fragmentShader);
  11500. fragmentShader = replaceLightNums(fragmentShader, parameters);
  11501. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  11502. vertexShader = unrollLoops(vertexShader);
  11503. fragmentShader = unrollLoops(fragmentShader);
  11504. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  11505. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  11506. versionString = '#version 300 es\n';
  11507. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  11508. 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;
  11509. }
  11510. var vertexGlsl = versionString + prefixVertex + vertexShader;
  11511. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  11512. // console.log( '*FRAGMENT*', fragmentGlsl );
  11513. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  11514. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  11515. gl.attachShader(program, glVertexShader);
  11516. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  11517. if (parameters.index0AttributeName !== undefined) {
  11518. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  11519. } else if (parameters.morphTargets === true) {
  11520. // programs with morphTargets displace position out of attribute 0
  11521. gl.bindAttribLocation(program, 0, 'position');
  11522. }
  11523. gl.linkProgram(program); // check for link errors
  11524. if (renderer.debug.checkShaderErrors) {
  11525. var programLog = gl.getProgramInfoLog(program).trim();
  11526. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  11527. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  11528. var runnable = true;
  11529. var haveDiagnostics = true;
  11530. if (gl.getProgramParameter(program, 35714) === false) {
  11531. runnable = false;
  11532. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  11533. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  11534. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  11535. } else if (programLog !== '') {
  11536. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  11537. } else if (vertexLog === '' || fragmentLog === '') {
  11538. haveDiagnostics = false;
  11539. }
  11540. if (haveDiagnostics) {
  11541. this.diagnostics = {
  11542. runnable: runnable,
  11543. programLog: programLog,
  11544. vertexShader: {
  11545. log: vertexLog,
  11546. prefix: prefixVertex
  11547. },
  11548. fragmentShader: {
  11549. log: fragmentLog,
  11550. prefix: prefixFragment
  11551. }
  11552. };
  11553. }
  11554. } // Clean up
  11555. // Crashes in iOS9 and iOS10. #18402
  11556. // gl.detachShader( program, glVertexShader );
  11557. // gl.detachShader( program, glFragmentShader );
  11558. gl.deleteShader(glVertexShader);
  11559. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  11560. var cachedUniforms;
  11561. this.getUniforms = function () {
  11562. if (cachedUniforms === undefined) {
  11563. cachedUniforms = new WebGLUniforms(gl, program);
  11564. }
  11565. return cachedUniforms;
  11566. }; // set up caching for attribute locations
  11567. var cachedAttributes;
  11568. this.getAttributes = function () {
  11569. if (cachedAttributes === undefined) {
  11570. cachedAttributes = fetchAttributeLocations(gl, program);
  11571. }
  11572. return cachedAttributes;
  11573. }; // free resource
  11574. this.destroy = function () {
  11575. bindingStates.releaseStatesOfProgram(this);
  11576. gl.deleteProgram(program);
  11577. this.program = undefined;
  11578. }; //
  11579. this.name = parameters.shaderName;
  11580. this.id = programIdCount++;
  11581. this.cacheKey = cacheKey;
  11582. this.usedTimes = 1;
  11583. this.program = program;
  11584. this.vertexShader = glVertexShader;
  11585. this.fragmentShader = glFragmentShader;
  11586. return this;
  11587. }
  11588. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  11589. var programs = [];
  11590. var isWebGL2 = capabilities.isWebGL2;
  11591. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  11592. var floatVertexTextures = capabilities.floatVertexTextures;
  11593. var maxVertexUniforms = capabilities.maxVertexUniforms;
  11594. var vertexTextures = capabilities.vertexTextures;
  11595. var precision = capabilities.precision;
  11596. var shaderIDs = {
  11597. MeshDepthMaterial: 'depth',
  11598. MeshDistanceMaterial: 'distanceRGBA',
  11599. MeshNormalMaterial: 'normal',
  11600. MeshBasicMaterial: 'basic',
  11601. MeshLambertMaterial: 'lambert',
  11602. MeshPhongMaterial: 'phong',
  11603. MeshToonMaterial: 'toon',
  11604. MeshStandardMaterial: 'physical',
  11605. MeshPhysicalMaterial: 'physical',
  11606. MeshMatcapMaterial: 'matcap',
  11607. LineBasicMaterial: 'basic',
  11608. LineDashedMaterial: 'dashed',
  11609. PointsMaterial: 'points',
  11610. ShadowMaterial: 'shadow',
  11611. SpriteMaterial: 'sprite'
  11612. };
  11613. 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'];
  11614. function getMaxBones(object) {
  11615. var skeleton = object.skeleton;
  11616. var bones = skeleton.bones;
  11617. if (floatVertexTextures) {
  11618. return 1024;
  11619. } else {
  11620. // default for when object is not specified
  11621. // ( for example when prebuilding shader to be used with multiple objects )
  11622. //
  11623. // - leave some extra space for other uniforms
  11624. // - limit here is ANGLE's 254 max uniform vectors
  11625. // (up to 54 should be safe)
  11626. var nVertexUniforms = maxVertexUniforms;
  11627. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  11628. var maxBones = Math.min(nVertexMatrices, bones.length);
  11629. if (maxBones < bones.length) {
  11630. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  11631. return 0;
  11632. }
  11633. return maxBones;
  11634. }
  11635. }
  11636. function getTextureEncodingFromMap(map) {
  11637. var encoding;
  11638. if (map && map.isTexture) {
  11639. encoding = map.encoding;
  11640. } else if (map && map.isWebGLRenderTarget) {
  11641. console.warn('THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.');
  11642. encoding = map.texture.encoding;
  11643. } else {
  11644. encoding = LinearEncoding;
  11645. }
  11646. return encoding;
  11647. }
  11648. function getParameters(material, lights, shadows, scene, object) {
  11649. var fog = scene.fog;
  11650. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  11651. var envMap = cubemaps.get(material.envMap || environment);
  11652. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  11653. // (not to blow over maxLights budget)
  11654. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  11655. if (material.precision !== null) {
  11656. precision = capabilities.getMaxPrecision(material.precision);
  11657. if (precision !== material.precision) {
  11658. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  11659. }
  11660. }
  11661. var vertexShader, fragmentShader;
  11662. if (shaderID) {
  11663. var shader = ShaderLib[shaderID];
  11664. vertexShader = shader.vertexShader;
  11665. fragmentShader = shader.fragmentShader;
  11666. } else {
  11667. vertexShader = material.vertexShader;
  11668. fragmentShader = material.fragmentShader;
  11669. }
  11670. var currentRenderTarget = renderer.getRenderTarget();
  11671. var parameters = {
  11672. isWebGL2: isWebGL2,
  11673. shaderID: shaderID,
  11674. shaderName: material.type,
  11675. vertexShader: vertexShader,
  11676. fragmentShader: fragmentShader,
  11677. defines: material.defines,
  11678. isRawShaderMaterial: material.isRawShaderMaterial === true,
  11679. glslVersion: material.glslVersion,
  11680. precision: precision,
  11681. instancing: object.isInstancedMesh === true,
  11682. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  11683. supportsVertexTextures: vertexTextures,
  11684. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  11685. map: !!material.map,
  11686. mapEncoding: getTextureEncodingFromMap(material.map),
  11687. matcap: !!material.matcap,
  11688. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  11689. envMap: !!envMap,
  11690. envMapMode: envMap && envMap.mapping,
  11691. envMapEncoding: getTextureEncodingFromMap(envMap),
  11692. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  11693. lightMap: !!material.lightMap,
  11694. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  11695. aoMap: !!material.aoMap,
  11696. emissiveMap: !!material.emissiveMap,
  11697. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  11698. bumpMap: !!material.bumpMap,
  11699. normalMap: !!material.normalMap,
  11700. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11701. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11702. clearcoatMap: !!material.clearcoatMap,
  11703. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  11704. clearcoatNormalMap: !!material.clearcoatNormalMap,
  11705. displacementMap: !!material.displacementMap,
  11706. roughnessMap: !!material.roughnessMap,
  11707. metalnessMap: !!material.metalnessMap,
  11708. specularMap: !!material.specularMap,
  11709. alphaMap: !!material.alphaMap,
  11710. gradientMap: !!material.gradientMap,
  11711. sheen: !!material.sheen,
  11712. transmissionMap: !!material.transmissionMap,
  11713. combine: material.combine,
  11714. vertexTangents: material.normalMap && material.vertexTangents,
  11715. vertexColors: material.vertexColors,
  11716. 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,
  11717. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  11718. fog: !!fog,
  11719. useFog: material.fog,
  11720. fogExp2: fog && fog.isFogExp2,
  11721. flatShading: !!material.flatShading,
  11722. sizeAttenuation: material.sizeAttenuation,
  11723. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11724. skinning: material.skinning && maxBones > 0,
  11725. maxBones: maxBones,
  11726. useVertexTexture: floatVertexTextures,
  11727. morphTargets: material.morphTargets,
  11728. morphNormals: material.morphNormals,
  11729. maxMorphTargets: renderer.maxMorphTargets,
  11730. maxMorphNormals: renderer.maxMorphNormals,
  11731. numDirLights: lights.directional.length,
  11732. numPointLights: lights.point.length,
  11733. numSpotLights: lights.spot.length,
  11734. numRectAreaLights: lights.rectArea.length,
  11735. numHemiLights: lights.hemi.length,
  11736. numDirLightShadows: lights.directionalShadowMap.length,
  11737. numPointLightShadows: lights.pointShadowMap.length,
  11738. numSpotLightShadows: lights.spotShadowMap.length,
  11739. numClippingPlanes: clipping.numPlanes,
  11740. numClipIntersection: clipping.numIntersection,
  11741. dithering: material.dithering,
  11742. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11743. shadowMapType: renderer.shadowMap.type,
  11744. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11745. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11746. premultipliedAlpha: material.premultipliedAlpha,
  11747. alphaTest: material.alphaTest,
  11748. doubleSided: material.side === DoubleSide,
  11749. flipSided: material.side === BackSide,
  11750. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  11751. index0AttributeName: material.index0AttributeName,
  11752. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11753. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11754. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11755. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11756. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  11757. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  11758. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  11759. customProgramCacheKey: material.customProgramCacheKey()
  11760. };
  11761. return parameters;
  11762. }
  11763. function getProgramCacheKey(parameters) {
  11764. var array = [];
  11765. if (parameters.shaderID) {
  11766. array.push(parameters.shaderID);
  11767. } else {
  11768. array.push(parameters.fragmentShader);
  11769. array.push(parameters.vertexShader);
  11770. }
  11771. if (parameters.defines !== undefined) {
  11772. for (var name in parameters.defines) {
  11773. array.push(name);
  11774. array.push(parameters.defines[name]);
  11775. }
  11776. }
  11777. if (parameters.isRawShaderMaterial === false) {
  11778. for (var i = 0; i < parameterNames.length; i++) {
  11779. array.push(parameters[parameterNames[i]]);
  11780. }
  11781. array.push(renderer.outputEncoding);
  11782. array.push(renderer.gammaFactor);
  11783. }
  11784. array.push(parameters.customProgramCacheKey);
  11785. return array.join();
  11786. }
  11787. function getUniforms(material) {
  11788. var shaderID = shaderIDs[material.type];
  11789. var uniforms;
  11790. if (shaderID) {
  11791. var shader = ShaderLib[shaderID];
  11792. uniforms = UniformsUtils.clone(shader.uniforms);
  11793. } else {
  11794. uniforms = material.uniforms;
  11795. }
  11796. return uniforms;
  11797. }
  11798. function acquireProgram(parameters, cacheKey) {
  11799. var program; // Check if code has been already compiled
  11800. for (var p = 0, pl = programs.length; p < pl; p++) {
  11801. var preexistingProgram = programs[p];
  11802. if (preexistingProgram.cacheKey === cacheKey) {
  11803. program = preexistingProgram;
  11804. ++program.usedTimes;
  11805. break;
  11806. }
  11807. }
  11808. if (program === undefined) {
  11809. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11810. programs.push(program);
  11811. }
  11812. return program;
  11813. }
  11814. function releaseProgram(program) {
  11815. if (--program.usedTimes === 0) {
  11816. // Remove from unordered set
  11817. var i = programs.indexOf(program);
  11818. programs[i] = programs[programs.length - 1];
  11819. programs.pop(); // Free WebGL resources
  11820. program.destroy();
  11821. }
  11822. }
  11823. return {
  11824. getParameters: getParameters,
  11825. getProgramCacheKey: getProgramCacheKey,
  11826. getUniforms: getUniforms,
  11827. acquireProgram: acquireProgram,
  11828. releaseProgram: releaseProgram,
  11829. // Exposed for resource monitoring & error feedback via renderer.info:
  11830. programs: programs
  11831. };
  11832. }
  11833. function WebGLProperties() {
  11834. var properties = new WeakMap();
  11835. function get(object) {
  11836. var map = properties.get(object);
  11837. if (map === undefined) {
  11838. map = {};
  11839. properties.set(object, map);
  11840. }
  11841. return map;
  11842. }
  11843. function remove(object) {
  11844. properties.delete(object);
  11845. }
  11846. function update(object, key, value) {
  11847. properties.get(object)[key] = value;
  11848. }
  11849. function dispose() {
  11850. properties = new WeakMap();
  11851. }
  11852. return {
  11853. get: get,
  11854. remove: remove,
  11855. update: update,
  11856. dispose: dispose
  11857. };
  11858. }
  11859. function painterSortStable(a, b) {
  11860. if (a.groupOrder !== b.groupOrder) {
  11861. return a.groupOrder - b.groupOrder;
  11862. } else if (a.renderOrder !== b.renderOrder) {
  11863. return a.renderOrder - b.renderOrder;
  11864. } else if (a.program !== b.program) {
  11865. return a.program.id - b.program.id;
  11866. } else if (a.material.id !== b.material.id) {
  11867. return a.material.id - b.material.id;
  11868. } else if (a.z !== b.z) {
  11869. return a.z - b.z;
  11870. } else {
  11871. return a.id - b.id;
  11872. }
  11873. }
  11874. function reversePainterSortStable(a, b) {
  11875. if (a.groupOrder !== b.groupOrder) {
  11876. return a.groupOrder - b.groupOrder;
  11877. } else if (a.renderOrder !== b.renderOrder) {
  11878. return a.renderOrder - b.renderOrder;
  11879. } else if (a.z !== b.z) {
  11880. return b.z - a.z;
  11881. } else {
  11882. return a.id - b.id;
  11883. }
  11884. }
  11885. function WebGLRenderList(properties) {
  11886. var renderItems = [];
  11887. var renderItemsIndex = 0;
  11888. var opaque = [];
  11889. var transparent = [];
  11890. var defaultProgram = {
  11891. id: -1
  11892. };
  11893. function init() {
  11894. renderItemsIndex = 0;
  11895. opaque.length = 0;
  11896. transparent.length = 0;
  11897. }
  11898. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11899. var renderItem = renderItems[renderItemsIndex];
  11900. var materialProperties = properties.get(material);
  11901. if (renderItem === undefined) {
  11902. renderItem = {
  11903. id: object.id,
  11904. object: object,
  11905. geometry: geometry,
  11906. material: material,
  11907. program: materialProperties.program || defaultProgram,
  11908. groupOrder: groupOrder,
  11909. renderOrder: object.renderOrder,
  11910. z: z,
  11911. group: group
  11912. };
  11913. renderItems[renderItemsIndex] = renderItem;
  11914. } else {
  11915. renderItem.id = object.id;
  11916. renderItem.object = object;
  11917. renderItem.geometry = geometry;
  11918. renderItem.material = material;
  11919. renderItem.program = materialProperties.program || defaultProgram;
  11920. renderItem.groupOrder = groupOrder;
  11921. renderItem.renderOrder = object.renderOrder;
  11922. renderItem.z = z;
  11923. renderItem.group = group;
  11924. }
  11925. renderItemsIndex++;
  11926. return renderItem;
  11927. }
  11928. function push(object, geometry, material, groupOrder, z, group) {
  11929. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11930. (material.transparent === true ? transparent : opaque).push(renderItem);
  11931. }
  11932. function unshift(object, geometry, material, groupOrder, z, group) {
  11933. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11934. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11935. }
  11936. function sort(customOpaqueSort, customTransparentSort) {
  11937. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11938. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11939. }
  11940. function finish() {
  11941. // Clear references from inactive renderItems in the list
  11942. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11943. var renderItem = renderItems[i];
  11944. if (renderItem.id === null) break;
  11945. renderItem.id = null;
  11946. renderItem.object = null;
  11947. renderItem.geometry = null;
  11948. renderItem.material = null;
  11949. renderItem.program = null;
  11950. renderItem.group = null;
  11951. }
  11952. }
  11953. return {
  11954. opaque: opaque,
  11955. transparent: transparent,
  11956. init: init,
  11957. push: push,
  11958. unshift: unshift,
  11959. finish: finish,
  11960. sort: sort
  11961. };
  11962. }
  11963. function WebGLRenderLists(properties) {
  11964. var lists = new WeakMap();
  11965. function get(scene, renderCallDepth) {
  11966. var list;
  11967. if (lists.has(scene) === false) {
  11968. list = new WebGLRenderList(properties);
  11969. lists.set(scene, [list]);
  11970. } else {
  11971. if (renderCallDepth >= lists.get(scene).length) {
  11972. list = new WebGLRenderList(properties);
  11973. lists.get(scene).push(list);
  11974. } else {
  11975. list = lists.get(scene)[renderCallDepth];
  11976. }
  11977. }
  11978. return list;
  11979. }
  11980. function dispose() {
  11981. lists = new WeakMap();
  11982. }
  11983. return {
  11984. get: get,
  11985. dispose: dispose
  11986. };
  11987. }
  11988. function UniformsCache() {
  11989. var lights = {};
  11990. return {
  11991. get: function get(light) {
  11992. if (lights[light.id] !== undefined) {
  11993. return lights[light.id];
  11994. }
  11995. var uniforms;
  11996. switch (light.type) {
  11997. case 'DirectionalLight':
  11998. uniforms = {
  11999. direction: new Vector3(),
  12000. color: new Color()
  12001. };
  12002. break;
  12003. case 'SpotLight':
  12004. uniforms = {
  12005. position: new Vector3(),
  12006. direction: new Vector3(),
  12007. color: new Color(),
  12008. distance: 0,
  12009. coneCos: 0,
  12010. penumbraCos: 0,
  12011. decay: 0
  12012. };
  12013. break;
  12014. case 'PointLight':
  12015. uniforms = {
  12016. position: new Vector3(),
  12017. color: new Color(),
  12018. distance: 0,
  12019. decay: 0
  12020. };
  12021. break;
  12022. case 'HemisphereLight':
  12023. uniforms = {
  12024. direction: new Vector3(),
  12025. skyColor: new Color(),
  12026. groundColor: new Color()
  12027. };
  12028. break;
  12029. case 'RectAreaLight':
  12030. uniforms = {
  12031. color: new Color(),
  12032. position: new Vector3(),
  12033. halfWidth: new Vector3(),
  12034. halfHeight: new Vector3()
  12035. };
  12036. break;
  12037. }
  12038. lights[light.id] = uniforms;
  12039. return uniforms;
  12040. }
  12041. };
  12042. }
  12043. function ShadowUniformsCache() {
  12044. var lights = {};
  12045. return {
  12046. get: function get(light) {
  12047. if (lights[light.id] !== undefined) {
  12048. return lights[light.id];
  12049. }
  12050. var uniforms;
  12051. switch (light.type) {
  12052. case 'DirectionalLight':
  12053. uniforms = {
  12054. shadowBias: 0,
  12055. shadowNormalBias: 0,
  12056. shadowRadius: 1,
  12057. shadowMapSize: new Vector2()
  12058. };
  12059. break;
  12060. case 'SpotLight':
  12061. uniforms = {
  12062. shadowBias: 0,
  12063. shadowNormalBias: 0,
  12064. shadowRadius: 1,
  12065. shadowMapSize: new Vector2()
  12066. };
  12067. break;
  12068. case 'PointLight':
  12069. uniforms = {
  12070. shadowBias: 0,
  12071. shadowNormalBias: 0,
  12072. shadowRadius: 1,
  12073. shadowMapSize: new Vector2(),
  12074. shadowCameraNear: 1,
  12075. shadowCameraFar: 1000
  12076. };
  12077. break;
  12078. // TODO (abelnation): set RectAreaLight shadow uniforms
  12079. }
  12080. lights[light.id] = uniforms;
  12081. return uniforms;
  12082. }
  12083. };
  12084. }
  12085. var nextVersion = 0;
  12086. function shadowCastingLightsFirst(lightA, lightB) {
  12087. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  12088. }
  12089. function WebGLLights(extensions, capabilities) {
  12090. var cache = new UniformsCache();
  12091. var shadowCache = ShadowUniformsCache();
  12092. var state = {
  12093. version: 0,
  12094. hash: {
  12095. directionalLength: -1,
  12096. pointLength: -1,
  12097. spotLength: -1,
  12098. rectAreaLength: -1,
  12099. hemiLength: -1,
  12100. numDirectionalShadows: -1,
  12101. numPointShadows: -1,
  12102. numSpotShadows: -1
  12103. },
  12104. ambient: [0, 0, 0],
  12105. probe: [],
  12106. directional: [],
  12107. directionalShadow: [],
  12108. directionalShadowMap: [],
  12109. directionalShadowMatrix: [],
  12110. spot: [],
  12111. spotShadow: [],
  12112. spotShadowMap: [],
  12113. spotShadowMatrix: [],
  12114. rectArea: [],
  12115. rectAreaLTC1: null,
  12116. rectAreaLTC2: null,
  12117. point: [],
  12118. pointShadow: [],
  12119. pointShadowMap: [],
  12120. pointShadowMatrix: [],
  12121. hemi: []
  12122. };
  12123. for (var i = 0; i < 9; i++) {
  12124. state.probe.push(new Vector3());
  12125. }
  12126. var vector3 = new Vector3();
  12127. var matrix4 = new Matrix4();
  12128. var matrix42 = new Matrix4();
  12129. function setup(lights) {
  12130. var r = 0,
  12131. g = 0,
  12132. b = 0;
  12133. for (var _i = 0; _i < 9; _i++) {
  12134. state.probe[_i].set(0, 0, 0);
  12135. }
  12136. var directionalLength = 0;
  12137. var pointLength = 0;
  12138. var spotLength = 0;
  12139. var rectAreaLength = 0;
  12140. var hemiLength = 0;
  12141. var numDirectionalShadows = 0;
  12142. var numPointShadows = 0;
  12143. var numSpotShadows = 0;
  12144. lights.sort(shadowCastingLightsFirst);
  12145. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  12146. var light = lights[_i2];
  12147. var color = light.color;
  12148. var intensity = light.intensity;
  12149. var distance = light.distance;
  12150. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  12151. if (light.isAmbientLight) {
  12152. r += color.r * intensity;
  12153. g += color.g * intensity;
  12154. b += color.b * intensity;
  12155. } else if (light.isLightProbe) {
  12156. for (var j = 0; j < 9; j++) {
  12157. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  12158. }
  12159. } else if (light.isDirectionalLight) {
  12160. var uniforms = cache.get(light);
  12161. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  12162. if (light.castShadow) {
  12163. var shadow = light.shadow;
  12164. var shadowUniforms = shadowCache.get(light);
  12165. shadowUniforms.shadowBias = shadow.bias;
  12166. shadowUniforms.shadowNormalBias = shadow.normalBias;
  12167. shadowUniforms.shadowRadius = shadow.radius;
  12168. shadowUniforms.shadowMapSize = shadow.mapSize;
  12169. state.directionalShadow[directionalLength] = shadowUniforms;
  12170. state.directionalShadowMap[directionalLength] = shadowMap;
  12171. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  12172. numDirectionalShadows++;
  12173. }
  12174. state.directional[directionalLength] = uniforms;
  12175. directionalLength++;
  12176. } else if (light.isSpotLight) {
  12177. var _uniforms = cache.get(light);
  12178. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  12179. _uniforms.color.copy(color).multiplyScalar(intensity);
  12180. _uniforms.distance = distance;
  12181. _uniforms.coneCos = Math.cos(light.angle);
  12182. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  12183. _uniforms.decay = light.decay;
  12184. if (light.castShadow) {
  12185. var _shadow = light.shadow;
  12186. var _shadowUniforms = shadowCache.get(light);
  12187. _shadowUniforms.shadowBias = _shadow.bias;
  12188. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  12189. _shadowUniforms.shadowRadius = _shadow.radius;
  12190. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  12191. state.spotShadow[spotLength] = _shadowUniforms;
  12192. state.spotShadowMap[spotLength] = shadowMap;
  12193. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  12194. numSpotShadows++;
  12195. }
  12196. state.spot[spotLength] = _uniforms;
  12197. spotLength++;
  12198. } else if (light.isRectAreaLight) {
  12199. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  12200. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  12201. // (b) intensity is the brightness of the light
  12202. _uniforms2.color.copy(color).multiplyScalar(intensity);
  12203. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  12204. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  12205. state.rectArea[rectAreaLength] = _uniforms2;
  12206. rectAreaLength++;
  12207. } else if (light.isPointLight) {
  12208. var _uniforms3 = cache.get(light);
  12209. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  12210. _uniforms3.distance = light.distance;
  12211. _uniforms3.decay = light.decay;
  12212. if (light.castShadow) {
  12213. var _shadow2 = light.shadow;
  12214. var _shadowUniforms2 = shadowCache.get(light);
  12215. _shadowUniforms2.shadowBias = _shadow2.bias;
  12216. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  12217. _shadowUniforms2.shadowRadius = _shadow2.radius;
  12218. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  12219. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  12220. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  12221. state.pointShadow[pointLength] = _shadowUniforms2;
  12222. state.pointShadowMap[pointLength] = shadowMap;
  12223. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  12224. numPointShadows++;
  12225. }
  12226. state.point[pointLength] = _uniforms3;
  12227. pointLength++;
  12228. } else if (light.isHemisphereLight) {
  12229. var _uniforms4 = cache.get(light);
  12230. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  12231. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  12232. state.hemi[hemiLength] = _uniforms4;
  12233. hemiLength++;
  12234. }
  12235. }
  12236. if (rectAreaLength > 0) {
  12237. if (capabilities.isWebGL2) {
  12238. // WebGL 2
  12239. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12240. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12241. } else {
  12242. // WebGL 1
  12243. if (extensions.has('OES_texture_float_linear') === true) {
  12244. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12245. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12246. } else if (extensions.has('OES_texture_half_float_linear') === true) {
  12247. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  12248. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  12249. } else {
  12250. console.error('THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.');
  12251. }
  12252. }
  12253. }
  12254. state.ambient[0] = r;
  12255. state.ambient[1] = g;
  12256. state.ambient[2] = b;
  12257. var hash = state.hash;
  12258. 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) {
  12259. state.directional.length = directionalLength;
  12260. state.spot.length = spotLength;
  12261. state.rectArea.length = rectAreaLength;
  12262. state.point.length = pointLength;
  12263. state.hemi.length = hemiLength;
  12264. state.directionalShadow.length = numDirectionalShadows;
  12265. state.directionalShadowMap.length = numDirectionalShadows;
  12266. state.pointShadow.length = numPointShadows;
  12267. state.pointShadowMap.length = numPointShadows;
  12268. state.spotShadow.length = numSpotShadows;
  12269. state.spotShadowMap.length = numSpotShadows;
  12270. state.directionalShadowMatrix.length = numDirectionalShadows;
  12271. state.pointShadowMatrix.length = numPointShadows;
  12272. state.spotShadowMatrix.length = numSpotShadows;
  12273. hash.directionalLength = directionalLength;
  12274. hash.pointLength = pointLength;
  12275. hash.spotLength = spotLength;
  12276. hash.rectAreaLength = rectAreaLength;
  12277. hash.hemiLength = hemiLength;
  12278. hash.numDirectionalShadows = numDirectionalShadows;
  12279. hash.numPointShadows = numPointShadows;
  12280. hash.numSpotShadows = numSpotShadows;
  12281. state.version = nextVersion++;
  12282. }
  12283. }
  12284. function setupView(lights, camera) {
  12285. var directionalLength = 0;
  12286. var pointLength = 0;
  12287. var spotLength = 0;
  12288. var rectAreaLength = 0;
  12289. var hemiLength = 0;
  12290. var viewMatrix = camera.matrixWorldInverse;
  12291. for (var _i3 = 0, l = lights.length; _i3 < l; _i3++) {
  12292. var light = lights[_i3];
  12293. if (light.isDirectionalLight) {
  12294. var uniforms = state.directional[directionalLength];
  12295. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  12296. vector3.setFromMatrixPosition(light.target.matrixWorld);
  12297. uniforms.direction.sub(vector3);
  12298. uniforms.direction.transformDirection(viewMatrix);
  12299. directionalLength++;
  12300. } else if (light.isSpotLight) {
  12301. var _uniforms5 = state.spot[spotLength];
  12302. _uniforms5.position.setFromMatrixPosition(light.matrixWorld);
  12303. _uniforms5.position.applyMatrix4(viewMatrix);
  12304. _uniforms5.direction.setFromMatrixPosition(light.matrixWorld);
  12305. vector3.setFromMatrixPosition(light.target.matrixWorld);
  12306. _uniforms5.direction.sub(vector3);
  12307. _uniforms5.direction.transformDirection(viewMatrix);
  12308. spotLength++;
  12309. } else if (light.isRectAreaLight) {
  12310. var _uniforms6 = state.rectArea[rectAreaLength];
  12311. _uniforms6.position.setFromMatrixPosition(light.matrixWorld);
  12312. _uniforms6.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  12313. matrix42.identity();
  12314. matrix4.copy(light.matrixWorld);
  12315. matrix4.premultiply(viewMatrix);
  12316. matrix42.extractRotation(matrix4);
  12317. _uniforms6.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  12318. _uniforms6.halfHeight.set(0.0, light.height * 0.5, 0.0);
  12319. _uniforms6.halfWidth.applyMatrix4(matrix42);
  12320. _uniforms6.halfHeight.applyMatrix4(matrix42);
  12321. rectAreaLength++;
  12322. } else if (light.isPointLight) {
  12323. var _uniforms7 = state.point[pointLength];
  12324. _uniforms7.position.setFromMatrixPosition(light.matrixWorld);
  12325. _uniforms7.position.applyMatrix4(viewMatrix);
  12326. pointLength++;
  12327. } else if (light.isHemisphereLight) {
  12328. var _uniforms8 = state.hemi[hemiLength];
  12329. _uniforms8.direction.setFromMatrixPosition(light.matrixWorld);
  12330. _uniforms8.direction.transformDirection(viewMatrix);
  12331. _uniforms8.direction.normalize();
  12332. hemiLength++;
  12333. }
  12334. }
  12335. }
  12336. return {
  12337. setup: setup,
  12338. setupView: setupView,
  12339. state: state
  12340. };
  12341. }
  12342. function WebGLRenderState(extensions, capabilities) {
  12343. var lights = new WebGLLights(extensions, capabilities);
  12344. var lightsArray = [];
  12345. var shadowsArray = [];
  12346. function init() {
  12347. lightsArray.length = 0;
  12348. shadowsArray.length = 0;
  12349. }
  12350. function pushLight(light) {
  12351. lightsArray.push(light);
  12352. }
  12353. function pushShadow(shadowLight) {
  12354. shadowsArray.push(shadowLight);
  12355. }
  12356. function setupLights() {
  12357. lights.setup(lightsArray);
  12358. }
  12359. function setupLightsView(camera) {
  12360. lights.setupView(lightsArray, camera);
  12361. }
  12362. var state = {
  12363. lightsArray: lightsArray,
  12364. shadowsArray: shadowsArray,
  12365. lights: lights
  12366. };
  12367. return {
  12368. init: init,
  12369. state: state,
  12370. setupLights: setupLights,
  12371. setupLightsView: setupLightsView,
  12372. pushLight: pushLight,
  12373. pushShadow: pushShadow
  12374. };
  12375. }
  12376. function WebGLRenderStates(extensions, capabilities) {
  12377. var renderStates = new WeakMap();
  12378. function get(scene, renderCallDepth) {
  12379. if (renderCallDepth === void 0) {
  12380. renderCallDepth = 0;
  12381. }
  12382. var renderState;
  12383. if (renderStates.has(scene) === false) {
  12384. renderState = new WebGLRenderState(extensions, capabilities);
  12385. renderStates.set(scene, [renderState]);
  12386. } else {
  12387. if (renderCallDepth >= renderStates.get(scene).length) {
  12388. renderState = new WebGLRenderState(extensions, capabilities);
  12389. renderStates.get(scene).push(renderState);
  12390. } else {
  12391. renderState = renderStates.get(scene)[renderCallDepth];
  12392. }
  12393. }
  12394. return renderState;
  12395. }
  12396. function dispose() {
  12397. renderStates = new WeakMap();
  12398. }
  12399. return {
  12400. get: get,
  12401. dispose: dispose
  12402. };
  12403. }
  12404. /**
  12405. * parameters = {
  12406. *
  12407. * opacity: <float>,
  12408. *
  12409. * map: new THREE.Texture( <Image> ),
  12410. *
  12411. * alphaMap: new THREE.Texture( <Image> ),
  12412. *
  12413. * displacementMap: new THREE.Texture( <Image> ),
  12414. * displacementScale: <float>,
  12415. * displacementBias: <float>,
  12416. *
  12417. * wireframe: <boolean>,
  12418. * wireframeLinewidth: <float>
  12419. * }
  12420. */
  12421. var MeshDepthMaterial = /*#__PURE__*/function (_Material) {
  12422. _inheritsLoose(MeshDepthMaterial, _Material);
  12423. function MeshDepthMaterial(parameters) {
  12424. var _this;
  12425. _this = _Material.call(this) || this;
  12426. _this.type = 'MeshDepthMaterial';
  12427. _this.depthPacking = BasicDepthPacking;
  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.wireframe = false;
  12436. _this.wireframeLinewidth = 1;
  12437. _this.fog = false;
  12438. _this.setValues(parameters);
  12439. return _this;
  12440. }
  12441. var _proto = MeshDepthMaterial.prototype;
  12442. _proto.copy = function copy(source) {
  12443. _Material.prototype.copy.call(this, source);
  12444. this.depthPacking = source.depthPacking;
  12445. this.skinning = source.skinning;
  12446. this.morphTargets = source.morphTargets;
  12447. this.map = source.map;
  12448. this.alphaMap = source.alphaMap;
  12449. this.displacementMap = source.displacementMap;
  12450. this.displacementScale = source.displacementScale;
  12451. this.displacementBias = source.displacementBias;
  12452. this.wireframe = source.wireframe;
  12453. this.wireframeLinewidth = source.wireframeLinewidth;
  12454. return this;
  12455. };
  12456. return MeshDepthMaterial;
  12457. }(Material);
  12458. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  12459. /**
  12460. * parameters = {
  12461. *
  12462. * referencePosition: <float>,
  12463. * nearDistance: <float>,
  12464. * farDistance: <float>,
  12465. *
  12466. * skinning: <bool>,
  12467. * morphTargets: <bool>,
  12468. *
  12469. * map: new THREE.Texture( <Image> ),
  12470. *
  12471. * alphaMap: new THREE.Texture( <Image> ),
  12472. *
  12473. * displacementMap: new THREE.Texture( <Image> ),
  12474. * displacementScale: <float>,
  12475. * displacementBias: <float>
  12476. *
  12477. * }
  12478. */
  12479. var MeshDistanceMaterial = /*#__PURE__*/function (_Material) {
  12480. _inheritsLoose(MeshDistanceMaterial, _Material);
  12481. function MeshDistanceMaterial(parameters) {
  12482. var _this;
  12483. _this = _Material.call(this) || this;
  12484. _this.type = 'MeshDistanceMaterial';
  12485. _this.referencePosition = new Vector3();
  12486. _this.nearDistance = 1;
  12487. _this.farDistance = 1000;
  12488. _this.skinning = false;
  12489. _this.morphTargets = false;
  12490. _this.map = null;
  12491. _this.alphaMap = null;
  12492. _this.displacementMap = null;
  12493. _this.displacementScale = 1;
  12494. _this.displacementBias = 0;
  12495. _this.fog = false;
  12496. _this.setValues(parameters);
  12497. return _this;
  12498. }
  12499. var _proto = MeshDistanceMaterial.prototype;
  12500. _proto.copy = function copy(source) {
  12501. _Material.prototype.copy.call(this, source);
  12502. this.referencePosition.copy(source.referencePosition);
  12503. this.nearDistance = source.nearDistance;
  12504. this.farDistance = source.farDistance;
  12505. this.skinning = source.skinning;
  12506. this.morphTargets = source.morphTargets;
  12507. this.map = source.map;
  12508. this.alphaMap = source.alphaMap;
  12509. this.displacementMap = source.displacementMap;
  12510. this.displacementScale = source.displacementScale;
  12511. this.displacementBias = source.displacementBias;
  12512. return this;
  12513. };
  12514. return MeshDistanceMaterial;
  12515. }(Material);
  12516. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  12517. 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}";
  12518. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  12519. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  12520. var _frustum = new Frustum();
  12521. var _shadowMapSize = new Vector2(),
  12522. _viewportSize = new Vector2(),
  12523. _viewport = new Vector4(),
  12524. _depthMaterials = [],
  12525. _distanceMaterials = [],
  12526. _materialCache = {};
  12527. var shadowSide = {
  12528. 0: BackSide,
  12529. 1: FrontSide,
  12530. 2: DoubleSide
  12531. };
  12532. var shadowMaterialVertical = new ShaderMaterial({
  12533. defines: {
  12534. SAMPLE_RATE: 2.0 / 8.0,
  12535. HALF_SAMPLE_RATE: 1.0 / 8.0
  12536. },
  12537. uniforms: {
  12538. shadow_pass: {
  12539. value: null
  12540. },
  12541. resolution: {
  12542. value: new Vector2()
  12543. },
  12544. radius: {
  12545. value: 4.0
  12546. }
  12547. },
  12548. vertexShader: vsm_vert,
  12549. fragmentShader: vsm_frag
  12550. });
  12551. var shadowMaterialHorizontal = shadowMaterialVertical.clone();
  12552. shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1;
  12553. var fullScreenTri = new BufferGeometry();
  12554. fullScreenTri.setAttribute('position', new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  12555. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  12556. var scope = this;
  12557. this.enabled = false;
  12558. this.autoUpdate = true;
  12559. this.needsUpdate = false;
  12560. this.type = PCFShadowMap;
  12561. this.render = function (lights, scene, camera) {
  12562. if (scope.enabled === false) return;
  12563. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  12564. if (lights.length === 0) return;
  12565. var currentRenderTarget = _renderer.getRenderTarget();
  12566. var activeCubeFace = _renderer.getActiveCubeFace();
  12567. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  12568. var _state = _renderer.state; // Set GL state for depth map.
  12569. _state.setBlending(NoBlending);
  12570. _state.buffers.color.setClear(1, 1, 1, 1);
  12571. _state.buffers.depth.setTest(true);
  12572. _state.setScissorTest(false); // render depth map
  12573. for (var i = 0, il = lights.length; i < il; i++) {
  12574. var light = lights[i];
  12575. var shadow = light.shadow;
  12576. if (shadow === undefined) {
  12577. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  12578. continue;
  12579. }
  12580. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  12581. _shadowMapSize.copy(shadow.mapSize);
  12582. var shadowFrameExtents = shadow.getFrameExtents();
  12583. _shadowMapSize.multiply(shadowFrameExtents);
  12584. _viewportSize.copy(shadow.mapSize);
  12585. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  12586. if (_shadowMapSize.x > maxTextureSize) {
  12587. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  12588. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  12589. shadow.mapSize.x = _viewportSize.x;
  12590. }
  12591. if (_shadowMapSize.y > maxTextureSize) {
  12592. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  12593. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  12594. shadow.mapSize.y = _viewportSize.y;
  12595. }
  12596. }
  12597. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12598. var pars = {
  12599. minFilter: LinearFilter,
  12600. magFilter: LinearFilter,
  12601. format: RGBAFormat
  12602. };
  12603. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12604. shadow.map.texture.name = light.name + '.shadowMap';
  12605. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12606. shadow.camera.updateProjectionMatrix();
  12607. }
  12608. if (shadow.map === null) {
  12609. var _pars = {
  12610. minFilter: NearestFilter,
  12611. magFilter: NearestFilter,
  12612. format: RGBAFormat
  12613. };
  12614. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  12615. shadow.map.texture.name = light.name + '.shadowMap';
  12616. shadow.camera.updateProjectionMatrix();
  12617. }
  12618. _renderer.setRenderTarget(shadow.map);
  12619. _renderer.clear();
  12620. var viewportCount = shadow.getViewportCount();
  12621. for (var vp = 0; vp < viewportCount; vp++) {
  12622. var viewport = shadow.getViewport(vp);
  12623. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  12624. _state.viewport(_viewport);
  12625. shadow.updateMatrices(light, vp);
  12626. _frustum = shadow.getFrustum();
  12627. renderObject(scene, camera, shadow.camera, light, this.type);
  12628. } // do blur pass for VSM
  12629. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12630. VSMPass(shadow, camera);
  12631. }
  12632. shadow.needsUpdate = false;
  12633. }
  12634. scope.needsUpdate = false;
  12635. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  12636. };
  12637. function VSMPass(shadow, camera) {
  12638. var geometry = _objects.update(fullScreenMesh); // vertical pass
  12639. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  12640. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  12641. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  12642. _renderer.setRenderTarget(shadow.mapPass);
  12643. _renderer.clear();
  12644. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizontal pass
  12645. shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  12646. shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize;
  12647. shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;
  12648. _renderer.setRenderTarget(shadow.map);
  12649. _renderer.clear();
  12650. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null);
  12651. }
  12652. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12653. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12654. var material = _depthMaterials[index];
  12655. if (material === undefined) {
  12656. material = new MeshDepthMaterial({
  12657. depthPacking: RGBADepthPacking,
  12658. morphTargets: useMorphing,
  12659. skinning: useSkinning
  12660. });
  12661. _depthMaterials[index] = material;
  12662. }
  12663. return material;
  12664. }
  12665. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12666. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12667. var material = _distanceMaterials[index];
  12668. if (material === undefined) {
  12669. material = new MeshDistanceMaterial({
  12670. morphTargets: useMorphing,
  12671. skinning: useSkinning
  12672. });
  12673. _distanceMaterials[index] = material;
  12674. }
  12675. return material;
  12676. }
  12677. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  12678. var result = null;
  12679. var getMaterialVariant = getDepthMaterialVariant;
  12680. var customMaterial = object.customDepthMaterial;
  12681. if (light.isPointLight === true) {
  12682. getMaterialVariant = getDistanceMaterialVariant;
  12683. customMaterial = object.customDistanceMaterial;
  12684. }
  12685. if (customMaterial === undefined) {
  12686. var useMorphing = false;
  12687. if (material.morphTargets === true) {
  12688. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  12689. }
  12690. var useSkinning = false;
  12691. if (object.isSkinnedMesh === true) {
  12692. if (material.skinning === true) {
  12693. useSkinning = true;
  12694. } else {
  12695. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  12696. }
  12697. }
  12698. var useInstancing = object.isInstancedMesh === true;
  12699. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  12700. } else {
  12701. result = customMaterial;
  12702. }
  12703. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  12704. // in this case we need a unique material instance reflecting the
  12705. // appropriate state
  12706. var keyA = result.uuid,
  12707. keyB = material.uuid;
  12708. var materialsForVariant = _materialCache[keyA];
  12709. if (materialsForVariant === undefined) {
  12710. materialsForVariant = {};
  12711. _materialCache[keyA] = materialsForVariant;
  12712. }
  12713. var cachedMaterial = materialsForVariant[keyB];
  12714. if (cachedMaterial === undefined) {
  12715. cachedMaterial = result.clone();
  12716. materialsForVariant[keyB] = cachedMaterial;
  12717. }
  12718. result = cachedMaterial;
  12719. }
  12720. result.visible = material.visible;
  12721. result.wireframe = material.wireframe;
  12722. if (type === VSMShadowMap) {
  12723. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  12724. } else {
  12725. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  12726. }
  12727. result.clipShadows = material.clipShadows;
  12728. result.clippingPlanes = material.clippingPlanes;
  12729. result.clipIntersection = material.clipIntersection;
  12730. result.wireframeLinewidth = material.wireframeLinewidth;
  12731. result.linewidth = material.linewidth;
  12732. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  12733. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  12734. result.nearDistance = shadowCameraNear;
  12735. result.farDistance = shadowCameraFar;
  12736. }
  12737. return result;
  12738. }
  12739. function renderObject(object, camera, shadowCamera, light, type) {
  12740. if (object.visible === false) return;
  12741. var visible = object.layers.test(camera.layers);
  12742. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  12743. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  12744. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  12745. var geometry = _objects.update(object);
  12746. var material = object.material;
  12747. if (Array.isArray(material)) {
  12748. var groups = geometry.groups;
  12749. for (var k = 0, kl = groups.length; k < kl; k++) {
  12750. var group = groups[k];
  12751. var groupMaterial = material[group.materialIndex];
  12752. if (groupMaterial && groupMaterial.visible) {
  12753. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  12754. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  12755. }
  12756. }
  12757. } else if (material.visible) {
  12758. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  12759. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  12760. }
  12761. }
  12762. }
  12763. var children = object.children;
  12764. for (var i = 0, l = children.length; i < l; i++) {
  12765. renderObject(children[i], camera, shadowCamera, light, type);
  12766. }
  12767. }
  12768. }
  12769. function WebGLState(gl, extensions, capabilities) {
  12770. var _equationToGL, _factorToGL;
  12771. var isWebGL2 = capabilities.isWebGL2;
  12772. function ColorBuffer() {
  12773. var locked = false;
  12774. var color = new Vector4();
  12775. var currentColorMask = null;
  12776. var currentColorClear = new Vector4(0, 0, 0, 0);
  12777. return {
  12778. setMask: function setMask(colorMask) {
  12779. if (currentColorMask !== colorMask && !locked) {
  12780. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  12781. currentColorMask = colorMask;
  12782. }
  12783. },
  12784. setLocked: function setLocked(lock) {
  12785. locked = lock;
  12786. },
  12787. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  12788. if (premultipliedAlpha === true) {
  12789. r *= a;
  12790. g *= a;
  12791. b *= a;
  12792. }
  12793. color.set(r, g, b, a);
  12794. if (currentColorClear.equals(color) === false) {
  12795. gl.clearColor(r, g, b, a);
  12796. currentColorClear.copy(color);
  12797. }
  12798. },
  12799. reset: function reset() {
  12800. locked = false;
  12801. currentColorMask = null;
  12802. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  12803. }
  12804. };
  12805. }
  12806. function DepthBuffer() {
  12807. var locked = false;
  12808. var currentDepthMask = null;
  12809. var currentDepthFunc = null;
  12810. var currentDepthClear = null;
  12811. return {
  12812. setTest: function setTest(depthTest) {
  12813. if (depthTest) {
  12814. enable(2929);
  12815. } else {
  12816. disable(2929);
  12817. }
  12818. },
  12819. setMask: function setMask(depthMask) {
  12820. if (currentDepthMask !== depthMask && !locked) {
  12821. gl.depthMask(depthMask);
  12822. currentDepthMask = depthMask;
  12823. }
  12824. },
  12825. setFunc: function setFunc(depthFunc) {
  12826. if (currentDepthFunc !== depthFunc) {
  12827. if (depthFunc) {
  12828. switch (depthFunc) {
  12829. case NeverDepth:
  12830. gl.depthFunc(512);
  12831. break;
  12832. case AlwaysDepth:
  12833. gl.depthFunc(519);
  12834. break;
  12835. case LessDepth:
  12836. gl.depthFunc(513);
  12837. break;
  12838. case LessEqualDepth:
  12839. gl.depthFunc(515);
  12840. break;
  12841. case EqualDepth:
  12842. gl.depthFunc(514);
  12843. break;
  12844. case GreaterEqualDepth:
  12845. gl.depthFunc(518);
  12846. break;
  12847. case GreaterDepth:
  12848. gl.depthFunc(516);
  12849. break;
  12850. case NotEqualDepth:
  12851. gl.depthFunc(517);
  12852. break;
  12853. default:
  12854. gl.depthFunc(515);
  12855. }
  12856. } else {
  12857. gl.depthFunc(515);
  12858. }
  12859. currentDepthFunc = depthFunc;
  12860. }
  12861. },
  12862. setLocked: function setLocked(lock) {
  12863. locked = lock;
  12864. },
  12865. setClear: function setClear(depth) {
  12866. if (currentDepthClear !== depth) {
  12867. gl.clearDepth(depth);
  12868. currentDepthClear = depth;
  12869. }
  12870. },
  12871. reset: function reset() {
  12872. locked = false;
  12873. currentDepthMask = null;
  12874. currentDepthFunc = null;
  12875. currentDepthClear = null;
  12876. }
  12877. };
  12878. }
  12879. function StencilBuffer() {
  12880. var locked = false;
  12881. var currentStencilMask = null;
  12882. var currentStencilFunc = null;
  12883. var currentStencilRef = null;
  12884. var currentStencilFuncMask = null;
  12885. var currentStencilFail = null;
  12886. var currentStencilZFail = null;
  12887. var currentStencilZPass = null;
  12888. var currentStencilClear = null;
  12889. return {
  12890. setTest: function setTest(stencilTest) {
  12891. if (!locked) {
  12892. if (stencilTest) {
  12893. enable(2960);
  12894. } else {
  12895. disable(2960);
  12896. }
  12897. }
  12898. },
  12899. setMask: function setMask(stencilMask) {
  12900. if (currentStencilMask !== stencilMask && !locked) {
  12901. gl.stencilMask(stencilMask);
  12902. currentStencilMask = stencilMask;
  12903. }
  12904. },
  12905. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12906. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12907. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12908. currentStencilFunc = stencilFunc;
  12909. currentStencilRef = stencilRef;
  12910. currentStencilFuncMask = stencilMask;
  12911. }
  12912. },
  12913. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12914. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12915. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12916. currentStencilFail = stencilFail;
  12917. currentStencilZFail = stencilZFail;
  12918. currentStencilZPass = stencilZPass;
  12919. }
  12920. },
  12921. setLocked: function setLocked(lock) {
  12922. locked = lock;
  12923. },
  12924. setClear: function setClear(stencil) {
  12925. if (currentStencilClear !== stencil) {
  12926. gl.clearStencil(stencil);
  12927. currentStencilClear = stencil;
  12928. }
  12929. },
  12930. reset: function reset() {
  12931. locked = false;
  12932. currentStencilMask = null;
  12933. currentStencilFunc = null;
  12934. currentStencilRef = null;
  12935. currentStencilFuncMask = null;
  12936. currentStencilFail = null;
  12937. currentStencilZFail = null;
  12938. currentStencilZPass = null;
  12939. currentStencilClear = null;
  12940. }
  12941. };
  12942. } //
  12943. var colorBuffer = new ColorBuffer();
  12944. var depthBuffer = new DepthBuffer();
  12945. var stencilBuffer = new StencilBuffer();
  12946. var enabledCapabilities = {};
  12947. var currentProgram = null;
  12948. var currentBlendingEnabled = false;
  12949. var currentBlending = null;
  12950. var currentBlendEquation = null;
  12951. var currentBlendSrc = null;
  12952. var currentBlendDst = null;
  12953. var currentBlendEquationAlpha = null;
  12954. var currentBlendSrcAlpha = null;
  12955. var currentBlendDstAlpha = null;
  12956. var currentPremultipledAlpha = false;
  12957. var currentFlipSided = null;
  12958. var currentCullFace = null;
  12959. var currentLineWidth = null;
  12960. var currentPolygonOffsetFactor = null;
  12961. var currentPolygonOffsetUnits = null;
  12962. var maxTextures = gl.getParameter(35661);
  12963. var lineWidthAvailable = false;
  12964. var version = 0;
  12965. var glVersion = gl.getParameter(7938);
  12966. if (glVersion.indexOf('WebGL') !== -1) {
  12967. version = parseFloat(/^WebGL (\d)/.exec(glVersion)[1]);
  12968. lineWidthAvailable = version >= 1.0;
  12969. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12970. version = parseFloat(/^OpenGL ES (\d)/.exec(glVersion)[1]);
  12971. lineWidthAvailable = version >= 2.0;
  12972. }
  12973. var currentTextureSlot = null;
  12974. var currentBoundTextures = {};
  12975. var currentScissor = new Vector4();
  12976. var currentViewport = new Vector4();
  12977. function createTexture(type, target, count) {
  12978. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12979. var texture = gl.createTexture();
  12980. gl.bindTexture(type, texture);
  12981. gl.texParameteri(type, 10241, 9728);
  12982. gl.texParameteri(type, 10240, 9728);
  12983. for (var i = 0; i < count; i++) {
  12984. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12985. }
  12986. return texture;
  12987. }
  12988. var emptyTextures = {};
  12989. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12990. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12991. colorBuffer.setClear(0, 0, 0, 1);
  12992. depthBuffer.setClear(1);
  12993. stencilBuffer.setClear(0);
  12994. enable(2929);
  12995. depthBuffer.setFunc(LessEqualDepth);
  12996. setFlipSided(false);
  12997. setCullFace(CullFaceBack);
  12998. enable(2884);
  12999. setBlending(NoBlending); //
  13000. function enable(id) {
  13001. if (enabledCapabilities[id] !== true) {
  13002. gl.enable(id);
  13003. enabledCapabilities[id] = true;
  13004. }
  13005. }
  13006. function disable(id) {
  13007. if (enabledCapabilities[id] !== false) {
  13008. gl.disable(id);
  13009. enabledCapabilities[id] = false;
  13010. }
  13011. }
  13012. function useProgram(program) {
  13013. if (currentProgram !== program) {
  13014. gl.useProgram(program);
  13015. currentProgram = program;
  13016. return true;
  13017. }
  13018. return false;
  13019. }
  13020. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  13021. if (isWebGL2) {
  13022. equationToGL[MinEquation] = 32775;
  13023. equationToGL[MaxEquation] = 32776;
  13024. } else {
  13025. var extension = extensions.get('EXT_blend_minmax');
  13026. if (extension !== null) {
  13027. equationToGL[MinEquation] = extension.MIN_EXT;
  13028. equationToGL[MaxEquation] = extension.MAX_EXT;
  13029. }
  13030. }
  13031. 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);
  13032. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  13033. if (blending === NoBlending) {
  13034. if (currentBlendingEnabled === true) {
  13035. disable(3042);
  13036. currentBlendingEnabled = false;
  13037. }
  13038. return;
  13039. }
  13040. if (currentBlendingEnabled === false) {
  13041. enable(3042);
  13042. currentBlendingEnabled = true;
  13043. }
  13044. if (blending !== CustomBlending) {
  13045. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  13046. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  13047. gl.blendEquation(32774);
  13048. currentBlendEquation = AddEquation;
  13049. currentBlendEquationAlpha = AddEquation;
  13050. }
  13051. if (premultipliedAlpha) {
  13052. switch (blending) {
  13053. case NormalBlending:
  13054. gl.blendFuncSeparate(1, 771, 1, 771);
  13055. break;
  13056. case AdditiveBlending:
  13057. gl.blendFunc(1, 1);
  13058. break;
  13059. case SubtractiveBlending:
  13060. gl.blendFuncSeparate(0, 0, 769, 771);
  13061. break;
  13062. case MultiplyBlending:
  13063. gl.blendFuncSeparate(0, 768, 0, 770);
  13064. break;
  13065. default:
  13066. console.error('THREE.WebGLState: Invalid blending: ', blending);
  13067. break;
  13068. }
  13069. } else {
  13070. switch (blending) {
  13071. case NormalBlending:
  13072. gl.blendFuncSeparate(770, 771, 1, 771);
  13073. break;
  13074. case AdditiveBlending:
  13075. gl.blendFunc(770, 1);
  13076. break;
  13077. case SubtractiveBlending:
  13078. gl.blendFunc(0, 769);
  13079. break;
  13080. case MultiplyBlending:
  13081. gl.blendFunc(0, 768);
  13082. break;
  13083. default:
  13084. console.error('THREE.WebGLState: Invalid blending: ', blending);
  13085. break;
  13086. }
  13087. }
  13088. currentBlendSrc = null;
  13089. currentBlendDst = null;
  13090. currentBlendSrcAlpha = null;
  13091. currentBlendDstAlpha = null;
  13092. currentBlending = blending;
  13093. currentPremultipledAlpha = premultipliedAlpha;
  13094. }
  13095. return;
  13096. } // custom blending
  13097. blendEquationAlpha = blendEquationAlpha || blendEquation;
  13098. blendSrcAlpha = blendSrcAlpha || blendSrc;
  13099. blendDstAlpha = blendDstAlpha || blendDst;
  13100. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  13101. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  13102. currentBlendEquation = blendEquation;
  13103. currentBlendEquationAlpha = blendEquationAlpha;
  13104. }
  13105. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  13106. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  13107. currentBlendSrc = blendSrc;
  13108. currentBlendDst = blendDst;
  13109. currentBlendSrcAlpha = blendSrcAlpha;
  13110. currentBlendDstAlpha = blendDstAlpha;
  13111. }
  13112. currentBlending = blending;
  13113. currentPremultipledAlpha = null;
  13114. }
  13115. function setMaterial(material, frontFaceCW) {
  13116. material.side === DoubleSide ? disable(2884) : enable(2884);
  13117. var flipSided = material.side === BackSide;
  13118. if (frontFaceCW) flipSided = !flipSided;
  13119. setFlipSided(flipSided);
  13120. 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);
  13121. depthBuffer.setFunc(material.depthFunc);
  13122. depthBuffer.setTest(material.depthTest);
  13123. depthBuffer.setMask(material.depthWrite);
  13124. colorBuffer.setMask(material.colorWrite);
  13125. var stencilWrite = material.stencilWrite;
  13126. stencilBuffer.setTest(stencilWrite);
  13127. if (stencilWrite) {
  13128. stencilBuffer.setMask(material.stencilWriteMask);
  13129. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  13130. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  13131. }
  13132. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  13133. } //
  13134. function setFlipSided(flipSided) {
  13135. if (currentFlipSided !== flipSided) {
  13136. if (flipSided) {
  13137. gl.frontFace(2304);
  13138. } else {
  13139. gl.frontFace(2305);
  13140. }
  13141. currentFlipSided = flipSided;
  13142. }
  13143. }
  13144. function setCullFace(cullFace) {
  13145. if (cullFace !== CullFaceNone) {
  13146. enable(2884);
  13147. if (cullFace !== currentCullFace) {
  13148. if (cullFace === CullFaceBack) {
  13149. gl.cullFace(1029);
  13150. } else if (cullFace === CullFaceFront) {
  13151. gl.cullFace(1028);
  13152. } else {
  13153. gl.cullFace(1032);
  13154. }
  13155. }
  13156. } else {
  13157. disable(2884);
  13158. }
  13159. currentCullFace = cullFace;
  13160. }
  13161. function setLineWidth(width) {
  13162. if (width !== currentLineWidth) {
  13163. if (lineWidthAvailable) gl.lineWidth(width);
  13164. currentLineWidth = width;
  13165. }
  13166. }
  13167. function setPolygonOffset(polygonOffset, factor, units) {
  13168. if (polygonOffset) {
  13169. enable(32823);
  13170. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  13171. gl.polygonOffset(factor, units);
  13172. currentPolygonOffsetFactor = factor;
  13173. currentPolygonOffsetUnits = units;
  13174. }
  13175. } else {
  13176. disable(32823);
  13177. }
  13178. }
  13179. function setScissorTest(scissorTest) {
  13180. if (scissorTest) {
  13181. enable(3089);
  13182. } else {
  13183. disable(3089);
  13184. }
  13185. } // texture
  13186. function activeTexture(webglSlot) {
  13187. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  13188. if (currentTextureSlot !== webglSlot) {
  13189. gl.activeTexture(webglSlot);
  13190. currentTextureSlot = webglSlot;
  13191. }
  13192. }
  13193. function bindTexture(webglType, webglTexture) {
  13194. if (currentTextureSlot === null) {
  13195. activeTexture();
  13196. }
  13197. var boundTexture = currentBoundTextures[currentTextureSlot];
  13198. if (boundTexture === undefined) {
  13199. boundTexture = {
  13200. type: undefined,
  13201. texture: undefined
  13202. };
  13203. currentBoundTextures[currentTextureSlot] = boundTexture;
  13204. }
  13205. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  13206. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  13207. boundTexture.type = webglType;
  13208. boundTexture.texture = webglTexture;
  13209. }
  13210. }
  13211. function unbindTexture() {
  13212. var boundTexture = currentBoundTextures[currentTextureSlot];
  13213. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  13214. gl.bindTexture(boundTexture.type, null);
  13215. boundTexture.type = undefined;
  13216. boundTexture.texture = undefined;
  13217. }
  13218. }
  13219. function compressedTexImage2D() {
  13220. try {
  13221. gl.compressedTexImage2D.apply(gl, arguments);
  13222. } catch (error) {
  13223. console.error('THREE.WebGLState:', error);
  13224. }
  13225. }
  13226. function texImage2D() {
  13227. try {
  13228. gl.texImage2D.apply(gl, arguments);
  13229. } catch (error) {
  13230. console.error('THREE.WebGLState:', error);
  13231. }
  13232. }
  13233. function texImage3D() {
  13234. try {
  13235. gl.texImage3D.apply(gl, arguments);
  13236. } catch (error) {
  13237. console.error('THREE.WebGLState:', error);
  13238. }
  13239. } //
  13240. function scissor(scissor) {
  13241. if (currentScissor.equals(scissor) === false) {
  13242. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  13243. currentScissor.copy(scissor);
  13244. }
  13245. }
  13246. function viewport(viewport) {
  13247. if (currentViewport.equals(viewport) === false) {
  13248. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  13249. currentViewport.copy(viewport);
  13250. }
  13251. } //
  13252. function reset() {
  13253. // reset state
  13254. gl.disable(3042);
  13255. gl.disable(2884);
  13256. gl.disable(2929);
  13257. gl.disable(32823);
  13258. gl.disable(3089);
  13259. gl.disable(2960);
  13260. gl.blendEquation(32774);
  13261. gl.blendFunc(1, 0);
  13262. gl.blendFuncSeparate(1, 0, 1, 0);
  13263. gl.colorMask(true, true, true, true);
  13264. gl.clearColor(0, 0, 0, 0);
  13265. gl.depthMask(true);
  13266. gl.depthFunc(513);
  13267. gl.clearDepth(1);
  13268. gl.stencilMask(0xffffffff);
  13269. gl.stencilFunc(519, 0, 0xffffffff);
  13270. gl.stencilOp(7680, 7680, 7680);
  13271. gl.clearStencil(0);
  13272. gl.cullFace(1029);
  13273. gl.frontFace(2305);
  13274. gl.polygonOffset(0, 0);
  13275. gl.activeTexture(33984);
  13276. gl.useProgram(null);
  13277. gl.lineWidth(1);
  13278. gl.scissor(0, 0, gl.canvas.width, gl.canvas.height);
  13279. gl.viewport(0, 0, gl.canvas.width, gl.canvas.height); // reset internals
  13280. enabledCapabilities = {};
  13281. currentTextureSlot = null;
  13282. currentBoundTextures = {};
  13283. currentProgram = null;
  13284. currentBlendingEnabled = false;
  13285. currentBlending = null;
  13286. currentBlendEquation = null;
  13287. currentBlendSrc = null;
  13288. currentBlendDst = null;
  13289. currentBlendEquationAlpha = null;
  13290. currentBlendSrcAlpha = null;
  13291. currentBlendDstAlpha = null;
  13292. currentPremultipledAlpha = false;
  13293. currentFlipSided = null;
  13294. currentCullFace = null;
  13295. currentLineWidth = null;
  13296. currentPolygonOffsetFactor = null;
  13297. currentPolygonOffsetUnits = null;
  13298. colorBuffer.reset();
  13299. depthBuffer.reset();
  13300. stencilBuffer.reset();
  13301. }
  13302. return {
  13303. buffers: {
  13304. color: colorBuffer,
  13305. depth: depthBuffer,
  13306. stencil: stencilBuffer
  13307. },
  13308. enable: enable,
  13309. disable: disable,
  13310. useProgram: useProgram,
  13311. setBlending: setBlending,
  13312. setMaterial: setMaterial,
  13313. setFlipSided: setFlipSided,
  13314. setCullFace: setCullFace,
  13315. setLineWidth: setLineWidth,
  13316. setPolygonOffset: setPolygonOffset,
  13317. setScissorTest: setScissorTest,
  13318. activeTexture: activeTexture,
  13319. bindTexture: bindTexture,
  13320. unbindTexture: unbindTexture,
  13321. compressedTexImage2D: compressedTexImage2D,
  13322. texImage2D: texImage2D,
  13323. texImage3D: texImage3D,
  13324. scissor: scissor,
  13325. viewport: viewport,
  13326. reset: reset
  13327. };
  13328. }
  13329. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  13330. var _wrappingToGL, _filterToGL;
  13331. var isWebGL2 = capabilities.isWebGL2;
  13332. var maxTextures = capabilities.maxTextures;
  13333. var maxCubemapSize = capabilities.maxCubemapSize;
  13334. var maxTextureSize = capabilities.maxTextureSize;
  13335. var maxSamples = capabilities.maxSamples;
  13336. var _videoTextures = new WeakMap();
  13337. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  13338. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  13339. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  13340. var useOffscreenCanvas = false;
  13341. try {
  13342. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext('2d') !== null;
  13343. } catch (err) {// Ignore any errors
  13344. }
  13345. function createCanvas(width, height) {
  13346. // Use OffscreenCanvas when available. Specially needed in web workers
  13347. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  13348. }
  13349. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  13350. var scale = 1; // handle case if texture exceeds max size
  13351. if (image.width > maxSize || image.height > maxSize) {
  13352. scale = maxSize / Math.max(image.width, image.height);
  13353. } // only perform resize if necessary
  13354. if (scale < 1 || needsPowerOfTwo === true) {
  13355. // only perform resize for certain image types
  13356. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  13357. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  13358. var width = floor(scale * image.width);
  13359. var height = floor(scale * image.height);
  13360. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  13361. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  13362. canvas.width = width;
  13363. canvas.height = height;
  13364. var context = canvas.getContext('2d');
  13365. context.drawImage(image, 0, 0, width, height);
  13366. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  13367. return canvas;
  13368. } else {
  13369. if ('data' in image) {
  13370. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  13371. }
  13372. return image;
  13373. }
  13374. }
  13375. return image;
  13376. }
  13377. function isPowerOfTwo(image) {
  13378. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  13379. }
  13380. function textureNeedsPowerOfTwo(texture) {
  13381. if (isWebGL2) return false;
  13382. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13383. }
  13384. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  13385. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13386. }
  13387. function generateMipmap(target, texture, width, height) {
  13388. _gl.generateMipmap(target);
  13389. var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  13390. textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
  13391. }
  13392. function getInternalFormat(internalFormatName, glFormat, glType) {
  13393. if (isWebGL2 === false) return glFormat;
  13394. if (internalFormatName !== null) {
  13395. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  13396. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  13397. }
  13398. var internalFormat = glFormat;
  13399. if (glFormat === 6403) {
  13400. if (glType === 5126) internalFormat = 33326;
  13401. if (glType === 5131) internalFormat = 33325;
  13402. if (glType === 5121) internalFormat = 33321;
  13403. }
  13404. if (glFormat === 6407) {
  13405. if (glType === 5126) internalFormat = 34837;
  13406. if (glType === 5131) internalFormat = 34843;
  13407. if (glType === 5121) internalFormat = 32849;
  13408. }
  13409. if (glFormat === 6408) {
  13410. if (glType === 5126) internalFormat = 34836;
  13411. if (glType === 5131) internalFormat = 34842;
  13412. if (glType === 5121) internalFormat = 32856;
  13413. }
  13414. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  13415. extensions.get('EXT_color_buffer_float');
  13416. }
  13417. return internalFormat;
  13418. } // Fallback filters for non-power-of-2 textures
  13419. function filterFallback(f) {
  13420. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  13421. return 9728;
  13422. }
  13423. return 9729;
  13424. } //
  13425. function onTextureDispose(event) {
  13426. var texture = event.target;
  13427. texture.removeEventListener('dispose', onTextureDispose);
  13428. deallocateTexture(texture);
  13429. if (texture.isVideoTexture) {
  13430. _videoTextures.delete(texture);
  13431. }
  13432. info.memory.textures--;
  13433. }
  13434. function onRenderTargetDispose(event) {
  13435. var renderTarget = event.target;
  13436. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  13437. deallocateRenderTarget(renderTarget);
  13438. info.memory.textures--;
  13439. } //
  13440. function deallocateTexture(texture) {
  13441. var textureProperties = properties.get(texture);
  13442. if (textureProperties.__webglInit === undefined) return;
  13443. _gl.deleteTexture(textureProperties.__webglTexture);
  13444. properties.remove(texture);
  13445. }
  13446. function deallocateRenderTarget(renderTarget) {
  13447. var texture = renderTarget.texture;
  13448. var renderTargetProperties = properties.get(renderTarget);
  13449. var textureProperties = properties.get(texture);
  13450. if (!renderTarget) return;
  13451. if (textureProperties.__webglTexture !== undefined) {
  13452. _gl.deleteTexture(textureProperties.__webglTexture);
  13453. }
  13454. if (renderTarget.depthTexture) {
  13455. renderTarget.depthTexture.dispose();
  13456. }
  13457. if (renderTarget.isWebGLCubeRenderTarget) {
  13458. for (var i = 0; i < 6; i++) {
  13459. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  13460. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  13461. }
  13462. } else {
  13463. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  13464. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  13465. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  13466. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  13467. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  13468. }
  13469. properties.remove(texture);
  13470. properties.remove(renderTarget);
  13471. } //
  13472. var textureUnits = 0;
  13473. function resetTextureUnits() {
  13474. textureUnits = 0;
  13475. }
  13476. function allocateTextureUnit() {
  13477. var textureUnit = textureUnits;
  13478. if (textureUnit >= maxTextures) {
  13479. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  13480. }
  13481. textureUnits += 1;
  13482. return textureUnit;
  13483. } //
  13484. function setTexture2D(texture, slot) {
  13485. var textureProperties = properties.get(texture);
  13486. if (texture.isVideoTexture) updateVideoTexture(texture);
  13487. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13488. var image = texture.image;
  13489. if (image === undefined) {
  13490. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  13491. } else if (image.complete === false) {
  13492. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  13493. } else {
  13494. uploadTexture(textureProperties, texture, slot);
  13495. return;
  13496. }
  13497. }
  13498. state.activeTexture(33984 + slot);
  13499. state.bindTexture(3553, textureProperties.__webglTexture);
  13500. }
  13501. function setTexture2DArray(texture, slot) {
  13502. var textureProperties = properties.get(texture);
  13503. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13504. uploadTexture(textureProperties, texture, slot);
  13505. return;
  13506. }
  13507. state.activeTexture(33984 + slot);
  13508. state.bindTexture(35866, textureProperties.__webglTexture);
  13509. }
  13510. function setTexture3D(texture, slot) {
  13511. var textureProperties = properties.get(texture);
  13512. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13513. uploadTexture(textureProperties, texture, slot);
  13514. return;
  13515. }
  13516. state.activeTexture(33984 + slot);
  13517. state.bindTexture(32879, textureProperties.__webglTexture);
  13518. }
  13519. function setTextureCube(texture, slot) {
  13520. var textureProperties = properties.get(texture);
  13521. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13522. uploadCubeTexture(textureProperties, texture, slot);
  13523. return;
  13524. }
  13525. state.activeTexture(33984 + slot);
  13526. state.bindTexture(34067, textureProperties.__webglTexture);
  13527. }
  13528. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  13529. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  13530. function setTextureParameters(textureType, texture, supportsMips) {
  13531. if (supportsMips) {
  13532. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  13533. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  13534. if (textureType === 32879 || textureType === 35866) {
  13535. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  13536. }
  13537. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  13538. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  13539. } else {
  13540. _gl.texParameteri(textureType, 10242, 33071);
  13541. _gl.texParameteri(textureType, 10243, 33071);
  13542. if (textureType === 32879 || textureType === 35866) {
  13543. _gl.texParameteri(textureType, 32882, 33071);
  13544. }
  13545. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  13546. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  13547. }
  13548. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  13549. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  13550. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  13551. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  13552. }
  13553. }
  13554. if (extensions.has('EXT_texture_filter_anisotropic') === true) {
  13555. var extension = extensions.get('EXT_texture_filter_anisotropic');
  13556. if (texture.type === FloatType && extensions.has('OES_texture_float_linear') === false) return; // verify extension for WebGL 1 and WebGL 2
  13557. if (isWebGL2 === false && texture.type === HalfFloatType && extensions.has('OES_texture_half_float_linear') === false) return; // verify extension for WebGL 1 only
  13558. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  13559. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  13560. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  13561. }
  13562. }
  13563. }
  13564. function initTexture(textureProperties, texture) {
  13565. if (textureProperties.__webglInit === undefined) {
  13566. textureProperties.__webglInit = true;
  13567. texture.addEventListener('dispose', onTextureDispose);
  13568. textureProperties.__webglTexture = _gl.createTexture();
  13569. info.memory.textures++;
  13570. }
  13571. }
  13572. function uploadTexture(textureProperties, texture, slot) {
  13573. var textureType = 3553;
  13574. if (texture.isDataTexture2DArray) textureType = 35866;
  13575. if (texture.isDataTexture3D) textureType = 32879;
  13576. initTexture(textureProperties, texture);
  13577. state.activeTexture(33984 + slot);
  13578. state.bindTexture(textureType, textureProperties.__webglTexture);
  13579. _gl.pixelStorei(37440, texture.flipY);
  13580. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13581. _gl.pixelStorei(3317, texture.unpackAlignment);
  13582. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  13583. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  13584. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  13585. glFormat = utils.convert(texture.format);
  13586. var glType = utils.convert(texture.type),
  13587. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13588. setTextureParameters(textureType, texture, supportsMips);
  13589. var mipmap;
  13590. var mipmaps = texture.mipmaps;
  13591. if (texture.isDepthTexture) {
  13592. // populate depth texture with dummy data
  13593. glInternalFormat = 6402;
  13594. if (isWebGL2) {
  13595. if (texture.type === FloatType) {
  13596. glInternalFormat = 36012;
  13597. } else if (texture.type === UnsignedIntType) {
  13598. glInternalFormat = 33190;
  13599. } else if (texture.type === UnsignedInt248Type) {
  13600. glInternalFormat = 35056;
  13601. } else {
  13602. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  13603. }
  13604. } else {
  13605. if (texture.type === FloatType) {
  13606. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  13607. }
  13608. } // validation checks for WebGL 1
  13609. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  13610. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13611. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  13612. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13613. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  13614. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  13615. texture.type = UnsignedShortType;
  13616. glType = utils.convert(texture.type);
  13617. }
  13618. }
  13619. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  13620. // Depth stencil textures need the DEPTH_STENCIL internal format
  13621. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13622. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13623. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  13624. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13625. if (texture.type !== UnsignedInt248Type) {
  13626. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  13627. texture.type = UnsignedInt248Type;
  13628. glType = utils.convert(texture.type);
  13629. }
  13630. } //
  13631. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  13632. } else if (texture.isDataTexture) {
  13633. // use manually created mipmaps if available
  13634. // if there are no manual mipmaps
  13635. // set 0 level mipmap and then use GL to generate other mipmap levels
  13636. if (mipmaps.length > 0 && supportsMips) {
  13637. for (var i = 0, il = mipmaps.length; i < il; i++) {
  13638. mipmap = mipmaps[i];
  13639. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13640. }
  13641. texture.generateMipmaps = false;
  13642. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13643. } else {
  13644. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  13645. textureProperties.__maxMipLevel = 0;
  13646. }
  13647. } else if (texture.isCompressedTexture) {
  13648. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  13649. mipmap = mipmaps[_i];
  13650. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13651. if (glFormat !== null) {
  13652. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13653. } else {
  13654. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  13655. }
  13656. } else {
  13657. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13658. }
  13659. }
  13660. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13661. } else if (texture.isDataTexture2DArray) {
  13662. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13663. textureProperties.__maxMipLevel = 0;
  13664. } else if (texture.isDataTexture3D) {
  13665. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13666. textureProperties.__maxMipLevel = 0;
  13667. } else {
  13668. // regular Texture (image, video, canvas)
  13669. // use manually created mipmaps if available
  13670. // if there are no manual mipmaps
  13671. // set 0 level mipmap and then use GL to generate other mipmap levels
  13672. if (mipmaps.length > 0 && supportsMips) {
  13673. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  13674. mipmap = mipmaps[_i2];
  13675. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  13676. }
  13677. texture.generateMipmaps = false;
  13678. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13679. } else {
  13680. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  13681. textureProperties.__maxMipLevel = 0;
  13682. }
  13683. }
  13684. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13685. generateMipmap(textureType, texture, image.width, image.height);
  13686. }
  13687. textureProperties.__version = texture.version;
  13688. if (texture.onUpdate) texture.onUpdate(texture);
  13689. }
  13690. function uploadCubeTexture(textureProperties, texture, slot) {
  13691. if (texture.image.length !== 6) return;
  13692. initTexture(textureProperties, texture);
  13693. state.activeTexture(33984 + slot);
  13694. state.bindTexture(34067, textureProperties.__webglTexture);
  13695. _gl.pixelStorei(37440, texture.flipY);
  13696. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13697. _gl.pixelStorei(3317, texture.unpackAlignment);
  13698. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  13699. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  13700. var cubeImage = [];
  13701. for (var i = 0; i < 6; i++) {
  13702. if (!isCompressed && !isDataTexture) {
  13703. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  13704. } else {
  13705. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  13706. }
  13707. }
  13708. var image = cubeImage[0],
  13709. supportsMips = isPowerOfTwo(image) || isWebGL2,
  13710. glFormat = utils.convert(texture.format),
  13711. glType = utils.convert(texture.type),
  13712. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13713. setTextureParameters(34067, texture, supportsMips);
  13714. var mipmaps;
  13715. if (isCompressed) {
  13716. for (var _i3 = 0; _i3 < 6; _i3++) {
  13717. mipmaps = cubeImage[_i3].mipmaps;
  13718. for (var j = 0; j < mipmaps.length; j++) {
  13719. var mipmap = mipmaps[j];
  13720. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13721. if (glFormat !== null) {
  13722. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13723. } else {
  13724. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  13725. }
  13726. } else {
  13727. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13728. }
  13729. }
  13730. }
  13731. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13732. } else {
  13733. mipmaps = texture.mipmaps;
  13734. for (var _i4 = 0; _i4 < 6; _i4++) {
  13735. if (isDataTexture) {
  13736. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  13737. for (var _j = 0; _j < mipmaps.length; _j++) {
  13738. var _mipmap = mipmaps[_j];
  13739. var mipmapImage = _mipmap.image[_i4].image;
  13740. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  13741. }
  13742. } else {
  13743. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  13744. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  13745. var _mipmap2 = mipmaps[_j2];
  13746. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  13747. }
  13748. }
  13749. }
  13750. textureProperties.__maxMipLevel = mipmaps.length;
  13751. }
  13752. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13753. // We assume images for cube map have the same size.
  13754. generateMipmap(34067, texture, image.width, image.height);
  13755. }
  13756. textureProperties.__version = texture.version;
  13757. if (texture.onUpdate) texture.onUpdate(texture);
  13758. } // Render targets
  13759. // Setup storage for target texture and bind it to correct framebuffer
  13760. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  13761. var texture = renderTarget.texture;
  13762. var glFormat = utils.convert(texture.format);
  13763. var glType = utils.convert(texture.type);
  13764. var glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13765. if (textureTarget === 32879 || textureTarget === 35866) {
  13766. state.texImage3D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, renderTarget.depth, 0, glFormat, glType, null);
  13767. } else {
  13768. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  13769. }
  13770. _gl.bindFramebuffer(36160, framebuffer);
  13771. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(texture).__webglTexture, 0);
  13772. _gl.bindFramebuffer(36160, null);
  13773. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13774. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  13775. _gl.bindRenderbuffer(36161, renderbuffer);
  13776. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  13777. var glInternalFormat = 33189;
  13778. if (isMultisample) {
  13779. var depthTexture = renderTarget.depthTexture;
  13780. if (depthTexture && depthTexture.isDepthTexture) {
  13781. if (depthTexture.type === FloatType) {
  13782. glInternalFormat = 36012;
  13783. } else if (depthTexture.type === UnsignedIntType) {
  13784. glInternalFormat = 33190;
  13785. }
  13786. }
  13787. var samples = getRenderTargetSamples(renderTarget);
  13788. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13789. } else {
  13790. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  13791. }
  13792. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  13793. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  13794. if (isMultisample) {
  13795. var _samples = getRenderTargetSamples(renderTarget);
  13796. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  13797. } else {
  13798. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  13799. }
  13800. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  13801. } else {
  13802. var texture = renderTarget.texture;
  13803. var glFormat = utils.convert(texture.format);
  13804. var glType = utils.convert(texture.type);
  13805. var _glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13806. if (isMultisample) {
  13807. var _samples2 = getRenderTargetSamples(renderTarget);
  13808. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  13809. } else {
  13810. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  13811. }
  13812. }
  13813. _gl.bindRenderbuffer(36161, null);
  13814. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  13815. function setupDepthTexture(framebuffer, renderTarget) {
  13816. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  13817. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  13818. _gl.bindFramebuffer(36160, framebuffer);
  13819. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  13820. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  13821. } // upload an empty depth texture with framebuffer size
  13822. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  13823. renderTarget.depthTexture.image.width = renderTarget.width;
  13824. renderTarget.depthTexture.image.height = renderTarget.height;
  13825. renderTarget.depthTexture.needsUpdate = true;
  13826. }
  13827. setTexture2D(renderTarget.depthTexture, 0);
  13828. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  13829. if (renderTarget.depthTexture.format === DepthFormat) {
  13830. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  13831. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  13832. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  13833. } else {
  13834. throw new Error('Unknown depthTexture format');
  13835. }
  13836. } // Setup GL resources for a non-texture depth buffer
  13837. function setupDepthRenderbuffer(renderTarget) {
  13838. var renderTargetProperties = properties.get(renderTarget);
  13839. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13840. if (renderTarget.depthTexture) {
  13841. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  13842. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  13843. } else {
  13844. if (isCube) {
  13845. renderTargetProperties.__webglDepthbuffer = [];
  13846. for (var i = 0; i < 6; i++) {
  13847. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  13848. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  13849. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  13850. }
  13851. } else {
  13852. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  13853. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13854. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  13855. }
  13856. }
  13857. _gl.bindFramebuffer(36160, null);
  13858. } // Set up GL resources for the render target
  13859. function setupRenderTarget(renderTarget) {
  13860. var texture = renderTarget.texture;
  13861. var renderTargetProperties = properties.get(renderTarget);
  13862. var textureProperties = properties.get(texture);
  13863. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  13864. textureProperties.__webglTexture = _gl.createTexture();
  13865. info.memory.textures++;
  13866. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13867. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  13868. var isRenderTarget3D = texture.isDataTexture3D || texture.isDataTexture2DArray;
  13869. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  13870. if (isWebGL2 && texture.format === RGBFormat && (texture.type === FloatType || texture.type === HalfFloatType)) {
  13871. texture.format = RGBAFormat;
  13872. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  13873. } // Setup framebuffer
  13874. if (isCube) {
  13875. renderTargetProperties.__webglFramebuffer = [];
  13876. for (var i = 0; i < 6; i++) {
  13877. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  13878. }
  13879. } else {
  13880. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13881. if (isMultisample) {
  13882. if (isWebGL2) {
  13883. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13884. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13885. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  13886. var glFormat = utils.convert(texture.format);
  13887. var glType = utils.convert(texture.type);
  13888. var glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13889. var samples = getRenderTargetSamples(renderTarget);
  13890. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13891. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13892. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13893. _gl.bindRenderbuffer(36161, null);
  13894. if (renderTarget.depthBuffer) {
  13895. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13896. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13897. }
  13898. _gl.bindFramebuffer(36160, null);
  13899. } else {
  13900. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13901. }
  13902. }
  13903. } // Setup color buffer
  13904. if (isCube) {
  13905. state.bindTexture(34067, textureProperties.__webglTexture);
  13906. setTextureParameters(34067, texture, supportsMips);
  13907. for (var _i5 = 0; _i5 < 6; _i5++) {
  13908. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13909. }
  13910. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13911. generateMipmap(34067, texture, renderTarget.width, renderTarget.height);
  13912. }
  13913. state.bindTexture(34067, null);
  13914. } else {
  13915. var glTextureType = 3553;
  13916. if (isRenderTarget3D) {
  13917. // Render targets containing layers, i.e: Texture 3D and 2d arrays
  13918. if (isWebGL2) {
  13919. var isTexture3D = texture.isDataTexture3D;
  13920. glTextureType = isTexture3D ? 32879 : 35866;
  13921. } else {
  13922. console.warn('THREE.DataTexture3D and THREE.DataTexture2DArray only supported with WebGL2.');
  13923. }
  13924. }
  13925. state.bindTexture(glTextureType, textureProperties.__webglTexture);
  13926. setTextureParameters(glTextureType, texture, supportsMips);
  13927. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, glTextureType);
  13928. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13929. generateMipmap(3553, texture, renderTarget.width, renderTarget.height);
  13930. }
  13931. state.bindTexture(3553, null);
  13932. } // Setup depth and stencil buffers
  13933. if (renderTarget.depthBuffer) {
  13934. setupDepthRenderbuffer(renderTarget);
  13935. }
  13936. }
  13937. function updateRenderTargetMipmap(renderTarget) {
  13938. var texture = renderTarget.texture;
  13939. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13940. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13941. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13942. var webglTexture = properties.get(texture).__webglTexture;
  13943. state.bindTexture(target, webglTexture);
  13944. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13945. state.bindTexture(target, null);
  13946. }
  13947. }
  13948. function updateMultisampleRenderTarget(renderTarget) {
  13949. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13950. if (isWebGL2) {
  13951. var renderTargetProperties = properties.get(renderTarget);
  13952. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13953. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13954. var width = renderTarget.width;
  13955. var height = renderTarget.height;
  13956. var mask = 16384;
  13957. if (renderTarget.depthBuffer) mask |= 256;
  13958. if (renderTarget.stencilBuffer) mask |= 1024;
  13959. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13960. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13961. } else {
  13962. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13963. }
  13964. }
  13965. }
  13966. function getRenderTargetSamples(renderTarget) {
  13967. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13968. }
  13969. function updateVideoTexture(texture) {
  13970. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13971. if (_videoTextures.get(texture) !== frame) {
  13972. _videoTextures.set(texture, frame);
  13973. texture.update();
  13974. }
  13975. } // backwards compatibility
  13976. var warnedTexture2D = false;
  13977. var warnedTextureCube = false;
  13978. function safeSetTexture2D(texture, slot) {
  13979. if (texture && texture.isWebGLRenderTarget) {
  13980. if (warnedTexture2D === false) {
  13981. console.warn('THREE.WebGLTextures.safeSetTexture2D: don\'t use render targets as textures. Use their .texture property instead.');
  13982. warnedTexture2D = true;
  13983. }
  13984. texture = texture.texture;
  13985. }
  13986. setTexture2D(texture, slot);
  13987. }
  13988. function safeSetTextureCube(texture, slot) {
  13989. if (texture && texture.isWebGLCubeRenderTarget) {
  13990. if (warnedTextureCube === false) {
  13991. console.warn('THREE.WebGLTextures.safeSetTextureCube: don\'t use cube render targets as textures. Use their .texture property instead.');
  13992. warnedTextureCube = true;
  13993. }
  13994. texture = texture.texture;
  13995. }
  13996. setTextureCube(texture, slot);
  13997. } //
  13998. this.allocateTextureUnit = allocateTextureUnit;
  13999. this.resetTextureUnits = resetTextureUnits;
  14000. this.setTexture2D = setTexture2D;
  14001. this.setTexture2DArray = setTexture2DArray;
  14002. this.setTexture3D = setTexture3D;
  14003. this.setTextureCube = setTextureCube;
  14004. this.setupRenderTarget = setupRenderTarget;
  14005. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  14006. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  14007. this.safeSetTexture2D = safeSetTexture2D;
  14008. this.safeSetTextureCube = safeSetTextureCube;
  14009. }
  14010. function WebGLUtils(gl, extensions, capabilities) {
  14011. var isWebGL2 = capabilities.isWebGL2;
  14012. function convert(p) {
  14013. var extension;
  14014. if (p === UnsignedByteType) return 5121;
  14015. if (p === UnsignedShort4444Type) return 32819;
  14016. if (p === UnsignedShort5551Type) return 32820;
  14017. if (p === UnsignedShort565Type) return 33635;
  14018. if (p === ByteType) return 5120;
  14019. if (p === ShortType) return 5122;
  14020. if (p === UnsignedShortType) return 5123;
  14021. if (p === IntType) return 5124;
  14022. if (p === UnsignedIntType) return 5125;
  14023. if (p === FloatType) return 5126;
  14024. if (p === HalfFloatType) {
  14025. if (isWebGL2) return 5131;
  14026. extension = extensions.get('OES_texture_half_float');
  14027. if (extension !== null) {
  14028. return extension.HALF_FLOAT_OES;
  14029. } else {
  14030. return null;
  14031. }
  14032. }
  14033. if (p === AlphaFormat) return 6406;
  14034. if (p === RGBFormat) return 6407;
  14035. if (p === RGBAFormat) return 6408;
  14036. if (p === LuminanceFormat) return 6409;
  14037. if (p === LuminanceAlphaFormat) return 6410;
  14038. if (p === DepthFormat) return 6402;
  14039. if (p === DepthStencilFormat) return 34041;
  14040. if (p === RedFormat) return 6403; // WebGL2 formats.
  14041. if (p === RedIntegerFormat) return 36244;
  14042. if (p === RGFormat) return 33319;
  14043. if (p === RGIntegerFormat) return 33320;
  14044. if (p === RGBIntegerFormat) return 36248;
  14045. if (p === RGBAIntegerFormat) return 36249;
  14046. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  14047. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  14048. if (extension !== null) {
  14049. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  14050. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  14051. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  14052. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  14053. } else {
  14054. return null;
  14055. }
  14056. }
  14057. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  14058. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  14059. if (extension !== null) {
  14060. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  14061. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  14062. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  14063. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  14064. } else {
  14065. return null;
  14066. }
  14067. }
  14068. if (p === RGB_ETC1_Format) {
  14069. extension = extensions.get('WEBGL_compressed_texture_etc1');
  14070. if (extension !== null) {
  14071. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  14072. } else {
  14073. return null;
  14074. }
  14075. }
  14076. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  14077. extension = extensions.get('WEBGL_compressed_texture_etc');
  14078. if (extension !== null) {
  14079. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  14080. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  14081. }
  14082. }
  14083. 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) {
  14084. extension = extensions.get('WEBGL_compressed_texture_astc');
  14085. if (extension !== null) {
  14086. // TODO Complete?
  14087. return p;
  14088. } else {
  14089. return null;
  14090. }
  14091. }
  14092. if (p === RGBA_BPTC_Format) {
  14093. extension = extensions.get('EXT_texture_compression_bptc');
  14094. if (extension !== null) {
  14095. // TODO Complete?
  14096. return p;
  14097. } else {
  14098. return null;
  14099. }
  14100. }
  14101. if (p === UnsignedInt248Type) {
  14102. if (isWebGL2) return 34042;
  14103. extension = extensions.get('WEBGL_depth_texture');
  14104. if (extension !== null) {
  14105. return extension.UNSIGNED_INT_24_8_WEBGL;
  14106. } else {
  14107. return null;
  14108. }
  14109. }
  14110. }
  14111. return {
  14112. convert: convert
  14113. };
  14114. }
  14115. function ArrayCamera(array) {
  14116. if (array === void 0) {
  14117. array = [];
  14118. }
  14119. PerspectiveCamera.call(this);
  14120. this.cameras = array;
  14121. }
  14122. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  14123. constructor: ArrayCamera,
  14124. isArrayCamera: true
  14125. });
  14126. var Group = /*#__PURE__*/function (_Object3D) {
  14127. _inheritsLoose(Group, _Object3D);
  14128. function Group() {
  14129. var _this;
  14130. _this = _Object3D.call(this) || this;
  14131. _this.type = 'Group';
  14132. return _this;
  14133. }
  14134. return Group;
  14135. }(Object3D);
  14136. Group.prototype.isGroup = true;
  14137. function WebXRController() {
  14138. this._targetRay = null;
  14139. this._grip = null;
  14140. this._hand = null;
  14141. }
  14142. Object.assign(WebXRController.prototype, {
  14143. constructor: WebXRController,
  14144. getHandSpace: function getHandSpace() {
  14145. if (this._hand === null) {
  14146. this._hand = new Group();
  14147. this._hand.matrixAutoUpdate = false;
  14148. this._hand.visible = false;
  14149. this._hand.joints = {};
  14150. this._hand.inputState = {
  14151. pinching: false
  14152. };
  14153. }
  14154. return this._hand;
  14155. },
  14156. getTargetRaySpace: function getTargetRaySpace() {
  14157. if (this._targetRay === null) {
  14158. this._targetRay = new Group();
  14159. this._targetRay.matrixAutoUpdate = false;
  14160. this._targetRay.visible = false;
  14161. }
  14162. return this._targetRay;
  14163. },
  14164. getGripSpace: function getGripSpace() {
  14165. if (this._grip === null) {
  14166. this._grip = new Group();
  14167. this._grip.matrixAutoUpdate = false;
  14168. this._grip.visible = false;
  14169. }
  14170. return this._grip;
  14171. },
  14172. dispatchEvent: function dispatchEvent(event) {
  14173. if (this._targetRay !== null) {
  14174. this._targetRay.dispatchEvent(event);
  14175. }
  14176. if (this._grip !== null) {
  14177. this._grip.dispatchEvent(event);
  14178. }
  14179. if (this._hand !== null) {
  14180. this._hand.dispatchEvent(event);
  14181. }
  14182. return this;
  14183. },
  14184. disconnect: function disconnect(inputSource) {
  14185. this.dispatchEvent({
  14186. type: 'disconnected',
  14187. data: inputSource
  14188. });
  14189. if (this._targetRay !== null) {
  14190. this._targetRay.visible = false;
  14191. }
  14192. if (this._grip !== null) {
  14193. this._grip.visible = false;
  14194. }
  14195. if (this._hand !== null) {
  14196. this._hand.visible = false;
  14197. }
  14198. return this;
  14199. },
  14200. update: function update(inputSource, frame, referenceSpace) {
  14201. var inputPose = null;
  14202. var gripPose = null;
  14203. var handPose = null;
  14204. var targetRay = this._targetRay;
  14205. var grip = this._grip;
  14206. var hand = this._hand;
  14207. if (inputSource && frame.session.visibilityState !== 'visible-blurred') {
  14208. if (hand && inputSource.hand) {
  14209. handPose = true;
  14210. for (var _iterator = _createForOfIteratorHelperLoose(inputSource.hand.values()), _step; !(_step = _iterator()).done;) {
  14211. var inputjoint = _step.value;
  14212. // Update the joints groups with the XRJoint poses
  14213. var jointPose = frame.getJointPose(inputjoint, referenceSpace);
  14214. if (hand.joints[inputjoint.jointName] === undefined) {
  14215. // The transform of this joint will be updated with the joint pose on each frame
  14216. var _joint = new Group();
  14217. _joint.matrixAutoUpdate = false;
  14218. _joint.visible = false;
  14219. hand.joints[inputjoint.jointName] = _joint; // ??
  14220. hand.add(_joint);
  14221. }
  14222. var joint = hand.joints[inputjoint.jointName];
  14223. if (jointPose !== null) {
  14224. joint.matrix.fromArray(jointPose.transform.matrix);
  14225. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  14226. joint.jointRadius = jointPose.radius;
  14227. }
  14228. joint.visible = jointPose !== null;
  14229. } // Custom events
  14230. // Check pinchz
  14231. var indexTip = hand.joints['index-finger-tip'];
  14232. var thumbTip = hand.joints['thumb-tip'];
  14233. var distance = indexTip.position.distanceTo(thumbTip.position);
  14234. var distanceToPinch = 0.02;
  14235. var threshold = 0.005;
  14236. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  14237. hand.inputState.pinching = false;
  14238. this.dispatchEvent({
  14239. type: 'pinchend',
  14240. handedness: inputSource.handedness,
  14241. target: this
  14242. });
  14243. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  14244. hand.inputState.pinching = true;
  14245. this.dispatchEvent({
  14246. type: 'pinchstart',
  14247. handedness: inputSource.handedness,
  14248. target: this
  14249. });
  14250. }
  14251. } else {
  14252. if (targetRay !== null) {
  14253. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  14254. if (inputPose !== null) {
  14255. targetRay.matrix.fromArray(inputPose.transform.matrix);
  14256. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  14257. }
  14258. }
  14259. if (grip !== null && inputSource.gripSpace) {
  14260. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  14261. if (gripPose !== null) {
  14262. grip.matrix.fromArray(gripPose.transform.matrix);
  14263. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  14264. }
  14265. }
  14266. }
  14267. }
  14268. if (targetRay !== null) {
  14269. targetRay.visible = inputPose !== null;
  14270. }
  14271. if (grip !== null) {
  14272. grip.visible = gripPose !== null;
  14273. }
  14274. if (hand !== null) {
  14275. hand.visible = handPose !== null;
  14276. }
  14277. return this;
  14278. }
  14279. });
  14280. function WebXRManager(renderer, gl) {
  14281. var scope = this;
  14282. var session = null;
  14283. var framebufferScaleFactor = 1.0;
  14284. var referenceSpace = null;
  14285. var referenceSpaceType = 'local-floor';
  14286. var pose = null;
  14287. var controllers = [];
  14288. var inputSourcesMap = new Map(); //
  14289. var cameraL = new PerspectiveCamera();
  14290. cameraL.layers.enable(1);
  14291. cameraL.viewport = new Vector4();
  14292. var cameraR = new PerspectiveCamera();
  14293. cameraR.layers.enable(2);
  14294. cameraR.viewport = new Vector4();
  14295. var cameras = [cameraL, cameraR];
  14296. var cameraVR = new ArrayCamera();
  14297. cameraVR.layers.enable(1);
  14298. cameraVR.layers.enable(2);
  14299. var _currentDepthNear = null;
  14300. var _currentDepthFar = null; //
  14301. this.enabled = false;
  14302. this.isPresenting = false;
  14303. this.getController = function (index) {
  14304. var controller = controllers[index];
  14305. if (controller === undefined) {
  14306. controller = new WebXRController();
  14307. controllers[index] = controller;
  14308. }
  14309. return controller.getTargetRaySpace();
  14310. };
  14311. this.getControllerGrip = function (index) {
  14312. var controller = controllers[index];
  14313. if (controller === undefined) {
  14314. controller = new WebXRController();
  14315. controllers[index] = controller;
  14316. }
  14317. return controller.getGripSpace();
  14318. };
  14319. this.getHand = function (index) {
  14320. var controller = controllers[index];
  14321. if (controller === undefined) {
  14322. controller = new WebXRController();
  14323. controllers[index] = controller;
  14324. }
  14325. return controller.getHandSpace();
  14326. }; //
  14327. function onSessionEvent(event) {
  14328. var controller = inputSourcesMap.get(event.inputSource);
  14329. if (controller) {
  14330. controller.dispatchEvent({
  14331. type: event.type,
  14332. data: event.inputSource
  14333. });
  14334. }
  14335. }
  14336. function onSessionEnd() {
  14337. inputSourcesMap.forEach(function (controller, inputSource) {
  14338. controller.disconnect(inputSource);
  14339. });
  14340. inputSourcesMap.clear();
  14341. _currentDepthNear = null;
  14342. _currentDepthFar = null; //
  14343. renderer.setFramebuffer(null);
  14344. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  14345. animation.stop();
  14346. scope.isPresenting = false;
  14347. scope.dispatchEvent({
  14348. type: 'sessionend'
  14349. });
  14350. }
  14351. this.setFramebufferScaleFactor = function (value) {
  14352. framebufferScaleFactor = value;
  14353. if (scope.isPresenting === true) {
  14354. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  14355. }
  14356. };
  14357. this.setReferenceSpaceType = function (value) {
  14358. referenceSpaceType = value;
  14359. if (scope.isPresenting === true) {
  14360. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  14361. }
  14362. };
  14363. this.getReferenceSpace = function () {
  14364. return referenceSpace;
  14365. };
  14366. this.getSession = function () {
  14367. return session;
  14368. };
  14369. this.setSession = /*#__PURE__*/function () {
  14370. var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(value) {
  14371. var attributes, layerInit, baseLayer;
  14372. return regeneratorRuntime.wrap(function _callee$(_context) {
  14373. while (1) {
  14374. switch (_context.prev = _context.next) {
  14375. case 0:
  14376. session = value;
  14377. if (!(session !== null)) {
  14378. _context.next = 24;
  14379. break;
  14380. }
  14381. session.addEventListener('select', onSessionEvent);
  14382. session.addEventListener('selectstart', onSessionEvent);
  14383. session.addEventListener('selectend', onSessionEvent);
  14384. session.addEventListener('squeeze', onSessionEvent);
  14385. session.addEventListener('squeezestart', onSessionEvent);
  14386. session.addEventListener('squeezeend', onSessionEvent);
  14387. session.addEventListener('end', onSessionEnd);
  14388. session.addEventListener('inputsourceschange', onInputSourcesChange);
  14389. attributes = gl.getContextAttributes();
  14390. if (!(attributes.xrCompatible !== true)) {
  14391. _context.next = 14;
  14392. break;
  14393. }
  14394. _context.next = 14;
  14395. return gl.makeXRCompatible();
  14396. case 14:
  14397. layerInit = {
  14398. antialias: attributes.antialias,
  14399. alpha: attributes.alpha,
  14400. depth: attributes.depth,
  14401. stencil: attributes.stencil,
  14402. framebufferScaleFactor: framebufferScaleFactor
  14403. }; // eslint-disable-next-line no-undef
  14404. baseLayer = new XRWebGLLayer(session, gl, layerInit);
  14405. session.updateRenderState({
  14406. baseLayer: baseLayer
  14407. });
  14408. _context.next = 19;
  14409. return session.requestReferenceSpace(referenceSpaceType);
  14410. case 19:
  14411. referenceSpace = _context.sent;
  14412. animation.setContext(session);
  14413. animation.start();
  14414. scope.isPresenting = true;
  14415. scope.dispatchEvent({
  14416. type: 'sessionstart'
  14417. });
  14418. case 24:
  14419. case "end":
  14420. return _context.stop();
  14421. }
  14422. }
  14423. }, _callee);
  14424. }));
  14425. return function (_x) {
  14426. return _ref.apply(this, arguments);
  14427. };
  14428. }();
  14429. function onInputSourcesChange(event) {
  14430. var inputSources = session.inputSources; // Assign inputSources to available controllers
  14431. for (var i = 0; i < controllers.length; i++) {
  14432. inputSourcesMap.set(inputSources[i], controllers[i]);
  14433. } // Notify disconnected
  14434. for (var _i = 0; _i < event.removed.length; _i++) {
  14435. var inputSource = event.removed[_i];
  14436. var controller = inputSourcesMap.get(inputSource);
  14437. if (controller) {
  14438. controller.dispatchEvent({
  14439. type: 'disconnected',
  14440. data: inputSource
  14441. });
  14442. inputSourcesMap.delete(inputSource);
  14443. }
  14444. } // Notify connected
  14445. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  14446. var _inputSource = event.added[_i2];
  14447. var _controller = inputSourcesMap.get(_inputSource);
  14448. if (_controller) {
  14449. _controller.dispatchEvent({
  14450. type: 'connected',
  14451. data: _inputSource
  14452. });
  14453. }
  14454. }
  14455. } //
  14456. var cameraLPos = new Vector3();
  14457. var cameraRPos = new Vector3();
  14458. /**
  14459. * Assumes 2 cameras that are parallel and share an X-axis, and that
  14460. * the cameras' projection and world matrices have already been set.
  14461. * And that near and far planes are identical for both cameras.
  14462. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  14463. */
  14464. function setProjectionFromUnion(camera, cameraL, cameraR) {
  14465. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  14466. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  14467. var ipd = cameraLPos.distanceTo(cameraRPos);
  14468. var projL = cameraL.projectionMatrix.elements;
  14469. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  14470. // most likely identical top and bottom frustum extents.
  14471. // Use the left camera for these values.
  14472. var near = projL[14] / (projL[10] - 1);
  14473. var far = projL[14] / (projL[10] + 1);
  14474. var topFov = (projL[9] + 1) / projL[5];
  14475. var bottomFov = (projL[9] - 1) / projL[5];
  14476. var leftFov = (projL[8] - 1) / projL[0];
  14477. var rightFov = (projR[8] + 1) / projR[0];
  14478. var left = near * leftFov;
  14479. var right = near * rightFov; // Calculate the new camera's position offset from the
  14480. // left camera. xOffset should be roughly half `ipd`.
  14481. var zOffset = ipd / (-leftFov + rightFov);
  14482. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  14483. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  14484. camera.translateX(xOffset);
  14485. camera.translateZ(zOffset);
  14486. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  14487. camera.matrixWorldInverse.copy(camera.matrixWorld).invert(); // Find the union of the frustum values of the cameras and scale
  14488. // the values so that the near plane's position does not change in world space,
  14489. // although must now be relative to the new union camera.
  14490. var near2 = near + zOffset;
  14491. var far2 = far + zOffset;
  14492. var left2 = left - xOffset;
  14493. var right2 = right + (ipd - xOffset);
  14494. var top2 = topFov * far / far2 * near2;
  14495. var bottom2 = bottomFov * far / far2 * near2;
  14496. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  14497. }
  14498. function updateCamera(camera, parent) {
  14499. if (parent === null) {
  14500. camera.matrixWorld.copy(camera.matrix);
  14501. } else {
  14502. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  14503. }
  14504. camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
  14505. }
  14506. this.getCamera = function (camera) {
  14507. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  14508. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  14509. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  14510. // Note that the new renderState won't apply until the next frame. See #18320
  14511. session.updateRenderState({
  14512. depthNear: cameraVR.near,
  14513. depthFar: cameraVR.far
  14514. });
  14515. _currentDepthNear = cameraVR.near;
  14516. _currentDepthFar = cameraVR.far;
  14517. }
  14518. var parent = camera.parent;
  14519. var cameras = cameraVR.cameras;
  14520. updateCamera(cameraVR, parent);
  14521. for (var i = 0; i < cameras.length; i++) {
  14522. updateCamera(cameras[i], parent);
  14523. } // update camera and its children
  14524. camera.matrixWorld.copy(cameraVR.matrixWorld);
  14525. camera.matrix.copy(cameraVR.matrix);
  14526. camera.matrix.decompose(camera.position, camera.quaternion, camera.scale);
  14527. var children = camera.children;
  14528. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  14529. children[_i3].updateMatrixWorld(true);
  14530. } // update projection matrix for proper view frustum culling
  14531. if (cameras.length === 2) {
  14532. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  14533. } else {
  14534. // assume single camera setup (AR)
  14535. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  14536. }
  14537. return cameraVR;
  14538. }; // Animation Loop
  14539. var onAnimationFrameCallback = null;
  14540. function onAnimationFrame(time, frame) {
  14541. pose = frame.getViewerPose(referenceSpace);
  14542. if (pose !== null) {
  14543. var views = pose.views;
  14544. var baseLayer = session.renderState.baseLayer;
  14545. renderer.setFramebuffer(baseLayer.framebuffer);
  14546. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  14547. if (views.length !== cameraVR.cameras.length) {
  14548. cameraVR.cameras.length = 0;
  14549. cameraVRNeedsUpdate = true;
  14550. }
  14551. for (var i = 0; i < views.length; i++) {
  14552. var view = views[i];
  14553. var viewport = baseLayer.getViewport(view);
  14554. var camera = cameras[i];
  14555. camera.matrix.fromArray(view.transform.matrix);
  14556. camera.projectionMatrix.fromArray(view.projectionMatrix);
  14557. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  14558. if (i === 0) {
  14559. cameraVR.matrix.copy(camera.matrix);
  14560. }
  14561. if (cameraVRNeedsUpdate === true) {
  14562. cameraVR.cameras.push(camera);
  14563. }
  14564. }
  14565. } //
  14566. var inputSources = session.inputSources;
  14567. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  14568. var controller = controllers[_i4];
  14569. var inputSource = inputSources[_i4];
  14570. controller.update(inputSource, frame, referenceSpace);
  14571. }
  14572. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  14573. }
  14574. var animation = new WebGLAnimation();
  14575. animation.setAnimationLoop(onAnimationFrame);
  14576. this.setAnimationLoop = function (callback) {
  14577. onAnimationFrameCallback = callback;
  14578. };
  14579. this.dispose = function () {};
  14580. }
  14581. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  14582. function WebGLMaterials(properties) {
  14583. function refreshFogUniforms(uniforms, fog) {
  14584. uniforms.fogColor.value.copy(fog.color);
  14585. if (fog.isFog) {
  14586. uniforms.fogNear.value = fog.near;
  14587. uniforms.fogFar.value = fog.far;
  14588. } else if (fog.isFogExp2) {
  14589. uniforms.fogDensity.value = fog.density;
  14590. }
  14591. }
  14592. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  14593. if (material.isMeshBasicMaterial) {
  14594. refreshUniformsCommon(uniforms, material);
  14595. } else if (material.isMeshLambertMaterial) {
  14596. refreshUniformsCommon(uniforms, material);
  14597. refreshUniformsLambert(uniforms, material);
  14598. } else if (material.isMeshToonMaterial) {
  14599. refreshUniformsCommon(uniforms, material);
  14600. refreshUniformsToon(uniforms, material);
  14601. } else if (material.isMeshPhongMaterial) {
  14602. refreshUniformsCommon(uniforms, material);
  14603. refreshUniformsPhong(uniforms, material);
  14604. } else if (material.isMeshStandardMaterial) {
  14605. refreshUniformsCommon(uniforms, material);
  14606. if (material.isMeshPhysicalMaterial) {
  14607. refreshUniformsPhysical(uniforms, material);
  14608. } else {
  14609. refreshUniformsStandard(uniforms, material);
  14610. }
  14611. } else if (material.isMeshMatcapMaterial) {
  14612. refreshUniformsCommon(uniforms, material);
  14613. refreshUniformsMatcap(uniforms, material);
  14614. } else if (material.isMeshDepthMaterial) {
  14615. refreshUniformsCommon(uniforms, material);
  14616. refreshUniformsDepth(uniforms, material);
  14617. } else if (material.isMeshDistanceMaterial) {
  14618. refreshUniformsCommon(uniforms, material);
  14619. refreshUniformsDistance(uniforms, material);
  14620. } else if (material.isMeshNormalMaterial) {
  14621. refreshUniformsCommon(uniforms, material);
  14622. refreshUniformsNormal(uniforms, material);
  14623. } else if (material.isLineBasicMaterial) {
  14624. refreshUniformsLine(uniforms, material);
  14625. if (material.isLineDashedMaterial) {
  14626. refreshUniformsDash(uniforms, material);
  14627. }
  14628. } else if (material.isPointsMaterial) {
  14629. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  14630. } else if (material.isSpriteMaterial) {
  14631. refreshUniformsSprites(uniforms, material);
  14632. } else if (material.isShadowMaterial) {
  14633. uniforms.color.value.copy(material.color);
  14634. uniforms.opacity.value = material.opacity;
  14635. } else if (material.isShaderMaterial) {
  14636. material.uniformsNeedUpdate = false; // #15581
  14637. }
  14638. }
  14639. function refreshUniformsCommon(uniforms, material) {
  14640. uniforms.opacity.value = material.opacity;
  14641. if (material.color) {
  14642. uniforms.diffuse.value.copy(material.color);
  14643. }
  14644. if (material.emissive) {
  14645. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  14646. }
  14647. if (material.map) {
  14648. uniforms.map.value = material.map;
  14649. }
  14650. if (material.alphaMap) {
  14651. uniforms.alphaMap.value = material.alphaMap;
  14652. }
  14653. if (material.specularMap) {
  14654. uniforms.specularMap.value = material.specularMap;
  14655. }
  14656. var envMap = properties.get(material).envMap;
  14657. if (envMap) {
  14658. uniforms.envMap.value = envMap;
  14659. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  14660. uniforms.reflectivity.value = material.reflectivity;
  14661. uniforms.refractionRatio.value = material.refractionRatio;
  14662. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  14663. if (maxMipLevel !== undefined) {
  14664. uniforms.maxMipLevel.value = maxMipLevel;
  14665. }
  14666. }
  14667. if (material.lightMap) {
  14668. uniforms.lightMap.value = material.lightMap;
  14669. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14670. }
  14671. if (material.aoMap) {
  14672. uniforms.aoMap.value = material.aoMap;
  14673. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14674. } // uv repeat and offset setting priorities
  14675. // 1. color map
  14676. // 2. specular map
  14677. // 3. displacementMap map
  14678. // 4. normal map
  14679. // 5. bump map
  14680. // 6. roughnessMap map
  14681. // 7. metalnessMap map
  14682. // 8. alphaMap map
  14683. // 9. emissiveMap map
  14684. // 10. clearcoat map
  14685. // 11. clearcoat normal map
  14686. // 12. clearcoat roughnessMap map
  14687. var uvScaleMap;
  14688. if (material.map) {
  14689. uvScaleMap = material.map;
  14690. } else if (material.specularMap) {
  14691. uvScaleMap = material.specularMap;
  14692. } else if (material.displacementMap) {
  14693. uvScaleMap = material.displacementMap;
  14694. } else if (material.normalMap) {
  14695. uvScaleMap = material.normalMap;
  14696. } else if (material.bumpMap) {
  14697. uvScaleMap = material.bumpMap;
  14698. } else if (material.roughnessMap) {
  14699. uvScaleMap = material.roughnessMap;
  14700. } else if (material.metalnessMap) {
  14701. uvScaleMap = material.metalnessMap;
  14702. } else if (material.alphaMap) {
  14703. uvScaleMap = material.alphaMap;
  14704. } else if (material.emissiveMap) {
  14705. uvScaleMap = material.emissiveMap;
  14706. } else if (material.clearcoatMap) {
  14707. uvScaleMap = material.clearcoatMap;
  14708. } else if (material.clearcoatNormalMap) {
  14709. uvScaleMap = material.clearcoatNormalMap;
  14710. } else if (material.clearcoatRoughnessMap) {
  14711. uvScaleMap = material.clearcoatRoughnessMap;
  14712. }
  14713. if (uvScaleMap !== undefined) {
  14714. // backwards compatibility
  14715. if (uvScaleMap.isWebGLRenderTarget) {
  14716. uvScaleMap = uvScaleMap.texture;
  14717. }
  14718. if (uvScaleMap.matrixAutoUpdate === true) {
  14719. uvScaleMap.updateMatrix();
  14720. }
  14721. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14722. } // uv repeat and offset setting priorities for uv2
  14723. // 1. ao map
  14724. // 2. light map
  14725. var uv2ScaleMap;
  14726. if (material.aoMap) {
  14727. uv2ScaleMap = material.aoMap;
  14728. } else if (material.lightMap) {
  14729. uv2ScaleMap = material.lightMap;
  14730. }
  14731. if (uv2ScaleMap !== undefined) {
  14732. // backwards compatibility
  14733. if (uv2ScaleMap.isWebGLRenderTarget) {
  14734. uv2ScaleMap = uv2ScaleMap.texture;
  14735. }
  14736. if (uv2ScaleMap.matrixAutoUpdate === true) {
  14737. uv2ScaleMap.updateMatrix();
  14738. }
  14739. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  14740. }
  14741. }
  14742. function refreshUniformsLine(uniforms, material) {
  14743. uniforms.diffuse.value.copy(material.color);
  14744. uniforms.opacity.value = material.opacity;
  14745. }
  14746. function refreshUniformsDash(uniforms, material) {
  14747. uniforms.dashSize.value = material.dashSize;
  14748. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14749. uniforms.scale.value = material.scale;
  14750. }
  14751. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  14752. uniforms.diffuse.value.copy(material.color);
  14753. uniforms.opacity.value = material.opacity;
  14754. uniforms.size.value = material.size * pixelRatio;
  14755. uniforms.scale.value = height * 0.5;
  14756. if (material.map) {
  14757. uniforms.map.value = material.map;
  14758. }
  14759. if (material.alphaMap) {
  14760. uniforms.alphaMap.value = material.alphaMap;
  14761. } // uv repeat and offset setting priorities
  14762. // 1. color map
  14763. // 2. alpha map
  14764. var uvScaleMap;
  14765. if (material.map) {
  14766. uvScaleMap = material.map;
  14767. } else if (material.alphaMap) {
  14768. uvScaleMap = material.alphaMap;
  14769. }
  14770. if (uvScaleMap !== undefined) {
  14771. if (uvScaleMap.matrixAutoUpdate === true) {
  14772. uvScaleMap.updateMatrix();
  14773. }
  14774. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14775. }
  14776. }
  14777. function refreshUniformsSprites(uniforms, material) {
  14778. uniforms.diffuse.value.copy(material.color);
  14779. uniforms.opacity.value = material.opacity;
  14780. uniforms.rotation.value = material.rotation;
  14781. if (material.map) {
  14782. uniforms.map.value = material.map;
  14783. }
  14784. if (material.alphaMap) {
  14785. uniforms.alphaMap.value = material.alphaMap;
  14786. } // uv repeat and offset setting priorities
  14787. // 1. color map
  14788. // 2. alpha map
  14789. var uvScaleMap;
  14790. if (material.map) {
  14791. uvScaleMap = material.map;
  14792. } else if (material.alphaMap) {
  14793. uvScaleMap = material.alphaMap;
  14794. }
  14795. if (uvScaleMap !== undefined) {
  14796. if (uvScaleMap.matrixAutoUpdate === true) {
  14797. uvScaleMap.updateMatrix();
  14798. }
  14799. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14800. }
  14801. }
  14802. function refreshUniformsLambert(uniforms, material) {
  14803. if (material.emissiveMap) {
  14804. uniforms.emissiveMap.value = material.emissiveMap;
  14805. }
  14806. }
  14807. function refreshUniformsPhong(uniforms, material) {
  14808. uniforms.specular.value.copy(material.specular);
  14809. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  14810. if (material.emissiveMap) {
  14811. uniforms.emissiveMap.value = material.emissiveMap;
  14812. }
  14813. if (material.bumpMap) {
  14814. uniforms.bumpMap.value = material.bumpMap;
  14815. uniforms.bumpScale.value = material.bumpScale;
  14816. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14817. }
  14818. if (material.normalMap) {
  14819. uniforms.normalMap.value = material.normalMap;
  14820. uniforms.normalScale.value.copy(material.normalScale);
  14821. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14822. }
  14823. if (material.displacementMap) {
  14824. uniforms.displacementMap.value = material.displacementMap;
  14825. uniforms.displacementScale.value = material.displacementScale;
  14826. uniforms.displacementBias.value = material.displacementBias;
  14827. }
  14828. }
  14829. function refreshUniformsToon(uniforms, material) {
  14830. if (material.gradientMap) {
  14831. uniforms.gradientMap.value = material.gradientMap;
  14832. }
  14833. if (material.emissiveMap) {
  14834. uniforms.emissiveMap.value = material.emissiveMap;
  14835. }
  14836. if (material.bumpMap) {
  14837. uniforms.bumpMap.value = material.bumpMap;
  14838. uniforms.bumpScale.value = material.bumpScale;
  14839. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14840. }
  14841. if (material.normalMap) {
  14842. uniforms.normalMap.value = material.normalMap;
  14843. uniforms.normalScale.value.copy(material.normalScale);
  14844. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14845. }
  14846. if (material.displacementMap) {
  14847. uniforms.displacementMap.value = material.displacementMap;
  14848. uniforms.displacementScale.value = material.displacementScale;
  14849. uniforms.displacementBias.value = material.displacementBias;
  14850. }
  14851. }
  14852. function refreshUniformsStandard(uniforms, material) {
  14853. uniforms.roughness.value = material.roughness;
  14854. uniforms.metalness.value = material.metalness;
  14855. if (material.roughnessMap) {
  14856. uniforms.roughnessMap.value = material.roughnessMap;
  14857. }
  14858. if (material.metalnessMap) {
  14859. uniforms.metalnessMap.value = material.metalnessMap;
  14860. }
  14861. if (material.emissiveMap) {
  14862. uniforms.emissiveMap.value = material.emissiveMap;
  14863. }
  14864. if (material.bumpMap) {
  14865. uniforms.bumpMap.value = material.bumpMap;
  14866. uniforms.bumpScale.value = material.bumpScale;
  14867. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14868. }
  14869. if (material.normalMap) {
  14870. uniforms.normalMap.value = material.normalMap;
  14871. uniforms.normalScale.value.copy(material.normalScale);
  14872. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14873. }
  14874. if (material.displacementMap) {
  14875. uniforms.displacementMap.value = material.displacementMap;
  14876. uniforms.displacementScale.value = material.displacementScale;
  14877. uniforms.displacementBias.value = material.displacementBias;
  14878. }
  14879. var envMap = properties.get(material).envMap;
  14880. if (envMap) {
  14881. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14882. uniforms.envMapIntensity.value = material.envMapIntensity;
  14883. }
  14884. }
  14885. function refreshUniformsPhysical(uniforms, material) {
  14886. refreshUniformsStandard(uniforms, material);
  14887. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14888. uniforms.clearcoat.value = material.clearcoat;
  14889. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14890. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  14891. if (material.clearcoatMap) {
  14892. uniforms.clearcoatMap.value = material.clearcoatMap;
  14893. }
  14894. if (material.clearcoatRoughnessMap) {
  14895. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14896. }
  14897. if (material.clearcoatNormalMap) {
  14898. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  14899. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14900. if (material.side === BackSide) {
  14901. uniforms.clearcoatNormalScale.value.negate();
  14902. }
  14903. }
  14904. uniforms.transmission.value = material.transmission;
  14905. if (material.transmissionMap) {
  14906. uniforms.transmissionMap.value = material.transmissionMap;
  14907. }
  14908. }
  14909. function refreshUniformsMatcap(uniforms, material) {
  14910. if (material.matcap) {
  14911. uniforms.matcap.value = material.matcap;
  14912. }
  14913. if (material.bumpMap) {
  14914. uniforms.bumpMap.value = material.bumpMap;
  14915. uniforms.bumpScale.value = material.bumpScale;
  14916. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14917. }
  14918. if (material.normalMap) {
  14919. uniforms.normalMap.value = material.normalMap;
  14920. uniforms.normalScale.value.copy(material.normalScale);
  14921. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14922. }
  14923. if (material.displacementMap) {
  14924. uniforms.displacementMap.value = material.displacementMap;
  14925. uniforms.displacementScale.value = material.displacementScale;
  14926. uniforms.displacementBias.value = material.displacementBias;
  14927. }
  14928. }
  14929. function refreshUniformsDepth(uniforms, material) {
  14930. if (material.displacementMap) {
  14931. uniforms.displacementMap.value = material.displacementMap;
  14932. uniforms.displacementScale.value = material.displacementScale;
  14933. uniforms.displacementBias.value = material.displacementBias;
  14934. }
  14935. }
  14936. function refreshUniformsDistance(uniforms, material) {
  14937. if (material.displacementMap) {
  14938. uniforms.displacementMap.value = material.displacementMap;
  14939. uniforms.displacementScale.value = material.displacementScale;
  14940. uniforms.displacementBias.value = material.displacementBias;
  14941. }
  14942. uniforms.referencePosition.value.copy(material.referencePosition);
  14943. uniforms.nearDistance.value = material.nearDistance;
  14944. uniforms.farDistance.value = material.farDistance;
  14945. }
  14946. function refreshUniformsNormal(uniforms, material) {
  14947. if (material.bumpMap) {
  14948. uniforms.bumpMap.value = material.bumpMap;
  14949. uniforms.bumpScale.value = material.bumpScale;
  14950. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14951. }
  14952. if (material.normalMap) {
  14953. uniforms.normalMap.value = material.normalMap;
  14954. uniforms.normalScale.value.copy(material.normalScale);
  14955. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14956. }
  14957. if (material.displacementMap) {
  14958. uniforms.displacementMap.value = material.displacementMap;
  14959. uniforms.displacementScale.value = material.displacementScale;
  14960. uniforms.displacementBias.value = material.displacementBias;
  14961. }
  14962. }
  14963. return {
  14964. refreshFogUniforms: refreshFogUniforms,
  14965. refreshMaterialUniforms: refreshMaterialUniforms
  14966. };
  14967. }
  14968. function createCanvasElement() {
  14969. var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  14970. canvas.style.display = 'block';
  14971. return canvas;
  14972. }
  14973. function WebGLRenderer(parameters) {
  14974. parameters = parameters || {};
  14975. var _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  14976. _context = parameters.context !== undefined ? parameters.context : null,
  14977. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14978. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14979. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14980. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14981. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14982. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14983. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14984. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14985. var currentRenderList = null;
  14986. var currentRenderState = null; // render() can be called from within a callback triggered by another render.
  14987. // We track this so that the nested render call gets its list and state isolated from the parent render call.
  14988. var renderListStack = [];
  14989. var renderStateStack = []; // public properties
  14990. this.domElement = _canvas; // Debug configuration container
  14991. this.debug = {
  14992. /**
  14993. * Enables error checking and reporting when shader programs are being compiled
  14994. * @type {boolean}
  14995. */
  14996. checkShaderErrors: true
  14997. }; // clearing
  14998. this.autoClear = true;
  14999. this.autoClearColor = true;
  15000. this.autoClearDepth = true;
  15001. this.autoClearStencil = true; // scene graph
  15002. this.sortObjects = true; // user-defined clipping
  15003. this.clippingPlanes = [];
  15004. this.localClippingEnabled = false; // physically based shading
  15005. this.gammaFactor = 2.0; // for backwards compatibility
  15006. this.outputEncoding = LinearEncoding; // physical lights
  15007. this.physicallyCorrectLights = false; // tone mapping
  15008. this.toneMapping = NoToneMapping;
  15009. this.toneMappingExposure = 1.0; // morphs
  15010. this.maxMorphTargets = 8;
  15011. this.maxMorphNormals = 4; // internal properties
  15012. var _this = this;
  15013. var _isContextLost = false; // internal state cache
  15014. var _framebuffer = null;
  15015. var _currentActiveCubeFace = 0;
  15016. var _currentActiveMipmapLevel = 0;
  15017. var _currentRenderTarget = null;
  15018. var _currentFramebuffer = null;
  15019. var _currentMaterialId = -1;
  15020. var _currentCamera = null;
  15021. var _currentViewport = new Vector4();
  15022. var _currentScissor = new Vector4();
  15023. var _currentScissorTest = null; //
  15024. var _width = _canvas.width;
  15025. var _height = _canvas.height;
  15026. var _pixelRatio = 1;
  15027. var _opaqueSort = null;
  15028. var _transparentSort = null;
  15029. var _viewport = new Vector4(0, 0, _width, _height);
  15030. var _scissor = new Vector4(0, 0, _width, _height);
  15031. var _scissorTest = false; // frustum
  15032. var _frustum = new Frustum(); // clipping
  15033. var _clippingEnabled = false;
  15034. var _localClippingEnabled = false; // camera matrices cache
  15035. var _projScreenMatrix = new Matrix4();
  15036. var _vector3 = new Vector3();
  15037. var _emptyScene = {
  15038. background: null,
  15039. fog: null,
  15040. environment: null,
  15041. overrideMaterial: null,
  15042. isScene: true
  15043. };
  15044. function getTargetPixelRatio() {
  15045. return _currentRenderTarget === null ? _pixelRatio : 1;
  15046. } // initialize
  15047. var _gl = _context;
  15048. function getContext(contextNames, contextAttributes) {
  15049. for (var i = 0; i < contextNames.length; i++) {
  15050. var contextName = contextNames[i];
  15051. var context = _canvas.getContext(contextName, contextAttributes);
  15052. if (context !== null) return context;
  15053. }
  15054. return null;
  15055. }
  15056. try {
  15057. var contextAttributes = {
  15058. alpha: _alpha,
  15059. depth: _depth,
  15060. stencil: _stencil,
  15061. antialias: _antialias,
  15062. premultipliedAlpha: _premultipliedAlpha,
  15063. preserveDrawingBuffer: _preserveDrawingBuffer,
  15064. powerPreference: _powerPreference,
  15065. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  15066. }; // event listeners must be registered before WebGL context is created, see #12753
  15067. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  15068. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  15069. if (_gl === null) {
  15070. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  15071. if (_this.isWebGL1Renderer === true) {
  15072. contextNames.shift();
  15073. }
  15074. _gl = getContext(contextNames, contextAttributes);
  15075. if (_gl === null) {
  15076. if (getContext(contextNames)) {
  15077. throw new Error('Error creating WebGL context with your selected attributes.');
  15078. } else {
  15079. throw new Error('Error creating WebGL context.');
  15080. }
  15081. }
  15082. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  15083. if (_gl.getShaderPrecisionFormat === undefined) {
  15084. _gl.getShaderPrecisionFormat = function () {
  15085. return {
  15086. 'rangeMin': 1,
  15087. 'rangeMax': 1,
  15088. 'precision': 1
  15089. };
  15090. };
  15091. }
  15092. } catch (error) {
  15093. console.error('THREE.WebGLRenderer: ' + error.message);
  15094. throw error;
  15095. }
  15096. var extensions, capabilities, state, info;
  15097. var properties, textures, cubemaps, attributes, geometries, objects;
  15098. var programCache, materials, renderLists, renderStates, clipping;
  15099. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  15100. var utils, bindingStates;
  15101. function initGLContext() {
  15102. extensions = new WebGLExtensions(_gl);
  15103. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  15104. extensions.init(capabilities);
  15105. utils = new WebGLUtils(_gl, extensions, capabilities);
  15106. state = new WebGLState(_gl, extensions, capabilities);
  15107. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  15108. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  15109. info = new WebGLInfo(_gl);
  15110. properties = new WebGLProperties();
  15111. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  15112. cubemaps = new WebGLCubeMaps(_this);
  15113. attributes = new WebGLAttributes(_gl, capabilities);
  15114. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  15115. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  15116. objects = new WebGLObjects(_gl, geometries, attributes, info);
  15117. morphtargets = new WebGLMorphtargets(_gl);
  15118. clipping = new WebGLClipping(properties);
  15119. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  15120. materials = new WebGLMaterials(properties);
  15121. renderLists = new WebGLRenderLists(properties);
  15122. renderStates = new WebGLRenderStates(extensions, capabilities);
  15123. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  15124. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  15125. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  15126. info.programs = programCache.programs;
  15127. _this.capabilities = capabilities;
  15128. _this.extensions = extensions;
  15129. _this.properties = properties;
  15130. _this.renderLists = renderLists;
  15131. _this.state = state;
  15132. _this.info = info;
  15133. }
  15134. initGLContext(); // xr
  15135. var xr = new WebXRManager(_this, _gl);
  15136. this.xr = xr; // shadow map
  15137. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  15138. this.shadowMap = shadowMap; // API
  15139. this.getContext = function () {
  15140. return _gl;
  15141. };
  15142. this.getContextAttributes = function () {
  15143. return _gl.getContextAttributes();
  15144. };
  15145. this.forceContextLoss = function () {
  15146. var extension = extensions.get('WEBGL_lose_context');
  15147. if (extension) extension.loseContext();
  15148. };
  15149. this.forceContextRestore = function () {
  15150. var extension = extensions.get('WEBGL_lose_context');
  15151. if (extension) extension.restoreContext();
  15152. };
  15153. this.getPixelRatio = function () {
  15154. return _pixelRatio;
  15155. };
  15156. this.setPixelRatio = function (value) {
  15157. if (value === undefined) return;
  15158. _pixelRatio = value;
  15159. this.setSize(_width, _height, false);
  15160. };
  15161. this.getSize = function (target) {
  15162. if (target === undefined) {
  15163. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  15164. target = new Vector2();
  15165. }
  15166. return target.set(_width, _height);
  15167. };
  15168. this.setSize = function (width, height, updateStyle) {
  15169. if (xr.isPresenting) {
  15170. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  15171. return;
  15172. }
  15173. _width = width;
  15174. _height = height;
  15175. _canvas.width = Math.floor(width * _pixelRatio);
  15176. _canvas.height = Math.floor(height * _pixelRatio);
  15177. if (updateStyle !== false) {
  15178. _canvas.style.width = width + 'px';
  15179. _canvas.style.height = height + 'px';
  15180. }
  15181. this.setViewport(0, 0, width, height);
  15182. };
  15183. this.getDrawingBufferSize = function (target) {
  15184. if (target === undefined) {
  15185. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  15186. target = new Vector2();
  15187. }
  15188. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  15189. };
  15190. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  15191. _width = width;
  15192. _height = height;
  15193. _pixelRatio = pixelRatio;
  15194. _canvas.width = Math.floor(width * pixelRatio);
  15195. _canvas.height = Math.floor(height * pixelRatio);
  15196. this.setViewport(0, 0, width, height);
  15197. };
  15198. this.getCurrentViewport = function (target) {
  15199. if (target === undefined) {
  15200. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  15201. target = new Vector4();
  15202. }
  15203. return target.copy(_currentViewport);
  15204. };
  15205. this.getViewport = function (target) {
  15206. return target.copy(_viewport);
  15207. };
  15208. this.setViewport = function (x, y, width, height) {
  15209. if (x.isVector4) {
  15210. _viewport.set(x.x, x.y, x.z, x.w);
  15211. } else {
  15212. _viewport.set(x, y, width, height);
  15213. }
  15214. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  15215. };
  15216. this.getScissor = function (target) {
  15217. return target.copy(_scissor);
  15218. };
  15219. this.setScissor = function (x, y, width, height) {
  15220. if (x.isVector4) {
  15221. _scissor.set(x.x, x.y, x.z, x.w);
  15222. } else {
  15223. _scissor.set(x, y, width, height);
  15224. }
  15225. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  15226. };
  15227. this.getScissorTest = function () {
  15228. return _scissorTest;
  15229. };
  15230. this.setScissorTest = function (boolean) {
  15231. state.setScissorTest(_scissorTest = boolean);
  15232. };
  15233. this.setOpaqueSort = function (method) {
  15234. _opaqueSort = method;
  15235. };
  15236. this.setTransparentSort = function (method) {
  15237. _transparentSort = method;
  15238. }; // Clearing
  15239. this.getClearColor = function (target) {
  15240. if (target === undefined) {
  15241. console.warn('WebGLRenderer: .getClearColor() now requires a Color as an argument');
  15242. target = new Color();
  15243. }
  15244. return target.copy(background.getClearColor());
  15245. };
  15246. this.setClearColor = function () {
  15247. background.setClearColor.apply(background, arguments);
  15248. };
  15249. this.getClearAlpha = function () {
  15250. return background.getClearAlpha();
  15251. };
  15252. this.setClearAlpha = function () {
  15253. background.setClearAlpha.apply(background, arguments);
  15254. };
  15255. this.clear = function (color, depth, stencil) {
  15256. var bits = 0;
  15257. if (color === undefined || color) bits |= 16384;
  15258. if (depth === undefined || depth) bits |= 256;
  15259. if (stencil === undefined || stencil) bits |= 1024;
  15260. _gl.clear(bits);
  15261. };
  15262. this.clearColor = function () {
  15263. this.clear(true, false, false);
  15264. };
  15265. this.clearDepth = function () {
  15266. this.clear(false, true, false);
  15267. };
  15268. this.clearStencil = function () {
  15269. this.clear(false, false, true);
  15270. }; //
  15271. this.dispose = function () {
  15272. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  15273. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  15274. renderLists.dispose();
  15275. renderStates.dispose();
  15276. properties.dispose();
  15277. cubemaps.dispose();
  15278. objects.dispose();
  15279. bindingStates.dispose();
  15280. xr.dispose();
  15281. animation.stop();
  15282. }; // Events
  15283. function onContextLost(event) {
  15284. event.preventDefault();
  15285. console.log('THREE.WebGLRenderer: Context Lost.');
  15286. _isContextLost = true;
  15287. }
  15288. function onContextRestore()
  15289. /* event */
  15290. {
  15291. console.log('THREE.WebGLRenderer: Context Restored.');
  15292. _isContextLost = false;
  15293. initGLContext();
  15294. }
  15295. function onMaterialDispose(event) {
  15296. var material = event.target;
  15297. material.removeEventListener('dispose', onMaterialDispose);
  15298. deallocateMaterial(material);
  15299. } // Buffer deallocation
  15300. function deallocateMaterial(material) {
  15301. releaseMaterialProgramReference(material);
  15302. properties.remove(material);
  15303. }
  15304. function releaseMaterialProgramReference(material) {
  15305. var programInfo = properties.get(material).program;
  15306. if (programInfo !== undefined) {
  15307. programCache.releaseProgram(programInfo);
  15308. }
  15309. } // Buffer rendering
  15310. function renderObjectImmediate(object, program) {
  15311. object.render(function (object) {
  15312. _this.renderBufferImmediate(object, program);
  15313. });
  15314. }
  15315. this.renderBufferImmediate = function (object, program) {
  15316. bindingStates.initAttributes();
  15317. var buffers = properties.get(object);
  15318. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  15319. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  15320. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  15321. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  15322. var programAttributes = program.getAttributes();
  15323. if (object.hasPositions) {
  15324. _gl.bindBuffer(34962, buffers.position);
  15325. _gl.bufferData(34962, object.positionArray, 35048);
  15326. bindingStates.enableAttribute(programAttributes.position);
  15327. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  15328. }
  15329. if (object.hasNormals) {
  15330. _gl.bindBuffer(34962, buffers.normal);
  15331. _gl.bufferData(34962, object.normalArray, 35048);
  15332. bindingStates.enableAttribute(programAttributes.normal);
  15333. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  15334. }
  15335. if (object.hasUvs) {
  15336. _gl.bindBuffer(34962, buffers.uv);
  15337. _gl.bufferData(34962, object.uvArray, 35048);
  15338. bindingStates.enableAttribute(programAttributes.uv);
  15339. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  15340. }
  15341. if (object.hasColors) {
  15342. _gl.bindBuffer(34962, buffers.color);
  15343. _gl.bufferData(34962, object.colorArray, 35048);
  15344. bindingStates.enableAttribute(programAttributes.color);
  15345. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  15346. }
  15347. bindingStates.disableUnusedAttributes();
  15348. _gl.drawArrays(4, 0, object.count);
  15349. object.count = 0;
  15350. };
  15351. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  15352. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  15353. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  15354. var program = setProgram(camera, scene, material, object);
  15355. state.setMaterial(material, frontFaceCW); //
  15356. var index = geometry.index;
  15357. var position = geometry.attributes.position; //
  15358. if (index === null) {
  15359. if (position === undefined || position.count === 0) return;
  15360. } else if (index.count === 0) {
  15361. return;
  15362. } //
  15363. var rangeFactor = 1;
  15364. if (material.wireframe === true) {
  15365. index = geometries.getWireframeAttribute(geometry);
  15366. rangeFactor = 2;
  15367. }
  15368. if (material.morphTargets || material.morphNormals) {
  15369. morphtargets.update(object, geometry, material, program);
  15370. }
  15371. bindingStates.setup(object, material, program, geometry, index);
  15372. var attribute;
  15373. var renderer = bufferRenderer;
  15374. if (index !== null) {
  15375. attribute = attributes.get(index);
  15376. renderer = indexedBufferRenderer;
  15377. renderer.setIndex(attribute);
  15378. } //
  15379. var dataCount = index !== null ? index.count : position.count;
  15380. var rangeStart = geometry.drawRange.start * rangeFactor;
  15381. var rangeCount = geometry.drawRange.count * rangeFactor;
  15382. var groupStart = group !== null ? group.start * rangeFactor : 0;
  15383. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  15384. var drawStart = Math.max(rangeStart, groupStart);
  15385. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  15386. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  15387. if (drawCount === 0) return; //
  15388. if (object.isMesh) {
  15389. if (material.wireframe === true) {
  15390. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  15391. renderer.setMode(1);
  15392. } else {
  15393. renderer.setMode(4);
  15394. }
  15395. } else if (object.isLine) {
  15396. var lineWidth = material.linewidth;
  15397. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  15398. state.setLineWidth(lineWidth * getTargetPixelRatio());
  15399. if (object.isLineSegments) {
  15400. renderer.setMode(1);
  15401. } else if (object.isLineLoop) {
  15402. renderer.setMode(2);
  15403. } else {
  15404. renderer.setMode(3);
  15405. }
  15406. } else if (object.isPoints) {
  15407. renderer.setMode(0);
  15408. } else if (object.isSprite) {
  15409. renderer.setMode(4);
  15410. }
  15411. if (object.isInstancedMesh) {
  15412. renderer.renderInstances(drawStart, drawCount, object.count);
  15413. } else if (geometry.isInstancedBufferGeometry) {
  15414. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  15415. renderer.renderInstances(drawStart, drawCount, instanceCount);
  15416. } else {
  15417. renderer.render(drawStart, drawCount);
  15418. }
  15419. }; // Compile
  15420. this.compile = function (scene, camera) {
  15421. currentRenderState = renderStates.get(scene);
  15422. currentRenderState.init();
  15423. scene.traverseVisible(function (object) {
  15424. if (object.isLight && object.layers.test(camera.layers)) {
  15425. currentRenderState.pushLight(object);
  15426. if (object.castShadow) {
  15427. currentRenderState.pushShadow(object);
  15428. }
  15429. }
  15430. });
  15431. currentRenderState.setupLights();
  15432. var compiled = new WeakMap();
  15433. scene.traverse(function (object) {
  15434. var material = object.material;
  15435. if (material) {
  15436. if (Array.isArray(material)) {
  15437. for (var i = 0; i < material.length; i++) {
  15438. var material2 = material[i];
  15439. if (compiled.has(material2) === false) {
  15440. initMaterial(material2, scene, object);
  15441. compiled.set(material2);
  15442. }
  15443. }
  15444. } else if (compiled.has(material) === false) {
  15445. initMaterial(material, scene, object);
  15446. compiled.set(material);
  15447. }
  15448. }
  15449. });
  15450. }; // Animation Loop
  15451. var onAnimationFrameCallback = null;
  15452. function onAnimationFrame(time) {
  15453. if (xr.isPresenting) return;
  15454. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  15455. }
  15456. var animation = new WebGLAnimation();
  15457. animation.setAnimationLoop(onAnimationFrame);
  15458. if (typeof window !== 'undefined') animation.setContext(window);
  15459. this.setAnimationLoop = function (callback) {
  15460. onAnimationFrameCallback = callback;
  15461. xr.setAnimationLoop(callback);
  15462. callback === null ? animation.stop() : animation.start();
  15463. }; // Rendering
  15464. this.render = function (scene, camera) {
  15465. var renderTarget, forceClear;
  15466. if (arguments[2] !== undefined) {
  15467. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  15468. renderTarget = arguments[2];
  15469. }
  15470. if (arguments[3] !== undefined) {
  15471. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  15472. forceClear = arguments[3];
  15473. }
  15474. if (camera !== undefined && camera.isCamera !== true) {
  15475. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  15476. return;
  15477. }
  15478. if (_isContextLost === true) return; // reset caching for this frame
  15479. bindingStates.resetDefaultState();
  15480. _currentMaterialId = -1;
  15481. _currentCamera = null; // update scene graph
  15482. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  15483. if (camera.parent === null) camera.updateMatrixWorld();
  15484. if (xr.enabled === true && xr.isPresenting === true) {
  15485. camera = xr.getCamera(camera);
  15486. } //
  15487. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  15488. currentRenderState = renderStates.get(scene, renderStateStack.length);
  15489. currentRenderState.init();
  15490. renderStateStack.push(currentRenderState);
  15491. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  15492. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  15493. _localClippingEnabled = this.localClippingEnabled;
  15494. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  15495. currentRenderList = renderLists.get(scene, renderListStack.length);
  15496. currentRenderList.init();
  15497. renderListStack.push(currentRenderList);
  15498. projectObject(scene, camera, 0, _this.sortObjects);
  15499. currentRenderList.finish();
  15500. if (_this.sortObjects === true) {
  15501. currentRenderList.sort(_opaqueSort, _transparentSort);
  15502. } //
  15503. if (_clippingEnabled === true) clipping.beginShadows();
  15504. var shadowsArray = currentRenderState.state.shadowsArray;
  15505. shadowMap.render(shadowsArray, scene, camera);
  15506. currentRenderState.setupLights();
  15507. currentRenderState.setupLightsView(camera);
  15508. if (_clippingEnabled === true) clipping.endShadows(); //
  15509. if (this.info.autoReset === true) this.info.reset();
  15510. if (renderTarget !== undefined) {
  15511. this.setRenderTarget(renderTarget);
  15512. } //
  15513. background.render(currentRenderList, scene, camera, forceClear); // render scene
  15514. var opaqueObjects = currentRenderList.opaque;
  15515. var transparentObjects = currentRenderList.transparent;
  15516. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  15517. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  15518. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  15519. if (_currentRenderTarget !== null) {
  15520. // Generate mipmap if we're using any kind of mipmap filtering
  15521. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  15522. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  15523. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  15524. state.buffers.depth.setTest(true);
  15525. state.buffers.depth.setMask(true);
  15526. state.buffers.color.setMask(true);
  15527. state.setPolygonOffset(false); // _gl.finish();
  15528. renderStateStack.pop();
  15529. if (renderStateStack.length > 0) {
  15530. currentRenderState = renderStateStack[renderStateStack.length - 1];
  15531. } else {
  15532. currentRenderState = null;
  15533. }
  15534. renderListStack.pop();
  15535. if (renderListStack.length > 0) {
  15536. currentRenderList = renderListStack[renderListStack.length - 1];
  15537. } else {
  15538. currentRenderList = null;
  15539. }
  15540. };
  15541. function projectObject(object, camera, groupOrder, sortObjects) {
  15542. if (object.visible === false) return;
  15543. var visible = object.layers.test(camera.layers);
  15544. if (visible) {
  15545. if (object.isGroup) {
  15546. groupOrder = object.renderOrder;
  15547. } else if (object.isLOD) {
  15548. if (object.autoUpdate === true) object.update(camera);
  15549. } else if (object.isLight) {
  15550. currentRenderState.pushLight(object);
  15551. if (object.castShadow) {
  15552. currentRenderState.pushShadow(object);
  15553. }
  15554. } else if (object.isSprite) {
  15555. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  15556. if (sortObjects) {
  15557. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15558. }
  15559. var geometry = objects.update(object);
  15560. var material = object.material;
  15561. if (material.visible) {
  15562. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  15563. }
  15564. }
  15565. } else if (object.isImmediateRenderObject) {
  15566. if (sortObjects) {
  15567. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15568. }
  15569. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  15570. } else if (object.isMesh || object.isLine || object.isPoints) {
  15571. if (object.isSkinnedMesh) {
  15572. // update skeleton only once in a frame
  15573. if (object.skeleton.frame !== info.render.frame) {
  15574. object.skeleton.update();
  15575. object.skeleton.frame = info.render.frame;
  15576. }
  15577. }
  15578. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  15579. if (sortObjects) {
  15580. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15581. }
  15582. var _geometry = objects.update(object);
  15583. var _material = object.material;
  15584. if (Array.isArray(_material)) {
  15585. var groups = _geometry.groups;
  15586. for (var i = 0, l = groups.length; i < l; i++) {
  15587. var group = groups[i];
  15588. var groupMaterial = _material[group.materialIndex];
  15589. if (groupMaterial && groupMaterial.visible) {
  15590. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  15591. }
  15592. }
  15593. } else if (_material.visible) {
  15594. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  15595. }
  15596. }
  15597. }
  15598. }
  15599. var children = object.children;
  15600. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  15601. projectObject(children[_i], camera, groupOrder, sortObjects);
  15602. }
  15603. }
  15604. function renderObjects(renderList, scene, camera) {
  15605. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  15606. for (var i = 0, l = renderList.length; i < l; i++) {
  15607. var renderItem = renderList[i];
  15608. var object = renderItem.object;
  15609. var geometry = renderItem.geometry;
  15610. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  15611. var group = renderItem.group;
  15612. if (camera.isArrayCamera) {
  15613. var cameras = camera.cameras;
  15614. for (var j = 0, jl = cameras.length; j < jl; j++) {
  15615. var camera2 = cameras[j];
  15616. if (object.layers.test(camera2.layers)) {
  15617. state.viewport(_currentViewport.copy(camera2.viewport));
  15618. currentRenderState.setupLightsView(camera2);
  15619. renderObject(object, scene, camera2, geometry, material, group);
  15620. }
  15621. }
  15622. } else {
  15623. renderObject(object, scene, camera, geometry, material, group);
  15624. }
  15625. }
  15626. }
  15627. function renderObject(object, scene, camera, geometry, material, group) {
  15628. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  15629. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  15630. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  15631. if (object.isImmediateRenderObject) {
  15632. var program = setProgram(camera, scene, material, object);
  15633. state.setMaterial(material);
  15634. bindingStates.reset();
  15635. renderObjectImmediate(object, program);
  15636. } else {
  15637. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  15638. }
  15639. object.onAfterRender(_this, scene, camera, geometry, material, group);
  15640. }
  15641. function initMaterial(material, scene, object) {
  15642. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15643. var materialProperties = properties.get(material);
  15644. var lights = currentRenderState.state.lights;
  15645. var shadowsArray = currentRenderState.state.shadowsArray;
  15646. var lightsStateVersion = lights.state.version;
  15647. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  15648. var programCacheKey = programCache.getProgramCacheKey(parameters);
  15649. var program = materialProperties.program;
  15650. var programChange = true; // always update environment and fog - changing these trigger an initMaterial call, but it's possible that the program doesn't change
  15651. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  15652. materialProperties.fog = scene.fog;
  15653. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment);
  15654. if (program === undefined) {
  15655. // new material
  15656. material.addEventListener('dispose', onMaterialDispose);
  15657. } else if (program.cacheKey !== programCacheKey) {
  15658. // changed glsl or parameters
  15659. releaseMaterialProgramReference(material);
  15660. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  15661. programChange = false;
  15662. } else if (parameters.shaderID !== undefined) {
  15663. // same glsl and uniform list
  15664. return;
  15665. } else {
  15666. // only rebuild uniform list
  15667. programChange = false;
  15668. }
  15669. if (programChange) {
  15670. parameters.uniforms = programCache.getUniforms(material);
  15671. material.onBeforeCompile(parameters, _this);
  15672. program = programCache.acquireProgram(parameters, programCacheKey);
  15673. materialProperties.program = program;
  15674. materialProperties.uniforms = parameters.uniforms;
  15675. materialProperties.outputEncoding = parameters.outputEncoding;
  15676. }
  15677. var uniforms = materialProperties.uniforms;
  15678. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  15679. materialProperties.numClippingPlanes = clipping.numPlanes;
  15680. materialProperties.numIntersection = clipping.numIntersection;
  15681. uniforms.clippingPlanes = clipping.uniform;
  15682. } // store the light setup it was created for
  15683. materialProperties.needsLights = materialNeedsLights(material);
  15684. materialProperties.lightsStateVersion = lightsStateVersion;
  15685. if (materialProperties.needsLights) {
  15686. // wire up the material to this renderer's lighting state
  15687. uniforms.ambientLightColor.value = lights.state.ambient;
  15688. uniforms.lightProbe.value = lights.state.probe;
  15689. uniforms.directionalLights.value = lights.state.directional;
  15690. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  15691. uniforms.spotLights.value = lights.state.spot;
  15692. uniforms.spotLightShadows.value = lights.state.spotShadow;
  15693. uniforms.rectAreaLights.value = lights.state.rectArea;
  15694. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  15695. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  15696. uniforms.pointLights.value = lights.state.point;
  15697. uniforms.pointLightShadows.value = lights.state.pointShadow;
  15698. uniforms.hemisphereLights.value = lights.state.hemi;
  15699. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  15700. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  15701. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  15702. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  15703. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  15704. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  15705. }
  15706. var progUniforms = materialProperties.program.getUniforms();
  15707. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  15708. materialProperties.uniformsList = uniformsList;
  15709. }
  15710. function setProgram(camera, scene, material, object) {
  15711. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15712. textures.resetTextureUnits();
  15713. var fog = scene.fog;
  15714. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  15715. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  15716. var envMap = cubemaps.get(material.envMap || environment);
  15717. var materialProperties = properties.get(material);
  15718. var lights = currentRenderState.state.lights;
  15719. if (_clippingEnabled === true) {
  15720. if (_localClippingEnabled === true || camera !== _currentCamera) {
  15721. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  15722. // object instead of the material, once it becomes feasible
  15723. // (#8465, #8379)
  15724. clipping.setState(material, camera, useCache);
  15725. }
  15726. }
  15727. if (material.version === materialProperties.__version) {
  15728. if (material.fog && materialProperties.fog !== fog) {
  15729. initMaterial(material, scene, object);
  15730. } else if (materialProperties.environment !== environment) {
  15731. initMaterial(material, scene, object);
  15732. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  15733. initMaterial(material, scene, object);
  15734. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  15735. initMaterial(material, scene, object);
  15736. } else if (materialProperties.outputEncoding !== encoding) {
  15737. initMaterial(material, scene, object);
  15738. } else if (materialProperties.envMap !== envMap) {
  15739. initMaterial(material, scene, object);
  15740. }
  15741. } else {
  15742. initMaterial(material, scene, object);
  15743. materialProperties.__version = material.version;
  15744. }
  15745. var refreshProgram = false;
  15746. var refreshMaterial = false;
  15747. var refreshLights = false;
  15748. var program = materialProperties.program,
  15749. p_uniforms = program.getUniforms(),
  15750. m_uniforms = materialProperties.uniforms;
  15751. if (state.useProgram(program.program)) {
  15752. refreshProgram = true;
  15753. refreshMaterial = true;
  15754. refreshLights = true;
  15755. }
  15756. if (material.id !== _currentMaterialId) {
  15757. _currentMaterialId = material.id;
  15758. refreshMaterial = true;
  15759. }
  15760. if (refreshProgram || _currentCamera !== camera) {
  15761. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  15762. if (capabilities.logarithmicDepthBuffer) {
  15763. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  15764. }
  15765. if (_currentCamera !== camera) {
  15766. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  15767. // now, in case this material supports lights - or later, when
  15768. // the next material that does gets activated:
  15769. refreshMaterial = true; // set to true on material change
  15770. refreshLights = true; // remains set until update done
  15771. } // load material specific uniforms
  15772. // (shader material also gets them for the sake of genericity)
  15773. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  15774. var uCamPos = p_uniforms.map.cameraPosition;
  15775. if (uCamPos !== undefined) {
  15776. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  15777. }
  15778. }
  15779. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  15780. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  15781. }
  15782. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  15783. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  15784. }
  15785. } // skinning uniforms must be set even if material didn't change
  15786. // auto-setting of texture unit for bone texture must go before other textures
  15787. // otherwise textures used for skinning can take over texture units reserved for other material textures
  15788. if (material.skinning) {
  15789. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  15790. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  15791. var skeleton = object.skeleton;
  15792. if (skeleton) {
  15793. var bones = skeleton.bones;
  15794. if (capabilities.floatVertexTextures) {
  15795. if (skeleton.boneTexture === null) {
  15796. // layout (1 matrix = 4 pixels)
  15797. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15798. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15799. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15800. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15801. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15802. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  15803. size = MathUtils.ceilPowerOfTwo(size);
  15804. size = Math.max(size, 4);
  15805. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  15806. boneMatrices.set(skeleton.boneMatrices); // copy current values
  15807. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  15808. skeleton.boneMatrices = boneMatrices;
  15809. skeleton.boneTexture = boneTexture;
  15810. skeleton.boneTextureSize = size;
  15811. }
  15812. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  15813. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  15814. } else {
  15815. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  15816. }
  15817. }
  15818. }
  15819. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  15820. materialProperties.receiveShadow = object.receiveShadow;
  15821. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  15822. }
  15823. if (refreshMaterial) {
  15824. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  15825. if (materialProperties.needsLights) {
  15826. // the current material requires lighting info
  15827. // note: all lighting uniforms are always set correctly
  15828. // they simply reference the renderer's state for their
  15829. // values
  15830. //
  15831. // use the current material's .needsUpdate flags to set
  15832. // the GL state when required
  15833. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  15834. } // refresh uniforms common to several materials
  15835. if (fog && material.fog) {
  15836. materials.refreshFogUniforms(m_uniforms, fog);
  15837. }
  15838. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  15839. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15840. }
  15841. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  15842. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15843. material.uniformsNeedUpdate = false;
  15844. }
  15845. if (material.isSpriteMaterial) {
  15846. p_uniforms.setValue(_gl, 'center', object.center);
  15847. } // common matrices
  15848. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  15849. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  15850. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  15851. return program;
  15852. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15853. function markUniformsLightsNeedsUpdate(uniforms, value) {
  15854. uniforms.ambientLightColor.needsUpdate = value;
  15855. uniforms.lightProbe.needsUpdate = value;
  15856. uniforms.directionalLights.needsUpdate = value;
  15857. uniforms.directionalLightShadows.needsUpdate = value;
  15858. uniforms.pointLights.needsUpdate = value;
  15859. uniforms.pointLightShadows.needsUpdate = value;
  15860. uniforms.spotLights.needsUpdate = value;
  15861. uniforms.spotLightShadows.needsUpdate = value;
  15862. uniforms.rectAreaLights.needsUpdate = value;
  15863. uniforms.hemisphereLights.needsUpdate = value;
  15864. }
  15865. function materialNeedsLights(material) {
  15866. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  15867. } //
  15868. this.setFramebuffer = function (value) {
  15869. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  15870. _framebuffer = value;
  15871. };
  15872. this.getActiveCubeFace = function () {
  15873. return _currentActiveCubeFace;
  15874. };
  15875. this.getActiveMipmapLevel = function () {
  15876. return _currentActiveMipmapLevel;
  15877. };
  15878. this.getRenderTarget = function () {
  15879. return _currentRenderTarget;
  15880. };
  15881. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  15882. if (activeCubeFace === void 0) {
  15883. activeCubeFace = 0;
  15884. }
  15885. if (activeMipmapLevel === void 0) {
  15886. activeMipmapLevel = 0;
  15887. }
  15888. _currentRenderTarget = renderTarget;
  15889. _currentActiveCubeFace = activeCubeFace;
  15890. _currentActiveMipmapLevel = activeMipmapLevel;
  15891. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  15892. textures.setupRenderTarget(renderTarget);
  15893. }
  15894. var framebuffer = _framebuffer;
  15895. var isCube = false;
  15896. var isRenderTarget3D = false;
  15897. if (renderTarget) {
  15898. var texture = renderTarget.texture;
  15899. if (texture.isDataTexture3D || texture.isDataTexture2DArray) {
  15900. isRenderTarget3D = true;
  15901. }
  15902. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  15903. if (renderTarget.isWebGLCubeRenderTarget) {
  15904. framebuffer = __webglFramebuffer[activeCubeFace];
  15905. isCube = true;
  15906. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  15907. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  15908. } else {
  15909. framebuffer = __webglFramebuffer;
  15910. }
  15911. _currentViewport.copy(renderTarget.viewport);
  15912. _currentScissor.copy(renderTarget.scissor);
  15913. _currentScissorTest = renderTarget.scissorTest;
  15914. } else {
  15915. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  15916. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  15917. _currentScissorTest = _scissorTest;
  15918. }
  15919. if (_currentFramebuffer !== framebuffer) {
  15920. _gl.bindFramebuffer(36160, framebuffer);
  15921. _currentFramebuffer = framebuffer;
  15922. }
  15923. state.viewport(_currentViewport);
  15924. state.scissor(_currentScissor);
  15925. state.setScissorTest(_currentScissorTest);
  15926. if (isCube) {
  15927. var textureProperties = properties.get(renderTarget.texture);
  15928. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  15929. } else if (isRenderTarget3D) {
  15930. var _textureProperties = properties.get(renderTarget.texture);
  15931. var layer = activeCubeFace || 0;
  15932. _gl.framebufferTextureLayer(36160, 36064, _textureProperties.__webglTexture, activeMipmapLevel || 0, layer);
  15933. }
  15934. };
  15935. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15936. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15937. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15938. return;
  15939. }
  15940. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15941. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15942. framebuffer = framebuffer[activeCubeFaceIndex];
  15943. }
  15944. if (framebuffer) {
  15945. var restore = false;
  15946. if (framebuffer !== _currentFramebuffer) {
  15947. _gl.bindFramebuffer(36160, framebuffer);
  15948. restore = true;
  15949. }
  15950. try {
  15951. var texture = renderTarget.texture;
  15952. var textureFormat = texture.format;
  15953. var textureType = texture.type;
  15954. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15955. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15956. return;
  15957. }
  15958. var halfFloatSupportedByExt = textureType === HalfFloatType && (extensions.has('EXT_color_buffer_half_float') || capabilities.isWebGL2 && extensions.has('EXT_color_buffer_float'));
  15959. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15960. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.has('OES_texture_float') || extensions.has('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15961. !halfFloatSupportedByExt) {
  15962. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15963. return;
  15964. }
  15965. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15966. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15967. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15968. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15969. }
  15970. } else {
  15971. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15972. }
  15973. } finally {
  15974. if (restore) {
  15975. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15976. }
  15977. }
  15978. }
  15979. };
  15980. this.copyFramebufferToTexture = function (position, texture, level) {
  15981. if (level === void 0) {
  15982. level = 0;
  15983. }
  15984. var levelScale = Math.pow(2, -level);
  15985. var width = Math.floor(texture.image.width * levelScale);
  15986. var height = Math.floor(texture.image.height * levelScale);
  15987. var glFormat = utils.convert(texture.format);
  15988. textures.setTexture2D(texture, 0);
  15989. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15990. state.unbindTexture();
  15991. };
  15992. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15993. if (level === void 0) {
  15994. level = 0;
  15995. }
  15996. var width = srcTexture.image.width;
  15997. var height = srcTexture.image.height;
  15998. var glFormat = utils.convert(dstTexture.format);
  15999. var glType = utils.convert(dstTexture.type);
  16000. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  16001. // parameters, make sure they are correct for the dstTexture
  16002. _gl.pixelStorei(37440, dstTexture.flipY);
  16003. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  16004. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  16005. if (srcTexture.isDataTexture) {
  16006. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  16007. } else {
  16008. if (srcTexture.isCompressedTexture) {
  16009. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  16010. } else {
  16011. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  16012. }
  16013. } // Generate mipmaps only when copying level 0
  16014. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  16015. state.unbindTexture();
  16016. };
  16017. this.copyTextureToTexture3D = function (sourceBox, position, srcTexture, dstTexture, level) {
  16018. if (level === void 0) {
  16019. level = 0;
  16020. }
  16021. if (_this.isWebGL1Renderer) {
  16022. console.warn('THREE.WebGLRenderer.copyTextureToTexture3D: can only be used with WebGL2.');
  16023. return;
  16024. }
  16025. var _srcTexture$image = srcTexture.image,
  16026. width = _srcTexture$image.width,
  16027. height = _srcTexture$image.height,
  16028. data = _srcTexture$image.data;
  16029. var glFormat = utils.convert(dstTexture.format);
  16030. var glType = utils.convert(dstTexture.type);
  16031. var glTarget;
  16032. if (dstTexture.isDataTexture3D) {
  16033. textures.setTexture3D(dstTexture, 0);
  16034. glTarget = 32879;
  16035. } else if (dstTexture.isDataTexture2DArray) {
  16036. textures.setTexture2DArray(dstTexture, 0);
  16037. glTarget = 35866;
  16038. } else {
  16039. console.warn('THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray.');
  16040. return;
  16041. }
  16042. _gl.pixelStorei(37440, dstTexture.flipY);
  16043. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  16044. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  16045. var unpackRowLen = _gl.getParameter(3314);
  16046. var unpackImageHeight = _gl.getParameter(32878);
  16047. var unpackSkipPixels = _gl.getParameter(3316);
  16048. var unpackSkipRows = _gl.getParameter(3315);
  16049. var unpackSkipImages = _gl.getParameter(32877);
  16050. _gl.pixelStorei(3314, width);
  16051. _gl.pixelStorei(32878, height);
  16052. _gl.pixelStorei(3316, sourceBox.min.x);
  16053. _gl.pixelStorei(3315, sourceBox.min.y);
  16054. _gl.pixelStorei(32877, sourceBox.min.z);
  16055. _gl.texSubImage3D(glTarget, level, position.x, position.y, position.z, sourceBox.max.x - sourceBox.min.x + 1, sourceBox.max.y - sourceBox.min.y + 1, sourceBox.max.z - sourceBox.min.z + 1, glFormat, glType, data);
  16056. _gl.pixelStorei(3314, unpackRowLen);
  16057. _gl.pixelStorei(32878, unpackImageHeight);
  16058. _gl.pixelStorei(3316, unpackSkipPixels);
  16059. _gl.pixelStorei(3315, unpackSkipRows);
  16060. _gl.pixelStorei(32877, unpackSkipImages); // Generate mipmaps only when copying level 0
  16061. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(glTarget);
  16062. state.unbindTexture();
  16063. };
  16064. this.initTexture = function (texture) {
  16065. textures.setTexture2D(texture, 0);
  16066. state.unbindTexture();
  16067. };
  16068. this.resetState = function () {
  16069. state.reset();
  16070. bindingStates.reset();
  16071. };
  16072. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  16073. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  16074. detail: this
  16075. })); // eslint-disable-line no-undef
  16076. }
  16077. }
  16078. var WebGL1Renderer = /*#__PURE__*/function (_WebGLRenderer) {
  16079. _inheritsLoose(WebGL1Renderer, _WebGLRenderer);
  16080. function WebGL1Renderer() {
  16081. return _WebGLRenderer.apply(this, arguments) || this;
  16082. }
  16083. return WebGL1Renderer;
  16084. }(WebGLRenderer);
  16085. WebGL1Renderer.prototype.isWebGL1Renderer = true;
  16086. var FogExp2 = /*#__PURE__*/function () {
  16087. function FogExp2(color, density) {
  16088. this.name = '';
  16089. this.color = new Color(color);
  16090. this.density = density !== undefined ? density : 0.00025;
  16091. }
  16092. var _proto = FogExp2.prototype;
  16093. _proto.clone = function clone() {
  16094. return new FogExp2(this.color, this.density);
  16095. };
  16096. _proto.toJSON = function toJSON()
  16097. /* meta */
  16098. {
  16099. return {
  16100. type: 'FogExp2',
  16101. color: this.color.getHex(),
  16102. density: this.density
  16103. };
  16104. };
  16105. return FogExp2;
  16106. }();
  16107. FogExp2.prototype.isFogExp2 = true;
  16108. var Fog = /*#__PURE__*/function () {
  16109. function Fog(color, near, far) {
  16110. this.name = '';
  16111. this.color = new Color(color);
  16112. this.near = near !== undefined ? near : 1;
  16113. this.far = far !== undefined ? far : 1000;
  16114. }
  16115. var _proto = Fog.prototype;
  16116. _proto.clone = function clone() {
  16117. return new Fog(this.color, this.near, this.far);
  16118. };
  16119. _proto.toJSON = function toJSON()
  16120. /* meta */
  16121. {
  16122. return {
  16123. type: 'Fog',
  16124. color: this.color.getHex(),
  16125. near: this.near,
  16126. far: this.far
  16127. };
  16128. };
  16129. return Fog;
  16130. }();
  16131. Fog.prototype.isFog = true;
  16132. var Scene = /*#__PURE__*/function (_Object3D) {
  16133. _inheritsLoose(Scene, _Object3D);
  16134. function Scene() {
  16135. var _this;
  16136. _this = _Object3D.call(this) || this;
  16137. _this.type = 'Scene';
  16138. _this.background = null;
  16139. _this.environment = null;
  16140. _this.fog = null;
  16141. _this.overrideMaterial = null;
  16142. _this.autoUpdate = true; // checked by the renderer
  16143. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  16144. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  16145. detail: _assertThisInitialized(_this)
  16146. })); // eslint-disable-line no-undef
  16147. }
  16148. return _this;
  16149. }
  16150. var _proto = Scene.prototype;
  16151. _proto.copy = function copy(source, recursive) {
  16152. _Object3D.prototype.copy.call(this, source, recursive);
  16153. if (source.background !== null) this.background = source.background.clone();
  16154. if (source.environment !== null) this.environment = source.environment.clone();
  16155. if (source.fog !== null) this.fog = source.fog.clone();
  16156. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  16157. this.autoUpdate = source.autoUpdate;
  16158. this.matrixAutoUpdate = source.matrixAutoUpdate;
  16159. return this;
  16160. };
  16161. _proto.toJSON = function toJSON(meta) {
  16162. var data = _Object3D.prototype.toJSON.call(this, meta);
  16163. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  16164. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  16165. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  16166. return data;
  16167. };
  16168. return Scene;
  16169. }(Object3D);
  16170. Scene.prototype.isScene = true;
  16171. function InterleavedBuffer(array, stride) {
  16172. this.array = array;
  16173. this.stride = stride;
  16174. this.count = array !== undefined ? array.length / stride : 0;
  16175. this.usage = StaticDrawUsage;
  16176. this.updateRange = {
  16177. offset: 0,
  16178. count: -1
  16179. };
  16180. this.version = 0;
  16181. this.uuid = MathUtils.generateUUID();
  16182. }
  16183. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  16184. set: function set(value) {
  16185. if (value === true) this.version++;
  16186. }
  16187. });
  16188. Object.assign(InterleavedBuffer.prototype, {
  16189. isInterleavedBuffer: true,
  16190. onUploadCallback: function onUploadCallback() {},
  16191. setUsage: function setUsage(value) {
  16192. this.usage = value;
  16193. return this;
  16194. },
  16195. copy: function copy(source) {
  16196. this.array = new source.array.constructor(source.array);
  16197. this.count = source.count;
  16198. this.stride = source.stride;
  16199. this.usage = source.usage;
  16200. return this;
  16201. },
  16202. copyAt: function copyAt(index1, attribute, index2) {
  16203. index1 *= this.stride;
  16204. index2 *= attribute.stride;
  16205. for (var i = 0, l = this.stride; i < l; i++) {
  16206. this.array[index1 + i] = attribute.array[index2 + i];
  16207. }
  16208. return this;
  16209. },
  16210. set: function set(value, offset) {
  16211. if (offset === void 0) {
  16212. offset = 0;
  16213. }
  16214. this.array.set(value, offset);
  16215. return this;
  16216. },
  16217. clone: function clone(data) {
  16218. if (data.arrayBuffers === undefined) {
  16219. data.arrayBuffers = {};
  16220. }
  16221. if (this.array.buffer._uuid === undefined) {
  16222. this.array.buffer._uuid = MathUtils.generateUUID();
  16223. }
  16224. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  16225. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  16226. }
  16227. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  16228. var ib = new InterleavedBuffer(array, this.stride);
  16229. ib.setUsage(this.usage);
  16230. return ib;
  16231. },
  16232. onUpload: function onUpload(callback) {
  16233. this.onUploadCallback = callback;
  16234. return this;
  16235. },
  16236. toJSON: function toJSON(data) {
  16237. if (data.arrayBuffers === undefined) {
  16238. data.arrayBuffers = {};
  16239. } // generate UUID for array buffer if necessary
  16240. if (this.array.buffer._uuid === undefined) {
  16241. this.array.buffer._uuid = MathUtils.generateUUID();
  16242. }
  16243. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  16244. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  16245. } //
  16246. return {
  16247. uuid: this.uuid,
  16248. buffer: this.array.buffer._uuid,
  16249. type: this.array.constructor.name,
  16250. stride: this.stride
  16251. };
  16252. }
  16253. });
  16254. var _vector$6 = new Vector3();
  16255. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  16256. this.name = '';
  16257. this.data = interleavedBuffer;
  16258. this.itemSize = itemSize;
  16259. this.offset = offset;
  16260. this.normalized = normalized === true;
  16261. }
  16262. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  16263. count: {
  16264. get: function get() {
  16265. return this.data.count;
  16266. }
  16267. },
  16268. array: {
  16269. get: function get() {
  16270. return this.data.array;
  16271. }
  16272. },
  16273. needsUpdate: {
  16274. set: function set(value) {
  16275. this.data.needsUpdate = value;
  16276. }
  16277. }
  16278. });
  16279. Object.assign(InterleavedBufferAttribute.prototype, {
  16280. isInterleavedBufferAttribute: true,
  16281. applyMatrix4: function applyMatrix4(m) {
  16282. for (var i = 0, l = this.data.count; i < l; i++) {
  16283. _vector$6.x = this.getX(i);
  16284. _vector$6.y = this.getY(i);
  16285. _vector$6.z = this.getZ(i);
  16286. _vector$6.applyMatrix4(m);
  16287. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  16288. }
  16289. return this;
  16290. },
  16291. setX: function setX(index, x) {
  16292. this.data.array[index * this.data.stride + this.offset] = x;
  16293. return this;
  16294. },
  16295. setY: function setY(index, y) {
  16296. this.data.array[index * this.data.stride + this.offset + 1] = y;
  16297. return this;
  16298. },
  16299. setZ: function setZ(index, z) {
  16300. this.data.array[index * this.data.stride + this.offset + 2] = z;
  16301. return this;
  16302. },
  16303. setW: function setW(index, w) {
  16304. this.data.array[index * this.data.stride + this.offset + 3] = w;
  16305. return this;
  16306. },
  16307. getX: function getX(index) {
  16308. return this.data.array[index * this.data.stride + this.offset];
  16309. },
  16310. getY: function getY(index) {
  16311. return this.data.array[index * this.data.stride + this.offset + 1];
  16312. },
  16313. getZ: function getZ(index) {
  16314. return this.data.array[index * this.data.stride + this.offset + 2];
  16315. },
  16316. getW: function getW(index) {
  16317. return this.data.array[index * this.data.stride + this.offset + 3];
  16318. },
  16319. setXY: function setXY(index, x, y) {
  16320. index = index * this.data.stride + this.offset;
  16321. this.data.array[index + 0] = x;
  16322. this.data.array[index + 1] = y;
  16323. return this;
  16324. },
  16325. setXYZ: function setXYZ(index, x, y, z) {
  16326. index = index * this.data.stride + this.offset;
  16327. this.data.array[index + 0] = x;
  16328. this.data.array[index + 1] = y;
  16329. this.data.array[index + 2] = z;
  16330. return this;
  16331. },
  16332. setXYZW: function setXYZW(index, x, y, z, w) {
  16333. index = index * this.data.stride + this.offset;
  16334. this.data.array[index + 0] = x;
  16335. this.data.array[index + 1] = y;
  16336. this.data.array[index + 2] = z;
  16337. this.data.array[index + 3] = w;
  16338. return this;
  16339. },
  16340. clone: function clone(data) {
  16341. if (data === undefined) {
  16342. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  16343. var array = [];
  16344. for (var i = 0; i < this.count; i++) {
  16345. var index = i * this.data.stride + this.offset;
  16346. for (var j = 0; j < this.itemSize; j++) {
  16347. array.push(this.data.array[index + j]);
  16348. }
  16349. }
  16350. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  16351. } else {
  16352. if (data.interleavedBuffers === undefined) {
  16353. data.interleavedBuffers = {};
  16354. }
  16355. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  16356. data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
  16357. }
  16358. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  16359. }
  16360. },
  16361. toJSON: function toJSON(data) {
  16362. if (data === undefined) {
  16363. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  16364. var array = [];
  16365. for (var i = 0; i < this.count; i++) {
  16366. var index = i * this.data.stride + this.offset;
  16367. for (var j = 0; j < this.itemSize; j++) {
  16368. array.push(this.data.array[index + j]);
  16369. }
  16370. } // deinterleave data and save it as an ordinary buffer attribute for now
  16371. return {
  16372. itemSize: this.itemSize,
  16373. type: this.array.constructor.name,
  16374. array: array,
  16375. normalized: this.normalized
  16376. };
  16377. } else {
  16378. // save as true interlaved attribtue
  16379. if (data.interleavedBuffers === undefined) {
  16380. data.interleavedBuffers = {};
  16381. }
  16382. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  16383. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  16384. }
  16385. return {
  16386. isInterleavedBufferAttribute: true,
  16387. itemSize: this.itemSize,
  16388. data: this.data.uuid,
  16389. offset: this.offset,
  16390. normalized: this.normalized
  16391. };
  16392. }
  16393. }
  16394. });
  16395. /**
  16396. * parameters = {
  16397. * color: <hex>,
  16398. * map: new THREE.Texture( <Image> ),
  16399. * alphaMap: new THREE.Texture( <Image> ),
  16400. * rotation: <float>,
  16401. * sizeAttenuation: <bool>
  16402. * }
  16403. */
  16404. var SpriteMaterial = /*#__PURE__*/function (_Material) {
  16405. _inheritsLoose(SpriteMaterial, _Material);
  16406. function SpriteMaterial(parameters) {
  16407. var _this;
  16408. _this = _Material.call(this) || this;
  16409. _this.type = 'SpriteMaterial';
  16410. _this.color = new Color(0xffffff);
  16411. _this.map = null;
  16412. _this.alphaMap = null;
  16413. _this.rotation = 0;
  16414. _this.sizeAttenuation = true;
  16415. _this.transparent = true;
  16416. _this.setValues(parameters);
  16417. return _this;
  16418. }
  16419. var _proto = SpriteMaterial.prototype;
  16420. _proto.copy = function copy(source) {
  16421. _Material.prototype.copy.call(this, source);
  16422. this.color.copy(source.color);
  16423. this.map = source.map;
  16424. this.alphaMap = source.alphaMap;
  16425. this.rotation = source.rotation;
  16426. this.sizeAttenuation = source.sizeAttenuation;
  16427. return this;
  16428. };
  16429. return SpriteMaterial;
  16430. }(Material);
  16431. SpriteMaterial.prototype.isSpriteMaterial = true;
  16432. var _geometry;
  16433. var _intersectPoint = /*@__PURE__*/new Vector3();
  16434. var _worldScale = /*@__PURE__*/new Vector3();
  16435. var _mvPosition = /*@__PURE__*/new Vector3();
  16436. var _alignedPosition = /*@__PURE__*/new Vector2();
  16437. var _rotatedPosition = /*@__PURE__*/new Vector2();
  16438. var _viewWorldMatrix = /*@__PURE__*/new Matrix4();
  16439. var _vA$1 = /*@__PURE__*/new Vector3();
  16440. var _vB$1 = /*@__PURE__*/new Vector3();
  16441. var _vC$1 = /*@__PURE__*/new Vector3();
  16442. var _uvA$1 = /*@__PURE__*/new Vector2();
  16443. var _uvB$1 = /*@__PURE__*/new Vector2();
  16444. var _uvC$1 = /*@__PURE__*/new Vector2();
  16445. var Sprite = /*#__PURE__*/function (_Object3D) {
  16446. _inheritsLoose(Sprite, _Object3D);
  16447. function Sprite(material) {
  16448. var _this;
  16449. _this = _Object3D.call(this) || this;
  16450. _this.type = 'Sprite';
  16451. if (_geometry === undefined) {
  16452. _geometry = new BufferGeometry();
  16453. 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]);
  16454. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  16455. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  16456. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  16457. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  16458. }
  16459. _this.geometry = _geometry;
  16460. _this.material = material !== undefined ? material : new SpriteMaterial();
  16461. _this.center = new Vector2(0.5, 0.5);
  16462. return _this;
  16463. }
  16464. var _proto = Sprite.prototype;
  16465. _proto.raycast = function raycast(raycaster, intersects) {
  16466. if (raycaster.camera === null) {
  16467. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  16468. }
  16469. _worldScale.setFromMatrixScale(this.matrixWorld);
  16470. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  16471. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  16472. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  16473. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  16474. _worldScale.multiplyScalar(-_mvPosition.z);
  16475. }
  16476. var rotation = this.material.rotation;
  16477. var sin, cos;
  16478. if (rotation !== 0) {
  16479. cos = Math.cos(rotation);
  16480. sin = Math.sin(rotation);
  16481. }
  16482. var center = this.center;
  16483. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16484. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16485. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16486. _uvA$1.set(0, 0);
  16487. _uvB$1.set(1, 0);
  16488. _uvC$1.set(1, 1); // check first triangle
  16489. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  16490. if (intersect === null) {
  16491. // check second triangle
  16492. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16493. _uvB$1.set(0, 1);
  16494. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  16495. if (intersect === null) {
  16496. return;
  16497. }
  16498. }
  16499. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  16500. if (distance < raycaster.near || distance > raycaster.far) return;
  16501. intersects.push({
  16502. distance: distance,
  16503. point: _intersectPoint.clone(),
  16504. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  16505. face: null,
  16506. object: this
  16507. });
  16508. };
  16509. _proto.copy = function copy(source) {
  16510. _Object3D.prototype.copy.call(this, source);
  16511. if (source.center !== undefined) this.center.copy(source.center);
  16512. this.material = source.material;
  16513. return this;
  16514. };
  16515. return Sprite;
  16516. }(Object3D);
  16517. Sprite.prototype.isSprite = true;
  16518. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  16519. // compute position in camera space
  16520. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  16521. if (sin !== undefined) {
  16522. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  16523. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  16524. } else {
  16525. _rotatedPosition.copy(_alignedPosition);
  16526. }
  16527. vertexPosition.copy(mvPosition);
  16528. vertexPosition.x += _rotatedPosition.x;
  16529. vertexPosition.y += _rotatedPosition.y; // transform to world space
  16530. vertexPosition.applyMatrix4(_viewWorldMatrix);
  16531. }
  16532. var _v1$4 = /*@__PURE__*/new Vector3();
  16533. var _v2$2 = /*@__PURE__*/new Vector3();
  16534. var LOD = /*#__PURE__*/function (_Object3D) {
  16535. _inheritsLoose(LOD, _Object3D);
  16536. function LOD() {
  16537. var _this;
  16538. _this = _Object3D.call(this) || this;
  16539. _this._currentLevel = 0;
  16540. _this.type = 'LOD';
  16541. Object.defineProperties(_assertThisInitialized(_this), {
  16542. levels: {
  16543. enumerable: true,
  16544. value: []
  16545. },
  16546. isLOD: {
  16547. value: true
  16548. }
  16549. });
  16550. _this.autoUpdate = true;
  16551. return _this;
  16552. }
  16553. var _proto = LOD.prototype;
  16554. _proto.copy = function copy(source) {
  16555. _Object3D.prototype.copy.call(this, source, false);
  16556. var levels = source.levels;
  16557. for (var i = 0, l = levels.length; i < l; i++) {
  16558. var level = levels[i];
  16559. this.addLevel(level.object.clone(), level.distance);
  16560. }
  16561. this.autoUpdate = source.autoUpdate;
  16562. return this;
  16563. };
  16564. _proto.addLevel = function addLevel(object, distance) {
  16565. if (distance === void 0) {
  16566. distance = 0;
  16567. }
  16568. distance = Math.abs(distance);
  16569. var levels = this.levels;
  16570. var l;
  16571. for (l = 0; l < levels.length; l++) {
  16572. if (distance < levels[l].distance) {
  16573. break;
  16574. }
  16575. }
  16576. levels.splice(l, 0, {
  16577. distance: distance,
  16578. object: object
  16579. });
  16580. this.add(object);
  16581. return this;
  16582. };
  16583. _proto.getCurrentLevel = function getCurrentLevel() {
  16584. return this._currentLevel;
  16585. };
  16586. _proto.getObjectForDistance = function getObjectForDistance(distance) {
  16587. var levels = this.levels;
  16588. if (levels.length > 0) {
  16589. var i, l;
  16590. for (i = 1, l = levels.length; i < l; i++) {
  16591. if (distance < levels[i].distance) {
  16592. break;
  16593. }
  16594. }
  16595. return levels[i - 1].object;
  16596. }
  16597. return null;
  16598. };
  16599. _proto.raycast = function raycast(raycaster, intersects) {
  16600. var levels = this.levels;
  16601. if (levels.length > 0) {
  16602. _v1$4.setFromMatrixPosition(this.matrixWorld);
  16603. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  16604. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  16605. }
  16606. };
  16607. _proto.update = function update(camera) {
  16608. var levels = this.levels;
  16609. if (levels.length > 1) {
  16610. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  16611. _v2$2.setFromMatrixPosition(this.matrixWorld);
  16612. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  16613. levels[0].object.visible = true;
  16614. var i, l;
  16615. for (i = 1, l = levels.length; i < l; i++) {
  16616. if (distance >= levels[i].distance) {
  16617. levels[i - 1].object.visible = false;
  16618. levels[i].object.visible = true;
  16619. } else {
  16620. break;
  16621. }
  16622. }
  16623. this._currentLevel = i - 1;
  16624. for (; i < l; i++) {
  16625. levels[i].object.visible = false;
  16626. }
  16627. }
  16628. };
  16629. _proto.toJSON = function toJSON(meta) {
  16630. var data = _Object3D.prototype.toJSON.call(this, meta);
  16631. if (this.autoUpdate === false) data.object.autoUpdate = false;
  16632. data.object.levels = [];
  16633. var levels = this.levels;
  16634. for (var i = 0, l = levels.length; i < l; i++) {
  16635. var level = levels[i];
  16636. data.object.levels.push({
  16637. object: level.object.uuid,
  16638. distance: level.distance
  16639. });
  16640. }
  16641. return data;
  16642. };
  16643. return LOD;
  16644. }(Object3D);
  16645. var _basePosition = new Vector3();
  16646. var _skinIndex = new Vector4();
  16647. var _skinWeight = new Vector4();
  16648. var _vector$7 = new Vector3();
  16649. var _matrix$1 = new Matrix4();
  16650. function SkinnedMesh(geometry, material) {
  16651. Mesh.call(this, geometry, material);
  16652. this.type = 'SkinnedMesh';
  16653. this.bindMode = 'attached';
  16654. this.bindMatrix = new Matrix4();
  16655. this.bindMatrixInverse = new Matrix4();
  16656. }
  16657. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16658. constructor: SkinnedMesh,
  16659. isSkinnedMesh: true,
  16660. copy: function copy(source) {
  16661. Mesh.prototype.copy.call(this, source);
  16662. this.bindMode = source.bindMode;
  16663. this.bindMatrix.copy(source.bindMatrix);
  16664. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  16665. this.skeleton = source.skeleton;
  16666. return this;
  16667. },
  16668. bind: function bind(skeleton, bindMatrix) {
  16669. this.skeleton = skeleton;
  16670. if (bindMatrix === undefined) {
  16671. this.updateMatrixWorld(true);
  16672. this.skeleton.calculateInverses();
  16673. bindMatrix = this.matrixWorld;
  16674. }
  16675. this.bindMatrix.copy(bindMatrix);
  16676. this.bindMatrixInverse.copy(bindMatrix).invert();
  16677. },
  16678. pose: function pose() {
  16679. this.skeleton.pose();
  16680. },
  16681. normalizeSkinWeights: function normalizeSkinWeights() {
  16682. var vector = new Vector4();
  16683. var skinWeight = this.geometry.attributes.skinWeight;
  16684. for (var i = 0, l = skinWeight.count; i < l; i++) {
  16685. vector.x = skinWeight.getX(i);
  16686. vector.y = skinWeight.getY(i);
  16687. vector.z = skinWeight.getZ(i);
  16688. vector.w = skinWeight.getW(i);
  16689. var scale = 1.0 / vector.manhattanLength();
  16690. if (scale !== Infinity) {
  16691. vector.multiplyScalar(scale);
  16692. } else {
  16693. vector.set(1, 0, 0, 0); // do something reasonable
  16694. }
  16695. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  16696. }
  16697. },
  16698. updateMatrixWorld: function updateMatrixWorld(force) {
  16699. Mesh.prototype.updateMatrixWorld.call(this, force);
  16700. if (this.bindMode === 'attached') {
  16701. this.bindMatrixInverse.copy(this.matrixWorld).invert();
  16702. } else if (this.bindMode === 'detached') {
  16703. this.bindMatrixInverse.copy(this.bindMatrix).invert();
  16704. } else {
  16705. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  16706. }
  16707. },
  16708. boneTransform: function boneTransform(index, target) {
  16709. var skeleton = this.skeleton;
  16710. var geometry = this.geometry;
  16711. _skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  16712. _skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  16713. _basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  16714. target.set(0, 0, 0);
  16715. for (var i = 0; i < 4; i++) {
  16716. var weight = _skinWeight.getComponent(i);
  16717. if (weight !== 0) {
  16718. var boneIndex = _skinIndex.getComponent(i);
  16719. _matrix$1.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  16720. target.addScaledVector(_vector$7.copy(_basePosition).applyMatrix4(_matrix$1), weight);
  16721. }
  16722. }
  16723. return target.applyMatrix4(this.bindMatrixInverse);
  16724. }
  16725. });
  16726. function Bone() {
  16727. Object3D.call(this);
  16728. this.type = 'Bone';
  16729. }
  16730. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  16731. constructor: Bone,
  16732. isBone: true
  16733. });
  16734. var _offsetMatrix = /*@__PURE__*/new Matrix4();
  16735. var _identityMatrix = /*@__PURE__*/new Matrix4();
  16736. var Skeleton = /*#__PURE__*/function () {
  16737. function Skeleton(bones, boneInverses) {
  16738. if (bones === void 0) {
  16739. bones = [];
  16740. }
  16741. if (boneInverses === void 0) {
  16742. boneInverses = [];
  16743. }
  16744. this.uuid = MathUtils.generateUUID();
  16745. this.bones = bones.slice(0);
  16746. this.boneInverses = boneInverses;
  16747. this.boneMatrices = null;
  16748. this.boneTexture = null;
  16749. this.boneTextureSize = 0;
  16750. this.frame = -1;
  16751. this.init();
  16752. }
  16753. var _proto = Skeleton.prototype;
  16754. _proto.init = function init() {
  16755. var bones = this.bones;
  16756. var boneInverses = this.boneInverses;
  16757. this.boneMatrices = new Float32Array(bones.length * 16); // calculate inverse bone matrices if necessary
  16758. if (boneInverses.length === 0) {
  16759. this.calculateInverses();
  16760. } else {
  16761. // handle special case
  16762. if (bones.length !== boneInverses.length) {
  16763. console.warn('THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.');
  16764. this.boneInverses = [];
  16765. for (var i = 0, il = this.bones.length; i < il; i++) {
  16766. this.boneInverses.push(new Matrix4());
  16767. }
  16768. }
  16769. }
  16770. };
  16771. _proto.calculateInverses = function calculateInverses() {
  16772. this.boneInverses.length = 0;
  16773. for (var i = 0, il = this.bones.length; i < il; i++) {
  16774. var inverse = new Matrix4();
  16775. if (this.bones[i]) {
  16776. inverse.copy(this.bones[i].matrixWorld).invert();
  16777. }
  16778. this.boneInverses.push(inverse);
  16779. }
  16780. };
  16781. _proto.pose = function pose() {
  16782. // recover the bind-time world matrices
  16783. for (var i = 0, il = this.bones.length; i < il; i++) {
  16784. var bone = this.bones[i];
  16785. if (bone) {
  16786. bone.matrixWorld.copy(this.boneInverses[i]).invert();
  16787. }
  16788. } // compute the local matrices, positions, rotations and scales
  16789. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  16790. var _bone = this.bones[_i];
  16791. if (_bone) {
  16792. if (_bone.parent && _bone.parent.isBone) {
  16793. _bone.matrix.copy(_bone.parent.matrixWorld).invert();
  16794. _bone.matrix.multiply(_bone.matrixWorld);
  16795. } else {
  16796. _bone.matrix.copy(_bone.matrixWorld);
  16797. }
  16798. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  16799. }
  16800. }
  16801. };
  16802. _proto.update = function update() {
  16803. var bones = this.bones;
  16804. var boneInverses = this.boneInverses;
  16805. var boneMatrices = this.boneMatrices;
  16806. var boneTexture = this.boneTexture; // flatten bone matrices to array
  16807. for (var i = 0, il = bones.length; i < il; i++) {
  16808. // compute the offset between the current and the original transform
  16809. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  16810. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  16811. _offsetMatrix.toArray(boneMatrices, i * 16);
  16812. }
  16813. if (boneTexture !== null) {
  16814. boneTexture.needsUpdate = true;
  16815. }
  16816. };
  16817. _proto.clone = function clone() {
  16818. return new Skeleton(this.bones, this.boneInverses);
  16819. };
  16820. _proto.getBoneByName = function getBoneByName(name) {
  16821. for (var i = 0, il = this.bones.length; i < il; i++) {
  16822. var bone = this.bones[i];
  16823. if (bone.name === name) {
  16824. return bone;
  16825. }
  16826. }
  16827. return undefined;
  16828. };
  16829. _proto.dispose = function dispose() {
  16830. if (this.boneTexture !== null) {
  16831. this.boneTexture.dispose();
  16832. this.boneTexture = null;
  16833. }
  16834. };
  16835. _proto.fromJSON = function fromJSON(json, bones) {
  16836. this.uuid = json.uuid;
  16837. for (var i = 0, l = json.bones.length; i < l; i++) {
  16838. var uuid = json.bones[i];
  16839. var bone = bones[uuid];
  16840. if (bone === undefined) {
  16841. console.warn('THREE.Skeleton: No bone found with UUID:', uuid);
  16842. bone = new Bone();
  16843. }
  16844. this.bones.push(bone);
  16845. this.boneInverses.push(new Matrix4().fromArray(json.boneInverses[i]));
  16846. }
  16847. this.init();
  16848. return this;
  16849. };
  16850. _proto.toJSON = function toJSON() {
  16851. var data = {
  16852. metadata: {
  16853. version: 4.5,
  16854. type: 'Skeleton',
  16855. generator: 'Skeleton.toJSON'
  16856. },
  16857. bones: [],
  16858. boneInverses: []
  16859. };
  16860. data.uuid = this.uuid;
  16861. var bones = this.bones;
  16862. var boneInverses = this.boneInverses;
  16863. for (var i = 0, l = bones.length; i < l; i++) {
  16864. var bone = bones[i];
  16865. data.bones.push(bone.uuid);
  16866. var boneInverse = boneInverses[i];
  16867. data.boneInverses.push(boneInverse.toArray());
  16868. }
  16869. return data;
  16870. };
  16871. return Skeleton;
  16872. }();
  16873. var _instanceLocalMatrix = new Matrix4();
  16874. var _instanceWorldMatrix = new Matrix4();
  16875. var _instanceIntersects = [];
  16876. var _mesh = new Mesh();
  16877. function InstancedMesh(geometry, material, count) {
  16878. Mesh.call(this, geometry, material);
  16879. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  16880. this.instanceColor = null;
  16881. this.count = count;
  16882. this.frustumCulled = false;
  16883. }
  16884. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16885. constructor: InstancedMesh,
  16886. isInstancedMesh: true,
  16887. copy: function copy(source) {
  16888. Mesh.prototype.copy.call(this, source);
  16889. this.instanceMatrix.copy(source.instanceMatrix);
  16890. if (source.instanceColor !== null) this.instanceColor = source.instanceColor.clone();
  16891. this.count = source.count;
  16892. return this;
  16893. },
  16894. getColorAt: function getColorAt(index, color) {
  16895. color.fromArray(this.instanceColor.array, index * 3);
  16896. },
  16897. getMatrixAt: function getMatrixAt(index, matrix) {
  16898. matrix.fromArray(this.instanceMatrix.array, index * 16);
  16899. },
  16900. raycast: function raycast(raycaster, intersects) {
  16901. var matrixWorld = this.matrixWorld;
  16902. var raycastTimes = this.count;
  16903. _mesh.geometry = this.geometry;
  16904. _mesh.material = this.material;
  16905. if (_mesh.material === undefined) return;
  16906. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  16907. // calculate the world matrix for each instance
  16908. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  16909. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  16910. _mesh.matrixWorld = _instanceWorldMatrix;
  16911. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  16912. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  16913. var intersect = _instanceIntersects[i];
  16914. intersect.instanceId = instanceId;
  16915. intersect.object = this;
  16916. intersects.push(intersect);
  16917. }
  16918. _instanceIntersects.length = 0;
  16919. }
  16920. },
  16921. setColorAt: function setColorAt(index, color) {
  16922. if (this.instanceColor === null) {
  16923. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  16924. }
  16925. color.toArray(this.instanceColor.array, index * 3);
  16926. },
  16927. setMatrixAt: function setMatrixAt(index, matrix) {
  16928. matrix.toArray(this.instanceMatrix.array, index * 16);
  16929. },
  16930. updateMorphTargets: function updateMorphTargets() {},
  16931. dispose: function dispose() {
  16932. this.dispatchEvent({
  16933. type: 'dispose'
  16934. });
  16935. }
  16936. });
  16937. /**
  16938. * parameters = {
  16939. * color: <hex>,
  16940. * opacity: <float>,
  16941. *
  16942. * linewidth: <float>,
  16943. * linecap: "round",
  16944. * linejoin: "round"
  16945. * }
  16946. */
  16947. var LineBasicMaterial = /*#__PURE__*/function (_Material) {
  16948. _inheritsLoose(LineBasicMaterial, _Material);
  16949. function LineBasicMaterial(parameters) {
  16950. var _this;
  16951. _this = _Material.call(this) || this;
  16952. _this.type = 'LineBasicMaterial';
  16953. _this.color = new Color(0xffffff);
  16954. _this.linewidth = 1;
  16955. _this.linecap = 'round';
  16956. _this.linejoin = 'round';
  16957. _this.morphTargets = false;
  16958. _this.setValues(parameters);
  16959. return _this;
  16960. }
  16961. var _proto = LineBasicMaterial.prototype;
  16962. _proto.copy = function copy(source) {
  16963. _Material.prototype.copy.call(this, source);
  16964. this.color.copy(source.color);
  16965. this.linewidth = source.linewidth;
  16966. this.linecap = source.linecap;
  16967. this.linejoin = source.linejoin;
  16968. this.morphTargets = source.morphTargets;
  16969. return this;
  16970. };
  16971. return LineBasicMaterial;
  16972. }(Material);
  16973. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16974. var _start = new Vector3();
  16975. var _end = new Vector3();
  16976. var _inverseMatrix$1 = new Matrix4();
  16977. var _ray$1 = new Ray();
  16978. var _sphere$2 = new Sphere();
  16979. function Line(geometry, material) {
  16980. if (geometry === void 0) {
  16981. geometry = new BufferGeometry();
  16982. }
  16983. if (material === void 0) {
  16984. material = new LineBasicMaterial();
  16985. }
  16986. Object3D.call(this);
  16987. this.type = 'Line';
  16988. this.geometry = geometry;
  16989. this.material = material;
  16990. this.updateMorphTargets();
  16991. }
  16992. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  16993. constructor: Line,
  16994. isLine: true,
  16995. copy: function copy(source) {
  16996. Object3D.prototype.copy.call(this, source);
  16997. this.material = source.material;
  16998. this.geometry = source.geometry;
  16999. return this;
  17000. },
  17001. computeLineDistances: function computeLineDistances() {
  17002. var geometry = this.geometry;
  17003. if (geometry.isBufferGeometry) {
  17004. // we assume non-indexed geometry
  17005. if (geometry.index === null) {
  17006. var positionAttribute = geometry.attributes.position;
  17007. var lineDistances = [0];
  17008. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  17009. _start.fromBufferAttribute(positionAttribute, i - 1);
  17010. _end.fromBufferAttribute(positionAttribute, i);
  17011. lineDistances[i] = lineDistances[i - 1];
  17012. lineDistances[i] += _start.distanceTo(_end);
  17013. }
  17014. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  17015. } else {
  17016. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  17017. }
  17018. } else if (geometry.isGeometry) {
  17019. console.error('THREE.Line.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17020. }
  17021. return this;
  17022. },
  17023. raycast: function raycast(raycaster, intersects) {
  17024. var geometry = this.geometry;
  17025. var matrixWorld = this.matrixWorld;
  17026. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  17027. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  17028. _sphere$2.copy(geometry.boundingSphere);
  17029. _sphere$2.applyMatrix4(matrixWorld);
  17030. _sphere$2.radius += threshold;
  17031. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  17032. _inverseMatrix$1.copy(matrixWorld).invert();
  17033. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  17034. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  17035. var localThresholdSq = localThreshold * localThreshold;
  17036. var vStart = new Vector3();
  17037. var vEnd = new Vector3();
  17038. var interSegment = new Vector3();
  17039. var interRay = new Vector3();
  17040. var step = this.isLineSegments ? 2 : 1;
  17041. if (geometry.isBufferGeometry) {
  17042. var index = geometry.index;
  17043. var attributes = geometry.attributes;
  17044. var positionAttribute = attributes.position;
  17045. if (index !== null) {
  17046. var indices = index.array;
  17047. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  17048. var a = indices[i];
  17049. var b = indices[i + 1];
  17050. vStart.fromBufferAttribute(positionAttribute, a);
  17051. vEnd.fromBufferAttribute(positionAttribute, b);
  17052. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  17053. if (distSq > localThresholdSq) continue;
  17054. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  17055. var distance = raycaster.ray.origin.distanceTo(interRay);
  17056. if (distance < raycaster.near || distance > raycaster.far) continue;
  17057. intersects.push({
  17058. distance: distance,
  17059. // What do we want? intersection point on the ray or on the segment??
  17060. // point: raycaster.ray.at( distance ),
  17061. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  17062. index: i,
  17063. face: null,
  17064. faceIndex: null,
  17065. object: this
  17066. });
  17067. }
  17068. } else {
  17069. for (var _i = 0, _l = positionAttribute.count - 1; _i < _l; _i += step) {
  17070. vStart.fromBufferAttribute(positionAttribute, _i);
  17071. vEnd.fromBufferAttribute(positionAttribute, _i + 1);
  17072. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  17073. if (_distSq > localThresholdSq) continue;
  17074. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  17075. var _distance = raycaster.ray.origin.distanceTo(interRay);
  17076. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  17077. intersects.push({
  17078. distance: _distance,
  17079. // What do we want? intersection point on the ray or on the segment??
  17080. // point: raycaster.ray.at( distance ),
  17081. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  17082. index: _i,
  17083. face: null,
  17084. faceIndex: null,
  17085. object: this
  17086. });
  17087. }
  17088. }
  17089. } else if (geometry.isGeometry) {
  17090. console.error('THREE.Line.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17091. }
  17092. },
  17093. updateMorphTargets: function updateMorphTargets() {
  17094. var geometry = this.geometry;
  17095. if (geometry.isBufferGeometry) {
  17096. var morphAttributes = geometry.morphAttributes;
  17097. var keys = Object.keys(morphAttributes);
  17098. if (keys.length > 0) {
  17099. var morphAttribute = morphAttributes[keys[0]];
  17100. if (morphAttribute !== undefined) {
  17101. this.morphTargetInfluences = [];
  17102. this.morphTargetDictionary = {};
  17103. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  17104. var name = morphAttribute[m].name || String(m);
  17105. this.morphTargetInfluences.push(0);
  17106. this.morphTargetDictionary[name] = m;
  17107. }
  17108. }
  17109. }
  17110. } else {
  17111. var morphTargets = geometry.morphTargets;
  17112. if (morphTargets !== undefined && morphTargets.length > 0) {
  17113. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  17114. }
  17115. }
  17116. }
  17117. });
  17118. var _start$1 = new Vector3();
  17119. var _end$1 = new Vector3();
  17120. function LineSegments(geometry, material) {
  17121. Line.call(this, geometry, material);
  17122. this.type = 'LineSegments';
  17123. }
  17124. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  17125. constructor: LineSegments,
  17126. isLineSegments: true,
  17127. computeLineDistances: function computeLineDistances() {
  17128. var geometry = this.geometry;
  17129. if (geometry.isBufferGeometry) {
  17130. // we assume non-indexed geometry
  17131. if (geometry.index === null) {
  17132. var positionAttribute = geometry.attributes.position;
  17133. var lineDistances = [];
  17134. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  17135. _start$1.fromBufferAttribute(positionAttribute, i);
  17136. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  17137. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  17138. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  17139. }
  17140. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  17141. } else {
  17142. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  17143. }
  17144. } else if (geometry.isGeometry) {
  17145. console.error('THREE.LineSegments.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17146. }
  17147. return this;
  17148. }
  17149. });
  17150. var LineLoop = /*#__PURE__*/function (_Line) {
  17151. _inheritsLoose(LineLoop, _Line);
  17152. function LineLoop(geometry, material) {
  17153. var _this;
  17154. _this = _Line.call(this, geometry, material) || this;
  17155. _this.type = 'LineLoop';
  17156. return _this;
  17157. }
  17158. return LineLoop;
  17159. }(Line);
  17160. LineLoop.prototype.isLineLoop = true;
  17161. /**
  17162. * parameters = {
  17163. * color: <hex>,
  17164. * opacity: <float>,
  17165. * map: new THREE.Texture( <Image> ),
  17166. * alphaMap: new THREE.Texture( <Image> ),
  17167. *
  17168. * size: <float>,
  17169. * sizeAttenuation: <bool>
  17170. *
  17171. * morphTargets: <bool>
  17172. * }
  17173. */
  17174. var PointsMaterial = /*#__PURE__*/function (_Material) {
  17175. _inheritsLoose(PointsMaterial, _Material);
  17176. function PointsMaterial(parameters) {
  17177. var _this;
  17178. _this = _Material.call(this) || this;
  17179. _this.type = 'PointsMaterial';
  17180. _this.color = new Color(0xffffff);
  17181. _this.map = null;
  17182. _this.alphaMap = null;
  17183. _this.size = 1;
  17184. _this.sizeAttenuation = true;
  17185. _this.morphTargets = false;
  17186. _this.setValues(parameters);
  17187. return _this;
  17188. }
  17189. var _proto = PointsMaterial.prototype;
  17190. _proto.copy = function copy(source) {
  17191. _Material.prototype.copy.call(this, source);
  17192. this.color.copy(source.color);
  17193. this.map = source.map;
  17194. this.alphaMap = source.alphaMap;
  17195. this.size = source.size;
  17196. this.sizeAttenuation = source.sizeAttenuation;
  17197. this.morphTargets = source.morphTargets;
  17198. return this;
  17199. };
  17200. return PointsMaterial;
  17201. }(Material);
  17202. PointsMaterial.prototype.isPointsMaterial = true;
  17203. var _inverseMatrix$2 = new Matrix4();
  17204. var _ray$2 = new Ray();
  17205. var _sphere$3 = new Sphere();
  17206. var _position$1 = new Vector3();
  17207. function Points(geometry, material) {
  17208. if (geometry === void 0) {
  17209. geometry = new BufferGeometry();
  17210. }
  17211. if (material === void 0) {
  17212. material = new PointsMaterial();
  17213. }
  17214. Object3D.call(this);
  17215. this.type = 'Points';
  17216. this.geometry = geometry;
  17217. this.material = material;
  17218. this.updateMorphTargets();
  17219. }
  17220. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  17221. constructor: Points,
  17222. isPoints: true,
  17223. copy: function copy(source) {
  17224. Object3D.prototype.copy.call(this, source);
  17225. this.material = source.material;
  17226. this.geometry = source.geometry;
  17227. return this;
  17228. },
  17229. raycast: function raycast(raycaster, intersects) {
  17230. var geometry = this.geometry;
  17231. var matrixWorld = this.matrixWorld;
  17232. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  17233. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  17234. _sphere$3.copy(geometry.boundingSphere);
  17235. _sphere$3.applyMatrix4(matrixWorld);
  17236. _sphere$3.radius += threshold;
  17237. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  17238. _inverseMatrix$2.copy(matrixWorld).invert();
  17239. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  17240. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  17241. var localThresholdSq = localThreshold * localThreshold;
  17242. if (geometry.isBufferGeometry) {
  17243. var index = geometry.index;
  17244. var attributes = geometry.attributes;
  17245. var positionAttribute = attributes.position;
  17246. if (index !== null) {
  17247. var indices = index.array;
  17248. for (var i = 0, il = indices.length; i < il; i++) {
  17249. var a = indices[i];
  17250. _position$1.fromBufferAttribute(positionAttribute, a);
  17251. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  17252. }
  17253. } else {
  17254. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  17255. _position$1.fromBufferAttribute(positionAttribute, _i);
  17256. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  17257. }
  17258. }
  17259. } else {
  17260. console.error('THREE.Points.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17261. }
  17262. },
  17263. updateMorphTargets: function updateMorphTargets() {
  17264. var geometry = this.geometry;
  17265. if (geometry.isBufferGeometry) {
  17266. var morphAttributes = geometry.morphAttributes;
  17267. var keys = Object.keys(morphAttributes);
  17268. if (keys.length > 0) {
  17269. var morphAttribute = morphAttributes[keys[0]];
  17270. if (morphAttribute !== undefined) {
  17271. this.morphTargetInfluences = [];
  17272. this.morphTargetDictionary = {};
  17273. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  17274. var name = morphAttribute[m].name || String(m);
  17275. this.morphTargetInfluences.push(0);
  17276. this.morphTargetDictionary[name] = m;
  17277. }
  17278. }
  17279. }
  17280. } else {
  17281. var morphTargets = geometry.morphTargets;
  17282. if (morphTargets !== undefined && morphTargets.length > 0) {
  17283. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  17284. }
  17285. }
  17286. }
  17287. });
  17288. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  17289. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  17290. if (rayPointDistanceSq < localThresholdSq) {
  17291. var intersectPoint = new Vector3();
  17292. _ray$2.closestPointToPoint(point, intersectPoint);
  17293. intersectPoint.applyMatrix4(matrixWorld);
  17294. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  17295. if (distance < raycaster.near || distance > raycaster.far) return;
  17296. intersects.push({
  17297. distance: distance,
  17298. distanceToRay: Math.sqrt(rayPointDistanceSq),
  17299. point: intersectPoint,
  17300. index: index,
  17301. face: null,
  17302. object: object
  17303. });
  17304. }
  17305. }
  17306. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  17307. Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17308. this.format = format !== undefined ? format : RGBFormat;
  17309. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  17310. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  17311. this.generateMipmaps = false;
  17312. var scope = this;
  17313. function updateVideo() {
  17314. scope.needsUpdate = true;
  17315. video.requestVideoFrameCallback(updateVideo);
  17316. }
  17317. if ('requestVideoFrameCallback' in video) {
  17318. video.requestVideoFrameCallback(updateVideo);
  17319. }
  17320. }
  17321. VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
  17322. constructor: VideoTexture,
  17323. clone: function clone() {
  17324. return new this.constructor(this.image).copy(this);
  17325. },
  17326. isVideoTexture: true,
  17327. update: function update() {
  17328. var video = this.image;
  17329. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  17330. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  17331. this.needsUpdate = true;
  17332. }
  17333. }
  17334. });
  17335. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  17336. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  17337. this.image = {
  17338. width: width,
  17339. height: height
  17340. };
  17341. this.mipmaps = mipmaps; // no flipping for cube textures
  17342. // (also flipping doesn't work for compressed textures )
  17343. this.flipY = false; // can't generate mipmaps for compressed textures
  17344. // mips must be embedded in DDS files
  17345. this.generateMipmaps = false;
  17346. }
  17347. CompressedTexture.prototype = Object.create(Texture.prototype);
  17348. CompressedTexture.prototype.constructor = CompressedTexture;
  17349. CompressedTexture.prototype.isCompressedTexture = true;
  17350. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  17351. Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17352. this.needsUpdate = true;
  17353. }
  17354. CanvasTexture.prototype = Object.create(Texture.prototype);
  17355. CanvasTexture.prototype.constructor = CanvasTexture;
  17356. CanvasTexture.prototype.isCanvasTexture = true;
  17357. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  17358. format = format !== undefined ? format : DepthFormat;
  17359. if (format !== DepthFormat && format !== DepthStencilFormat) {
  17360. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  17361. }
  17362. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  17363. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  17364. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17365. this.image = {
  17366. width: width,
  17367. height: height
  17368. };
  17369. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  17370. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  17371. this.flipY = false;
  17372. this.generateMipmaps = false;
  17373. }
  17374. DepthTexture.prototype = Object.create(Texture.prototype);
  17375. DepthTexture.prototype.constructor = DepthTexture;
  17376. DepthTexture.prototype.isDepthTexture = true;
  17377. var CircleGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17378. _inheritsLoose(CircleGeometry, _BufferGeometry);
  17379. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  17380. var _this;
  17381. if (radius === void 0) {
  17382. radius = 1;
  17383. }
  17384. if (segments === void 0) {
  17385. segments = 8;
  17386. }
  17387. if (thetaStart === void 0) {
  17388. thetaStart = 0;
  17389. }
  17390. if (thetaLength === void 0) {
  17391. thetaLength = Math.PI * 2;
  17392. }
  17393. _this = _BufferGeometry.call(this) || this;
  17394. _this.type = 'CircleGeometry';
  17395. _this.parameters = {
  17396. radius: radius,
  17397. segments: segments,
  17398. thetaStart: thetaStart,
  17399. thetaLength: thetaLength
  17400. };
  17401. segments = Math.max(3, segments); // buffers
  17402. var indices = [];
  17403. var vertices = [];
  17404. var normals = [];
  17405. var uvs = []; // helper variables
  17406. var vertex = new Vector3();
  17407. var uv = new Vector2(); // center point
  17408. vertices.push(0, 0, 0);
  17409. normals.push(0, 0, 1);
  17410. uvs.push(0.5, 0.5);
  17411. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  17412. var segment = thetaStart + s / segments * thetaLength; // vertex
  17413. vertex.x = radius * Math.cos(segment);
  17414. vertex.y = radius * Math.sin(segment);
  17415. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17416. normals.push(0, 0, 1); // uvs
  17417. uv.x = (vertices[i] / radius + 1) / 2;
  17418. uv.y = (vertices[i + 1] / radius + 1) / 2;
  17419. uvs.push(uv.x, uv.y);
  17420. } // indices
  17421. for (var _i = 1; _i <= segments; _i++) {
  17422. indices.push(_i, _i + 1, 0);
  17423. } // build geometry
  17424. _this.setIndex(indices);
  17425. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17426. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17427. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17428. return _this;
  17429. }
  17430. return CircleGeometry;
  17431. }(BufferGeometry);
  17432. var CylinderGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17433. _inheritsLoose(CylinderGeometry, _BufferGeometry);
  17434. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17435. var _this;
  17436. if (radiusTop === void 0) {
  17437. radiusTop = 1;
  17438. }
  17439. if (radiusBottom === void 0) {
  17440. radiusBottom = 1;
  17441. }
  17442. if (height === void 0) {
  17443. height = 1;
  17444. }
  17445. if (radialSegments === void 0) {
  17446. radialSegments = 8;
  17447. }
  17448. if (heightSegments === void 0) {
  17449. heightSegments = 1;
  17450. }
  17451. if (openEnded === void 0) {
  17452. openEnded = false;
  17453. }
  17454. if (thetaStart === void 0) {
  17455. thetaStart = 0;
  17456. }
  17457. if (thetaLength === void 0) {
  17458. thetaLength = Math.PI * 2;
  17459. }
  17460. _this = _BufferGeometry.call(this) || this;
  17461. _this.type = 'CylinderGeometry';
  17462. _this.parameters = {
  17463. radiusTop: radiusTop,
  17464. radiusBottom: radiusBottom,
  17465. height: height,
  17466. radialSegments: radialSegments,
  17467. heightSegments: heightSegments,
  17468. openEnded: openEnded,
  17469. thetaStart: thetaStart,
  17470. thetaLength: thetaLength
  17471. };
  17472. var scope = _assertThisInitialized(_this);
  17473. radialSegments = Math.floor(radialSegments);
  17474. heightSegments = Math.floor(heightSegments); // buffers
  17475. var indices = [];
  17476. var vertices = [];
  17477. var normals = [];
  17478. var uvs = []; // helper variables
  17479. var index = 0;
  17480. var indexArray = [];
  17481. var halfHeight = height / 2;
  17482. var groupStart = 0; // generate geometry
  17483. generateTorso();
  17484. if (openEnded === false) {
  17485. if (radiusTop > 0) generateCap(true);
  17486. if (radiusBottom > 0) generateCap(false);
  17487. } // build geometry
  17488. _this.setIndex(indices);
  17489. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17490. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17491. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17492. function generateTorso() {
  17493. var normal = new Vector3();
  17494. var vertex = new Vector3();
  17495. var groupCount = 0; // this will be used to calculate the normal
  17496. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  17497. for (var y = 0; y <= heightSegments; y++) {
  17498. var indexRow = [];
  17499. var v = y / heightSegments; // calculate the radius of the current row
  17500. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  17501. for (var x = 0; x <= radialSegments; x++) {
  17502. var u = x / radialSegments;
  17503. var theta = u * thetaLength + thetaStart;
  17504. var sinTheta = Math.sin(theta);
  17505. var cosTheta = Math.cos(theta); // vertex
  17506. vertex.x = radius * sinTheta;
  17507. vertex.y = -v * height + halfHeight;
  17508. vertex.z = radius * cosTheta;
  17509. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17510. normal.set(sinTheta, slope, cosTheta).normalize();
  17511. normals.push(normal.x, normal.y, normal.z); // uv
  17512. uvs.push(u, 1 - v); // save index of vertex in respective row
  17513. indexRow.push(index++);
  17514. } // now save vertices of the row in our index array
  17515. indexArray.push(indexRow);
  17516. } // generate indices
  17517. for (var _x = 0; _x < radialSegments; _x++) {
  17518. for (var _y = 0; _y < heightSegments; _y++) {
  17519. // we use the index array to access the correct indices
  17520. var a = indexArray[_y][_x];
  17521. var b = indexArray[_y + 1][_x];
  17522. var c = indexArray[_y + 1][_x + 1];
  17523. var d = indexArray[_y][_x + 1]; // faces
  17524. indices.push(a, b, d);
  17525. indices.push(b, c, d); // update group counter
  17526. groupCount += 6;
  17527. }
  17528. } // add a group to the geometry. this will ensure multi material support
  17529. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  17530. groupStart += groupCount;
  17531. }
  17532. function generateCap(top) {
  17533. // save the index of the first center vertex
  17534. var centerIndexStart = index;
  17535. var uv = new Vector2();
  17536. var vertex = new Vector3();
  17537. var groupCount = 0;
  17538. var radius = top === true ? radiusTop : radiusBottom;
  17539. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  17540. // because the geometry needs one set of uvs per face,
  17541. // we must generate a center vertex per face/segment
  17542. for (var x = 1; x <= radialSegments; x++) {
  17543. // vertex
  17544. vertices.push(0, halfHeight * sign, 0); // normal
  17545. normals.push(0, sign, 0); // uv
  17546. uvs.push(0.5, 0.5); // increase index
  17547. index++;
  17548. } // save the index of the last center vertex
  17549. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  17550. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  17551. var u = _x2 / radialSegments;
  17552. var theta = u * thetaLength + thetaStart;
  17553. var cosTheta = Math.cos(theta);
  17554. var sinTheta = Math.sin(theta); // vertex
  17555. vertex.x = radius * sinTheta;
  17556. vertex.y = halfHeight * sign;
  17557. vertex.z = radius * cosTheta;
  17558. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17559. normals.push(0, sign, 0); // uv
  17560. uv.x = cosTheta * 0.5 + 0.5;
  17561. uv.y = sinTheta * 0.5 * sign + 0.5;
  17562. uvs.push(uv.x, uv.y); // increase index
  17563. index++;
  17564. } // generate indices
  17565. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  17566. var c = centerIndexStart + _x3;
  17567. var i = centerIndexEnd + _x3;
  17568. if (top === true) {
  17569. // face top
  17570. indices.push(i, i + 1, c);
  17571. } else {
  17572. // face bottom
  17573. indices.push(i + 1, i, c);
  17574. }
  17575. groupCount += 3;
  17576. } // add a group to the geometry. this will ensure multi material support
  17577. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  17578. groupStart += groupCount;
  17579. }
  17580. return _this;
  17581. }
  17582. return CylinderGeometry;
  17583. }(BufferGeometry);
  17584. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  17585. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  17586. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17587. var _this;
  17588. if (radius === void 0) {
  17589. radius = 1;
  17590. }
  17591. if (height === void 0) {
  17592. height = 1;
  17593. }
  17594. if (radialSegments === void 0) {
  17595. radialSegments = 8;
  17596. }
  17597. if (heightSegments === void 0) {
  17598. heightSegments = 1;
  17599. }
  17600. if (openEnded === void 0) {
  17601. openEnded = false;
  17602. }
  17603. if (thetaStart === void 0) {
  17604. thetaStart = 0;
  17605. }
  17606. if (thetaLength === void 0) {
  17607. thetaLength = Math.PI * 2;
  17608. }
  17609. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17610. _this.type = 'ConeGeometry';
  17611. _this.parameters = {
  17612. radius: radius,
  17613. height: height,
  17614. radialSegments: radialSegments,
  17615. heightSegments: heightSegments,
  17616. openEnded: openEnded,
  17617. thetaStart: thetaStart,
  17618. thetaLength: thetaLength
  17619. };
  17620. return _this;
  17621. }
  17622. return ConeGeometry;
  17623. }(CylinderGeometry);
  17624. var PolyhedronGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17625. _inheritsLoose(PolyhedronGeometry, _BufferGeometry);
  17626. function PolyhedronGeometry(vertices, indices, radius, detail) {
  17627. var _this;
  17628. if (radius === void 0) {
  17629. radius = 1;
  17630. }
  17631. if (detail === void 0) {
  17632. detail = 0;
  17633. }
  17634. _this = _BufferGeometry.call(this) || this;
  17635. _this.type = 'PolyhedronGeometry';
  17636. _this.parameters = {
  17637. vertices: vertices,
  17638. indices: indices,
  17639. radius: radius,
  17640. detail: detail
  17641. }; // default buffer data
  17642. var vertexBuffer = [];
  17643. var uvBuffer = []; // the subdivision creates the vertex buffer data
  17644. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  17645. applyRadius(radius); // finally, create the uv data
  17646. generateUVs(); // build non-indexed geometry
  17647. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  17648. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  17649. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  17650. if (detail === 0) {
  17651. _this.computeVertexNormals(); // flat normals
  17652. } else {
  17653. _this.normalizeNormals(); // smooth normals
  17654. } // helper functions
  17655. function subdivide(detail) {
  17656. var a = new Vector3();
  17657. var b = new Vector3();
  17658. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  17659. for (var i = 0; i < indices.length; i += 3) {
  17660. // get the vertices of the face
  17661. getVertexByIndex(indices[i + 0], a);
  17662. getVertexByIndex(indices[i + 1], b);
  17663. getVertexByIndex(indices[i + 2], c); // perform subdivision
  17664. subdivideFace(a, b, c, detail);
  17665. }
  17666. }
  17667. function subdivideFace(a, b, c, detail) {
  17668. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  17669. var v = []; // construct all of the vertices for this subdivision
  17670. for (var i = 0; i <= cols; i++) {
  17671. v[i] = [];
  17672. var aj = a.clone().lerp(c, i / cols);
  17673. var bj = b.clone().lerp(c, i / cols);
  17674. var rows = cols - i;
  17675. for (var j = 0; j <= rows; j++) {
  17676. if (j === 0 && i === cols) {
  17677. v[i][j] = aj;
  17678. } else {
  17679. v[i][j] = aj.clone().lerp(bj, j / rows);
  17680. }
  17681. }
  17682. } // construct all of the faces
  17683. for (var _i = 0; _i < cols; _i++) {
  17684. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  17685. var k = Math.floor(_j / 2);
  17686. if (_j % 2 === 0) {
  17687. pushVertex(v[_i][k + 1]);
  17688. pushVertex(v[_i + 1][k]);
  17689. pushVertex(v[_i][k]);
  17690. } else {
  17691. pushVertex(v[_i][k + 1]);
  17692. pushVertex(v[_i + 1][k + 1]);
  17693. pushVertex(v[_i + 1][k]);
  17694. }
  17695. }
  17696. }
  17697. }
  17698. function applyRadius(radius) {
  17699. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  17700. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17701. vertex.x = vertexBuffer[i + 0];
  17702. vertex.y = vertexBuffer[i + 1];
  17703. vertex.z = vertexBuffer[i + 2];
  17704. vertex.normalize().multiplyScalar(radius);
  17705. vertexBuffer[i + 0] = vertex.x;
  17706. vertexBuffer[i + 1] = vertex.y;
  17707. vertexBuffer[i + 2] = vertex.z;
  17708. }
  17709. }
  17710. function generateUVs() {
  17711. var vertex = new Vector3();
  17712. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17713. vertex.x = vertexBuffer[i + 0];
  17714. vertex.y = vertexBuffer[i + 1];
  17715. vertex.z = vertexBuffer[i + 2];
  17716. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17717. var v = inclination(vertex) / Math.PI + 0.5;
  17718. uvBuffer.push(u, 1 - v);
  17719. }
  17720. correctUVs();
  17721. correctSeam();
  17722. }
  17723. function correctSeam() {
  17724. // handle case when face straddles the seam, see #3269
  17725. for (var i = 0; i < uvBuffer.length; i += 6) {
  17726. // uv data of a single face
  17727. var x0 = uvBuffer[i + 0];
  17728. var x1 = uvBuffer[i + 2];
  17729. var x2 = uvBuffer[i + 4];
  17730. var max = Math.max(x0, x1, x2);
  17731. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17732. if (max > 0.9 && min < 0.1) {
  17733. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17734. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17735. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17736. }
  17737. }
  17738. }
  17739. function pushVertex(vertex) {
  17740. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17741. }
  17742. function getVertexByIndex(index, vertex) {
  17743. var stride = index * 3;
  17744. vertex.x = vertices[stride + 0];
  17745. vertex.y = vertices[stride + 1];
  17746. vertex.z = vertices[stride + 2];
  17747. }
  17748. function correctUVs() {
  17749. var a = new Vector3();
  17750. var b = new Vector3();
  17751. var c = new Vector3();
  17752. var centroid = new Vector3();
  17753. var uvA = new Vector2();
  17754. var uvB = new Vector2();
  17755. var uvC = new Vector2();
  17756. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17757. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17758. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17759. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17760. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17761. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17762. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17763. centroid.copy(a).add(b).add(c).divideScalar(3);
  17764. var azi = azimuth(centroid);
  17765. correctUV(uvA, j + 0, a, azi);
  17766. correctUV(uvB, j + 2, b, azi);
  17767. correctUV(uvC, j + 4, c, azi);
  17768. }
  17769. }
  17770. function correctUV(uv, stride, vector, azimuth) {
  17771. if (azimuth < 0 && uv.x === 1) {
  17772. uvBuffer[stride] = uv.x - 1;
  17773. }
  17774. if (vector.x === 0 && vector.z === 0) {
  17775. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17776. }
  17777. } // Angle around the Y axis, counter-clockwise when looking from above.
  17778. function azimuth(vector) {
  17779. return Math.atan2(vector.z, -vector.x);
  17780. } // Angle above the XZ plane.
  17781. function inclination(vector) {
  17782. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17783. }
  17784. return _this;
  17785. }
  17786. return PolyhedronGeometry;
  17787. }(BufferGeometry);
  17788. var DodecahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  17789. _inheritsLoose(DodecahedronGeometry, _PolyhedronGeometry);
  17790. function DodecahedronGeometry(radius, detail) {
  17791. var _this;
  17792. if (radius === void 0) {
  17793. radius = 1;
  17794. }
  17795. if (detail === void 0) {
  17796. detail = 0;
  17797. }
  17798. var t = (1 + Math.sqrt(5)) / 2;
  17799. var r = 1 / t;
  17800. var vertices = [// (±1, ±1, ±1)
  17801. -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/φ, ±φ)
  17802. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17803. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17804. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17805. 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];
  17806. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  17807. _this.type = 'DodecahedronGeometry';
  17808. _this.parameters = {
  17809. radius: radius,
  17810. detail: detail
  17811. };
  17812. return _this;
  17813. }
  17814. return DodecahedronGeometry;
  17815. }(PolyhedronGeometry);
  17816. var _v0$2 = new Vector3();
  17817. var _v1$5 = new Vector3();
  17818. var _normal$1 = new Vector3();
  17819. var _triangle = new Triangle();
  17820. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17821. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17822. function EdgesGeometry(geometry, thresholdAngle) {
  17823. var _this;
  17824. _this = _BufferGeometry.call(this) || this;
  17825. _this.type = 'EdgesGeometry';
  17826. _this.parameters = {
  17827. thresholdAngle: thresholdAngle
  17828. };
  17829. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  17830. if (geometry.isGeometry === true) {
  17831. console.error('THREE.EdgesGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17832. return _assertThisInitialized(_this);
  17833. }
  17834. var precisionPoints = 4;
  17835. var precision = Math.pow(10, precisionPoints);
  17836. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  17837. var indexAttr = geometry.getIndex();
  17838. var positionAttr = geometry.getAttribute('position');
  17839. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  17840. var indexArr = [0, 0, 0];
  17841. var vertKeys = ['a', 'b', 'c'];
  17842. var hashes = new Array(3);
  17843. var edgeData = {};
  17844. var vertices = [];
  17845. for (var i = 0; i < indexCount; i += 3) {
  17846. if (indexAttr) {
  17847. indexArr[0] = indexAttr.getX(i);
  17848. indexArr[1] = indexAttr.getX(i + 1);
  17849. indexArr[2] = indexAttr.getX(i + 2);
  17850. } else {
  17851. indexArr[0] = i;
  17852. indexArr[1] = i + 1;
  17853. indexArr[2] = i + 2;
  17854. }
  17855. var a = _triangle.a,
  17856. b = _triangle.b,
  17857. c = _triangle.c;
  17858. a.fromBufferAttribute(positionAttr, indexArr[0]);
  17859. b.fromBufferAttribute(positionAttr, indexArr[1]);
  17860. c.fromBufferAttribute(positionAttr, indexArr[2]);
  17861. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  17862. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  17863. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  17864. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  17865. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  17866. continue;
  17867. } // iterate over every edge
  17868. for (var j = 0; j < 3; j++) {
  17869. // get the first and next vertex making up the edge
  17870. var jNext = (j + 1) % 3;
  17871. var vecHash0 = hashes[j];
  17872. var vecHash1 = hashes[jNext];
  17873. var v0 = _triangle[vertKeys[j]];
  17874. var v1 = _triangle[vertKeys[jNext]];
  17875. var hash = vecHash0 + "_" + vecHash1;
  17876. var reverseHash = vecHash1 + "_" + vecHash0;
  17877. if (reverseHash in edgeData && edgeData[reverseHash]) {
  17878. // if we found a sibling edge add it into the vertex array if
  17879. // it meets the angle threshold and delete the edge from the map.
  17880. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  17881. vertices.push(v0.x, v0.y, v0.z);
  17882. vertices.push(v1.x, v1.y, v1.z);
  17883. }
  17884. edgeData[reverseHash] = null;
  17885. } else if (!(hash in edgeData)) {
  17886. // if we've already got an edge here then skip adding a new one
  17887. edgeData[hash] = {
  17888. index0: indexArr[j],
  17889. index1: indexArr[jNext],
  17890. normal: _normal$1.clone()
  17891. };
  17892. }
  17893. }
  17894. } // iterate over all remaining, unmatched edges and add them to the vertex array
  17895. for (var key in edgeData) {
  17896. if (edgeData[key]) {
  17897. var _edgeData$key = edgeData[key],
  17898. index0 = _edgeData$key.index0,
  17899. index1 = _edgeData$key.index1;
  17900. _v0$2.fromBufferAttribute(positionAttr, index0);
  17901. _v1$5.fromBufferAttribute(positionAttr, index1);
  17902. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  17903. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  17904. }
  17905. }
  17906. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17907. return _this;
  17908. }
  17909. return EdgesGeometry;
  17910. }(BufferGeometry);
  17911. /**
  17912. * Port from https://github.com/mapbox/earcut (v2.2.2)
  17913. */
  17914. var Earcut = {
  17915. triangulate: function triangulate(data, holeIndices, dim) {
  17916. dim = dim || 2;
  17917. var hasHoles = holeIndices && holeIndices.length;
  17918. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  17919. var outerNode = linkedList(data, 0, outerLen, dim, true);
  17920. var triangles = [];
  17921. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  17922. var minX, minY, maxX, maxY, x, y, invSize;
  17923. 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
  17924. if (data.length > 80 * dim) {
  17925. minX = maxX = data[0];
  17926. minY = maxY = data[1];
  17927. for (var i = dim; i < outerLen; i += dim) {
  17928. x = data[i];
  17929. y = data[i + 1];
  17930. if (x < minX) minX = x;
  17931. if (y < minY) minY = y;
  17932. if (x > maxX) maxX = x;
  17933. if (y > maxY) maxY = y;
  17934. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17935. invSize = Math.max(maxX - minX, maxY - minY);
  17936. invSize = invSize !== 0 ? 1 / invSize : 0;
  17937. }
  17938. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  17939. return triangles;
  17940. }
  17941. }; // create a circular doubly linked list from polygon points in the specified winding order
  17942. function linkedList(data, start, end, dim, clockwise) {
  17943. var i, last;
  17944. if (clockwise === signedArea(data, start, end, dim) > 0) {
  17945. for (i = start; i < end; i += dim) {
  17946. last = insertNode(i, data[i], data[i + 1], last);
  17947. }
  17948. } else {
  17949. for (i = end - dim; i >= start; i -= dim) {
  17950. last = insertNode(i, data[i], data[i + 1], last);
  17951. }
  17952. }
  17953. if (last && equals(last, last.next)) {
  17954. removeNode(last);
  17955. last = last.next;
  17956. }
  17957. return last;
  17958. } // eliminate colinear or duplicate points
  17959. function filterPoints(start, end) {
  17960. if (!start) return start;
  17961. if (!end) end = start;
  17962. var p = start,
  17963. again;
  17964. do {
  17965. again = false;
  17966. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  17967. removeNode(p);
  17968. p = end = p.prev;
  17969. if (p === p.next) break;
  17970. again = true;
  17971. } else {
  17972. p = p.next;
  17973. }
  17974. } while (again || p !== end);
  17975. return end;
  17976. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  17977. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  17978. if (!ear) return; // interlink polygon nodes in z-order
  17979. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  17980. var stop = ear,
  17981. prev,
  17982. next; // iterate through ears, slicing them one by one
  17983. while (ear.prev !== ear.next) {
  17984. prev = ear.prev;
  17985. next = ear.next;
  17986. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  17987. // cut off the triangle
  17988. triangles.push(prev.i / dim);
  17989. triangles.push(ear.i / dim);
  17990. triangles.push(next.i / dim);
  17991. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  17992. ear = next.next;
  17993. stop = next.next;
  17994. continue;
  17995. }
  17996. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  17997. if (ear === stop) {
  17998. // try filtering points and slicing again
  17999. if (!pass) {
  18000. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  18001. } else if (pass === 1) {
  18002. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  18003. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  18004. } else if (pass === 2) {
  18005. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  18006. }
  18007. break;
  18008. }
  18009. }
  18010. } // check whether a polygon node forms a valid ear with adjacent nodes
  18011. function isEar(ear) {
  18012. var a = ear.prev,
  18013. b = ear,
  18014. c = ear.next;
  18015. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  18016. // now make sure we don't have other points inside the potential ear
  18017. var p = ear.next.next;
  18018. while (p !== ear.prev) {
  18019. 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;
  18020. p = p.next;
  18021. }
  18022. return true;
  18023. }
  18024. function isEarHashed(ear, minX, minY, invSize) {
  18025. var a = ear.prev,
  18026. b = ear,
  18027. c = ear.next;
  18028. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  18029. // triangle bbox; min & max are calculated like this for speed
  18030. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  18031. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  18032. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  18033. 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;
  18034. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  18035. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  18036. var p = ear.prevZ,
  18037. n = ear.nextZ; // look for points inside the triangle in both directions
  18038. while (p && p.z >= minZ && n && n.z <= maxZ) {
  18039. 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;
  18040. p = p.prevZ;
  18041. 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;
  18042. n = n.nextZ;
  18043. } // look for remaining points in decreasing z-order
  18044. while (p && p.z >= minZ) {
  18045. 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;
  18046. p = p.prevZ;
  18047. } // look for remaining points in increasing z-order
  18048. while (n && n.z <= maxZ) {
  18049. 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;
  18050. n = n.nextZ;
  18051. }
  18052. return true;
  18053. } // go through all polygon nodes and cure small local self-intersections
  18054. function cureLocalIntersections(start, triangles, dim) {
  18055. var p = start;
  18056. do {
  18057. var a = p.prev,
  18058. b = p.next.next;
  18059. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  18060. triangles.push(a.i / dim);
  18061. triangles.push(p.i / dim);
  18062. triangles.push(b.i / dim); // remove two nodes involved
  18063. removeNode(p);
  18064. removeNode(p.next);
  18065. p = start = b;
  18066. }
  18067. p = p.next;
  18068. } while (p !== start);
  18069. return filterPoints(p);
  18070. } // try splitting polygon into two and triangulate them independently
  18071. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  18072. // look for a valid diagonal that divides the polygon into two
  18073. var a = start;
  18074. do {
  18075. var b = a.next.next;
  18076. while (b !== a.prev) {
  18077. if (a.i !== b.i && isValidDiagonal(a, b)) {
  18078. // split the polygon in two by the diagonal
  18079. var c = splitPolygon(a, b); // filter colinear points around the cuts
  18080. a = filterPoints(a, a.next);
  18081. c = filterPoints(c, c.next); // run earcut on each half
  18082. earcutLinked(a, triangles, dim, minX, minY, invSize);
  18083. earcutLinked(c, triangles, dim, minX, minY, invSize);
  18084. return;
  18085. }
  18086. b = b.next;
  18087. }
  18088. a = a.next;
  18089. } while (a !== start);
  18090. } // link every hole into the outer loop, producing a single-ring polygon without holes
  18091. function eliminateHoles(data, holeIndices, outerNode, dim) {
  18092. var queue = [];
  18093. var i, len, start, end, list;
  18094. for (i = 0, len = holeIndices.length; i < len; i++) {
  18095. start = holeIndices[i] * dim;
  18096. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  18097. list = linkedList(data, start, end, dim, false);
  18098. if (list === list.next) list.steiner = true;
  18099. queue.push(getLeftmost(list));
  18100. }
  18101. queue.sort(compareX); // process holes from left to right
  18102. for (i = 0; i < queue.length; i++) {
  18103. eliminateHole(queue[i], outerNode);
  18104. outerNode = filterPoints(outerNode, outerNode.next);
  18105. }
  18106. return outerNode;
  18107. }
  18108. function compareX(a, b) {
  18109. return a.x - b.x;
  18110. } // find a bridge between vertices that connects hole with an outer ring and and link it
  18111. function eliminateHole(hole, outerNode) {
  18112. outerNode = findHoleBridge(hole, outerNode);
  18113. if (outerNode) {
  18114. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  18115. filterPoints(outerNode, outerNode.next);
  18116. filterPoints(b, b.next);
  18117. }
  18118. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  18119. function findHoleBridge(hole, outerNode) {
  18120. var p = outerNode;
  18121. var hx = hole.x;
  18122. var hy = hole.y;
  18123. var qx = -Infinity,
  18124. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  18125. // segment's endpoint with lesser x will be potential connection point
  18126. do {
  18127. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  18128. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  18129. if (x <= hx && x > qx) {
  18130. qx = x;
  18131. if (x === hx) {
  18132. if (hy === p.y) return p;
  18133. if (hy === p.next.y) return p.next;
  18134. }
  18135. m = p.x < p.next.x ? p : p.next;
  18136. }
  18137. }
  18138. p = p.next;
  18139. } while (p !== outerNode);
  18140. if (!m) return null;
  18141. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  18142. // look for points inside the triangle of hole point, segment intersection and endpoint;
  18143. // if there are no points found, we have a valid connection;
  18144. // otherwise choose the point of the minimum angle with the ray as connection point
  18145. var stop = m,
  18146. mx = m.x,
  18147. my = m.y;
  18148. var tanMin = Infinity,
  18149. tan;
  18150. p = m;
  18151. do {
  18152. 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)) {
  18153. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  18154. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  18155. m = p;
  18156. tanMin = tan;
  18157. }
  18158. }
  18159. p = p.next;
  18160. } while (p !== stop);
  18161. return m;
  18162. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  18163. function sectorContainsSector(m, p) {
  18164. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  18165. } // interlink polygon nodes in z-order
  18166. function indexCurve(start, minX, minY, invSize) {
  18167. var p = start;
  18168. do {
  18169. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  18170. p.prevZ = p.prev;
  18171. p.nextZ = p.next;
  18172. p = p.next;
  18173. } while (p !== start);
  18174. p.prevZ.nextZ = null;
  18175. p.prevZ = null;
  18176. sortLinked(p);
  18177. } // Simon Tatham's linked list merge sort algorithm
  18178. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  18179. function sortLinked(list) {
  18180. var i,
  18181. p,
  18182. q,
  18183. e,
  18184. tail,
  18185. numMerges,
  18186. pSize,
  18187. qSize,
  18188. inSize = 1;
  18189. do {
  18190. p = list;
  18191. list = null;
  18192. tail = null;
  18193. numMerges = 0;
  18194. while (p) {
  18195. numMerges++;
  18196. q = p;
  18197. pSize = 0;
  18198. for (i = 0; i < inSize; i++) {
  18199. pSize++;
  18200. q = q.nextZ;
  18201. if (!q) break;
  18202. }
  18203. qSize = inSize;
  18204. while (pSize > 0 || qSize > 0 && q) {
  18205. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  18206. e = p;
  18207. p = p.nextZ;
  18208. pSize--;
  18209. } else {
  18210. e = q;
  18211. q = q.nextZ;
  18212. qSize--;
  18213. }
  18214. if (tail) tail.nextZ = e;else list = e;
  18215. e.prevZ = tail;
  18216. tail = e;
  18217. }
  18218. p = q;
  18219. }
  18220. tail.nextZ = null;
  18221. inSize *= 2;
  18222. } while (numMerges > 1);
  18223. return list;
  18224. } // z-order of a point given coords and inverse of the longer side of data bbox
  18225. function zOrder(x, y, minX, minY, invSize) {
  18226. // coords are transformed into non-negative 15-bit integer range
  18227. x = 32767 * (x - minX) * invSize;
  18228. y = 32767 * (y - minY) * invSize;
  18229. x = (x | x << 8) & 0x00FF00FF;
  18230. x = (x | x << 4) & 0x0F0F0F0F;
  18231. x = (x | x << 2) & 0x33333333;
  18232. x = (x | x << 1) & 0x55555555;
  18233. y = (y | y << 8) & 0x00FF00FF;
  18234. y = (y | y << 4) & 0x0F0F0F0F;
  18235. y = (y | y << 2) & 0x33333333;
  18236. y = (y | y << 1) & 0x55555555;
  18237. return x | y << 1;
  18238. } // find the leftmost node of a polygon ring
  18239. function getLeftmost(start) {
  18240. var p = start,
  18241. leftmost = start;
  18242. do {
  18243. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  18244. p = p.next;
  18245. } while (p !== start);
  18246. return leftmost;
  18247. } // check if a point lies within a convex triangle
  18248. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  18249. 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;
  18250. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18251. function isValidDiagonal(a, b) {
  18252. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  18253. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  18254. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  18255. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  18256. } // signed area of a triangle
  18257. function area(p, q, r) {
  18258. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  18259. } // check if two points are equal
  18260. function equals(p1, p2) {
  18261. return p1.x === p2.x && p1.y === p2.y;
  18262. } // check if two segments intersect
  18263. function intersects(p1, q1, p2, q2) {
  18264. var o1 = sign(area(p1, q1, p2));
  18265. var o2 = sign(area(p1, q1, q2));
  18266. var o3 = sign(area(p2, q2, p1));
  18267. var o4 = sign(area(p2, q2, q1));
  18268. if (o1 !== o2 && o3 !== o4) return true; // general case
  18269. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18270. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18271. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18272. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18273. return false;
  18274. } // for collinear points p, q, r, check if point q lies on segment pr
  18275. function onSegment(p, q, r) {
  18276. 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);
  18277. }
  18278. function sign(num) {
  18279. return num > 0 ? 1 : num < 0 ? -1 : 0;
  18280. } // check if a polygon diagonal intersects any polygon segments
  18281. function intersectsPolygon(a, b) {
  18282. var p = a;
  18283. do {
  18284. 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;
  18285. p = p.next;
  18286. } while (p !== a);
  18287. return false;
  18288. } // check if a polygon diagonal is locally inside the polygon
  18289. function locallyInside(a, b) {
  18290. 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;
  18291. } // check if the middle point of a polygon diagonal is inside the polygon
  18292. function middleInside(a, b) {
  18293. var p = a,
  18294. inside = false;
  18295. var px = (a.x + b.x) / 2,
  18296. py = (a.y + b.y) / 2;
  18297. do {
  18298. 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;
  18299. p = p.next;
  18300. } while (p !== a);
  18301. return inside;
  18302. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18303. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18304. function splitPolygon(a, b) {
  18305. var a2 = new Node(a.i, a.x, a.y),
  18306. b2 = new Node(b.i, b.x, b.y),
  18307. an = a.next,
  18308. bp = b.prev;
  18309. a.next = b;
  18310. b.prev = a;
  18311. a2.next = an;
  18312. an.prev = a2;
  18313. b2.next = a2;
  18314. a2.prev = b2;
  18315. bp.next = b2;
  18316. b2.prev = bp;
  18317. return b2;
  18318. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  18319. function insertNode(i, x, y, last) {
  18320. var p = new Node(i, x, y);
  18321. if (!last) {
  18322. p.prev = p;
  18323. p.next = p;
  18324. } else {
  18325. p.next = last.next;
  18326. p.prev = last;
  18327. last.next.prev = p;
  18328. last.next = p;
  18329. }
  18330. return p;
  18331. }
  18332. function removeNode(p) {
  18333. p.next.prev = p.prev;
  18334. p.prev.next = p.next;
  18335. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  18336. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  18337. }
  18338. function Node(i, x, y) {
  18339. // vertex index in coordinates array
  18340. this.i = i; // vertex coordinates
  18341. this.x = x;
  18342. this.y = y; // previous and next vertex nodes in a polygon ring
  18343. this.prev = null;
  18344. this.next = null; // z-order curve value
  18345. this.z = null; // previous and next nodes in z-order
  18346. this.prevZ = null;
  18347. this.nextZ = null; // indicates whether this is a steiner point
  18348. this.steiner = false;
  18349. }
  18350. function signedArea(data, start, end, dim) {
  18351. var sum = 0;
  18352. for (var i = start, j = end - dim; i < end; i += dim) {
  18353. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  18354. j = i;
  18355. }
  18356. return sum;
  18357. }
  18358. var ShapeUtils = {
  18359. // calculate area of the contour polygon
  18360. area: function area(contour) {
  18361. var n = contour.length;
  18362. var a = 0.0;
  18363. for (var p = n - 1, q = 0; q < n; p = q++) {
  18364. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  18365. }
  18366. return a * 0.5;
  18367. },
  18368. isClockWise: function isClockWise(pts) {
  18369. return ShapeUtils.area(pts) < 0;
  18370. },
  18371. triangulateShape: function triangulateShape(contour, holes) {
  18372. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18373. var holeIndices = []; // array of hole indices
  18374. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18375. removeDupEndPts(contour);
  18376. addContour(vertices, contour); //
  18377. var holeIndex = contour.length;
  18378. holes.forEach(removeDupEndPts);
  18379. for (var i = 0; i < holes.length; i++) {
  18380. holeIndices.push(holeIndex);
  18381. holeIndex += holes[i].length;
  18382. addContour(vertices, holes[i]);
  18383. } //
  18384. var triangles = Earcut.triangulate(vertices, holeIndices); //
  18385. for (var _i = 0; _i < triangles.length; _i += 3) {
  18386. faces.push(triangles.slice(_i, _i + 3));
  18387. }
  18388. return faces;
  18389. }
  18390. };
  18391. function removeDupEndPts(points) {
  18392. var l = points.length;
  18393. if (l > 2 && points[l - 1].equals(points[0])) {
  18394. points.pop();
  18395. }
  18396. }
  18397. function addContour(vertices, contour) {
  18398. for (var i = 0; i < contour.length; i++) {
  18399. vertices.push(contour[i].x);
  18400. vertices.push(contour[i].y);
  18401. }
  18402. }
  18403. var ExtrudeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18404. _inheritsLoose(ExtrudeGeometry, _BufferGeometry);
  18405. function ExtrudeGeometry(shapes, options) {
  18406. var _this;
  18407. _this = _BufferGeometry.call(this) || this;
  18408. _this.type = 'ExtrudeGeometry';
  18409. _this.parameters = {
  18410. shapes: shapes,
  18411. options: options
  18412. };
  18413. shapes = Array.isArray(shapes) ? shapes : [shapes];
  18414. var scope = _assertThisInitialized(_this);
  18415. var verticesArray = [];
  18416. var uvArray = [];
  18417. for (var i = 0, l = shapes.length; i < l; i++) {
  18418. var shape = shapes[i];
  18419. addShape(shape);
  18420. } // build geometry
  18421. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  18422. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  18423. _this.computeVertexNormals(); // functions
  18424. function addShape(shape) {
  18425. var placeholder = []; // options
  18426. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18427. var steps = options.steps !== undefined ? options.steps : 1;
  18428. var depth = options.depth !== undefined ? options.depth : 100;
  18429. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18430. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18431. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18432. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18433. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18434. var extrudePath = options.extrudePath;
  18435. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  18436. if (options.amount !== undefined) {
  18437. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  18438. depth = options.amount;
  18439. } //
  18440. var extrudePts,
  18441. extrudeByPath = false;
  18442. var splineTube, binormal, normal, position2;
  18443. if (extrudePath) {
  18444. extrudePts = extrudePath.getSpacedPoints(steps);
  18445. extrudeByPath = true;
  18446. bevelEnabled = false; // bevels not supported for path extrusion
  18447. // SETUP TNB variables
  18448. // TODO1 - have a .isClosed in spline?
  18449. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18450. binormal = new Vector3();
  18451. normal = new Vector3();
  18452. position2 = new Vector3();
  18453. } // Safeguards if bevels are not enabled
  18454. if (!bevelEnabled) {
  18455. bevelSegments = 0;
  18456. bevelThickness = 0;
  18457. bevelSize = 0;
  18458. bevelOffset = 0;
  18459. } // Variables initialization
  18460. var shapePoints = shape.extractPoints(curveSegments);
  18461. var vertices = shapePoints.shape;
  18462. var holes = shapePoints.holes;
  18463. var reverse = !ShapeUtils.isClockWise(vertices);
  18464. if (reverse) {
  18465. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18466. for (var h = 0, hl = holes.length; h < hl; h++) {
  18467. var ahole = holes[h];
  18468. if (ShapeUtils.isClockWise(ahole)) {
  18469. holes[h] = ahole.reverse();
  18470. }
  18471. }
  18472. }
  18473. var faces = ShapeUtils.triangulateShape(vertices, holes);
  18474. /* Vertices */
  18475. var contour = vertices; // vertices has all points but contour has only points of circumference
  18476. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  18477. var _ahole = holes[_h];
  18478. vertices = vertices.concat(_ahole);
  18479. }
  18480. function scalePt2(pt, vec, size) {
  18481. if (!vec) console.error('THREE.ExtrudeGeometry: vec does not exist');
  18482. return vec.clone().multiplyScalar(size).add(pt);
  18483. }
  18484. var vlen = vertices.length,
  18485. flen = faces.length; // Find directions for point movement
  18486. function getBevelVec(inPt, inPrev, inNext) {
  18487. // computes for inPt the corresponding point inPt' on a new contour
  18488. // shifted by 1 unit (length of normalized vector) to the left
  18489. // if we walk along contour clockwise, this new contour is outside the old one
  18490. //
  18491. // inPt' is the intersection of the two lines parallel to the two
  18492. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18493. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18494. // good reading for geometry algorithms (here: line-line intersection)
  18495. // http://geomalgorithms.com/a05-_intersect-1.html
  18496. var v_prev_x = inPt.x - inPrev.x,
  18497. v_prev_y = inPt.y - inPrev.y;
  18498. var v_next_x = inNext.x - inPt.x,
  18499. v_next_y = inNext.y - inPt.y;
  18500. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  18501. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  18502. if (Math.abs(collinear0) > Number.EPSILON) {
  18503. // not collinear
  18504. // length of vectors for normalizing
  18505. var v_prev_len = Math.sqrt(v_prev_lensq);
  18506. 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
  18507. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  18508. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  18509. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  18510. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  18511. 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
  18512. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  18513. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  18514. // but prevent crazy spikes
  18515. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  18516. if (v_trans_lensq <= 2) {
  18517. return new Vector2(v_trans_x, v_trans_y);
  18518. } else {
  18519. shrink_by = Math.sqrt(v_trans_lensq / 2);
  18520. }
  18521. } else {
  18522. // handle special case of collinear edges
  18523. var direction_eq = false; // assumes: opposite
  18524. if (v_prev_x > Number.EPSILON) {
  18525. if (v_next_x > Number.EPSILON) {
  18526. direction_eq = true;
  18527. }
  18528. } else {
  18529. if (v_prev_x < -Number.EPSILON) {
  18530. if (v_next_x < -Number.EPSILON) {
  18531. direction_eq = true;
  18532. }
  18533. } else {
  18534. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  18535. direction_eq = true;
  18536. }
  18537. }
  18538. }
  18539. if (direction_eq) {
  18540. // console.log("Warning: lines are a straight sequence");
  18541. v_trans_x = -v_prev_y;
  18542. v_trans_y = v_prev_x;
  18543. shrink_by = Math.sqrt(v_prev_lensq);
  18544. } else {
  18545. // console.log("Warning: lines are a straight spike");
  18546. v_trans_x = v_prev_x;
  18547. v_trans_y = v_prev_y;
  18548. shrink_by = Math.sqrt(v_prev_lensq / 2);
  18549. }
  18550. }
  18551. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  18552. }
  18553. var contourMovements = [];
  18554. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  18555. if (j === il) j = 0;
  18556. if (k === il) k = 0; // (j)---(i)---(k)
  18557. // console.log('i,j,k', i, j , k)
  18558. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  18559. }
  18560. var holesMovements = [];
  18561. var oneHoleMovements,
  18562. verticesMovements = contourMovements.concat();
  18563. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  18564. var _ahole2 = holes[_h2];
  18565. oneHoleMovements = [];
  18566. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  18567. if (_j === _il) _j = 0;
  18568. if (_k === _il) _k = 0; // (j)---(i)---(k)
  18569. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  18570. }
  18571. holesMovements.push(oneHoleMovements);
  18572. verticesMovements = verticesMovements.concat(oneHoleMovements);
  18573. } // Loop bevelSegments, 1 for the front, 1 for the back
  18574. for (var b = 0; b < bevelSegments; b++) {
  18575. //for ( b = bevelSegments; b > 0; b -- ) {
  18576. var t = b / bevelSegments;
  18577. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  18578. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  18579. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  18580. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  18581. v(vert.x, vert.y, -z);
  18582. } // expand holes
  18583. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  18584. var _ahole3 = holes[_h3];
  18585. oneHoleMovements = holesMovements[_h3];
  18586. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  18587. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  18588. v(_vert.x, _vert.y, -z);
  18589. }
  18590. }
  18591. }
  18592. var bs = bevelSize + bevelOffset; // Back facing vertices
  18593. for (var _i5 = 0; _i5 < vlen; _i5++) {
  18594. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  18595. if (!extrudeByPath) {
  18596. v(_vert2.x, _vert2.y, 0);
  18597. } else {
  18598. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18599. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  18600. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  18601. position2.copy(extrudePts[0]).add(normal).add(binormal);
  18602. v(position2.x, position2.y, position2.z);
  18603. }
  18604. } // Add stepped vertices...
  18605. // Including front facing vertices
  18606. for (var s = 1; s <= steps; s++) {
  18607. for (var _i6 = 0; _i6 < vlen; _i6++) {
  18608. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  18609. if (!extrudeByPath) {
  18610. v(_vert3.x, _vert3.y, depth / steps * s);
  18611. } else {
  18612. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18613. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  18614. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  18615. position2.copy(extrudePts[s]).add(normal).add(binormal);
  18616. v(position2.x, position2.y, position2.z);
  18617. }
  18618. }
  18619. } // Add bevel segments planes
  18620. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18621. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  18622. var _t = _b / bevelSegments;
  18623. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  18624. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  18625. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  18626. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  18627. v(_vert4.x, _vert4.y, depth + _z);
  18628. } // expand holes
  18629. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  18630. var _ahole4 = holes[_h4];
  18631. oneHoleMovements = holesMovements[_h4];
  18632. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  18633. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  18634. if (!extrudeByPath) {
  18635. v(_vert5.x, _vert5.y, depth + _z);
  18636. } else {
  18637. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  18638. }
  18639. }
  18640. }
  18641. }
  18642. /* Faces */
  18643. // Top and bottom faces
  18644. buildLidFaces(); // Sides faces
  18645. buildSideFaces(); ///// Internal functions
  18646. function buildLidFaces() {
  18647. var start = verticesArray.length / 3;
  18648. if (bevelEnabled) {
  18649. var layer = 0; // steps + 1
  18650. var offset = vlen * layer; // Bottom faces
  18651. for (var _i9 = 0; _i9 < flen; _i9++) {
  18652. var face = faces[_i9];
  18653. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  18654. }
  18655. layer = steps + bevelSegments * 2;
  18656. offset = vlen * layer; // Top faces
  18657. for (var _i10 = 0; _i10 < flen; _i10++) {
  18658. var _face = faces[_i10];
  18659. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  18660. }
  18661. } else {
  18662. // Bottom faces
  18663. for (var _i11 = 0; _i11 < flen; _i11++) {
  18664. var _face2 = faces[_i11];
  18665. f3(_face2[2], _face2[1], _face2[0]);
  18666. } // Top faces
  18667. for (var _i12 = 0; _i12 < flen; _i12++) {
  18668. var _face3 = faces[_i12];
  18669. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  18670. }
  18671. }
  18672. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  18673. } // Create faces for the z-sides of the shape
  18674. function buildSideFaces() {
  18675. var start = verticesArray.length / 3;
  18676. var layeroffset = 0;
  18677. sidewalls(contour, layeroffset);
  18678. layeroffset += contour.length;
  18679. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  18680. var _ahole5 = holes[_h5];
  18681. sidewalls(_ahole5, layeroffset); //, true
  18682. layeroffset += _ahole5.length;
  18683. }
  18684. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  18685. }
  18686. function sidewalls(contour, layeroffset) {
  18687. var i = contour.length;
  18688. while (--i >= 0) {
  18689. var _j2 = i;
  18690. var _k2 = i - 1;
  18691. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  18692. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  18693. var slen1 = vlen * _s;
  18694. var slen2 = vlen * (_s + 1);
  18695. var a = layeroffset + _j2 + slen1,
  18696. _b2 = layeroffset + _k2 + slen1,
  18697. c = layeroffset + _k2 + slen2,
  18698. d = layeroffset + _j2 + slen2;
  18699. f4(a, _b2, c, d);
  18700. }
  18701. }
  18702. }
  18703. function v(x, y, z) {
  18704. placeholder.push(x);
  18705. placeholder.push(y);
  18706. placeholder.push(z);
  18707. }
  18708. function f3(a, b, c) {
  18709. addVertex(a);
  18710. addVertex(b);
  18711. addVertex(c);
  18712. var nextIndex = verticesArray.length / 3;
  18713. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18714. addUV(uvs[0]);
  18715. addUV(uvs[1]);
  18716. addUV(uvs[2]);
  18717. }
  18718. function f4(a, b, c, d) {
  18719. addVertex(a);
  18720. addVertex(b);
  18721. addVertex(d);
  18722. addVertex(b);
  18723. addVertex(c);
  18724. addVertex(d);
  18725. var nextIndex = verticesArray.length / 3;
  18726. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18727. addUV(uvs[0]);
  18728. addUV(uvs[1]);
  18729. addUV(uvs[3]);
  18730. addUV(uvs[1]);
  18731. addUV(uvs[2]);
  18732. addUV(uvs[3]);
  18733. }
  18734. function addVertex(index) {
  18735. verticesArray.push(placeholder[index * 3 + 0]);
  18736. verticesArray.push(placeholder[index * 3 + 1]);
  18737. verticesArray.push(placeholder[index * 3 + 2]);
  18738. }
  18739. function addUV(vector2) {
  18740. uvArray.push(vector2.x);
  18741. uvArray.push(vector2.y);
  18742. }
  18743. }
  18744. return _this;
  18745. }
  18746. var _proto = ExtrudeGeometry.prototype;
  18747. _proto.toJSON = function toJSON() {
  18748. var data = BufferGeometry.prototype.toJSON.call(this);
  18749. var shapes = this.parameters.shapes;
  18750. var options = this.parameters.options;
  18751. return _toJSON(shapes, options, data);
  18752. };
  18753. return ExtrudeGeometry;
  18754. }(BufferGeometry);
  18755. var WorldUVGenerator = {
  18756. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18757. var a_x = vertices[indexA * 3];
  18758. var a_y = vertices[indexA * 3 + 1];
  18759. var b_x = vertices[indexB * 3];
  18760. var b_y = vertices[indexB * 3 + 1];
  18761. var c_x = vertices[indexC * 3];
  18762. var c_y = vertices[indexC * 3 + 1];
  18763. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18764. },
  18765. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18766. var a_x = vertices[indexA * 3];
  18767. var a_y = vertices[indexA * 3 + 1];
  18768. var a_z = vertices[indexA * 3 + 2];
  18769. var b_x = vertices[indexB * 3];
  18770. var b_y = vertices[indexB * 3 + 1];
  18771. var b_z = vertices[indexB * 3 + 2];
  18772. var c_x = vertices[indexC * 3];
  18773. var c_y = vertices[indexC * 3 + 1];
  18774. var c_z = vertices[indexC * 3 + 2];
  18775. var d_x = vertices[indexD * 3];
  18776. var d_y = vertices[indexD * 3 + 1];
  18777. var d_z = vertices[indexD * 3 + 2];
  18778. if (Math.abs(a_y - b_y) < 0.01) {
  18779. 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)];
  18780. } else {
  18781. 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)];
  18782. }
  18783. }
  18784. };
  18785. function _toJSON(shapes, options, data) {
  18786. data.shapes = [];
  18787. if (Array.isArray(shapes)) {
  18788. for (var i = 0, l = shapes.length; i < l; i++) {
  18789. var shape = shapes[i];
  18790. data.shapes.push(shape.uuid);
  18791. }
  18792. } else {
  18793. data.shapes.push(shapes.uuid);
  18794. }
  18795. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18796. return data;
  18797. }
  18798. var IcosahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18799. _inheritsLoose(IcosahedronGeometry, _PolyhedronGeometry);
  18800. function IcosahedronGeometry(radius, detail) {
  18801. var _this;
  18802. if (radius === void 0) {
  18803. radius = 1;
  18804. }
  18805. if (detail === void 0) {
  18806. detail = 0;
  18807. }
  18808. var t = (1 + Math.sqrt(5)) / 2;
  18809. 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];
  18810. 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];
  18811. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18812. _this.type = 'IcosahedronGeometry';
  18813. _this.parameters = {
  18814. radius: radius,
  18815. detail: detail
  18816. };
  18817. return _this;
  18818. }
  18819. return IcosahedronGeometry;
  18820. }(PolyhedronGeometry);
  18821. var LatheGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18822. _inheritsLoose(LatheGeometry, _BufferGeometry);
  18823. function LatheGeometry(points, segments, phiStart, phiLength) {
  18824. var _this;
  18825. if (segments === void 0) {
  18826. segments = 12;
  18827. }
  18828. if (phiStart === void 0) {
  18829. phiStart = 0;
  18830. }
  18831. if (phiLength === void 0) {
  18832. phiLength = Math.PI * 2;
  18833. }
  18834. _this = _BufferGeometry.call(this) || this;
  18835. _this.type = 'LatheGeometry';
  18836. _this.parameters = {
  18837. points: points,
  18838. segments: segments,
  18839. phiStart: phiStart,
  18840. phiLength: phiLength
  18841. };
  18842. segments = Math.floor(segments); // clamp phiLength so it's in range of [ 0, 2PI ]
  18843. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  18844. var indices = [];
  18845. var vertices = [];
  18846. var uvs = []; // helper variables
  18847. var inverseSegments = 1.0 / segments;
  18848. var vertex = new Vector3();
  18849. var uv = new Vector2(); // generate vertices and uvs
  18850. for (var i = 0; i <= segments; i++) {
  18851. var phi = phiStart + i * inverseSegments * phiLength;
  18852. var sin = Math.sin(phi);
  18853. var cos = Math.cos(phi);
  18854. for (var j = 0; j <= points.length - 1; j++) {
  18855. // vertex
  18856. vertex.x = points[j].x * sin;
  18857. vertex.y = points[j].y;
  18858. vertex.z = points[j].x * cos;
  18859. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  18860. uv.x = i / segments;
  18861. uv.y = j / (points.length - 1);
  18862. uvs.push(uv.x, uv.y);
  18863. }
  18864. } // indices
  18865. for (var _i = 0; _i < segments; _i++) {
  18866. for (var _j = 0; _j < points.length - 1; _j++) {
  18867. var base = _j + _i * points.length;
  18868. var a = base;
  18869. var b = base + points.length;
  18870. var c = base + points.length + 1;
  18871. var d = base + 1; // faces
  18872. indices.push(a, b, d);
  18873. indices.push(b, c, d);
  18874. }
  18875. } // build geometry
  18876. _this.setIndex(indices);
  18877. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18878. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  18879. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  18880. // because the corresponding vertices are identical (but still have different UVs).
  18881. if (phiLength === Math.PI * 2) {
  18882. var normals = _this.attributes.normal.array;
  18883. var n1 = new Vector3();
  18884. var n2 = new Vector3();
  18885. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  18886. var _base = segments * points.length * 3;
  18887. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  18888. // select the normal of the vertex in the first line
  18889. n1.x = normals[_j2 + 0];
  18890. n1.y = normals[_j2 + 1];
  18891. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  18892. n2.x = normals[_base + _j2 + 0];
  18893. n2.y = normals[_base + _j2 + 1];
  18894. n2.z = normals[_base + _j2 + 2]; // average normals
  18895. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  18896. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  18897. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  18898. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  18899. }
  18900. }
  18901. return _this;
  18902. }
  18903. return LatheGeometry;
  18904. }(BufferGeometry);
  18905. var OctahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18906. _inheritsLoose(OctahedronGeometry, _PolyhedronGeometry);
  18907. function OctahedronGeometry(radius, detail) {
  18908. var _this;
  18909. if (radius === void 0) {
  18910. radius = 1;
  18911. }
  18912. if (detail === void 0) {
  18913. detail = 0;
  18914. }
  18915. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  18916. 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];
  18917. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18918. _this.type = 'OctahedronGeometry';
  18919. _this.parameters = {
  18920. radius: radius,
  18921. detail: detail
  18922. };
  18923. return _this;
  18924. }
  18925. return OctahedronGeometry;
  18926. }(PolyhedronGeometry);
  18927. /**
  18928. * Parametric Surfaces Geometry
  18929. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18930. */
  18931. function ParametricGeometry(func, slices, stacks) {
  18932. BufferGeometry.call(this);
  18933. this.type = 'ParametricGeometry';
  18934. this.parameters = {
  18935. func: func,
  18936. slices: slices,
  18937. stacks: stacks
  18938. }; // buffers
  18939. var indices = [];
  18940. var vertices = [];
  18941. var normals = [];
  18942. var uvs = [];
  18943. var EPS = 0.00001;
  18944. var normal = new Vector3();
  18945. var p0 = new Vector3(),
  18946. p1 = new Vector3();
  18947. var pu = new Vector3(),
  18948. pv = new Vector3();
  18949. if (func.length < 3) {
  18950. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  18951. } // generate vertices, normals and uvs
  18952. var sliceCount = slices + 1;
  18953. for (var i = 0; i <= stacks; i++) {
  18954. var v = i / stacks;
  18955. for (var j = 0; j <= slices; j++) {
  18956. var u = j / slices; // vertex
  18957. func(u, v, p0);
  18958. vertices.push(p0.x, p0.y, p0.z); // normal
  18959. // approximate tangent vectors via finite differences
  18960. if (u - EPS >= 0) {
  18961. func(u - EPS, v, p1);
  18962. pu.subVectors(p0, p1);
  18963. } else {
  18964. func(u + EPS, v, p1);
  18965. pu.subVectors(p1, p0);
  18966. }
  18967. if (v - EPS >= 0) {
  18968. func(u, v - EPS, p1);
  18969. pv.subVectors(p0, p1);
  18970. } else {
  18971. func(u, v + EPS, p1);
  18972. pv.subVectors(p1, p0);
  18973. } // cross product of tangent vectors returns surface normal
  18974. normal.crossVectors(pu, pv).normalize();
  18975. normals.push(normal.x, normal.y, normal.z); // uv
  18976. uvs.push(u, v);
  18977. }
  18978. } // generate indices
  18979. for (var _i = 0; _i < stacks; _i++) {
  18980. for (var _j = 0; _j < slices; _j++) {
  18981. var a = _i * sliceCount + _j;
  18982. var b = _i * sliceCount + _j + 1;
  18983. var c = (_i + 1) * sliceCount + _j + 1;
  18984. var d = (_i + 1) * sliceCount + _j; // faces one and two
  18985. indices.push(a, b, d);
  18986. indices.push(b, c, d);
  18987. }
  18988. } // build geometry
  18989. this.setIndex(indices);
  18990. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18991. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18992. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18993. }
  18994. ParametricGeometry.prototype = Object.create(BufferGeometry.prototype);
  18995. ParametricGeometry.prototype.constructor = ParametricGeometry;
  18996. var RingGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18997. _inheritsLoose(RingGeometry, _BufferGeometry);
  18998. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  18999. var _this;
  19000. if (innerRadius === void 0) {
  19001. innerRadius = 0.5;
  19002. }
  19003. if (outerRadius === void 0) {
  19004. outerRadius = 1;
  19005. }
  19006. if (thetaSegments === void 0) {
  19007. thetaSegments = 8;
  19008. }
  19009. if (phiSegments === void 0) {
  19010. phiSegments = 1;
  19011. }
  19012. if (thetaStart === void 0) {
  19013. thetaStart = 0;
  19014. }
  19015. if (thetaLength === void 0) {
  19016. thetaLength = Math.PI * 2;
  19017. }
  19018. _this = _BufferGeometry.call(this) || this;
  19019. _this.type = 'RingGeometry';
  19020. _this.parameters = {
  19021. innerRadius: innerRadius,
  19022. outerRadius: outerRadius,
  19023. thetaSegments: thetaSegments,
  19024. phiSegments: phiSegments,
  19025. thetaStart: thetaStart,
  19026. thetaLength: thetaLength
  19027. };
  19028. thetaSegments = Math.max(3, thetaSegments);
  19029. phiSegments = Math.max(1, phiSegments); // buffers
  19030. var indices = [];
  19031. var vertices = [];
  19032. var normals = [];
  19033. var uvs = []; // some helper variables
  19034. var radius = innerRadius;
  19035. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  19036. var vertex = new Vector3();
  19037. var uv = new Vector2(); // generate vertices, normals and uvs
  19038. for (var j = 0; j <= phiSegments; j++) {
  19039. for (var i = 0; i <= thetaSegments; i++) {
  19040. // values are generate from the inside of the ring to the outside
  19041. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  19042. vertex.x = radius * Math.cos(segment);
  19043. vertex.y = radius * Math.sin(segment);
  19044. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19045. normals.push(0, 0, 1); // uv
  19046. uv.x = (vertex.x / outerRadius + 1) / 2;
  19047. uv.y = (vertex.y / outerRadius + 1) / 2;
  19048. uvs.push(uv.x, uv.y);
  19049. } // increase the radius for next row of vertices
  19050. radius += radiusStep;
  19051. } // indices
  19052. for (var _j = 0; _j < phiSegments; _j++) {
  19053. var thetaSegmentLevel = _j * (thetaSegments + 1);
  19054. for (var _i = 0; _i < thetaSegments; _i++) {
  19055. var _segment = _i + thetaSegmentLevel;
  19056. var a = _segment;
  19057. var b = _segment + thetaSegments + 1;
  19058. var c = _segment + thetaSegments + 2;
  19059. var d = _segment + 1; // faces
  19060. indices.push(a, b, d);
  19061. indices.push(b, c, d);
  19062. }
  19063. } // build geometry
  19064. _this.setIndex(indices);
  19065. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19066. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19067. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19068. return _this;
  19069. }
  19070. return RingGeometry;
  19071. }(BufferGeometry);
  19072. var ShapeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19073. _inheritsLoose(ShapeGeometry, _BufferGeometry);
  19074. function ShapeGeometry(shapes, curveSegments) {
  19075. var _this;
  19076. if (curveSegments === void 0) {
  19077. curveSegments = 12;
  19078. }
  19079. _this = _BufferGeometry.call(this) || this;
  19080. _this.type = 'ShapeGeometry';
  19081. _this.parameters = {
  19082. shapes: shapes,
  19083. curveSegments: curveSegments
  19084. }; // buffers
  19085. var indices = [];
  19086. var vertices = [];
  19087. var normals = [];
  19088. var uvs = []; // helper variables
  19089. var groupStart = 0;
  19090. var groupCount = 0; // allow single and array values for "shapes" parameter
  19091. if (Array.isArray(shapes) === false) {
  19092. addShape(shapes);
  19093. } else {
  19094. for (var i = 0; i < shapes.length; i++) {
  19095. addShape(shapes[i]);
  19096. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  19097. groupStart += groupCount;
  19098. groupCount = 0;
  19099. }
  19100. } // build geometry
  19101. _this.setIndex(indices);
  19102. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19103. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19104. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  19105. function addShape(shape) {
  19106. var indexOffset = vertices.length / 3;
  19107. var points = shape.extractPoints(curveSegments);
  19108. var shapeVertices = points.shape;
  19109. var shapeHoles = points.holes; // check direction of vertices
  19110. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  19111. shapeVertices = shapeVertices.reverse();
  19112. }
  19113. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  19114. var shapeHole = shapeHoles[_i];
  19115. if (ShapeUtils.isClockWise(shapeHole) === true) {
  19116. shapeHoles[_i] = shapeHole.reverse();
  19117. }
  19118. }
  19119. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  19120. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  19121. var _shapeHole = shapeHoles[_i2];
  19122. shapeVertices = shapeVertices.concat(_shapeHole);
  19123. } // vertices, normals, uvs
  19124. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  19125. var vertex = shapeVertices[_i3];
  19126. vertices.push(vertex.x, vertex.y, 0);
  19127. normals.push(0, 0, 1);
  19128. uvs.push(vertex.x, vertex.y); // world uvs
  19129. } // incides
  19130. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  19131. var face = faces[_i4];
  19132. var a = face[0] + indexOffset;
  19133. var b = face[1] + indexOffset;
  19134. var c = face[2] + indexOffset;
  19135. indices.push(a, b, c);
  19136. groupCount += 3;
  19137. }
  19138. }
  19139. return _this;
  19140. }
  19141. var _proto = ShapeGeometry.prototype;
  19142. _proto.toJSON = function toJSON() {
  19143. var data = BufferGeometry.prototype.toJSON.call(this);
  19144. var shapes = this.parameters.shapes;
  19145. return _toJSON$1(shapes, data);
  19146. };
  19147. return ShapeGeometry;
  19148. }(BufferGeometry);
  19149. function _toJSON$1(shapes, data) {
  19150. data.shapes = [];
  19151. if (Array.isArray(shapes)) {
  19152. for (var i = 0, l = shapes.length; i < l; i++) {
  19153. var shape = shapes[i];
  19154. data.shapes.push(shape.uuid);
  19155. }
  19156. } else {
  19157. data.shapes.push(shapes.uuid);
  19158. }
  19159. return data;
  19160. }
  19161. var SphereGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19162. _inheritsLoose(SphereGeometry, _BufferGeometry);
  19163. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19164. var _this;
  19165. if (radius === void 0) {
  19166. radius = 1;
  19167. }
  19168. if (widthSegments === void 0) {
  19169. widthSegments = 8;
  19170. }
  19171. if (heightSegments === void 0) {
  19172. heightSegments = 6;
  19173. }
  19174. if (phiStart === void 0) {
  19175. phiStart = 0;
  19176. }
  19177. if (phiLength === void 0) {
  19178. phiLength = Math.PI * 2;
  19179. }
  19180. if (thetaStart === void 0) {
  19181. thetaStart = 0;
  19182. }
  19183. if (thetaLength === void 0) {
  19184. thetaLength = Math.PI;
  19185. }
  19186. _this = _BufferGeometry.call(this) || this;
  19187. _this.type = 'SphereGeometry';
  19188. _this.parameters = {
  19189. radius: radius,
  19190. widthSegments: widthSegments,
  19191. heightSegments: heightSegments,
  19192. phiStart: phiStart,
  19193. phiLength: phiLength,
  19194. thetaStart: thetaStart,
  19195. thetaLength: thetaLength
  19196. };
  19197. widthSegments = Math.max(3, Math.floor(widthSegments));
  19198. heightSegments = Math.max(2, Math.floor(heightSegments));
  19199. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  19200. var index = 0;
  19201. var grid = [];
  19202. var vertex = new Vector3();
  19203. var normal = new Vector3(); // buffers
  19204. var indices = [];
  19205. var vertices = [];
  19206. var normals = [];
  19207. var uvs = []; // generate vertices, normals and uvs
  19208. for (var iy = 0; iy <= heightSegments; iy++) {
  19209. var verticesRow = [];
  19210. var v = iy / heightSegments; // special case for the poles
  19211. var uOffset = 0;
  19212. if (iy == 0 && thetaStart == 0) {
  19213. uOffset = 0.5 / widthSegments;
  19214. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  19215. uOffset = -0.5 / widthSegments;
  19216. }
  19217. for (var ix = 0; ix <= widthSegments; ix++) {
  19218. var u = ix / widthSegments; // vertex
  19219. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19220. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  19221. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19222. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19223. normal.copy(vertex).normalize();
  19224. normals.push(normal.x, normal.y, normal.z); // uv
  19225. uvs.push(u + uOffset, 1 - v);
  19226. verticesRow.push(index++);
  19227. }
  19228. grid.push(verticesRow);
  19229. } // indices
  19230. for (var _iy = 0; _iy < heightSegments; _iy++) {
  19231. for (var _ix = 0; _ix < widthSegments; _ix++) {
  19232. var a = grid[_iy][_ix + 1];
  19233. var b = grid[_iy][_ix];
  19234. var c = grid[_iy + 1][_ix];
  19235. var d = grid[_iy + 1][_ix + 1];
  19236. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  19237. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  19238. }
  19239. } // build geometry
  19240. _this.setIndex(indices);
  19241. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19242. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19243. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19244. return _this;
  19245. }
  19246. return SphereGeometry;
  19247. }(BufferGeometry);
  19248. var TetrahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  19249. _inheritsLoose(TetrahedronGeometry, _PolyhedronGeometry);
  19250. function TetrahedronGeometry(radius, detail) {
  19251. var _this;
  19252. if (radius === void 0) {
  19253. radius = 1;
  19254. }
  19255. if (detail === void 0) {
  19256. detail = 0;
  19257. }
  19258. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  19259. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  19260. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  19261. _this.type = 'TetrahedronGeometry';
  19262. _this.parameters = {
  19263. radius: radius,
  19264. detail: detail
  19265. };
  19266. return _this;
  19267. }
  19268. return TetrahedronGeometry;
  19269. }(PolyhedronGeometry);
  19270. var TextGeometry = /*#__PURE__*/function (_ExtrudeGeometry) {
  19271. _inheritsLoose(TextGeometry, _ExtrudeGeometry);
  19272. function TextGeometry(text, parameters) {
  19273. var _this;
  19274. if (parameters === void 0) {
  19275. parameters = {};
  19276. }
  19277. var font = parameters.font;
  19278. if (!(font && font.isFont)) {
  19279. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  19280. return new BufferGeometry() || _assertThisInitialized(_this);
  19281. }
  19282. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  19283. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  19284. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  19285. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  19286. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  19287. _this = _ExtrudeGeometry.call(this, shapes, parameters) || this;
  19288. _this.type = 'TextGeometry';
  19289. return _this;
  19290. }
  19291. return TextGeometry;
  19292. }(ExtrudeGeometry);
  19293. var TorusGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19294. _inheritsLoose(TorusGeometry, _BufferGeometry);
  19295. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19296. var _this;
  19297. if (radius === void 0) {
  19298. radius = 1;
  19299. }
  19300. if (tube === void 0) {
  19301. tube = 0.4;
  19302. }
  19303. if (radialSegments === void 0) {
  19304. radialSegments = 8;
  19305. }
  19306. if (tubularSegments === void 0) {
  19307. tubularSegments = 6;
  19308. }
  19309. if (arc === void 0) {
  19310. arc = Math.PI * 2;
  19311. }
  19312. _this = _BufferGeometry.call(this) || this;
  19313. _this.type = 'TorusGeometry';
  19314. _this.parameters = {
  19315. radius: radius,
  19316. tube: tube,
  19317. radialSegments: radialSegments,
  19318. tubularSegments: tubularSegments,
  19319. arc: arc
  19320. };
  19321. radialSegments = Math.floor(radialSegments);
  19322. tubularSegments = Math.floor(tubularSegments); // buffers
  19323. var indices = [];
  19324. var vertices = [];
  19325. var normals = [];
  19326. var uvs = []; // helper variables
  19327. var center = new Vector3();
  19328. var vertex = new Vector3();
  19329. var normal = new Vector3(); // generate vertices, normals and uvs
  19330. for (var j = 0; j <= radialSegments; j++) {
  19331. for (var i = 0; i <= tubularSegments; i++) {
  19332. var u = i / tubularSegments * arc;
  19333. var v = j / radialSegments * Math.PI * 2; // vertex
  19334. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  19335. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  19336. vertex.z = tube * Math.sin(v);
  19337. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19338. center.x = radius * Math.cos(u);
  19339. center.y = radius * Math.sin(u);
  19340. normal.subVectors(vertex, center).normalize();
  19341. normals.push(normal.x, normal.y, normal.z); // uv
  19342. uvs.push(i / tubularSegments);
  19343. uvs.push(j / radialSegments);
  19344. }
  19345. } // generate indices
  19346. for (var _j = 1; _j <= radialSegments; _j++) {
  19347. for (var _i = 1; _i <= tubularSegments; _i++) {
  19348. // indices
  19349. var a = (tubularSegments + 1) * _j + _i - 1;
  19350. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  19351. var c = (tubularSegments + 1) * (_j - 1) + _i;
  19352. var d = (tubularSegments + 1) * _j + _i; // faces
  19353. indices.push(a, b, d);
  19354. indices.push(b, c, d);
  19355. }
  19356. } // build geometry
  19357. _this.setIndex(indices);
  19358. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19359. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19360. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19361. return _this;
  19362. }
  19363. return TorusGeometry;
  19364. }(BufferGeometry);
  19365. var TorusKnotGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19366. _inheritsLoose(TorusKnotGeometry, _BufferGeometry);
  19367. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  19368. var _this;
  19369. if (radius === void 0) {
  19370. radius = 1;
  19371. }
  19372. if (tube === void 0) {
  19373. tube = 0.4;
  19374. }
  19375. if (tubularSegments === void 0) {
  19376. tubularSegments = 64;
  19377. }
  19378. if (radialSegments === void 0) {
  19379. radialSegments = 8;
  19380. }
  19381. if (p === void 0) {
  19382. p = 2;
  19383. }
  19384. if (q === void 0) {
  19385. q = 3;
  19386. }
  19387. _this = _BufferGeometry.call(this) || this;
  19388. _this.type = 'TorusKnotGeometry';
  19389. _this.parameters = {
  19390. radius: radius,
  19391. tube: tube,
  19392. tubularSegments: tubularSegments,
  19393. radialSegments: radialSegments,
  19394. p: p,
  19395. q: q
  19396. };
  19397. tubularSegments = Math.floor(tubularSegments);
  19398. radialSegments = Math.floor(radialSegments); // buffers
  19399. var indices = [];
  19400. var vertices = [];
  19401. var normals = [];
  19402. var uvs = []; // helper variables
  19403. var vertex = new Vector3();
  19404. var normal = new Vector3();
  19405. var P1 = new Vector3();
  19406. var P2 = new Vector3();
  19407. var B = new Vector3();
  19408. var T = new Vector3();
  19409. var N = new Vector3(); // generate vertices, normals and uvs
  19410. for (var i = 0; i <= tubularSegments; ++i) {
  19411. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19412. 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.
  19413. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19414. calculatePositionOnCurve(u, p, q, radius, P1);
  19415. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  19416. T.subVectors(P2, P1);
  19417. N.addVectors(P2, P1);
  19418. B.crossVectors(T, N);
  19419. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  19420. B.normalize();
  19421. N.normalize();
  19422. for (var j = 0; j <= radialSegments; ++j) {
  19423. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19424. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19425. var v = j / radialSegments * Math.PI * 2;
  19426. var cx = -tube * Math.cos(v);
  19427. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  19428. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19429. vertex.x = P1.x + (cx * N.x + cy * B.x);
  19430. vertex.y = P1.y + (cx * N.y + cy * B.y);
  19431. vertex.z = P1.z + (cx * N.z + cy * B.z);
  19432. 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)
  19433. normal.subVectors(vertex, P1).normalize();
  19434. normals.push(normal.x, normal.y, normal.z); // uv
  19435. uvs.push(i / tubularSegments);
  19436. uvs.push(j / radialSegments);
  19437. }
  19438. } // generate indices
  19439. for (var _j = 1; _j <= tubularSegments; _j++) {
  19440. for (var _i = 1; _i <= radialSegments; _i++) {
  19441. // indices
  19442. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  19443. var b = (radialSegments + 1) * _j + (_i - 1);
  19444. var c = (radialSegments + 1) * _j + _i;
  19445. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  19446. indices.push(a, b, d);
  19447. indices.push(b, c, d);
  19448. }
  19449. } // build geometry
  19450. _this.setIndex(indices);
  19451. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19452. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19453. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  19454. function calculatePositionOnCurve(u, p, q, radius, position) {
  19455. var cu = Math.cos(u);
  19456. var su = Math.sin(u);
  19457. var quOverP = q / p * u;
  19458. var cs = Math.cos(quOverP);
  19459. position.x = radius * (2 + cs) * 0.5 * cu;
  19460. position.y = radius * (2 + cs) * su * 0.5;
  19461. position.z = radius * Math.sin(quOverP) * 0.5;
  19462. }
  19463. return _this;
  19464. }
  19465. return TorusKnotGeometry;
  19466. }(BufferGeometry);
  19467. var TubeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19468. _inheritsLoose(TubeGeometry, _BufferGeometry);
  19469. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed) {
  19470. var _this;
  19471. if (tubularSegments === void 0) {
  19472. tubularSegments = 64;
  19473. }
  19474. if (radius === void 0) {
  19475. radius = 1;
  19476. }
  19477. if (radialSegments === void 0) {
  19478. radialSegments = 8;
  19479. }
  19480. if (closed === void 0) {
  19481. closed = false;
  19482. }
  19483. _this = _BufferGeometry.call(this) || this;
  19484. _this.type = 'TubeGeometry';
  19485. _this.parameters = {
  19486. path: path,
  19487. tubularSegments: tubularSegments,
  19488. radius: radius,
  19489. radialSegments: radialSegments,
  19490. closed: closed
  19491. };
  19492. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  19493. _this.tangents = frames.tangents;
  19494. _this.normals = frames.normals;
  19495. _this.binormals = frames.binormals; // helper variables
  19496. var vertex = new Vector3();
  19497. var normal = new Vector3();
  19498. var uv = new Vector2();
  19499. var P = new Vector3(); // buffer
  19500. var vertices = [];
  19501. var normals = [];
  19502. var uvs = [];
  19503. var indices = []; // create buffer data
  19504. generateBufferData(); // build geometry
  19505. _this.setIndex(indices);
  19506. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19507. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19508. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  19509. function generateBufferData() {
  19510. for (var i = 0; i < tubularSegments; i++) {
  19511. generateSegment(i);
  19512. } // if the geometry is not closed, generate the last row of vertices and normals
  19513. // at the regular position on the given path
  19514. //
  19515. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19516. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  19517. // this makes it easy compute correct values for closed geometries
  19518. generateUVs(); // finally create faces
  19519. generateIndices();
  19520. }
  19521. function generateSegment(i) {
  19522. // we use getPointAt to sample evenly distributed points from the given path
  19523. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  19524. var N = frames.normals[i];
  19525. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  19526. for (var j = 0; j <= radialSegments; j++) {
  19527. var v = j / radialSegments * Math.PI * 2;
  19528. var sin = Math.sin(v);
  19529. var cos = -Math.cos(v); // normal
  19530. normal.x = cos * N.x + sin * B.x;
  19531. normal.y = cos * N.y + sin * B.y;
  19532. normal.z = cos * N.z + sin * B.z;
  19533. normal.normalize();
  19534. normals.push(normal.x, normal.y, normal.z); // vertex
  19535. vertex.x = P.x + radius * normal.x;
  19536. vertex.y = P.y + radius * normal.y;
  19537. vertex.z = P.z + radius * normal.z;
  19538. vertices.push(vertex.x, vertex.y, vertex.z);
  19539. }
  19540. }
  19541. function generateIndices() {
  19542. for (var j = 1; j <= tubularSegments; j++) {
  19543. for (var i = 1; i <= radialSegments; i++) {
  19544. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  19545. var b = (radialSegments + 1) * j + (i - 1);
  19546. var c = (radialSegments + 1) * j + i;
  19547. var d = (radialSegments + 1) * (j - 1) + i; // faces
  19548. indices.push(a, b, d);
  19549. indices.push(b, c, d);
  19550. }
  19551. }
  19552. }
  19553. function generateUVs() {
  19554. for (var i = 0; i <= tubularSegments; i++) {
  19555. for (var j = 0; j <= radialSegments; j++) {
  19556. uv.x = i / tubularSegments;
  19557. uv.y = j / radialSegments;
  19558. uvs.push(uv.x, uv.y);
  19559. }
  19560. }
  19561. }
  19562. return _this;
  19563. }
  19564. var _proto = TubeGeometry.prototype;
  19565. _proto.toJSON = function toJSON() {
  19566. var data = BufferGeometry.prototype.toJSON.call(this);
  19567. data.path = this.parameters.path.toJSON();
  19568. return data;
  19569. };
  19570. return TubeGeometry;
  19571. }(BufferGeometry);
  19572. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19573. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  19574. function WireframeGeometry(geometry) {
  19575. var _this;
  19576. _this = _BufferGeometry.call(this) || this;
  19577. _this.type = 'WireframeGeometry';
  19578. if (geometry.isGeometry === true) {
  19579. console.error('THREE.WireframeGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  19580. return _assertThisInitialized(_this);
  19581. } // buffer
  19582. var vertices = []; // helper variables
  19583. var edge = [0, 0],
  19584. edges = {};
  19585. var vertex = new Vector3();
  19586. if (geometry.index !== null) {
  19587. // indexed BufferGeometry
  19588. var position = geometry.attributes.position;
  19589. var indices = geometry.index;
  19590. var groups = geometry.groups;
  19591. if (groups.length === 0) {
  19592. groups = [{
  19593. start: 0,
  19594. count: indices.count,
  19595. materialIndex: 0
  19596. }];
  19597. } // create a data structure that contains all eges without duplicates
  19598. for (var o = 0, ol = groups.length; o < ol; ++o) {
  19599. var group = groups[o];
  19600. var start = group.start;
  19601. var count = group.count;
  19602. for (var i = start, l = start + count; i < l; i += 3) {
  19603. for (var j = 0; j < 3; j++) {
  19604. var edge1 = indices.getX(i + j);
  19605. var edge2 = indices.getX(i + (j + 1) % 3);
  19606. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  19607. edge[1] = Math.max(edge1, edge2);
  19608. var key = edge[0] + ',' + edge[1];
  19609. if (edges[key] === undefined) {
  19610. edges[key] = {
  19611. index1: edge[0],
  19612. index2: edge[1]
  19613. };
  19614. }
  19615. }
  19616. }
  19617. } // generate vertices
  19618. for (var _key in edges) {
  19619. var e = edges[_key];
  19620. vertex.fromBufferAttribute(position, e.index1);
  19621. vertices.push(vertex.x, vertex.y, vertex.z);
  19622. vertex.fromBufferAttribute(position, e.index2);
  19623. vertices.push(vertex.x, vertex.y, vertex.z);
  19624. }
  19625. } else {
  19626. // non-indexed BufferGeometry
  19627. var _position = geometry.attributes.position;
  19628. for (var _i = 0, _l = _position.count / 3; _i < _l; _i++) {
  19629. for (var _j = 0; _j < 3; _j++) {
  19630. // three edges per triangle, an edge is represented as (index1, index2)
  19631. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  19632. var index1 = 3 * _i + _j;
  19633. vertex.fromBufferAttribute(_position, index1);
  19634. vertices.push(vertex.x, vertex.y, vertex.z);
  19635. var index2 = 3 * _i + (_j + 1) % 3;
  19636. vertex.fromBufferAttribute(_position, index2);
  19637. vertices.push(vertex.x, vertex.y, vertex.z);
  19638. }
  19639. }
  19640. } // build geometry
  19641. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19642. return _this;
  19643. }
  19644. return WireframeGeometry;
  19645. }(BufferGeometry);
  19646. var Geometries = /*#__PURE__*/Object.freeze({
  19647. __proto__: null,
  19648. BoxGeometry: BoxGeometry,
  19649. BoxBufferGeometry: BoxGeometry,
  19650. CircleGeometry: CircleGeometry,
  19651. CircleBufferGeometry: CircleGeometry,
  19652. ConeGeometry: ConeGeometry,
  19653. ConeBufferGeometry: ConeGeometry,
  19654. CylinderGeometry: CylinderGeometry,
  19655. CylinderBufferGeometry: CylinderGeometry,
  19656. DodecahedronGeometry: DodecahedronGeometry,
  19657. DodecahedronBufferGeometry: DodecahedronGeometry,
  19658. EdgesGeometry: EdgesGeometry,
  19659. ExtrudeGeometry: ExtrudeGeometry,
  19660. ExtrudeBufferGeometry: ExtrudeGeometry,
  19661. IcosahedronGeometry: IcosahedronGeometry,
  19662. IcosahedronBufferGeometry: IcosahedronGeometry,
  19663. LatheGeometry: LatheGeometry,
  19664. LatheBufferGeometry: LatheGeometry,
  19665. OctahedronGeometry: OctahedronGeometry,
  19666. OctahedronBufferGeometry: OctahedronGeometry,
  19667. ParametricGeometry: ParametricGeometry,
  19668. ParametricBufferGeometry: ParametricGeometry,
  19669. PlaneGeometry: PlaneGeometry,
  19670. PlaneBufferGeometry: PlaneGeometry,
  19671. PolyhedronGeometry: PolyhedronGeometry,
  19672. PolyhedronBufferGeometry: PolyhedronGeometry,
  19673. RingGeometry: RingGeometry,
  19674. RingBufferGeometry: RingGeometry,
  19675. ShapeGeometry: ShapeGeometry,
  19676. ShapeBufferGeometry: ShapeGeometry,
  19677. SphereGeometry: SphereGeometry,
  19678. SphereBufferGeometry: SphereGeometry,
  19679. TetrahedronGeometry: TetrahedronGeometry,
  19680. TetrahedronBufferGeometry: TetrahedronGeometry,
  19681. TextGeometry: TextGeometry,
  19682. TextBufferGeometry: TextGeometry,
  19683. TorusGeometry: TorusGeometry,
  19684. TorusBufferGeometry: TorusGeometry,
  19685. TorusKnotGeometry: TorusKnotGeometry,
  19686. TorusKnotBufferGeometry: TorusKnotGeometry,
  19687. TubeGeometry: TubeGeometry,
  19688. TubeBufferGeometry: TubeGeometry,
  19689. WireframeGeometry: WireframeGeometry
  19690. });
  19691. /**
  19692. * parameters = {
  19693. * color: <THREE.Color>
  19694. * }
  19695. */
  19696. var ShadowMaterial = /*#__PURE__*/function (_Material) {
  19697. _inheritsLoose(ShadowMaterial, _Material);
  19698. function ShadowMaterial(parameters) {
  19699. var _this;
  19700. _this = _Material.call(this) || this;
  19701. _this.type = 'ShadowMaterial';
  19702. _this.color = new Color(0x000000);
  19703. _this.transparent = true;
  19704. _this.setValues(parameters);
  19705. return _this;
  19706. }
  19707. var _proto = ShadowMaterial.prototype;
  19708. _proto.copy = function copy(source) {
  19709. _Material.prototype.copy.call(this, source);
  19710. this.color.copy(source.color);
  19711. return this;
  19712. };
  19713. return ShadowMaterial;
  19714. }(Material);
  19715. ShadowMaterial.prototype.isShadowMaterial = true;
  19716. var RawShaderMaterial = /*#__PURE__*/function (_ShaderMaterial) {
  19717. _inheritsLoose(RawShaderMaterial, _ShaderMaterial);
  19718. function RawShaderMaterial(parameters) {
  19719. var _this;
  19720. _this = _ShaderMaterial.call(this, parameters) || this;
  19721. _this.type = 'RawShaderMaterial';
  19722. return _this;
  19723. }
  19724. return RawShaderMaterial;
  19725. }(ShaderMaterial);
  19726. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19727. /**
  19728. * parameters = {
  19729. * color: <hex>,
  19730. * roughness: <float>,
  19731. * metalness: <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. * roughnessMap: new THREE.Texture( <Image> ),
  19758. *
  19759. * metalnessMap: new THREE.Texture( <Image> ),
  19760. *
  19761. * alphaMap: new THREE.Texture( <Image> ),
  19762. *
  19763. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19764. * envMapIntensity: <float>
  19765. *
  19766. * refractionRatio: <float>,
  19767. *
  19768. * wireframe: <boolean>,
  19769. * wireframeLinewidth: <float>,
  19770. *
  19771. * skinning: <bool>,
  19772. * morphTargets: <bool>,
  19773. * morphNormals: <bool>,
  19774. *
  19775. * flatShading: <bool>
  19776. * }
  19777. */
  19778. var MeshStandardMaterial = /*#__PURE__*/function (_Material) {
  19779. _inheritsLoose(MeshStandardMaterial, _Material);
  19780. function MeshStandardMaterial(parameters) {
  19781. var _this;
  19782. _this = _Material.call(this) || this;
  19783. _this.defines = {
  19784. 'STANDARD': ''
  19785. };
  19786. _this.type = 'MeshStandardMaterial';
  19787. _this.color = new Color(0xffffff); // diffuse
  19788. _this.roughness = 1.0;
  19789. _this.metalness = 0.0;
  19790. _this.map = null;
  19791. _this.lightMap = null;
  19792. _this.lightMapIntensity = 1.0;
  19793. _this.aoMap = null;
  19794. _this.aoMapIntensity = 1.0;
  19795. _this.emissive = new Color(0x000000);
  19796. _this.emissiveIntensity = 1.0;
  19797. _this.emissiveMap = null;
  19798. _this.bumpMap = null;
  19799. _this.bumpScale = 1;
  19800. _this.normalMap = null;
  19801. _this.normalMapType = TangentSpaceNormalMap;
  19802. _this.normalScale = new Vector2(1, 1);
  19803. _this.displacementMap = null;
  19804. _this.displacementScale = 1;
  19805. _this.displacementBias = 0;
  19806. _this.roughnessMap = null;
  19807. _this.metalnessMap = null;
  19808. _this.alphaMap = null;
  19809. _this.envMap = null;
  19810. _this.envMapIntensity = 1.0;
  19811. _this.refractionRatio = 0.98;
  19812. _this.wireframe = false;
  19813. _this.wireframeLinewidth = 1;
  19814. _this.wireframeLinecap = 'round';
  19815. _this.wireframeLinejoin = 'round';
  19816. _this.skinning = false;
  19817. _this.morphTargets = false;
  19818. _this.morphNormals = false;
  19819. _this.flatShading = false;
  19820. _this.vertexTangents = false;
  19821. _this.setValues(parameters);
  19822. return _this;
  19823. }
  19824. var _proto = MeshStandardMaterial.prototype;
  19825. _proto.copy = function copy(source) {
  19826. _Material.prototype.copy.call(this, source);
  19827. this.defines = {
  19828. 'STANDARD': ''
  19829. };
  19830. this.color.copy(source.color);
  19831. this.roughness = source.roughness;
  19832. this.metalness = source.metalness;
  19833. this.map = source.map;
  19834. this.lightMap = source.lightMap;
  19835. this.lightMapIntensity = source.lightMapIntensity;
  19836. this.aoMap = source.aoMap;
  19837. this.aoMapIntensity = source.aoMapIntensity;
  19838. this.emissive.copy(source.emissive);
  19839. this.emissiveMap = source.emissiveMap;
  19840. this.emissiveIntensity = source.emissiveIntensity;
  19841. this.bumpMap = source.bumpMap;
  19842. this.bumpScale = source.bumpScale;
  19843. this.normalMap = source.normalMap;
  19844. this.normalMapType = source.normalMapType;
  19845. this.normalScale.copy(source.normalScale);
  19846. this.displacementMap = source.displacementMap;
  19847. this.displacementScale = source.displacementScale;
  19848. this.displacementBias = source.displacementBias;
  19849. this.roughnessMap = source.roughnessMap;
  19850. this.metalnessMap = source.metalnessMap;
  19851. this.alphaMap = source.alphaMap;
  19852. this.envMap = source.envMap;
  19853. this.envMapIntensity = source.envMapIntensity;
  19854. this.refractionRatio = source.refractionRatio;
  19855. this.wireframe = source.wireframe;
  19856. this.wireframeLinewidth = source.wireframeLinewidth;
  19857. this.wireframeLinecap = source.wireframeLinecap;
  19858. this.wireframeLinejoin = source.wireframeLinejoin;
  19859. this.skinning = source.skinning;
  19860. this.morphTargets = source.morphTargets;
  19861. this.morphNormals = source.morphNormals;
  19862. this.flatShading = source.flatShading;
  19863. this.vertexTangents = source.vertexTangents;
  19864. return this;
  19865. };
  19866. return MeshStandardMaterial;
  19867. }(Material);
  19868. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19869. /**
  19870. * parameters = {
  19871. * clearcoat: <float>,
  19872. * clearcoatMap: new THREE.Texture( <Image> ),
  19873. * clearcoatRoughness: <float>,
  19874. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  19875. * clearcoatNormalScale: <Vector2>,
  19876. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  19877. *
  19878. * reflectivity: <float>,
  19879. * ior: <float>,
  19880. *
  19881. * sheen: <Color>,
  19882. *
  19883. * transmission: <float>,
  19884. * transmissionMap: new THREE.Texture( <Image> )
  19885. * }
  19886. */
  19887. var MeshPhysicalMaterial = /*#__PURE__*/function (_MeshStandardMaterial) {
  19888. _inheritsLoose(MeshPhysicalMaterial, _MeshStandardMaterial);
  19889. function MeshPhysicalMaterial(parameters) {
  19890. var _this;
  19891. _this = _MeshStandardMaterial.call(this) || this;
  19892. _this.defines = {
  19893. 'STANDARD': '',
  19894. 'PHYSICAL': ''
  19895. };
  19896. _this.type = 'MeshPhysicalMaterial';
  19897. _this.clearcoat = 0.0;
  19898. _this.clearcoatMap = null;
  19899. _this.clearcoatRoughness = 0.0;
  19900. _this.clearcoatRoughnessMap = null;
  19901. _this.clearcoatNormalScale = new Vector2(1, 1);
  19902. _this.clearcoatNormalMap = null;
  19903. _this.reflectivity = 0.5; // maps to F0 = 0.04
  19904. Object.defineProperty(_assertThisInitialized(_this), 'ior', {
  19905. get: function get() {
  19906. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  19907. },
  19908. set: function set(ior) {
  19909. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  19910. }
  19911. });
  19912. _this.sheen = null; // null will disable sheen bsdf
  19913. _this.transmission = 0.0;
  19914. _this.transmissionMap = null;
  19915. _this.setValues(parameters);
  19916. return _this;
  19917. }
  19918. var _proto = MeshPhysicalMaterial.prototype;
  19919. _proto.copy = function copy(source) {
  19920. _MeshStandardMaterial.prototype.copy.call(this, source);
  19921. this.defines = {
  19922. 'STANDARD': '',
  19923. 'PHYSICAL': ''
  19924. };
  19925. this.clearcoat = source.clearcoat;
  19926. this.clearcoatMap = source.clearcoatMap;
  19927. this.clearcoatRoughness = source.clearcoatRoughness;
  19928. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  19929. this.clearcoatNormalMap = source.clearcoatNormalMap;
  19930. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  19931. this.reflectivity = source.reflectivity;
  19932. if (source.sheen) {
  19933. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  19934. } else {
  19935. this.sheen = null;
  19936. }
  19937. this.transmission = source.transmission;
  19938. this.transmissionMap = source.transmissionMap;
  19939. return this;
  19940. };
  19941. return MeshPhysicalMaterial;
  19942. }(MeshStandardMaterial);
  19943. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19944. /**
  19945. * parameters = {
  19946. * color: <hex>,
  19947. * specular: <hex>,
  19948. * shininess: <float>,
  19949. * opacity: <float>,
  19950. *
  19951. * map: new THREE.Texture( <Image> ),
  19952. *
  19953. * lightMap: new THREE.Texture( <Image> ),
  19954. * lightMapIntensity: <float>
  19955. *
  19956. * aoMap: new THREE.Texture( <Image> ),
  19957. * aoMapIntensity: <float>
  19958. *
  19959. * emissive: <hex>,
  19960. * emissiveIntensity: <float>
  19961. * emissiveMap: new THREE.Texture( <Image> ),
  19962. *
  19963. * bumpMap: new THREE.Texture( <Image> ),
  19964. * bumpScale: <float>,
  19965. *
  19966. * normalMap: new THREE.Texture( <Image> ),
  19967. * normalMapType: THREE.TangentSpaceNormalMap,
  19968. * normalScale: <Vector2>,
  19969. *
  19970. * displacementMap: new THREE.Texture( <Image> ),
  19971. * displacementScale: <float>,
  19972. * displacementBias: <float>,
  19973. *
  19974. * specularMap: new THREE.Texture( <Image> ),
  19975. *
  19976. * alphaMap: new THREE.Texture( <Image> ),
  19977. *
  19978. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19979. * combine: THREE.MultiplyOperation,
  19980. * reflectivity: <float>,
  19981. * refractionRatio: <float>,
  19982. *
  19983. * wireframe: <boolean>,
  19984. * wireframeLinewidth: <float>,
  19985. *
  19986. * skinning: <bool>,
  19987. * morphTargets: <bool>,
  19988. * morphNormals: <bool>,
  19989. *
  19990. * flatShading: <bool>
  19991. * }
  19992. */
  19993. var MeshPhongMaterial = /*#__PURE__*/function (_Material) {
  19994. _inheritsLoose(MeshPhongMaterial, _Material);
  19995. function MeshPhongMaterial(parameters) {
  19996. var _this;
  19997. _this = _Material.call(this) || this;
  19998. _this.type = 'MeshPhongMaterial';
  19999. _this.color = new Color(0xffffff); // diffuse
  20000. _this.specular = new Color(0x111111);
  20001. _this.shininess = 30;
  20002. _this.map = null;
  20003. _this.lightMap = null;
  20004. _this.lightMapIntensity = 1.0;
  20005. _this.aoMap = null;
  20006. _this.aoMapIntensity = 1.0;
  20007. _this.emissive = new Color(0x000000);
  20008. _this.emissiveIntensity = 1.0;
  20009. _this.emissiveMap = null;
  20010. _this.bumpMap = null;
  20011. _this.bumpScale = 1;
  20012. _this.normalMap = null;
  20013. _this.normalMapType = TangentSpaceNormalMap;
  20014. _this.normalScale = new Vector2(1, 1);
  20015. _this.displacementMap = null;
  20016. _this.displacementScale = 1;
  20017. _this.displacementBias = 0;
  20018. _this.specularMap = null;
  20019. _this.alphaMap = null;
  20020. _this.envMap = null;
  20021. _this.combine = MultiplyOperation;
  20022. _this.reflectivity = 1;
  20023. _this.refractionRatio = 0.98;
  20024. _this.wireframe = false;
  20025. _this.wireframeLinewidth = 1;
  20026. _this.wireframeLinecap = 'round';
  20027. _this.wireframeLinejoin = 'round';
  20028. _this.skinning = false;
  20029. _this.morphTargets = false;
  20030. _this.morphNormals = false;
  20031. _this.flatShading = false;
  20032. _this.setValues(parameters);
  20033. return _this;
  20034. }
  20035. var _proto = MeshPhongMaterial.prototype;
  20036. _proto.copy = function copy(source) {
  20037. _Material.prototype.copy.call(this, source);
  20038. this.color.copy(source.color);
  20039. this.specular.copy(source.specular);
  20040. this.shininess = source.shininess;
  20041. this.map = source.map;
  20042. this.lightMap = source.lightMap;
  20043. this.lightMapIntensity = source.lightMapIntensity;
  20044. this.aoMap = source.aoMap;
  20045. this.aoMapIntensity = source.aoMapIntensity;
  20046. this.emissive.copy(source.emissive);
  20047. this.emissiveMap = source.emissiveMap;
  20048. this.emissiveIntensity = source.emissiveIntensity;
  20049. this.bumpMap = source.bumpMap;
  20050. this.bumpScale = source.bumpScale;
  20051. this.normalMap = source.normalMap;
  20052. this.normalMapType = source.normalMapType;
  20053. this.normalScale.copy(source.normalScale);
  20054. this.displacementMap = source.displacementMap;
  20055. this.displacementScale = source.displacementScale;
  20056. this.displacementBias = source.displacementBias;
  20057. this.specularMap = source.specularMap;
  20058. this.alphaMap = source.alphaMap;
  20059. this.envMap = source.envMap;
  20060. this.combine = source.combine;
  20061. this.reflectivity = source.reflectivity;
  20062. this.refractionRatio = source.refractionRatio;
  20063. this.wireframe = source.wireframe;
  20064. this.wireframeLinewidth = source.wireframeLinewidth;
  20065. this.wireframeLinecap = source.wireframeLinecap;
  20066. this.wireframeLinejoin = source.wireframeLinejoin;
  20067. this.skinning = source.skinning;
  20068. this.morphTargets = source.morphTargets;
  20069. this.morphNormals = source.morphNormals;
  20070. this.flatShading = source.flatShading;
  20071. return this;
  20072. };
  20073. return MeshPhongMaterial;
  20074. }(Material);
  20075. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  20076. /**
  20077. * parameters = {
  20078. * color: <hex>,
  20079. *
  20080. * map: new THREE.Texture( <Image> ),
  20081. * gradientMap: new THREE.Texture( <Image> ),
  20082. *
  20083. * lightMap: new THREE.Texture( <Image> ),
  20084. * lightMapIntensity: <float>
  20085. *
  20086. * aoMap: new THREE.Texture( <Image> ),
  20087. * aoMapIntensity: <float>
  20088. *
  20089. * emissive: <hex>,
  20090. * emissiveIntensity: <float>
  20091. * emissiveMap: new THREE.Texture( <Image> ),
  20092. *
  20093. * bumpMap: new THREE.Texture( <Image> ),
  20094. * bumpScale: <float>,
  20095. *
  20096. * normalMap: new THREE.Texture( <Image> ),
  20097. * normalMapType: THREE.TangentSpaceNormalMap,
  20098. * normalScale: <Vector2>,
  20099. *
  20100. * displacementMap: new THREE.Texture( <Image> ),
  20101. * displacementScale: <float>,
  20102. * displacementBias: <float>,
  20103. *
  20104. * alphaMap: new THREE.Texture( <Image> ),
  20105. *
  20106. * wireframe: <boolean>,
  20107. * wireframeLinewidth: <float>,
  20108. *
  20109. * skinning: <bool>,
  20110. * morphTargets: <bool>,
  20111. * morphNormals: <bool>
  20112. * }
  20113. */
  20114. var MeshToonMaterial = /*#__PURE__*/function (_Material) {
  20115. _inheritsLoose(MeshToonMaterial, _Material);
  20116. function MeshToonMaterial(parameters) {
  20117. var _this;
  20118. _this = _Material.call(this) || this;
  20119. _this.defines = {
  20120. 'TOON': ''
  20121. };
  20122. _this.type = 'MeshToonMaterial';
  20123. _this.color = new Color(0xffffff);
  20124. _this.map = null;
  20125. _this.gradientMap = null;
  20126. _this.lightMap = null;
  20127. _this.lightMapIntensity = 1.0;
  20128. _this.aoMap = null;
  20129. _this.aoMapIntensity = 1.0;
  20130. _this.emissive = new Color(0x000000);
  20131. _this.emissiveIntensity = 1.0;
  20132. _this.emissiveMap = null;
  20133. _this.bumpMap = null;
  20134. _this.bumpScale = 1;
  20135. _this.normalMap = null;
  20136. _this.normalMapType = TangentSpaceNormalMap;
  20137. _this.normalScale = new Vector2(1, 1);
  20138. _this.displacementMap = null;
  20139. _this.displacementScale = 1;
  20140. _this.displacementBias = 0;
  20141. _this.alphaMap = null;
  20142. _this.wireframe = false;
  20143. _this.wireframeLinewidth = 1;
  20144. _this.wireframeLinecap = 'round';
  20145. _this.wireframeLinejoin = 'round';
  20146. _this.skinning = false;
  20147. _this.morphTargets = false;
  20148. _this.morphNormals = false;
  20149. _this.setValues(parameters);
  20150. return _this;
  20151. }
  20152. var _proto = MeshToonMaterial.prototype;
  20153. _proto.copy = function copy(source) {
  20154. _Material.prototype.copy.call(this, source);
  20155. this.color.copy(source.color);
  20156. this.map = source.map;
  20157. this.gradientMap = source.gradientMap;
  20158. this.lightMap = source.lightMap;
  20159. this.lightMapIntensity = source.lightMapIntensity;
  20160. this.aoMap = source.aoMap;
  20161. this.aoMapIntensity = source.aoMapIntensity;
  20162. this.emissive.copy(source.emissive);
  20163. this.emissiveMap = source.emissiveMap;
  20164. this.emissiveIntensity = source.emissiveIntensity;
  20165. this.bumpMap = source.bumpMap;
  20166. this.bumpScale = source.bumpScale;
  20167. this.normalMap = source.normalMap;
  20168. this.normalMapType = source.normalMapType;
  20169. this.normalScale.copy(source.normalScale);
  20170. this.displacementMap = source.displacementMap;
  20171. this.displacementScale = source.displacementScale;
  20172. this.displacementBias = source.displacementBias;
  20173. this.alphaMap = source.alphaMap;
  20174. this.wireframe = source.wireframe;
  20175. this.wireframeLinewidth = source.wireframeLinewidth;
  20176. this.wireframeLinecap = source.wireframeLinecap;
  20177. this.wireframeLinejoin = source.wireframeLinejoin;
  20178. this.skinning = source.skinning;
  20179. this.morphTargets = source.morphTargets;
  20180. this.morphNormals = source.morphNormals;
  20181. return this;
  20182. };
  20183. return MeshToonMaterial;
  20184. }(Material);
  20185. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  20186. /**
  20187. * parameters = {
  20188. * opacity: <float>,
  20189. *
  20190. * bumpMap: new THREE.Texture( <Image> ),
  20191. * bumpScale: <float>,
  20192. *
  20193. * normalMap: new THREE.Texture( <Image> ),
  20194. * normalMapType: THREE.TangentSpaceNormalMap,
  20195. * normalScale: <Vector2>,
  20196. *
  20197. * displacementMap: new THREE.Texture( <Image> ),
  20198. * displacementScale: <float>,
  20199. * displacementBias: <float>,
  20200. *
  20201. * wireframe: <boolean>,
  20202. * wireframeLinewidth: <float>
  20203. *
  20204. * skinning: <bool>,
  20205. * morphTargets: <bool>,
  20206. * morphNormals: <bool>,
  20207. *
  20208. * flatShading: <bool>
  20209. * }
  20210. */
  20211. var MeshNormalMaterial = /*#__PURE__*/function (_Material) {
  20212. _inheritsLoose(MeshNormalMaterial, _Material);
  20213. function MeshNormalMaterial(parameters) {
  20214. var _this;
  20215. _this = _Material.call(this) || this;
  20216. _this.type = 'MeshNormalMaterial';
  20217. _this.bumpMap = null;
  20218. _this.bumpScale = 1;
  20219. _this.normalMap = null;
  20220. _this.normalMapType = TangentSpaceNormalMap;
  20221. _this.normalScale = new Vector2(1, 1);
  20222. _this.displacementMap = null;
  20223. _this.displacementScale = 1;
  20224. _this.displacementBias = 0;
  20225. _this.wireframe = false;
  20226. _this.wireframeLinewidth = 1;
  20227. _this.fog = false;
  20228. _this.skinning = false;
  20229. _this.morphTargets = false;
  20230. _this.morphNormals = false;
  20231. _this.flatShading = false;
  20232. _this.setValues(parameters);
  20233. return _this;
  20234. }
  20235. var _proto = MeshNormalMaterial.prototype;
  20236. _proto.copy = function copy(source) {
  20237. _Material.prototype.copy.call(this, source);
  20238. this.bumpMap = source.bumpMap;
  20239. this.bumpScale = source.bumpScale;
  20240. this.normalMap = source.normalMap;
  20241. this.normalMapType = source.normalMapType;
  20242. this.normalScale.copy(source.normalScale);
  20243. this.displacementMap = source.displacementMap;
  20244. this.displacementScale = source.displacementScale;
  20245. this.displacementBias = source.displacementBias;
  20246. this.wireframe = source.wireframe;
  20247. this.wireframeLinewidth = source.wireframeLinewidth;
  20248. this.skinning = source.skinning;
  20249. this.morphTargets = source.morphTargets;
  20250. this.morphNormals = source.morphNormals;
  20251. this.flatShading = source.flatShading;
  20252. return this;
  20253. };
  20254. return MeshNormalMaterial;
  20255. }(Material);
  20256. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20257. /**
  20258. * parameters = {
  20259. * color: <hex>,
  20260. * opacity: <float>,
  20261. *
  20262. * map: new THREE.Texture( <Image> ),
  20263. *
  20264. * lightMap: new THREE.Texture( <Image> ),
  20265. * lightMapIntensity: <float>
  20266. *
  20267. * aoMap: new THREE.Texture( <Image> ),
  20268. * aoMapIntensity: <float>
  20269. *
  20270. * emissive: <hex>,
  20271. * emissiveIntensity: <float>
  20272. * emissiveMap: new THREE.Texture( <Image> ),
  20273. *
  20274. * specularMap: new THREE.Texture( <Image> ),
  20275. *
  20276. * alphaMap: new THREE.Texture( <Image> ),
  20277. *
  20278. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20279. * combine: THREE.Multiply,
  20280. * reflectivity: <float>,
  20281. * refractionRatio: <float>,
  20282. *
  20283. * wireframe: <boolean>,
  20284. * wireframeLinewidth: <float>,
  20285. *
  20286. * skinning: <bool>,
  20287. * morphTargets: <bool>,
  20288. * morphNormals: <bool>
  20289. * }
  20290. */
  20291. var MeshLambertMaterial = /*#__PURE__*/function (_Material) {
  20292. _inheritsLoose(MeshLambertMaterial, _Material);
  20293. function MeshLambertMaterial(parameters) {
  20294. var _this;
  20295. _this = _Material.call(this) || this;
  20296. _this.type = 'MeshLambertMaterial';
  20297. _this.color = new Color(0xffffff); // diffuse
  20298. _this.map = null;
  20299. _this.lightMap = null;
  20300. _this.lightMapIntensity = 1.0;
  20301. _this.aoMap = null;
  20302. _this.aoMapIntensity = 1.0;
  20303. _this.emissive = new Color(0x000000);
  20304. _this.emissiveIntensity = 1.0;
  20305. _this.emissiveMap = null;
  20306. _this.specularMap = null;
  20307. _this.alphaMap = null;
  20308. _this.envMap = null;
  20309. _this.combine = MultiplyOperation;
  20310. _this.reflectivity = 1;
  20311. _this.refractionRatio = 0.98;
  20312. _this.wireframe = false;
  20313. _this.wireframeLinewidth = 1;
  20314. _this.wireframeLinecap = 'round';
  20315. _this.wireframeLinejoin = 'round';
  20316. _this.skinning = false;
  20317. _this.morphTargets = false;
  20318. _this.morphNormals = false;
  20319. _this.setValues(parameters);
  20320. return _this;
  20321. }
  20322. var _proto = MeshLambertMaterial.prototype;
  20323. _proto.copy = function copy(source) {
  20324. _Material.prototype.copy.call(this, source);
  20325. this.color.copy(source.color);
  20326. this.map = source.map;
  20327. this.lightMap = source.lightMap;
  20328. this.lightMapIntensity = source.lightMapIntensity;
  20329. this.aoMap = source.aoMap;
  20330. this.aoMapIntensity = source.aoMapIntensity;
  20331. this.emissive.copy(source.emissive);
  20332. this.emissiveMap = source.emissiveMap;
  20333. this.emissiveIntensity = source.emissiveIntensity;
  20334. this.specularMap = source.specularMap;
  20335. this.alphaMap = source.alphaMap;
  20336. this.envMap = source.envMap;
  20337. this.combine = source.combine;
  20338. this.reflectivity = source.reflectivity;
  20339. this.refractionRatio = source.refractionRatio;
  20340. this.wireframe = source.wireframe;
  20341. this.wireframeLinewidth = source.wireframeLinewidth;
  20342. this.wireframeLinecap = source.wireframeLinecap;
  20343. this.wireframeLinejoin = source.wireframeLinejoin;
  20344. this.skinning = source.skinning;
  20345. this.morphTargets = source.morphTargets;
  20346. this.morphNormals = source.morphNormals;
  20347. return this;
  20348. };
  20349. return MeshLambertMaterial;
  20350. }(Material);
  20351. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20352. /**
  20353. * parameters = {
  20354. * color: <hex>,
  20355. * opacity: <float>,
  20356. *
  20357. * matcap: new THREE.Texture( <Image> ),
  20358. *
  20359. * map: new THREE.Texture( <Image> ),
  20360. *
  20361. * bumpMap: new THREE.Texture( <Image> ),
  20362. * bumpScale: <float>,
  20363. *
  20364. * normalMap: new THREE.Texture( <Image> ),
  20365. * normalMapType: THREE.TangentSpaceNormalMap,
  20366. * normalScale: <Vector2>,
  20367. *
  20368. * displacementMap: new THREE.Texture( <Image> ),
  20369. * displacementScale: <float>,
  20370. * displacementBias: <float>,
  20371. *
  20372. * alphaMap: new THREE.Texture( <Image> ),
  20373. *
  20374. * skinning: <bool>,
  20375. * morphTargets: <bool>,
  20376. * morphNormals: <bool>
  20377. *
  20378. * flatShading: <bool>
  20379. * }
  20380. */
  20381. var MeshMatcapMaterial = /*#__PURE__*/function (_Material) {
  20382. _inheritsLoose(MeshMatcapMaterial, _Material);
  20383. function MeshMatcapMaterial(parameters) {
  20384. var _this;
  20385. _this = _Material.call(this) || this;
  20386. _this.defines = {
  20387. 'MATCAP': ''
  20388. };
  20389. _this.type = 'MeshMatcapMaterial';
  20390. _this.color = new Color(0xffffff); // diffuse
  20391. _this.matcap = null;
  20392. _this.map = null;
  20393. _this.bumpMap = null;
  20394. _this.bumpScale = 1;
  20395. _this.normalMap = null;
  20396. _this.normalMapType = TangentSpaceNormalMap;
  20397. _this.normalScale = new Vector2(1, 1);
  20398. _this.displacementMap = null;
  20399. _this.displacementScale = 1;
  20400. _this.displacementBias = 0;
  20401. _this.alphaMap = null;
  20402. _this.skinning = false;
  20403. _this.morphTargets = false;
  20404. _this.morphNormals = false;
  20405. _this.flatShading = false;
  20406. _this.setValues(parameters);
  20407. return _this;
  20408. }
  20409. var _proto = MeshMatcapMaterial.prototype;
  20410. _proto.copy = function copy(source) {
  20411. _Material.prototype.copy.call(this, source);
  20412. this.defines = {
  20413. 'MATCAP': ''
  20414. };
  20415. this.color.copy(source.color);
  20416. this.matcap = source.matcap;
  20417. this.map = source.map;
  20418. this.bumpMap = source.bumpMap;
  20419. this.bumpScale = source.bumpScale;
  20420. this.normalMap = source.normalMap;
  20421. this.normalMapType = source.normalMapType;
  20422. this.normalScale.copy(source.normalScale);
  20423. this.displacementMap = source.displacementMap;
  20424. this.displacementScale = source.displacementScale;
  20425. this.displacementBias = source.displacementBias;
  20426. this.alphaMap = source.alphaMap;
  20427. this.skinning = source.skinning;
  20428. this.morphTargets = source.morphTargets;
  20429. this.morphNormals = source.morphNormals;
  20430. this.flatShading = source.flatShading;
  20431. return this;
  20432. };
  20433. return MeshMatcapMaterial;
  20434. }(Material);
  20435. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20436. /**
  20437. * parameters = {
  20438. * color: <hex>,
  20439. * opacity: <float>,
  20440. *
  20441. * linewidth: <float>,
  20442. *
  20443. * scale: <float>,
  20444. * dashSize: <float>,
  20445. * gapSize: <float>
  20446. * }
  20447. */
  20448. var LineDashedMaterial = /*#__PURE__*/function (_LineBasicMaterial) {
  20449. _inheritsLoose(LineDashedMaterial, _LineBasicMaterial);
  20450. function LineDashedMaterial(parameters) {
  20451. var _this;
  20452. _this = _LineBasicMaterial.call(this) || this;
  20453. _this.type = 'LineDashedMaterial';
  20454. _this.scale = 1;
  20455. _this.dashSize = 3;
  20456. _this.gapSize = 1;
  20457. _this.setValues(parameters);
  20458. return _this;
  20459. }
  20460. var _proto = LineDashedMaterial.prototype;
  20461. _proto.copy = function copy(source) {
  20462. _LineBasicMaterial.prototype.copy.call(this, source);
  20463. this.scale = source.scale;
  20464. this.dashSize = source.dashSize;
  20465. this.gapSize = source.gapSize;
  20466. return this;
  20467. };
  20468. return LineDashedMaterial;
  20469. }(LineBasicMaterial);
  20470. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20471. var Materials = /*#__PURE__*/Object.freeze({
  20472. __proto__: null,
  20473. ShadowMaterial: ShadowMaterial,
  20474. SpriteMaterial: SpriteMaterial,
  20475. RawShaderMaterial: RawShaderMaterial,
  20476. ShaderMaterial: ShaderMaterial,
  20477. PointsMaterial: PointsMaterial,
  20478. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20479. MeshStandardMaterial: MeshStandardMaterial,
  20480. MeshPhongMaterial: MeshPhongMaterial,
  20481. MeshToonMaterial: MeshToonMaterial,
  20482. MeshNormalMaterial: MeshNormalMaterial,
  20483. MeshLambertMaterial: MeshLambertMaterial,
  20484. MeshDepthMaterial: MeshDepthMaterial,
  20485. MeshDistanceMaterial: MeshDistanceMaterial,
  20486. MeshBasicMaterial: MeshBasicMaterial,
  20487. MeshMatcapMaterial: MeshMatcapMaterial,
  20488. LineDashedMaterial: LineDashedMaterial,
  20489. LineBasicMaterial: LineBasicMaterial,
  20490. Material: Material
  20491. });
  20492. var AnimationUtils = {
  20493. // same as Array.prototype.slice, but also works on typed arrays
  20494. arraySlice: function arraySlice(array, from, to) {
  20495. if (AnimationUtils.isTypedArray(array)) {
  20496. // in ios9 array.subarray(from, undefined) will return empty array
  20497. // but array.subarray(from) or array.subarray(from, len) is correct
  20498. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  20499. }
  20500. return array.slice(from, to);
  20501. },
  20502. // converts an array to a specific type
  20503. convertArray: function convertArray(array, type, forceClone) {
  20504. if (!array || // let 'undefined' and 'null' pass
  20505. !forceClone && array.constructor === type) return array;
  20506. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  20507. return new type(array); // create typed array
  20508. }
  20509. return Array.prototype.slice.call(array); // create Array
  20510. },
  20511. isTypedArray: function isTypedArray(object) {
  20512. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  20513. },
  20514. // returns an array by which times and values can be sorted
  20515. getKeyframeOrder: function getKeyframeOrder(times) {
  20516. function compareTime(i, j) {
  20517. return times[i] - times[j];
  20518. }
  20519. var n = times.length;
  20520. var result = new Array(n);
  20521. for (var i = 0; i !== n; ++i) {
  20522. result[i] = i;
  20523. }
  20524. result.sort(compareTime);
  20525. return result;
  20526. },
  20527. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20528. sortedArray: function sortedArray(values, stride, order) {
  20529. var nValues = values.length;
  20530. var result = new values.constructor(nValues);
  20531. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  20532. var srcOffset = order[i] * stride;
  20533. for (var j = 0; j !== stride; ++j) {
  20534. result[dstOffset++] = values[srcOffset + j];
  20535. }
  20536. }
  20537. return result;
  20538. },
  20539. // function for parsing AOS keyframe formats
  20540. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  20541. var i = 1,
  20542. key = jsonKeys[0];
  20543. while (key !== undefined && key[valuePropertyName] === undefined) {
  20544. key = jsonKeys[i++];
  20545. }
  20546. if (key === undefined) return; // no data
  20547. var value = key[valuePropertyName];
  20548. if (value === undefined) return; // no data
  20549. if (Array.isArray(value)) {
  20550. do {
  20551. value = key[valuePropertyName];
  20552. if (value !== undefined) {
  20553. times.push(key.time);
  20554. values.push.apply(values, value); // push all elements
  20555. }
  20556. key = jsonKeys[i++];
  20557. } while (key !== undefined);
  20558. } else if (value.toArray !== undefined) {
  20559. // ...assume THREE.Math-ish
  20560. do {
  20561. value = key[valuePropertyName];
  20562. if (value !== undefined) {
  20563. times.push(key.time);
  20564. value.toArray(values, values.length);
  20565. }
  20566. key = jsonKeys[i++];
  20567. } while (key !== undefined);
  20568. } else {
  20569. // otherwise push as-is
  20570. do {
  20571. value = key[valuePropertyName];
  20572. if (value !== undefined) {
  20573. times.push(key.time);
  20574. values.push(value);
  20575. }
  20576. key = jsonKeys[i++];
  20577. } while (key !== undefined);
  20578. }
  20579. },
  20580. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  20581. if (fps === void 0) {
  20582. fps = 30;
  20583. }
  20584. var clip = sourceClip.clone();
  20585. clip.name = name;
  20586. var tracks = [];
  20587. for (var i = 0; i < clip.tracks.length; ++i) {
  20588. var track = clip.tracks[i];
  20589. var valueSize = track.getValueSize();
  20590. var times = [];
  20591. var values = [];
  20592. for (var j = 0; j < track.times.length; ++j) {
  20593. var frame = track.times[j] * fps;
  20594. if (frame < startFrame || frame >= endFrame) continue;
  20595. times.push(track.times[j]);
  20596. for (var k = 0; k < valueSize; ++k) {
  20597. values.push(track.values[j * valueSize + k]);
  20598. }
  20599. }
  20600. if (times.length === 0) continue;
  20601. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  20602. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  20603. tracks.push(track);
  20604. }
  20605. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  20606. var minStartTime = Infinity;
  20607. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  20608. if (minStartTime > clip.tracks[_i].times[0]) {
  20609. minStartTime = clip.tracks[_i].times[0];
  20610. }
  20611. } // shift all tracks such that clip begins at t=0
  20612. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  20613. clip.tracks[_i2].shift(-1 * minStartTime);
  20614. }
  20615. clip.resetDuration();
  20616. return clip;
  20617. },
  20618. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  20619. if (referenceFrame === void 0) {
  20620. referenceFrame = 0;
  20621. }
  20622. if (referenceClip === void 0) {
  20623. referenceClip = targetClip;
  20624. }
  20625. if (fps === void 0) {
  20626. fps = 30;
  20627. }
  20628. if (fps <= 0) fps = 30;
  20629. var numTracks = referenceClip.tracks.length;
  20630. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  20631. var _loop = function _loop(i) {
  20632. var referenceTrack = referenceClip.tracks[i];
  20633. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  20634. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  20635. var targetTrack = targetClip.tracks.find(function (track) {
  20636. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  20637. });
  20638. if (targetTrack === undefined) return "continue";
  20639. var referenceOffset = 0;
  20640. var referenceValueSize = referenceTrack.getValueSize();
  20641. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20642. referenceOffset = referenceValueSize / 3;
  20643. }
  20644. var targetOffset = 0;
  20645. var targetValueSize = targetTrack.getValueSize();
  20646. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20647. targetOffset = targetValueSize / 3;
  20648. }
  20649. var lastIndex = referenceTrack.times.length - 1;
  20650. var referenceValue = void 0; // Find the value to subtract out of the track
  20651. if (referenceTime <= referenceTrack.times[0]) {
  20652. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  20653. var startIndex = referenceOffset;
  20654. var endIndex = referenceValueSize - referenceOffset;
  20655. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  20656. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  20657. // Reference frame is after the last keyframe, so just use the last keyframe
  20658. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  20659. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  20660. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  20661. } else {
  20662. // Interpolate to the reference value
  20663. var interpolant = referenceTrack.createInterpolant();
  20664. var _startIndex2 = referenceOffset;
  20665. var _endIndex2 = referenceValueSize - referenceOffset;
  20666. interpolant.evaluate(referenceTime);
  20667. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  20668. } // Conjugate the quaternion
  20669. if (referenceTrackType === 'quaternion') {
  20670. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  20671. referenceQuat.toArray(referenceValue);
  20672. } // Subtract the reference value from all of the track values
  20673. var numTimes = targetTrack.times.length;
  20674. for (var j = 0; j < numTimes; ++j) {
  20675. var valueStart = j * targetValueSize + targetOffset;
  20676. if (referenceTrackType === 'quaternion') {
  20677. // Multiply the conjugate for quaternion track types
  20678. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  20679. } else {
  20680. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  20681. for (var k = 0; k < valueEnd; ++k) {
  20682. targetTrack.values[valueStart + k] -= referenceValue[k];
  20683. }
  20684. }
  20685. }
  20686. };
  20687. for (var i = 0; i < numTracks; ++i) {
  20688. var _ret = _loop(i);
  20689. if (_ret === "continue") continue;
  20690. }
  20691. targetClip.blendMode = AdditiveAnimationBlendMode;
  20692. return targetClip;
  20693. }
  20694. };
  20695. /**
  20696. * Abstract base class of interpolants over parametric samples.
  20697. *
  20698. * The parameter domain is one dimensional, typically the time or a path
  20699. * along a curve defined by the data.
  20700. *
  20701. * The sample values can have any dimensionality and derived classes may
  20702. * apply special interpretations to the data.
  20703. *
  20704. * This class provides the interval seek in a Template Method, deferring
  20705. * the actual interpolation to derived classes.
  20706. *
  20707. * Time complexity is O(1) for linear access crossing at most two points
  20708. * and O(log N) for random access, where N is the number of positions.
  20709. *
  20710. * References:
  20711. *
  20712. * http://www.oodesign.com/template-method-pattern.html
  20713. *
  20714. */
  20715. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20716. this.parameterPositions = parameterPositions;
  20717. this._cachedIndex = 0;
  20718. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  20719. this.sampleValues = sampleValues;
  20720. this.valueSize = sampleSize;
  20721. }
  20722. Object.assign(Interpolant.prototype, {
  20723. evaluate: function evaluate(t) {
  20724. var pp = this.parameterPositions;
  20725. var i1 = this._cachedIndex,
  20726. t1 = pp[i1],
  20727. t0 = pp[i1 - 1];
  20728. validate_interval: {
  20729. seek: {
  20730. var right;
  20731. linear_scan: {
  20732. //- See http://jsperf.com/comparison-to-undefined/3
  20733. //- slower code:
  20734. //-
  20735. //- if ( t >= t1 || t1 === undefined ) {
  20736. forward_scan: if (!(t < t1)) {
  20737. for (var giveUpAt = i1 + 2;;) {
  20738. if (t1 === undefined) {
  20739. if (t < t0) break forward_scan; // after end
  20740. i1 = pp.length;
  20741. this._cachedIndex = i1;
  20742. return this.afterEnd_(i1 - 1, t, t0);
  20743. }
  20744. if (i1 === giveUpAt) break; // this loop
  20745. t0 = t1;
  20746. t1 = pp[++i1];
  20747. if (t < t1) {
  20748. // we have arrived at the sought interval
  20749. break seek;
  20750. }
  20751. } // prepare binary search on the right side of the index
  20752. right = pp.length;
  20753. break linear_scan;
  20754. } //- slower code:
  20755. //- if ( t < t0 || t0 === undefined ) {
  20756. if (!(t >= t0)) {
  20757. // looping?
  20758. var t1global = pp[1];
  20759. if (t < t1global) {
  20760. i1 = 2; // + 1, using the scan for the details
  20761. t0 = t1global;
  20762. } // linear reverse scan
  20763. for (var _giveUpAt = i1 - 2;;) {
  20764. if (t0 === undefined) {
  20765. // before start
  20766. this._cachedIndex = 0;
  20767. return this.beforeStart_(0, t, t1);
  20768. }
  20769. if (i1 === _giveUpAt) break; // this loop
  20770. t1 = t0;
  20771. t0 = pp[--i1 - 1];
  20772. if (t >= t0) {
  20773. // we have arrived at the sought interval
  20774. break seek;
  20775. }
  20776. } // prepare binary search on the left side of the index
  20777. right = i1;
  20778. i1 = 0;
  20779. break linear_scan;
  20780. } // the interval is valid
  20781. break validate_interval;
  20782. } // linear scan
  20783. // binary search
  20784. while (i1 < right) {
  20785. var mid = i1 + right >>> 1;
  20786. if (t < pp[mid]) {
  20787. right = mid;
  20788. } else {
  20789. i1 = mid + 1;
  20790. }
  20791. }
  20792. t1 = pp[i1];
  20793. t0 = pp[i1 - 1]; // check boundary cases, again
  20794. if (t0 === undefined) {
  20795. this._cachedIndex = 0;
  20796. return this.beforeStart_(0, t, t1);
  20797. }
  20798. if (t1 === undefined) {
  20799. i1 = pp.length;
  20800. this._cachedIndex = i1;
  20801. return this.afterEnd_(i1 - 1, t0, t);
  20802. }
  20803. } // seek
  20804. this._cachedIndex = i1;
  20805. this.intervalChanged_(i1, t0, t1);
  20806. } // validate_interval
  20807. return this.interpolate_(i1, t0, t, t1);
  20808. },
  20809. settings: null,
  20810. // optional, subclass-specific settings structure
  20811. // Note: The indirection allows central control of many interpolants.
  20812. // --- Protected interface
  20813. DefaultSettings_: {},
  20814. getSettings_: function getSettings_() {
  20815. return this.settings || this.DefaultSettings_;
  20816. },
  20817. copySampleValue_: function copySampleValue_(index) {
  20818. // copies a sample value to the result buffer
  20819. var result = this.resultBuffer,
  20820. values = this.sampleValues,
  20821. stride = this.valueSize,
  20822. offset = index * stride;
  20823. for (var i = 0; i !== stride; ++i) {
  20824. result[i] = values[offset + i];
  20825. }
  20826. return result;
  20827. },
  20828. // Template methods for derived classes:
  20829. interpolate_: function interpolate_()
  20830. /* i1, t0, t, t1 */
  20831. {
  20832. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  20833. },
  20834. intervalChanged_: function intervalChanged_()
  20835. /* i1, t0, t1 */
  20836. {// empty
  20837. }
  20838. }); // DECLARE ALIAS AFTER assign prototype
  20839. Object.assign(Interpolant.prototype, {
  20840. //( 0, t, t0 ), returns this.resultBuffer
  20841. beforeStart_: Interpolant.prototype.copySampleValue_,
  20842. //( N-1, tN-1, t ), returns this.resultBuffer
  20843. afterEnd_: Interpolant.prototype.copySampleValue_
  20844. });
  20845. /**
  20846. * Fast and simple cubic spline interpolant.
  20847. *
  20848. * It was derived from a Hermitian construction setting the first derivative
  20849. * at each sample position to the linear slope between neighboring positions
  20850. * over their parameter interval.
  20851. */
  20852. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20853. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20854. this._weightPrev = -0;
  20855. this._offsetPrev = -0;
  20856. this._weightNext = -0;
  20857. this._offsetNext = -0;
  20858. }
  20859. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20860. constructor: CubicInterpolant,
  20861. DefaultSettings_: {
  20862. endingStart: ZeroCurvatureEnding,
  20863. endingEnd: ZeroCurvatureEnding
  20864. },
  20865. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  20866. var pp = this.parameterPositions;
  20867. var iPrev = i1 - 2,
  20868. iNext = i1 + 1,
  20869. tPrev = pp[iPrev],
  20870. tNext = pp[iNext];
  20871. if (tPrev === undefined) {
  20872. switch (this.getSettings_().endingStart) {
  20873. case ZeroSlopeEnding:
  20874. // f'(t0) = 0
  20875. iPrev = i1;
  20876. tPrev = 2 * t0 - t1;
  20877. break;
  20878. case WrapAroundEnding:
  20879. // use the other end of the curve
  20880. iPrev = pp.length - 2;
  20881. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  20882. break;
  20883. default:
  20884. // ZeroCurvatureEnding
  20885. // f''(t0) = 0 a.k.a. Natural Spline
  20886. iPrev = i1;
  20887. tPrev = t1;
  20888. }
  20889. }
  20890. if (tNext === undefined) {
  20891. switch (this.getSettings_().endingEnd) {
  20892. case ZeroSlopeEnding:
  20893. // f'(tN) = 0
  20894. iNext = i1;
  20895. tNext = 2 * t1 - t0;
  20896. break;
  20897. case WrapAroundEnding:
  20898. // use the other end of the curve
  20899. iNext = 1;
  20900. tNext = t1 + pp[1] - pp[0];
  20901. break;
  20902. default:
  20903. // ZeroCurvatureEnding
  20904. // f''(tN) = 0, a.k.a. Natural Spline
  20905. iNext = i1 - 1;
  20906. tNext = t0;
  20907. }
  20908. }
  20909. var halfDt = (t1 - t0) * 0.5,
  20910. stride = this.valueSize;
  20911. this._weightPrev = halfDt / (t0 - tPrev);
  20912. this._weightNext = halfDt / (tNext - t1);
  20913. this._offsetPrev = iPrev * stride;
  20914. this._offsetNext = iNext * stride;
  20915. },
  20916. interpolate_: function interpolate_(i1, t0, t, t1) {
  20917. var result = this.resultBuffer,
  20918. values = this.sampleValues,
  20919. stride = this.valueSize,
  20920. o1 = i1 * stride,
  20921. o0 = o1 - stride,
  20922. oP = this._offsetPrev,
  20923. oN = this._offsetNext,
  20924. wP = this._weightPrev,
  20925. wN = this._weightNext,
  20926. p = (t - t0) / (t1 - t0),
  20927. pp = p * p,
  20928. ppp = pp * p; // evaluate polynomials
  20929. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  20930. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  20931. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  20932. var sN = wN * ppp - wN * pp; // combine data linearly
  20933. for (var i = 0; i !== stride; ++i) {
  20934. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  20935. }
  20936. return result;
  20937. }
  20938. });
  20939. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20940. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20941. }
  20942. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20943. constructor: LinearInterpolant,
  20944. interpolate_: function interpolate_(i1, t0, t, t1) {
  20945. var result = this.resultBuffer,
  20946. values = this.sampleValues,
  20947. stride = this.valueSize,
  20948. offset1 = i1 * stride,
  20949. offset0 = offset1 - stride,
  20950. weight1 = (t - t0) / (t1 - t0),
  20951. weight0 = 1 - weight1;
  20952. for (var i = 0; i !== stride; ++i) {
  20953. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  20954. }
  20955. return result;
  20956. }
  20957. });
  20958. /**
  20959. *
  20960. * Interpolant that evaluates to the sample value at the position preceeding
  20961. * the parameter.
  20962. */
  20963. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20964. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20965. }
  20966. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20967. constructor: DiscreteInterpolant,
  20968. interpolate_: function interpolate_(i1
  20969. /*, t0, t, t1 */
  20970. ) {
  20971. return this.copySampleValue_(i1 - 1);
  20972. }
  20973. });
  20974. var KeyframeTrack = /*#__PURE__*/function () {
  20975. function KeyframeTrack(name, times, values, interpolation) {
  20976. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  20977. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  20978. this.name = name;
  20979. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  20980. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  20981. this.setInterpolation(interpolation || this.DefaultInterpolation);
  20982. } // Serialization (in static context, because of constructor invocation
  20983. // and automatic invocation of .toJSON):
  20984. KeyframeTrack.toJSON = function toJSON(track) {
  20985. var trackType = track.constructor;
  20986. var json; // derived classes can define a static toJSON method
  20987. if (trackType.toJSON !== undefined) {
  20988. json = trackType.toJSON(track);
  20989. } else {
  20990. // by default, we assume the data can be serialized as-is
  20991. json = {
  20992. 'name': track.name,
  20993. 'times': AnimationUtils.convertArray(track.times, Array),
  20994. 'values': AnimationUtils.convertArray(track.values, Array)
  20995. };
  20996. var interpolation = track.getInterpolation();
  20997. if (interpolation !== track.DefaultInterpolation) {
  20998. json.interpolation = interpolation;
  20999. }
  21000. }
  21001. json.type = track.ValueTypeName; // mandatory
  21002. return json;
  21003. };
  21004. var _proto = KeyframeTrack.prototype;
  21005. _proto.InterpolantFactoryMethodDiscrete = function InterpolantFactoryMethodDiscrete(result) {
  21006. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  21007. };
  21008. _proto.InterpolantFactoryMethodLinear = function InterpolantFactoryMethodLinear(result) {
  21009. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21010. };
  21011. _proto.InterpolantFactoryMethodSmooth = function InterpolantFactoryMethodSmooth(result) {
  21012. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  21013. };
  21014. _proto.setInterpolation = function setInterpolation(interpolation) {
  21015. var factoryMethod;
  21016. switch (interpolation) {
  21017. case InterpolateDiscrete:
  21018. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  21019. break;
  21020. case InterpolateLinear:
  21021. factoryMethod = this.InterpolantFactoryMethodLinear;
  21022. break;
  21023. case InterpolateSmooth:
  21024. factoryMethod = this.InterpolantFactoryMethodSmooth;
  21025. break;
  21026. }
  21027. if (factoryMethod === undefined) {
  21028. var message = 'unsupported interpolation for ' + this.ValueTypeName + ' keyframe track named ' + this.name;
  21029. if (this.createInterpolant === undefined) {
  21030. // fall back to default, unless the default itself is messed up
  21031. if (interpolation !== this.DefaultInterpolation) {
  21032. this.setInterpolation(this.DefaultInterpolation);
  21033. } else {
  21034. throw new Error(message); // fatal, in this case
  21035. }
  21036. }
  21037. console.warn('THREE.KeyframeTrack:', message);
  21038. return this;
  21039. }
  21040. this.createInterpolant = factoryMethod;
  21041. return this;
  21042. };
  21043. _proto.getInterpolation = function getInterpolation() {
  21044. switch (this.createInterpolant) {
  21045. case this.InterpolantFactoryMethodDiscrete:
  21046. return InterpolateDiscrete;
  21047. case this.InterpolantFactoryMethodLinear:
  21048. return InterpolateLinear;
  21049. case this.InterpolantFactoryMethodSmooth:
  21050. return InterpolateSmooth;
  21051. }
  21052. };
  21053. _proto.getValueSize = function getValueSize() {
  21054. return this.values.length / this.times.length;
  21055. } // move all keyframes either forwards or backwards in time
  21056. ;
  21057. _proto.shift = function shift(timeOffset) {
  21058. if (timeOffset !== 0.0) {
  21059. var times = this.times;
  21060. for (var i = 0, n = times.length; i !== n; ++i) {
  21061. times[i] += timeOffset;
  21062. }
  21063. }
  21064. return this;
  21065. } // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  21066. ;
  21067. _proto.scale = function scale(timeScale) {
  21068. if (timeScale !== 1.0) {
  21069. var times = this.times;
  21070. for (var i = 0, n = times.length; i !== n; ++i) {
  21071. times[i] *= timeScale;
  21072. }
  21073. }
  21074. return this;
  21075. } // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  21076. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  21077. ;
  21078. _proto.trim = function trim(startTime, endTime) {
  21079. var times = this.times,
  21080. nKeys = times.length;
  21081. var from = 0,
  21082. to = nKeys - 1;
  21083. while (from !== nKeys && times[from] < startTime) {
  21084. ++from;
  21085. }
  21086. while (to !== -1 && times[to] > endTime) {
  21087. --to;
  21088. }
  21089. ++to; // inclusive -> exclusive bound
  21090. if (from !== 0 || to !== nKeys) {
  21091. // empty tracks are forbidden, so keep at least one keyframe
  21092. if (from >= to) {
  21093. to = Math.max(to, 1);
  21094. from = to - 1;
  21095. }
  21096. var stride = this.getValueSize();
  21097. this.times = AnimationUtils.arraySlice(times, from, to);
  21098. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  21099. }
  21100. return this;
  21101. } // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  21102. ;
  21103. _proto.validate = function validate() {
  21104. var valid = true;
  21105. var valueSize = this.getValueSize();
  21106. if (valueSize - Math.floor(valueSize) !== 0) {
  21107. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  21108. valid = false;
  21109. }
  21110. var times = this.times,
  21111. values = this.values,
  21112. nKeys = times.length;
  21113. if (nKeys === 0) {
  21114. console.error('THREE.KeyframeTrack: Track is empty.', this);
  21115. valid = false;
  21116. }
  21117. var prevTime = null;
  21118. for (var i = 0; i !== nKeys; i++) {
  21119. var currTime = times[i];
  21120. if (typeof currTime === 'number' && isNaN(currTime)) {
  21121. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  21122. valid = false;
  21123. break;
  21124. }
  21125. if (prevTime !== null && prevTime > currTime) {
  21126. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  21127. valid = false;
  21128. break;
  21129. }
  21130. prevTime = currTime;
  21131. }
  21132. if (values !== undefined) {
  21133. if (AnimationUtils.isTypedArray(values)) {
  21134. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  21135. var value = values[_i];
  21136. if (isNaN(value)) {
  21137. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  21138. valid = false;
  21139. break;
  21140. }
  21141. }
  21142. }
  21143. }
  21144. return valid;
  21145. } // removes equivalent sequential keys as common in morph target sequences
  21146. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21147. ;
  21148. _proto.optimize = function optimize() {
  21149. // times or values may be shared with other tracks, so overwriting is unsafe
  21150. var times = AnimationUtils.arraySlice(this.times),
  21151. values = AnimationUtils.arraySlice(this.values),
  21152. stride = this.getValueSize(),
  21153. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21154. lastIndex = times.length - 1;
  21155. var writeIndex = 1;
  21156. for (var i = 1; i < lastIndex; ++i) {
  21157. var keep = false;
  21158. var time = times[i];
  21159. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  21160. if (time !== timeNext && (i !== 1 || time !== times[0])) {
  21161. if (!smoothInterpolation) {
  21162. // remove unnecessary keyframes same as their neighbors
  21163. var offset = i * stride,
  21164. offsetP = offset - stride,
  21165. offsetN = offset + stride;
  21166. for (var j = 0; j !== stride; ++j) {
  21167. var value = values[offset + j];
  21168. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  21169. keep = true;
  21170. break;
  21171. }
  21172. }
  21173. } else {
  21174. keep = true;
  21175. }
  21176. } // in-place compaction
  21177. if (keep) {
  21178. if (i !== writeIndex) {
  21179. times[writeIndex] = times[i];
  21180. var readOffset = i * stride,
  21181. writeOffset = writeIndex * stride;
  21182. for (var _j = 0; _j !== stride; ++_j) {
  21183. values[writeOffset + _j] = values[readOffset + _j];
  21184. }
  21185. }
  21186. ++writeIndex;
  21187. }
  21188. } // flush last keyframe (compaction looks ahead)
  21189. if (lastIndex > 0) {
  21190. times[writeIndex] = times[lastIndex];
  21191. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  21192. values[_writeOffset + _j2] = values[_readOffset + _j2];
  21193. }
  21194. ++writeIndex;
  21195. }
  21196. if (writeIndex !== times.length) {
  21197. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  21198. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  21199. } else {
  21200. this.times = times;
  21201. this.values = values;
  21202. }
  21203. return this;
  21204. };
  21205. _proto.clone = function clone() {
  21206. var times = AnimationUtils.arraySlice(this.times, 0);
  21207. var values = AnimationUtils.arraySlice(this.values, 0);
  21208. var TypedKeyframeTrack = this.constructor;
  21209. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21210. track.createInterpolant = this.createInterpolant;
  21211. return track;
  21212. };
  21213. return KeyframeTrack;
  21214. }();
  21215. KeyframeTrack.prototype.TimeBufferType = Float32Array;
  21216. KeyframeTrack.prototype.ValueBufferType = Float32Array;
  21217. KeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
  21218. /**
  21219. * A Track of Boolean keyframe values.
  21220. */
  21221. var BooleanKeyframeTrack = /*#__PURE__*/function (_KeyframeTrack) {
  21222. _inheritsLoose(BooleanKeyframeTrack, _KeyframeTrack);
  21223. function BooleanKeyframeTrack() {
  21224. return _KeyframeTrack.apply(this, arguments) || this;
  21225. }
  21226. return BooleanKeyframeTrack;
  21227. }(KeyframeTrack);
  21228. BooleanKeyframeTrack.prototype.ValueTypeName = 'bool';
  21229. BooleanKeyframeTrack.prototype.ValueBufferType = Array;
  21230. BooleanKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  21231. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  21232. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined; // Note: Actually this track could have a optimized / compressed
  21233. /**
  21234. * A Track of keyframe values that represent color.
  21235. */
  21236. var ColorKeyframeTrack = /*#__PURE__*/function (_KeyframeTrack) {
  21237. _inheritsLoose(ColorKeyframeTrack, _KeyframeTrack);
  21238. function ColorKeyframeTrack() {
  21239. return _KeyframeTrack.apply(this, arguments) || this;
  21240. }
  21241. return ColorKeyframeTrack;
  21242. }(KeyframeTrack);
  21243. ColorKeyframeTrack.prototype.ValueTypeName = 'color'; // ValueBufferType is inherited
  21244. /**
  21245. * A Track of numeric keyframe values.
  21246. */
  21247. var NumberKeyframeTrack = /*#__PURE__*/function (_KeyframeTrack) {
  21248. _inheritsLoose(NumberKeyframeTrack, _KeyframeTrack);
  21249. function NumberKeyframeTrack() {
  21250. return _KeyframeTrack.apply(this, arguments) || this;
  21251. }
  21252. return NumberKeyframeTrack;
  21253. }(KeyframeTrack);
  21254. NumberKeyframeTrack.prototype.ValueTypeName = 'number'; // ValueBufferType is inherited
  21255. /**
  21256. * Spherical linear unit quaternion interpolant.
  21257. */
  21258. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21259. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21260. }
  21261. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21262. constructor: QuaternionLinearInterpolant,
  21263. interpolate_: function interpolate_(i1, t0, t, t1) {
  21264. var result = this.resultBuffer,
  21265. values = this.sampleValues,
  21266. stride = this.valueSize,
  21267. alpha = (t - t0) / (t1 - t0);
  21268. var offset = i1 * stride;
  21269. for (var end = offset + stride; offset !== end; offset += 4) {
  21270. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  21271. }
  21272. return result;
  21273. }
  21274. });
  21275. /**
  21276. * A Track of quaternion keyframe values.
  21277. */
  21278. var QuaternionKeyframeTrack = /*#__PURE__*/function (_KeyframeTrack) {
  21279. _inheritsLoose(QuaternionKeyframeTrack, _KeyframeTrack);
  21280. function QuaternionKeyframeTrack() {
  21281. return _KeyframeTrack.apply(this, arguments) || this;
  21282. }
  21283. var _proto = QuaternionKeyframeTrack.prototype;
  21284. _proto.InterpolantFactoryMethodLinear = function InterpolantFactoryMethodLinear(result) {
  21285. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21286. };
  21287. return QuaternionKeyframeTrack;
  21288. }(KeyframeTrack);
  21289. QuaternionKeyframeTrack.prototype.ValueTypeName = 'quaternion'; // ValueBufferType is inherited
  21290. QuaternionKeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
  21291. QuaternionKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  21292. /**
  21293. * A Track that interpolates Strings
  21294. */
  21295. var StringKeyframeTrack = /*#__PURE__*/function (_KeyframeTrack) {
  21296. _inheritsLoose(StringKeyframeTrack, _KeyframeTrack);
  21297. function StringKeyframeTrack() {
  21298. return _KeyframeTrack.apply(this, arguments) || this;
  21299. }
  21300. return StringKeyframeTrack;
  21301. }(KeyframeTrack);
  21302. StringKeyframeTrack.prototype.ValueTypeName = 'string';
  21303. StringKeyframeTrack.prototype.ValueBufferType = Array;
  21304. StringKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  21305. StringKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  21306. StringKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  21307. /**
  21308. * A Track of vectored keyframe values.
  21309. */
  21310. var VectorKeyframeTrack = /*#__PURE__*/function (_KeyframeTrack) {
  21311. _inheritsLoose(VectorKeyframeTrack, _KeyframeTrack);
  21312. function VectorKeyframeTrack() {
  21313. return _KeyframeTrack.apply(this, arguments) || this;
  21314. }
  21315. return VectorKeyframeTrack;
  21316. }(KeyframeTrack);
  21317. VectorKeyframeTrack.prototype.ValueTypeName = 'vector'; // ValueBufferType is inherited
  21318. function AnimationClip(name, duration, tracks, blendMode) {
  21319. if (duration === void 0) {
  21320. duration = -1;
  21321. }
  21322. if (blendMode === void 0) {
  21323. blendMode = NormalAnimationBlendMode;
  21324. }
  21325. this.name = name;
  21326. this.tracks = tracks;
  21327. this.duration = duration;
  21328. this.blendMode = blendMode;
  21329. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  21330. if (this.duration < 0) {
  21331. this.resetDuration();
  21332. }
  21333. }
  21334. function getTrackTypeForValueTypeName(typeName) {
  21335. switch (typeName.toLowerCase()) {
  21336. case 'scalar':
  21337. case 'double':
  21338. case 'float':
  21339. case 'number':
  21340. case 'integer':
  21341. return NumberKeyframeTrack;
  21342. case 'vector':
  21343. case 'vector2':
  21344. case 'vector3':
  21345. case 'vector4':
  21346. return VectorKeyframeTrack;
  21347. case 'color':
  21348. return ColorKeyframeTrack;
  21349. case 'quaternion':
  21350. return QuaternionKeyframeTrack;
  21351. case 'bool':
  21352. case 'boolean':
  21353. return BooleanKeyframeTrack;
  21354. case 'string':
  21355. return StringKeyframeTrack;
  21356. }
  21357. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  21358. }
  21359. function parseKeyframeTrack(json) {
  21360. if (json.type === undefined) {
  21361. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  21362. }
  21363. var trackType = getTrackTypeForValueTypeName(json.type);
  21364. if (json.times === undefined) {
  21365. var times = [],
  21366. values = [];
  21367. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  21368. json.times = times;
  21369. json.values = values;
  21370. } // derived classes can define a static parse method
  21371. if (trackType.parse !== undefined) {
  21372. return trackType.parse(json);
  21373. } else {
  21374. // by default, we assume a constructor compatible with the base
  21375. return new trackType(json.name, json.times, json.values, json.interpolation);
  21376. }
  21377. }
  21378. Object.assign(AnimationClip, {
  21379. parse: function parse(json) {
  21380. var tracks = [],
  21381. jsonTracks = json.tracks,
  21382. frameTime = 1.0 / (json.fps || 1.0);
  21383. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  21384. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  21385. }
  21386. var clip = new AnimationClip(json.name, json.duration, tracks, json.blendMode);
  21387. clip.uuid = json.uuid;
  21388. return clip;
  21389. },
  21390. toJSON: function toJSON(clip) {
  21391. var tracks = [],
  21392. clipTracks = clip.tracks;
  21393. var json = {
  21394. 'name': clip.name,
  21395. 'duration': clip.duration,
  21396. 'tracks': tracks,
  21397. 'uuid': clip.uuid,
  21398. 'blendMode': clip.blendMode
  21399. };
  21400. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  21401. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  21402. }
  21403. return json;
  21404. },
  21405. CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  21406. var numMorphTargets = morphTargetSequence.length;
  21407. var tracks = [];
  21408. for (var i = 0; i < numMorphTargets; i++) {
  21409. var times = [];
  21410. var values = [];
  21411. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  21412. values.push(0, 1, 0);
  21413. var order = AnimationUtils.getKeyframeOrder(times);
  21414. times = AnimationUtils.sortedArray(times, 1, order);
  21415. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  21416. // last frame as well for perfect loop.
  21417. if (!noLoop && times[0] === 0) {
  21418. times.push(numMorphTargets);
  21419. values.push(values[0]);
  21420. }
  21421. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  21422. }
  21423. return new AnimationClip(name, -1, tracks);
  21424. },
  21425. findByName: function findByName(objectOrClipArray, name) {
  21426. var clipArray = objectOrClipArray;
  21427. if (!Array.isArray(objectOrClipArray)) {
  21428. var o = objectOrClipArray;
  21429. clipArray = o.geometry && o.geometry.animations || o.animations;
  21430. }
  21431. for (var i = 0; i < clipArray.length; i++) {
  21432. if (clipArray[i].name === name) {
  21433. return clipArray[i];
  21434. }
  21435. }
  21436. return null;
  21437. },
  21438. CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  21439. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  21440. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21441. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  21442. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21443. for (var i = 0, il = morphTargets.length; i < il; i++) {
  21444. var morphTarget = morphTargets[i];
  21445. var parts = morphTarget.name.match(pattern);
  21446. if (parts && parts.length > 1) {
  21447. var name = parts[1];
  21448. var animationMorphTargets = animationToMorphTargets[name];
  21449. if (!animationMorphTargets) {
  21450. animationToMorphTargets[name] = animationMorphTargets = [];
  21451. }
  21452. animationMorphTargets.push(morphTarget);
  21453. }
  21454. }
  21455. var clips = [];
  21456. for (var _name in animationToMorphTargets) {
  21457. clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  21458. }
  21459. return clips;
  21460. },
  21461. // parse the animation.hierarchy format
  21462. parseAnimation: function parseAnimation(animation, bones) {
  21463. if (!animation) {
  21464. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  21465. return null;
  21466. }
  21467. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  21468. // only return track if there are actually keys.
  21469. if (animationKeys.length !== 0) {
  21470. var times = [];
  21471. var values = [];
  21472. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  21473. if (times.length !== 0) {
  21474. destTracks.push(new trackType(trackName, times, values));
  21475. }
  21476. }
  21477. };
  21478. var tracks = [];
  21479. var clipName = animation.name || 'default';
  21480. var fps = animation.fps || 30;
  21481. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  21482. var duration = animation.length || -1;
  21483. var hierarchyTracks = animation.hierarchy || [];
  21484. for (var h = 0; h < hierarchyTracks.length; h++) {
  21485. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  21486. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  21487. if (animationKeys[0].morphTargets) {
  21488. // figure out all morph targets used in this track
  21489. var morphTargetNames = {};
  21490. var k = void 0;
  21491. for (k = 0; k < animationKeys.length; k++) {
  21492. if (animationKeys[k].morphTargets) {
  21493. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  21494. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  21495. }
  21496. }
  21497. } // create a track for each morph target with all zero
  21498. // morphTargetInfluences except for the keys in which
  21499. // the morphTarget is named.
  21500. for (var morphTargetName in morphTargetNames) {
  21501. var times = [];
  21502. var values = [];
  21503. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  21504. var animationKey = animationKeys[k];
  21505. times.push(animationKey.time);
  21506. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  21507. }
  21508. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  21509. }
  21510. duration = morphTargetNames.length * (fps || 1.0);
  21511. } else {
  21512. // ...assume skeletal animation
  21513. var boneName = '.bones[' + bones[h].name + ']';
  21514. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  21515. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  21516. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  21517. }
  21518. }
  21519. if (tracks.length === 0) {
  21520. return null;
  21521. }
  21522. var clip = new AnimationClip(clipName, duration, tracks, blendMode);
  21523. return clip;
  21524. }
  21525. });
  21526. Object.assign(AnimationClip.prototype, {
  21527. resetDuration: function resetDuration() {
  21528. var tracks = this.tracks;
  21529. var duration = 0;
  21530. for (var i = 0, n = tracks.length; i !== n; ++i) {
  21531. var track = this.tracks[i];
  21532. duration = Math.max(duration, track.times[track.times.length - 1]);
  21533. }
  21534. this.duration = duration;
  21535. return this;
  21536. },
  21537. trim: function trim() {
  21538. for (var i = 0; i < this.tracks.length; i++) {
  21539. this.tracks[i].trim(0, this.duration);
  21540. }
  21541. return this;
  21542. },
  21543. validate: function validate() {
  21544. var valid = true;
  21545. for (var i = 0; i < this.tracks.length; i++) {
  21546. valid = valid && this.tracks[i].validate();
  21547. }
  21548. return valid;
  21549. },
  21550. optimize: function optimize() {
  21551. for (var i = 0; i < this.tracks.length; i++) {
  21552. this.tracks[i].optimize();
  21553. }
  21554. return this;
  21555. },
  21556. clone: function clone() {
  21557. var tracks = [];
  21558. for (var i = 0; i < this.tracks.length; i++) {
  21559. tracks.push(this.tracks[i].clone());
  21560. }
  21561. return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
  21562. },
  21563. toJSON: function toJSON() {
  21564. return AnimationClip.toJSON(this);
  21565. }
  21566. });
  21567. var Cache = {
  21568. enabled: false,
  21569. files: {},
  21570. add: function add(key, file) {
  21571. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  21572. this.files[key] = file;
  21573. },
  21574. get: function get(key) {
  21575. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  21576. return this.files[key];
  21577. },
  21578. remove: function remove(key) {
  21579. delete this.files[key];
  21580. },
  21581. clear: function clear() {
  21582. this.files = {};
  21583. }
  21584. };
  21585. function LoadingManager(onLoad, onProgress, onError) {
  21586. var scope = this;
  21587. var isLoading = false;
  21588. var itemsLoaded = 0;
  21589. var itemsTotal = 0;
  21590. var urlModifier = undefined;
  21591. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  21592. // in the constructor
  21593. this.onStart = undefined;
  21594. this.onLoad = onLoad;
  21595. this.onProgress = onProgress;
  21596. this.onError = onError;
  21597. this.itemStart = function (url) {
  21598. itemsTotal++;
  21599. if (isLoading === false) {
  21600. if (scope.onStart !== undefined) {
  21601. scope.onStart(url, itemsLoaded, itemsTotal);
  21602. }
  21603. }
  21604. isLoading = true;
  21605. };
  21606. this.itemEnd = function (url) {
  21607. itemsLoaded++;
  21608. if (scope.onProgress !== undefined) {
  21609. scope.onProgress(url, itemsLoaded, itemsTotal);
  21610. }
  21611. if (itemsLoaded === itemsTotal) {
  21612. isLoading = false;
  21613. if (scope.onLoad !== undefined) {
  21614. scope.onLoad();
  21615. }
  21616. }
  21617. };
  21618. this.itemError = function (url) {
  21619. if (scope.onError !== undefined) {
  21620. scope.onError(url);
  21621. }
  21622. };
  21623. this.resolveURL = function (url) {
  21624. if (urlModifier) {
  21625. return urlModifier(url);
  21626. }
  21627. return url;
  21628. };
  21629. this.setURLModifier = function (transform) {
  21630. urlModifier = transform;
  21631. return this;
  21632. };
  21633. this.addHandler = function (regex, loader) {
  21634. handlers.push(regex, loader);
  21635. return this;
  21636. };
  21637. this.removeHandler = function (regex) {
  21638. var index = handlers.indexOf(regex);
  21639. if (index !== -1) {
  21640. handlers.splice(index, 2);
  21641. }
  21642. return this;
  21643. };
  21644. this.getHandler = function (file) {
  21645. for (var i = 0, l = handlers.length; i < l; i += 2) {
  21646. var regex = handlers[i];
  21647. var loader = handlers[i + 1];
  21648. if (regex.global) regex.lastIndex = 0; // see #17920
  21649. if (regex.test(file)) {
  21650. return loader;
  21651. }
  21652. }
  21653. return null;
  21654. };
  21655. }
  21656. var DefaultLoadingManager = new LoadingManager();
  21657. function Loader(manager) {
  21658. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  21659. this.crossOrigin = 'anonymous';
  21660. this.withCredentials = false;
  21661. this.path = '';
  21662. this.resourcePath = '';
  21663. this.requestHeader = {};
  21664. }
  21665. Object.assign(Loader.prototype, {
  21666. load: function load()
  21667. /* url, onLoad, onProgress, onError */
  21668. {},
  21669. loadAsync: function loadAsync(url, onProgress) {
  21670. var scope = this;
  21671. return new Promise(function (resolve, reject) {
  21672. scope.load(url, resolve, onProgress, reject);
  21673. });
  21674. },
  21675. parse: function parse()
  21676. /* data */
  21677. {},
  21678. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  21679. this.crossOrigin = crossOrigin;
  21680. return this;
  21681. },
  21682. setWithCredentials: function setWithCredentials(value) {
  21683. this.withCredentials = value;
  21684. return this;
  21685. },
  21686. setPath: function setPath(path) {
  21687. this.path = path;
  21688. return this;
  21689. },
  21690. setResourcePath: function setResourcePath(resourcePath) {
  21691. this.resourcePath = resourcePath;
  21692. return this;
  21693. },
  21694. setRequestHeader: function setRequestHeader(requestHeader) {
  21695. this.requestHeader = requestHeader;
  21696. return this;
  21697. }
  21698. });
  21699. var loading = {};
  21700. function FileLoader(manager) {
  21701. Loader.call(this, manager);
  21702. }
  21703. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21704. constructor: FileLoader,
  21705. load: function load(url, onLoad, onProgress, onError) {
  21706. if (url === undefined) url = '';
  21707. if (this.path !== undefined) url = this.path + url;
  21708. url = this.manager.resolveURL(url);
  21709. var scope = this;
  21710. var cached = Cache.get(url);
  21711. if (cached !== undefined) {
  21712. scope.manager.itemStart(url);
  21713. setTimeout(function () {
  21714. if (onLoad) onLoad(cached);
  21715. scope.manager.itemEnd(url);
  21716. }, 0);
  21717. return cached;
  21718. } // Check if request is duplicate
  21719. if (loading[url] !== undefined) {
  21720. loading[url].push({
  21721. onLoad: onLoad,
  21722. onProgress: onProgress,
  21723. onError: onError
  21724. });
  21725. return;
  21726. } // Check for data: URI
  21727. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  21728. var dataUriRegexResult = url.match(dataUriRegex);
  21729. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  21730. if (dataUriRegexResult) {
  21731. var mimeType = dataUriRegexResult[1];
  21732. var isBase64 = !!dataUriRegexResult[2];
  21733. var data = dataUriRegexResult[3];
  21734. data = decodeURIComponent(data);
  21735. if (isBase64) data = atob(data);
  21736. try {
  21737. var response;
  21738. var responseType = (this.responseType || '').toLowerCase();
  21739. switch (responseType) {
  21740. case 'arraybuffer':
  21741. case 'blob':
  21742. var view = new Uint8Array(data.length);
  21743. for (var i = 0; i < data.length; i++) {
  21744. view[i] = data.charCodeAt(i);
  21745. }
  21746. if (responseType === 'blob') {
  21747. response = new Blob([view.buffer], {
  21748. type: mimeType
  21749. });
  21750. } else {
  21751. response = view.buffer;
  21752. }
  21753. break;
  21754. case 'document':
  21755. var parser = new DOMParser();
  21756. response = parser.parseFromString(data, mimeType);
  21757. break;
  21758. case 'json':
  21759. response = JSON.parse(data);
  21760. break;
  21761. default:
  21762. // 'text' or other
  21763. response = data;
  21764. break;
  21765. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21766. setTimeout(function () {
  21767. if (onLoad) onLoad(response);
  21768. scope.manager.itemEnd(url);
  21769. }, 0);
  21770. } catch (error) {
  21771. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21772. setTimeout(function () {
  21773. if (onError) onError(error);
  21774. scope.manager.itemError(url);
  21775. scope.manager.itemEnd(url);
  21776. }, 0);
  21777. }
  21778. } else {
  21779. // Initialise array for duplicate requests
  21780. loading[url] = [];
  21781. loading[url].push({
  21782. onLoad: onLoad,
  21783. onProgress: onProgress,
  21784. onError: onError
  21785. });
  21786. request = new XMLHttpRequest();
  21787. request.open('GET', url, true);
  21788. request.addEventListener('load', function (event) {
  21789. var response = this.response;
  21790. var callbacks = loading[url];
  21791. delete loading[url];
  21792. if (this.status === 200 || this.status === 0) {
  21793. // Some browsers return HTTP Status 0 when using non-http protocol
  21794. // e.g. 'file://' or 'data://'. Handle as success.
  21795. 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
  21796. // error response bodies as proper responses to requests.
  21797. Cache.add(url, response);
  21798. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  21799. var callback = callbacks[_i];
  21800. if (callback.onLoad) callback.onLoad(response);
  21801. }
  21802. scope.manager.itemEnd(url);
  21803. } else {
  21804. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  21805. var _callback = callbacks[_i2];
  21806. if (_callback.onError) _callback.onError(event);
  21807. }
  21808. scope.manager.itemError(url);
  21809. scope.manager.itemEnd(url);
  21810. }
  21811. }, false);
  21812. request.addEventListener('progress', function (event) {
  21813. var callbacks = loading[url];
  21814. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  21815. var callback = callbacks[_i3];
  21816. if (callback.onProgress) callback.onProgress(event);
  21817. }
  21818. }, false);
  21819. request.addEventListener('error', function (event) {
  21820. var callbacks = loading[url];
  21821. delete loading[url];
  21822. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  21823. var callback = callbacks[_i4];
  21824. if (callback.onError) callback.onError(event);
  21825. }
  21826. scope.manager.itemError(url);
  21827. scope.manager.itemEnd(url);
  21828. }, false);
  21829. request.addEventListener('abort', function (event) {
  21830. var callbacks = loading[url];
  21831. delete loading[url];
  21832. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  21833. var callback = callbacks[_i5];
  21834. if (callback.onError) callback.onError(event);
  21835. }
  21836. scope.manager.itemError(url);
  21837. scope.manager.itemEnd(url);
  21838. }, false);
  21839. if (this.responseType !== undefined) request.responseType = this.responseType;
  21840. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  21841. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  21842. for (var header in this.requestHeader) {
  21843. request.setRequestHeader(header, this.requestHeader[header]);
  21844. }
  21845. request.send(null);
  21846. }
  21847. scope.manager.itemStart(url);
  21848. return request;
  21849. },
  21850. setResponseType: function setResponseType(value) {
  21851. this.responseType = value;
  21852. return this;
  21853. },
  21854. setMimeType: function setMimeType(value) {
  21855. this.mimeType = value;
  21856. return this;
  21857. }
  21858. });
  21859. var AnimationLoader = /*#__PURE__*/function (_Loader) {
  21860. _inheritsLoose(AnimationLoader, _Loader);
  21861. function AnimationLoader(manager) {
  21862. return _Loader.call(this, manager) || this;
  21863. }
  21864. var _proto = AnimationLoader.prototype;
  21865. _proto.load = function load(url, onLoad, onProgress, onError) {
  21866. var scope = this;
  21867. var loader = new FileLoader(this.manager);
  21868. loader.setPath(this.path);
  21869. loader.setRequestHeader(this.requestHeader);
  21870. loader.setWithCredentials(this.withCredentials);
  21871. loader.load(url, function (text) {
  21872. try {
  21873. onLoad(scope.parse(JSON.parse(text)));
  21874. } catch (e) {
  21875. if (onError) {
  21876. onError(e);
  21877. } else {
  21878. console.error(e);
  21879. }
  21880. scope.manager.itemError(url);
  21881. }
  21882. }, onProgress, onError);
  21883. };
  21884. _proto.parse = function parse(json) {
  21885. var animations = [];
  21886. for (var i = 0; i < json.length; i++) {
  21887. var clip = AnimationClip.parse(json[i]);
  21888. animations.push(clip);
  21889. }
  21890. return animations;
  21891. };
  21892. return AnimationLoader;
  21893. }(Loader);
  21894. /**
  21895. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21896. *
  21897. * Sub classes have to implement the parse() method which will be used in load().
  21898. */
  21899. function CompressedTextureLoader(manager) {
  21900. Loader.call(this, manager);
  21901. }
  21902. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21903. constructor: CompressedTextureLoader,
  21904. load: function load(url, onLoad, onProgress, onError) {
  21905. var scope = this;
  21906. var images = [];
  21907. var texture = new CompressedTexture();
  21908. var loader = new FileLoader(this.manager);
  21909. loader.setPath(this.path);
  21910. loader.setResponseType('arraybuffer');
  21911. loader.setRequestHeader(this.requestHeader);
  21912. loader.setWithCredentials(scope.withCredentials);
  21913. var loaded = 0;
  21914. function loadTexture(i) {
  21915. loader.load(url[i], function (buffer) {
  21916. var texDatas = scope.parse(buffer, true);
  21917. images[i] = {
  21918. width: texDatas.width,
  21919. height: texDatas.height,
  21920. format: texDatas.format,
  21921. mipmaps: texDatas.mipmaps
  21922. };
  21923. loaded += 1;
  21924. if (loaded === 6) {
  21925. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  21926. texture.image = images;
  21927. texture.format = texDatas.format;
  21928. texture.needsUpdate = true;
  21929. if (onLoad) onLoad(texture);
  21930. }
  21931. }, onProgress, onError);
  21932. }
  21933. if (Array.isArray(url)) {
  21934. for (var i = 0, il = url.length; i < il; ++i) {
  21935. loadTexture(i);
  21936. }
  21937. } else {
  21938. // compressed cubemap texture stored in a single DDS file
  21939. loader.load(url, function (buffer) {
  21940. var texDatas = scope.parse(buffer, true);
  21941. if (texDatas.isCubemap) {
  21942. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21943. for (var f = 0; f < faces; f++) {
  21944. images[f] = {
  21945. mipmaps: []
  21946. };
  21947. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  21948. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  21949. images[f].format = texDatas.format;
  21950. images[f].width = texDatas.width;
  21951. images[f].height = texDatas.height;
  21952. }
  21953. }
  21954. texture.image = images;
  21955. } else {
  21956. texture.image.width = texDatas.width;
  21957. texture.image.height = texDatas.height;
  21958. texture.mipmaps = texDatas.mipmaps;
  21959. }
  21960. if (texDatas.mipmapCount === 1) {
  21961. texture.minFilter = LinearFilter;
  21962. }
  21963. texture.format = texDatas.format;
  21964. texture.needsUpdate = true;
  21965. if (onLoad) onLoad(texture);
  21966. }, onProgress, onError);
  21967. }
  21968. return texture;
  21969. }
  21970. });
  21971. var ImageLoader = /*#__PURE__*/function (_Loader) {
  21972. _inheritsLoose(ImageLoader, _Loader);
  21973. function ImageLoader(manager) {
  21974. return _Loader.call(this, manager) || this;
  21975. }
  21976. var _proto = ImageLoader.prototype;
  21977. _proto.load = function load(url, onLoad, onProgress, onError) {
  21978. if (this.path !== undefined) url = this.path + url;
  21979. url = this.manager.resolveURL(url);
  21980. var scope = this;
  21981. var cached = Cache.get(url);
  21982. if (cached !== undefined) {
  21983. scope.manager.itemStart(url);
  21984. setTimeout(function () {
  21985. if (onLoad) onLoad(cached);
  21986. scope.manager.itemEnd(url);
  21987. }, 0);
  21988. return cached;
  21989. }
  21990. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  21991. function onImageLoad() {
  21992. image.removeEventListener('load', onImageLoad, false);
  21993. image.removeEventListener('error', onImageError, false);
  21994. Cache.add(url, this);
  21995. if (onLoad) onLoad(this);
  21996. scope.manager.itemEnd(url);
  21997. }
  21998. function onImageError(event) {
  21999. image.removeEventListener('load', onImageLoad, false);
  22000. image.removeEventListener('error', onImageError, false);
  22001. if (onError) onError(event);
  22002. scope.manager.itemError(url);
  22003. scope.manager.itemEnd(url);
  22004. }
  22005. image.addEventListener('load', onImageLoad, false);
  22006. image.addEventListener('error', onImageError, false);
  22007. if (url.substr(0, 5) !== 'data:') {
  22008. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  22009. }
  22010. scope.manager.itemStart(url);
  22011. image.src = url;
  22012. return image;
  22013. };
  22014. return ImageLoader;
  22015. }(Loader);
  22016. var CubeTextureLoader = /*#__PURE__*/function (_Loader) {
  22017. _inheritsLoose(CubeTextureLoader, _Loader);
  22018. function CubeTextureLoader(manager) {
  22019. return _Loader.call(this, manager) || this;
  22020. }
  22021. var _proto = CubeTextureLoader.prototype;
  22022. _proto.load = function load(urls, onLoad, onProgress, onError) {
  22023. var texture = new CubeTexture();
  22024. var loader = new ImageLoader(this.manager);
  22025. loader.setCrossOrigin(this.crossOrigin);
  22026. loader.setPath(this.path);
  22027. var loaded = 0;
  22028. function loadTexture(i) {
  22029. loader.load(urls[i], function (image) {
  22030. texture.images[i] = image;
  22031. loaded++;
  22032. if (loaded === 6) {
  22033. texture.needsUpdate = true;
  22034. if (onLoad) onLoad(texture);
  22035. }
  22036. }, undefined, onError);
  22037. }
  22038. for (var i = 0; i < urls.length; ++i) {
  22039. loadTexture(i);
  22040. }
  22041. return texture;
  22042. };
  22043. return CubeTextureLoader;
  22044. }(Loader);
  22045. /**
  22046. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  22047. *
  22048. * Sub classes have to implement the parse() method which will be used in load().
  22049. */
  22050. function DataTextureLoader(manager) {
  22051. Loader.call(this, manager);
  22052. }
  22053. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22054. constructor: DataTextureLoader,
  22055. load: function load(url, onLoad, onProgress, onError) {
  22056. var scope = this;
  22057. var texture = new DataTexture();
  22058. var loader = new FileLoader(this.manager);
  22059. loader.setResponseType('arraybuffer');
  22060. loader.setRequestHeader(this.requestHeader);
  22061. loader.setPath(this.path);
  22062. loader.setWithCredentials(scope.withCredentials);
  22063. loader.load(url, function (buffer) {
  22064. var texData = scope.parse(buffer);
  22065. if (!texData) return;
  22066. if (texData.image !== undefined) {
  22067. texture.image = texData.image;
  22068. } else if (texData.data !== undefined) {
  22069. texture.image.width = texData.width;
  22070. texture.image.height = texData.height;
  22071. texture.image.data = texData.data;
  22072. }
  22073. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  22074. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  22075. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  22076. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  22077. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  22078. if (texData.encoding !== undefined) {
  22079. texture.encoding = texData.encoding;
  22080. }
  22081. if (texData.flipY !== undefined) {
  22082. texture.flipY = texData.flipY;
  22083. }
  22084. if (texData.format !== undefined) {
  22085. texture.format = texData.format;
  22086. }
  22087. if (texData.type !== undefined) {
  22088. texture.type = texData.type;
  22089. }
  22090. if (texData.mipmaps !== undefined) {
  22091. texture.mipmaps = texData.mipmaps;
  22092. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  22093. }
  22094. if (texData.mipmapCount === 1) {
  22095. texture.minFilter = LinearFilter;
  22096. }
  22097. texture.needsUpdate = true;
  22098. if (onLoad) onLoad(texture, texData);
  22099. }, onProgress, onError);
  22100. return texture;
  22101. }
  22102. });
  22103. function TextureLoader(manager) {
  22104. Loader.call(this, manager);
  22105. }
  22106. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22107. constructor: TextureLoader,
  22108. load: function load(url, onLoad, onProgress, onError) {
  22109. var texture = new Texture();
  22110. var loader = new ImageLoader(this.manager);
  22111. loader.setCrossOrigin(this.crossOrigin);
  22112. loader.setPath(this.path);
  22113. loader.load(url, function (image) {
  22114. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  22115. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  22116. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  22117. texture.needsUpdate = true;
  22118. if (onLoad !== undefined) {
  22119. onLoad(texture);
  22120. }
  22121. }, onProgress, onError);
  22122. return texture;
  22123. }
  22124. });
  22125. /**
  22126. * Extensible curve object.
  22127. *
  22128. * Some common of curve methods:
  22129. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  22130. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  22131. * .getPoints(), .getSpacedPoints()
  22132. * .getLength()
  22133. * .updateArcLengths()
  22134. *
  22135. * This following curves inherit from THREE.Curve:
  22136. *
  22137. * -- 2D curves --
  22138. * THREE.ArcCurve
  22139. * THREE.CubicBezierCurve
  22140. * THREE.EllipseCurve
  22141. * THREE.LineCurve
  22142. * THREE.QuadraticBezierCurve
  22143. * THREE.SplineCurve
  22144. *
  22145. * -- 3D curves --
  22146. * THREE.CatmullRomCurve3
  22147. * THREE.CubicBezierCurve3
  22148. * THREE.LineCurve3
  22149. * THREE.QuadraticBezierCurve3
  22150. *
  22151. * A series of curves can be represented as a THREE.CurvePath.
  22152. *
  22153. **/
  22154. function Curve() {
  22155. this.type = 'Curve';
  22156. this.arcLengthDivisions = 200;
  22157. }
  22158. Object.assign(Curve.prototype, {
  22159. // Virtual base class method to overwrite and implement in subclasses
  22160. // - t [0 .. 1]
  22161. getPoint: function getPoint()
  22162. /* t, optionalTarget */
  22163. {
  22164. console.warn('THREE.Curve: .getPoint() not implemented.');
  22165. return null;
  22166. },
  22167. // Get point at relative position in curve according to arc length
  22168. // - u [0 .. 1]
  22169. getPointAt: function getPointAt(u, optionalTarget) {
  22170. var t = this.getUtoTmapping(u);
  22171. return this.getPoint(t, optionalTarget);
  22172. },
  22173. // Get sequence of points using getPoint( t )
  22174. getPoints: function getPoints(divisions) {
  22175. if (divisions === void 0) {
  22176. divisions = 5;
  22177. }
  22178. var points = [];
  22179. for (var d = 0; d <= divisions; d++) {
  22180. points.push(this.getPoint(d / divisions));
  22181. }
  22182. return points;
  22183. },
  22184. // Get sequence of points using getPointAt( u )
  22185. getSpacedPoints: function getSpacedPoints(divisions) {
  22186. if (divisions === void 0) {
  22187. divisions = 5;
  22188. }
  22189. var points = [];
  22190. for (var d = 0; d <= divisions; d++) {
  22191. points.push(this.getPointAt(d / divisions));
  22192. }
  22193. return points;
  22194. },
  22195. // Get total curve arc length
  22196. getLength: function getLength() {
  22197. var lengths = this.getLengths();
  22198. return lengths[lengths.length - 1];
  22199. },
  22200. // Get list of cumulative segment lengths
  22201. getLengths: function getLengths(divisions) {
  22202. if (divisions === undefined) divisions = this.arcLengthDivisions;
  22203. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  22204. return this.cacheArcLengths;
  22205. }
  22206. this.needsUpdate = false;
  22207. var cache = [];
  22208. var current,
  22209. last = this.getPoint(0);
  22210. var sum = 0;
  22211. cache.push(0);
  22212. for (var p = 1; p <= divisions; p++) {
  22213. current = this.getPoint(p / divisions);
  22214. sum += current.distanceTo(last);
  22215. cache.push(sum);
  22216. last = current;
  22217. }
  22218. this.cacheArcLengths = cache;
  22219. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22220. },
  22221. updateArcLengths: function updateArcLengths() {
  22222. this.needsUpdate = true;
  22223. this.getLengths();
  22224. },
  22225. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22226. getUtoTmapping: function getUtoTmapping(u, distance) {
  22227. var arcLengths = this.getLengths();
  22228. var i = 0;
  22229. var il = arcLengths.length;
  22230. var targetArcLength; // The targeted u distance value to get
  22231. if (distance) {
  22232. targetArcLength = distance;
  22233. } else {
  22234. targetArcLength = u * arcLengths[il - 1];
  22235. } // binary search for the index with largest value smaller than target u distance
  22236. var low = 0,
  22237. high = il - 1,
  22238. comparison;
  22239. while (low <= high) {
  22240. 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
  22241. comparison = arcLengths[i] - targetArcLength;
  22242. if (comparison < 0) {
  22243. low = i + 1;
  22244. } else if (comparison > 0) {
  22245. high = i - 1;
  22246. } else {
  22247. high = i;
  22248. break; // DONE
  22249. }
  22250. }
  22251. i = high;
  22252. if (arcLengths[i] === targetArcLength) {
  22253. return i / (il - 1);
  22254. } // we could get finer grain at lengths, or use simple interpolation between two points
  22255. var lengthBefore = arcLengths[i];
  22256. var lengthAfter = arcLengths[i + 1];
  22257. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  22258. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  22259. var t = (i + segmentFraction) / (il - 1);
  22260. return t;
  22261. },
  22262. // Returns a unit vector tangent at t
  22263. // In case any sub curve does not implement its tangent derivation,
  22264. // 2 points a small delta apart will be used to find its gradient
  22265. // which seems to give a reasonable approximation
  22266. getTangent: function getTangent(t, optionalTarget) {
  22267. var delta = 0.0001;
  22268. var t1 = t - delta;
  22269. var t2 = t + delta; // Capping in case of danger
  22270. if (t1 < 0) t1 = 0;
  22271. if (t2 > 1) t2 = 1;
  22272. var pt1 = this.getPoint(t1);
  22273. var pt2 = this.getPoint(t2);
  22274. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  22275. tangent.copy(pt2).sub(pt1).normalize();
  22276. return tangent;
  22277. },
  22278. getTangentAt: function getTangentAt(u, optionalTarget) {
  22279. var t = this.getUtoTmapping(u);
  22280. return this.getTangent(t, optionalTarget);
  22281. },
  22282. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  22283. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22284. var normal = new Vector3();
  22285. var tangents = [];
  22286. var normals = [];
  22287. var binormals = [];
  22288. var vec = new Vector3();
  22289. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  22290. for (var i = 0; i <= segments; i++) {
  22291. var u = i / segments;
  22292. tangents[i] = this.getTangentAt(u, new Vector3());
  22293. tangents[i].normalize();
  22294. } // select an initial normal vector perpendicular to the first tangent vector,
  22295. // and in the direction of the minimum tangent xyz component
  22296. normals[0] = new Vector3();
  22297. binormals[0] = new Vector3();
  22298. var min = Number.MAX_VALUE;
  22299. var tx = Math.abs(tangents[0].x);
  22300. var ty = Math.abs(tangents[0].y);
  22301. var tz = Math.abs(tangents[0].z);
  22302. if (tx <= min) {
  22303. min = tx;
  22304. normal.set(1, 0, 0);
  22305. }
  22306. if (ty <= min) {
  22307. min = ty;
  22308. normal.set(0, 1, 0);
  22309. }
  22310. if (tz <= min) {
  22311. normal.set(0, 0, 1);
  22312. }
  22313. vec.crossVectors(tangents[0], normal).normalize();
  22314. normals[0].crossVectors(tangents[0], vec);
  22315. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22316. for (var _i = 1; _i <= segments; _i++) {
  22317. normals[_i] = normals[_i - 1].clone();
  22318. binormals[_i] = binormals[_i - 1].clone();
  22319. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  22320. if (vec.length() > Number.EPSILON) {
  22321. vec.normalize();
  22322. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  22323. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  22324. }
  22325. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  22326. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22327. if (closed === true) {
  22328. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  22329. _theta /= segments;
  22330. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  22331. _theta = -_theta;
  22332. }
  22333. for (var _i2 = 1; _i2 <= segments; _i2++) {
  22334. // twist a little...
  22335. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  22336. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  22337. }
  22338. }
  22339. return {
  22340. tangents: tangents,
  22341. normals: normals,
  22342. binormals: binormals
  22343. };
  22344. },
  22345. clone: function clone() {
  22346. return new this.constructor().copy(this);
  22347. },
  22348. copy: function copy(source) {
  22349. this.arcLengthDivisions = source.arcLengthDivisions;
  22350. return this;
  22351. },
  22352. toJSON: function toJSON() {
  22353. var data = {
  22354. metadata: {
  22355. version: 4.5,
  22356. type: 'Curve',
  22357. generator: 'Curve.toJSON'
  22358. }
  22359. };
  22360. data.arcLengthDivisions = this.arcLengthDivisions;
  22361. data.type = this.type;
  22362. return data;
  22363. },
  22364. fromJSON: function fromJSON(json) {
  22365. this.arcLengthDivisions = json.arcLengthDivisions;
  22366. return this;
  22367. }
  22368. });
  22369. var EllipseCurve = /*#__PURE__*/function (_Curve) {
  22370. _inheritsLoose(EllipseCurve, _Curve);
  22371. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22372. var _this;
  22373. if (aX === void 0) {
  22374. aX = 0;
  22375. }
  22376. if (aY === void 0) {
  22377. aY = 0;
  22378. }
  22379. if (xRadius === void 0) {
  22380. xRadius = 1;
  22381. }
  22382. if (yRadius === void 0) {
  22383. yRadius = 1;
  22384. }
  22385. if (aStartAngle === void 0) {
  22386. aStartAngle = 0;
  22387. }
  22388. if (aEndAngle === void 0) {
  22389. aEndAngle = Math.PI * 2;
  22390. }
  22391. if (aClockwise === void 0) {
  22392. aClockwise = false;
  22393. }
  22394. if (aRotation === void 0) {
  22395. aRotation = 0;
  22396. }
  22397. _this = _Curve.call(this) || this;
  22398. _this.type = 'EllipseCurve';
  22399. _this.aX = aX;
  22400. _this.aY = aY;
  22401. _this.xRadius = xRadius;
  22402. _this.yRadius = yRadius;
  22403. _this.aStartAngle = aStartAngle;
  22404. _this.aEndAngle = aEndAngle;
  22405. _this.aClockwise = aClockwise;
  22406. _this.aRotation = aRotation;
  22407. return _this;
  22408. }
  22409. var _proto = EllipseCurve.prototype;
  22410. _proto.getPoint = function getPoint(t, optionalTarget) {
  22411. var point = optionalTarget || new Vector2();
  22412. var twoPi = Math.PI * 2;
  22413. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22414. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  22415. while (deltaAngle < 0) {
  22416. deltaAngle += twoPi;
  22417. }
  22418. while (deltaAngle > twoPi) {
  22419. deltaAngle -= twoPi;
  22420. }
  22421. if (deltaAngle < Number.EPSILON) {
  22422. if (samePoints) {
  22423. deltaAngle = 0;
  22424. } else {
  22425. deltaAngle = twoPi;
  22426. }
  22427. }
  22428. if (this.aClockwise === true && !samePoints) {
  22429. if (deltaAngle === twoPi) {
  22430. deltaAngle = -twoPi;
  22431. } else {
  22432. deltaAngle = deltaAngle - twoPi;
  22433. }
  22434. }
  22435. var angle = this.aStartAngle + t * deltaAngle;
  22436. var x = this.aX + this.xRadius * Math.cos(angle);
  22437. var y = this.aY + this.yRadius * Math.sin(angle);
  22438. if (this.aRotation !== 0) {
  22439. var cos = Math.cos(this.aRotation);
  22440. var sin = Math.sin(this.aRotation);
  22441. var tx = x - this.aX;
  22442. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  22443. x = tx * cos - ty * sin + this.aX;
  22444. y = tx * sin + ty * cos + this.aY;
  22445. }
  22446. return point.set(x, y);
  22447. };
  22448. _proto.copy = function copy(source) {
  22449. _Curve.prototype.copy.call(this, source);
  22450. this.aX = source.aX;
  22451. this.aY = source.aY;
  22452. this.xRadius = source.xRadius;
  22453. this.yRadius = source.yRadius;
  22454. this.aStartAngle = source.aStartAngle;
  22455. this.aEndAngle = source.aEndAngle;
  22456. this.aClockwise = source.aClockwise;
  22457. this.aRotation = source.aRotation;
  22458. return this;
  22459. };
  22460. _proto.toJSON = function toJSON() {
  22461. var data = _Curve.prototype.toJSON.call(this);
  22462. data.aX = this.aX;
  22463. data.aY = this.aY;
  22464. data.xRadius = this.xRadius;
  22465. data.yRadius = this.yRadius;
  22466. data.aStartAngle = this.aStartAngle;
  22467. data.aEndAngle = this.aEndAngle;
  22468. data.aClockwise = this.aClockwise;
  22469. data.aRotation = this.aRotation;
  22470. return data;
  22471. };
  22472. _proto.fromJSON = function fromJSON(json) {
  22473. _Curve.prototype.fromJSON.call(this, json);
  22474. this.aX = json.aX;
  22475. this.aY = json.aY;
  22476. this.xRadius = json.xRadius;
  22477. this.yRadius = json.yRadius;
  22478. this.aStartAngle = json.aStartAngle;
  22479. this.aEndAngle = json.aEndAngle;
  22480. this.aClockwise = json.aClockwise;
  22481. this.aRotation = json.aRotation;
  22482. return this;
  22483. };
  22484. return EllipseCurve;
  22485. }(Curve);
  22486. EllipseCurve.prototype.isEllipseCurve = true;
  22487. var ArcCurve = /*#__PURE__*/function (_EllipseCurve) {
  22488. _inheritsLoose(ArcCurve, _EllipseCurve);
  22489. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22490. var _this;
  22491. _this = _EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise) || this;
  22492. _this.type = 'ArcCurve';
  22493. return _this;
  22494. }
  22495. return ArcCurve;
  22496. }(EllipseCurve);
  22497. ArcCurve.prototype.isArcCurve = true;
  22498. /**
  22499. * Centripetal CatmullRom Curve - which is useful for avoiding
  22500. * cusps and self-intersections in non-uniform catmull rom curves.
  22501. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22502. *
  22503. * curve.type accepts centripetal(default), chordal and catmullrom
  22504. * curve.tension is used for catmullrom which defaults to 0.5
  22505. */
  22506. /*
  22507. Based on an optimized c++ solution in
  22508. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22509. - http://ideone.com/NoEbVM
  22510. This CubicPoly class could be used for reusing some variables and calculations,
  22511. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22512. which can be placed in CurveUtils.
  22513. */
  22514. function CubicPoly() {
  22515. var c0 = 0,
  22516. c1 = 0,
  22517. c2 = 0,
  22518. c3 = 0;
  22519. /*
  22520. * Compute coefficients for a cubic polynomial
  22521. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22522. * such that
  22523. * p(0) = x0, p(1) = x1
  22524. * and
  22525. * p'(0) = t0, p'(1) = t1.
  22526. */
  22527. function init(x0, x1, t0, t1) {
  22528. c0 = x0;
  22529. c1 = t0;
  22530. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  22531. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22532. }
  22533. return {
  22534. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  22535. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  22536. },
  22537. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  22538. // compute tangents when parameterized in [t1,t2]
  22539. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  22540. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  22541. t1 *= dt1;
  22542. t2 *= dt1;
  22543. init(x1, x2, t1, t2);
  22544. },
  22545. calc: function calc(t) {
  22546. var t2 = t * t;
  22547. var t3 = t2 * t;
  22548. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22549. }
  22550. };
  22551. } //
  22552. var tmp = new Vector3();
  22553. var px = new CubicPoly(),
  22554. py = new CubicPoly(),
  22555. pz = new CubicPoly();
  22556. var CatmullRomCurve3 = /*#__PURE__*/function (_Curve) {
  22557. _inheritsLoose(CatmullRomCurve3, _Curve);
  22558. function CatmullRomCurve3(points, closed, curveType, tension) {
  22559. var _this;
  22560. if (points === void 0) {
  22561. points = [];
  22562. }
  22563. if (closed === void 0) {
  22564. closed = false;
  22565. }
  22566. if (curveType === void 0) {
  22567. curveType = 'centripetal';
  22568. }
  22569. if (tension === void 0) {
  22570. tension = 0.5;
  22571. }
  22572. _this = _Curve.call(this) || this;
  22573. _this.type = 'CatmullRomCurve3';
  22574. _this.points = points;
  22575. _this.closed = closed;
  22576. _this.curveType = curveType;
  22577. _this.tension = tension;
  22578. return _this;
  22579. }
  22580. var _proto = CatmullRomCurve3.prototype;
  22581. _proto.getPoint = function getPoint(t, optionalTarget) {
  22582. if (optionalTarget === void 0) {
  22583. optionalTarget = new Vector3();
  22584. }
  22585. var point = optionalTarget;
  22586. var points = this.points;
  22587. var l = points.length;
  22588. var p = (l - (this.closed ? 0 : 1)) * t;
  22589. var intPoint = Math.floor(p);
  22590. var weight = p - intPoint;
  22591. if (this.closed) {
  22592. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  22593. } else if (weight === 0 && intPoint === l - 1) {
  22594. intPoint = l - 2;
  22595. weight = 1;
  22596. }
  22597. var p0, p3; // 4 points (p1 & p2 defined below)
  22598. if (this.closed || intPoint > 0) {
  22599. p0 = points[(intPoint - 1) % l];
  22600. } else {
  22601. // extrapolate first point
  22602. tmp.subVectors(points[0], points[1]).add(points[0]);
  22603. p0 = tmp;
  22604. }
  22605. var p1 = points[intPoint % l];
  22606. var p2 = points[(intPoint + 1) % l];
  22607. if (this.closed || intPoint + 2 < l) {
  22608. p3 = points[(intPoint + 2) % l];
  22609. } else {
  22610. // extrapolate last point
  22611. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  22612. p3 = tmp;
  22613. }
  22614. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  22615. // init Centripetal / Chordal Catmull-Rom
  22616. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22617. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  22618. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  22619. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  22620. if (dt1 < 1e-4) dt1 = 1.0;
  22621. if (dt0 < 1e-4) dt0 = dt1;
  22622. if (dt2 < 1e-4) dt2 = dt1;
  22623. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  22624. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  22625. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  22626. } else if (this.curveType === 'catmullrom') {
  22627. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  22628. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  22629. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  22630. }
  22631. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  22632. return point;
  22633. };
  22634. _proto.copy = function copy(source) {
  22635. _Curve.prototype.copy.call(this, source);
  22636. this.points = [];
  22637. for (var i = 0, l = source.points.length; i < l; i++) {
  22638. var point = source.points[i];
  22639. this.points.push(point.clone());
  22640. }
  22641. this.closed = source.closed;
  22642. this.curveType = source.curveType;
  22643. this.tension = source.tension;
  22644. return this;
  22645. };
  22646. _proto.toJSON = function toJSON() {
  22647. var data = _Curve.prototype.toJSON.call(this);
  22648. data.points = [];
  22649. for (var i = 0, l = this.points.length; i < l; i++) {
  22650. var point = this.points[i];
  22651. data.points.push(point.toArray());
  22652. }
  22653. data.closed = this.closed;
  22654. data.curveType = this.curveType;
  22655. data.tension = this.tension;
  22656. return data;
  22657. };
  22658. _proto.fromJSON = function fromJSON(json) {
  22659. _Curve.prototype.fromJSON.call(this, json);
  22660. this.points = [];
  22661. for (var i = 0, l = json.points.length; i < l; i++) {
  22662. var point = json.points[i];
  22663. this.points.push(new Vector3().fromArray(point));
  22664. }
  22665. this.closed = json.closed;
  22666. this.curveType = json.curveType;
  22667. this.tension = json.tension;
  22668. return this;
  22669. };
  22670. return CatmullRomCurve3;
  22671. }(Curve);
  22672. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22673. /**
  22674. * Bezier Curves formulas obtained from
  22675. * http://en.wikipedia.org/wiki/Bézier_curve
  22676. */
  22677. function CatmullRom(t, p0, p1, p2, p3) {
  22678. var v0 = (p2 - p0) * 0.5;
  22679. var v1 = (p3 - p1) * 0.5;
  22680. var t2 = t * t;
  22681. var t3 = t * t2;
  22682. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  22683. } //
  22684. function QuadraticBezierP0(t, p) {
  22685. var k = 1 - t;
  22686. return k * k * p;
  22687. }
  22688. function QuadraticBezierP1(t, p) {
  22689. return 2 * (1 - t) * t * p;
  22690. }
  22691. function QuadraticBezierP2(t, p) {
  22692. return t * t * p;
  22693. }
  22694. function QuadraticBezier(t, p0, p1, p2) {
  22695. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  22696. } //
  22697. function CubicBezierP0(t, p) {
  22698. var k = 1 - t;
  22699. return k * k * k * p;
  22700. }
  22701. function CubicBezierP1(t, p) {
  22702. var k = 1 - t;
  22703. return 3 * k * k * t * p;
  22704. }
  22705. function CubicBezierP2(t, p) {
  22706. return 3 * (1 - t) * t * t * p;
  22707. }
  22708. function CubicBezierP3(t, p) {
  22709. return t * t * t * p;
  22710. }
  22711. function CubicBezier(t, p0, p1, p2, p3) {
  22712. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  22713. }
  22714. var CubicBezierCurve = /*#__PURE__*/function (_Curve) {
  22715. _inheritsLoose(CubicBezierCurve, _Curve);
  22716. function CubicBezierCurve(v0, v1, v2, v3) {
  22717. var _this;
  22718. if (v0 === void 0) {
  22719. v0 = new Vector2();
  22720. }
  22721. if (v1 === void 0) {
  22722. v1 = new Vector2();
  22723. }
  22724. if (v2 === void 0) {
  22725. v2 = new Vector2();
  22726. }
  22727. if (v3 === void 0) {
  22728. v3 = new Vector2();
  22729. }
  22730. _this = _Curve.call(this) || this;
  22731. _this.type = 'CubicBezierCurve';
  22732. _this.v0 = v0;
  22733. _this.v1 = v1;
  22734. _this.v2 = v2;
  22735. _this.v3 = v3;
  22736. return _this;
  22737. }
  22738. var _proto = CubicBezierCurve.prototype;
  22739. _proto.getPoint = function getPoint(t, optionalTarget) {
  22740. if (optionalTarget === void 0) {
  22741. optionalTarget = new Vector2();
  22742. }
  22743. var point = optionalTarget;
  22744. var v0 = this.v0,
  22745. v1 = this.v1,
  22746. v2 = this.v2,
  22747. v3 = this.v3;
  22748. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  22749. return point;
  22750. };
  22751. _proto.copy = function copy(source) {
  22752. _Curve.prototype.copy.call(this, source);
  22753. this.v0.copy(source.v0);
  22754. this.v1.copy(source.v1);
  22755. this.v2.copy(source.v2);
  22756. this.v3.copy(source.v3);
  22757. return this;
  22758. };
  22759. _proto.toJSON = function toJSON() {
  22760. var data = _Curve.prototype.toJSON.call(this);
  22761. data.v0 = this.v0.toArray();
  22762. data.v1 = this.v1.toArray();
  22763. data.v2 = this.v2.toArray();
  22764. data.v3 = this.v3.toArray();
  22765. return data;
  22766. };
  22767. _proto.fromJSON = function fromJSON(json) {
  22768. _Curve.prototype.fromJSON.call(this, json);
  22769. this.v0.fromArray(json.v0);
  22770. this.v1.fromArray(json.v1);
  22771. this.v2.fromArray(json.v2);
  22772. this.v3.fromArray(json.v3);
  22773. return this;
  22774. };
  22775. return CubicBezierCurve;
  22776. }(Curve);
  22777. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  22778. var CubicBezierCurve3 = /*#__PURE__*/function (_Curve) {
  22779. _inheritsLoose(CubicBezierCurve3, _Curve);
  22780. function CubicBezierCurve3(v0, v1, v2, v3) {
  22781. var _this;
  22782. if (v0 === void 0) {
  22783. v0 = new Vector3();
  22784. }
  22785. if (v1 === void 0) {
  22786. v1 = new Vector3();
  22787. }
  22788. if (v2 === void 0) {
  22789. v2 = new Vector3();
  22790. }
  22791. if (v3 === void 0) {
  22792. v3 = new Vector3();
  22793. }
  22794. _this = _Curve.call(this) || this;
  22795. _this.type = 'CubicBezierCurve3';
  22796. _this.v0 = v0;
  22797. _this.v1 = v1;
  22798. _this.v2 = v2;
  22799. _this.v3 = v3;
  22800. return _this;
  22801. }
  22802. var _proto = CubicBezierCurve3.prototype;
  22803. _proto.getPoint = function getPoint(t, optionalTarget) {
  22804. if (optionalTarget === void 0) {
  22805. optionalTarget = new Vector3();
  22806. }
  22807. var point = optionalTarget;
  22808. var v0 = this.v0,
  22809. v1 = this.v1,
  22810. v2 = this.v2,
  22811. v3 = this.v3;
  22812. 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));
  22813. return point;
  22814. };
  22815. _proto.copy = function copy(source) {
  22816. _Curve.prototype.copy.call(this, source);
  22817. this.v0.copy(source.v0);
  22818. this.v1.copy(source.v1);
  22819. this.v2.copy(source.v2);
  22820. this.v3.copy(source.v3);
  22821. return this;
  22822. };
  22823. _proto.toJSON = function toJSON() {
  22824. var data = _Curve.prototype.toJSON.call(this);
  22825. data.v0 = this.v0.toArray();
  22826. data.v1 = this.v1.toArray();
  22827. data.v2 = this.v2.toArray();
  22828. data.v3 = this.v3.toArray();
  22829. return data;
  22830. };
  22831. _proto.fromJSON = function fromJSON(json) {
  22832. _Curve.prototype.fromJSON.call(this, json);
  22833. this.v0.fromArray(json.v0);
  22834. this.v1.fromArray(json.v1);
  22835. this.v2.fromArray(json.v2);
  22836. this.v3.fromArray(json.v3);
  22837. return this;
  22838. };
  22839. return CubicBezierCurve3;
  22840. }(Curve);
  22841. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  22842. var LineCurve = /*#__PURE__*/function (_Curve) {
  22843. _inheritsLoose(LineCurve, _Curve);
  22844. function LineCurve(v1, v2) {
  22845. var _this;
  22846. if (v1 === void 0) {
  22847. v1 = new Vector2();
  22848. }
  22849. if (v2 === void 0) {
  22850. v2 = new Vector2();
  22851. }
  22852. _this = _Curve.call(this) || this;
  22853. _this.type = 'LineCurve';
  22854. _this.v1 = v1;
  22855. _this.v2 = v2;
  22856. return _this;
  22857. }
  22858. var _proto = LineCurve.prototype;
  22859. _proto.getPoint = function getPoint(t, optionalTarget) {
  22860. if (optionalTarget === void 0) {
  22861. optionalTarget = new Vector2();
  22862. }
  22863. var point = optionalTarget;
  22864. if (t === 1) {
  22865. point.copy(this.v2);
  22866. } else {
  22867. point.copy(this.v2).sub(this.v1);
  22868. point.multiplyScalar(t).add(this.v1);
  22869. }
  22870. return point;
  22871. } // Line curve is linear, so we can overwrite default getPointAt
  22872. ;
  22873. _proto.getPointAt = function getPointAt(u, optionalTarget) {
  22874. return this.getPoint(u, optionalTarget);
  22875. };
  22876. _proto.getTangent = function getTangent(t, optionalTarget) {
  22877. var tangent = optionalTarget || new Vector2();
  22878. tangent.copy(this.v2).sub(this.v1).normalize();
  22879. return tangent;
  22880. };
  22881. _proto.copy = function copy(source) {
  22882. _Curve.prototype.copy.call(this, source);
  22883. this.v1.copy(source.v1);
  22884. this.v2.copy(source.v2);
  22885. return this;
  22886. };
  22887. _proto.toJSON = function toJSON() {
  22888. var data = _Curve.prototype.toJSON.call(this);
  22889. data.v1 = this.v1.toArray();
  22890. data.v2 = this.v2.toArray();
  22891. return data;
  22892. };
  22893. _proto.fromJSON = function fromJSON(json) {
  22894. _Curve.prototype.fromJSON.call(this, json);
  22895. this.v1.fromArray(json.v1);
  22896. this.v2.fromArray(json.v2);
  22897. return this;
  22898. };
  22899. return LineCurve;
  22900. }(Curve);
  22901. LineCurve.prototype.isLineCurve = true;
  22902. var LineCurve3 = /*#__PURE__*/function (_Curve) {
  22903. _inheritsLoose(LineCurve3, _Curve);
  22904. function LineCurve3(v1, v2) {
  22905. var _this;
  22906. if (v1 === void 0) {
  22907. v1 = new Vector3();
  22908. }
  22909. if (v2 === void 0) {
  22910. v2 = new Vector3();
  22911. }
  22912. _this = _Curve.call(this) || this;
  22913. _this.type = 'LineCurve3';
  22914. _this.isLineCurve3 = true;
  22915. _this.v1 = v1;
  22916. _this.v2 = v2;
  22917. return _this;
  22918. }
  22919. var _proto = LineCurve3.prototype;
  22920. _proto.getPoint = function getPoint(t, optionalTarget) {
  22921. if (optionalTarget === void 0) {
  22922. optionalTarget = new Vector3();
  22923. }
  22924. var point = optionalTarget;
  22925. if (t === 1) {
  22926. point.copy(this.v2);
  22927. } else {
  22928. point.copy(this.v2).sub(this.v1);
  22929. point.multiplyScalar(t).add(this.v1);
  22930. }
  22931. return point;
  22932. } // Line curve is linear, so we can overwrite default getPointAt
  22933. ;
  22934. _proto.getPointAt = function getPointAt(u, optionalTarget) {
  22935. return this.getPoint(u, optionalTarget);
  22936. };
  22937. _proto.copy = function copy(source) {
  22938. _Curve.prototype.copy.call(this, source);
  22939. this.v1.copy(source.v1);
  22940. this.v2.copy(source.v2);
  22941. return this;
  22942. };
  22943. _proto.toJSON = function toJSON() {
  22944. var data = _Curve.prototype.toJSON.call(this);
  22945. data.v1 = this.v1.toArray();
  22946. data.v2 = this.v2.toArray();
  22947. return data;
  22948. };
  22949. _proto.fromJSON = function fromJSON(json) {
  22950. _Curve.prototype.fromJSON.call(this, json);
  22951. this.v1.fromArray(json.v1);
  22952. this.v2.fromArray(json.v2);
  22953. return this;
  22954. };
  22955. return LineCurve3;
  22956. }(Curve);
  22957. var QuadraticBezierCurve = /*#__PURE__*/function (_Curve) {
  22958. _inheritsLoose(QuadraticBezierCurve, _Curve);
  22959. function QuadraticBezierCurve(v0, v1, v2) {
  22960. var _this;
  22961. if (v0 === void 0) {
  22962. v0 = new Vector2();
  22963. }
  22964. if (v1 === void 0) {
  22965. v1 = new Vector2();
  22966. }
  22967. if (v2 === void 0) {
  22968. v2 = new Vector2();
  22969. }
  22970. _this = _Curve.call(this) || this;
  22971. _this.type = 'QuadraticBezierCurve';
  22972. _this.v0 = v0;
  22973. _this.v1 = v1;
  22974. _this.v2 = v2;
  22975. return _this;
  22976. }
  22977. var _proto = QuadraticBezierCurve.prototype;
  22978. _proto.getPoint = function getPoint(t, optionalTarget) {
  22979. if (optionalTarget === void 0) {
  22980. optionalTarget = new Vector2();
  22981. }
  22982. var point = optionalTarget;
  22983. var v0 = this.v0,
  22984. v1 = this.v1,
  22985. v2 = this.v2;
  22986. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  22987. return point;
  22988. };
  22989. _proto.copy = function copy(source) {
  22990. _Curve.prototype.copy.call(this, source);
  22991. this.v0.copy(source.v0);
  22992. this.v1.copy(source.v1);
  22993. this.v2.copy(source.v2);
  22994. return this;
  22995. };
  22996. _proto.toJSON = function toJSON() {
  22997. var data = _Curve.prototype.toJSON.call(this);
  22998. data.v0 = this.v0.toArray();
  22999. data.v1 = this.v1.toArray();
  23000. data.v2 = this.v2.toArray();
  23001. return data;
  23002. };
  23003. _proto.fromJSON = function fromJSON(json) {
  23004. _Curve.prototype.fromJSON.call(this, json);
  23005. this.v0.fromArray(json.v0);
  23006. this.v1.fromArray(json.v1);
  23007. this.v2.fromArray(json.v2);
  23008. return this;
  23009. };
  23010. return QuadraticBezierCurve;
  23011. }(Curve);
  23012. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  23013. var QuadraticBezierCurve3 = /*#__PURE__*/function (_Curve) {
  23014. _inheritsLoose(QuadraticBezierCurve3, _Curve);
  23015. function QuadraticBezierCurve3(v0, v1, v2) {
  23016. var _this;
  23017. if (v0 === void 0) {
  23018. v0 = new Vector3();
  23019. }
  23020. if (v1 === void 0) {
  23021. v1 = new Vector3();
  23022. }
  23023. if (v2 === void 0) {
  23024. v2 = new Vector3();
  23025. }
  23026. _this = _Curve.call(this) || this;
  23027. _this.type = 'QuadraticBezierCurve3';
  23028. _this.v0 = v0;
  23029. _this.v1 = v1;
  23030. _this.v2 = v2;
  23031. return _this;
  23032. }
  23033. var _proto = QuadraticBezierCurve3.prototype;
  23034. _proto.getPoint = function getPoint(t, optionalTarget) {
  23035. if (optionalTarget === void 0) {
  23036. optionalTarget = new Vector3();
  23037. }
  23038. var point = optionalTarget;
  23039. var v0 = this.v0,
  23040. v1 = this.v1,
  23041. v2 = this.v2;
  23042. 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));
  23043. return point;
  23044. };
  23045. _proto.copy = function copy(source) {
  23046. _Curve.prototype.copy.call(this, source);
  23047. this.v0.copy(source.v0);
  23048. this.v1.copy(source.v1);
  23049. this.v2.copy(source.v2);
  23050. return this;
  23051. };
  23052. _proto.toJSON = function toJSON() {
  23053. var data = _Curve.prototype.toJSON.call(this);
  23054. data.v0 = this.v0.toArray();
  23055. data.v1 = this.v1.toArray();
  23056. data.v2 = this.v2.toArray();
  23057. return data;
  23058. };
  23059. _proto.fromJSON = function fromJSON(json) {
  23060. _Curve.prototype.fromJSON.call(this, json);
  23061. this.v0.fromArray(json.v0);
  23062. this.v1.fromArray(json.v1);
  23063. this.v2.fromArray(json.v2);
  23064. return this;
  23065. };
  23066. return QuadraticBezierCurve3;
  23067. }(Curve);
  23068. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  23069. var SplineCurve = /*#__PURE__*/function (_Curve) {
  23070. _inheritsLoose(SplineCurve, _Curve);
  23071. function SplineCurve(points) {
  23072. var _this;
  23073. if (points === void 0) {
  23074. points = [];
  23075. }
  23076. _this = _Curve.call(this) || this;
  23077. _this.type = 'SplineCurve';
  23078. _this.points = points;
  23079. return _this;
  23080. }
  23081. var _proto = SplineCurve.prototype;
  23082. _proto.getPoint = function getPoint(t, optionalTarget) {
  23083. if (optionalTarget === void 0) {
  23084. optionalTarget = new Vector2();
  23085. }
  23086. var point = optionalTarget;
  23087. var points = this.points;
  23088. var p = (points.length - 1) * t;
  23089. var intPoint = Math.floor(p);
  23090. var weight = p - intPoint;
  23091. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  23092. var p1 = points[intPoint];
  23093. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  23094. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  23095. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  23096. return point;
  23097. };
  23098. _proto.copy = function copy(source) {
  23099. _Curve.prototype.copy.call(this, source);
  23100. this.points = [];
  23101. for (var i = 0, l = source.points.length; i < l; i++) {
  23102. var point = source.points[i];
  23103. this.points.push(point.clone());
  23104. }
  23105. return this;
  23106. };
  23107. _proto.toJSON = function toJSON() {
  23108. var data = _Curve.prototype.toJSON.call(this);
  23109. data.points = [];
  23110. for (var i = 0, l = this.points.length; i < l; i++) {
  23111. var point = this.points[i];
  23112. data.points.push(point.toArray());
  23113. }
  23114. return data;
  23115. };
  23116. _proto.fromJSON = function fromJSON(json) {
  23117. _Curve.prototype.fromJSON.call(this, json);
  23118. this.points = [];
  23119. for (var i = 0, l = json.points.length; i < l; i++) {
  23120. var point = json.points[i];
  23121. this.points.push(new Vector2().fromArray(point));
  23122. }
  23123. return this;
  23124. };
  23125. return SplineCurve;
  23126. }(Curve);
  23127. SplineCurve.prototype.isSplineCurve = true;
  23128. var Curves = /*#__PURE__*/Object.freeze({
  23129. __proto__: null,
  23130. ArcCurve: ArcCurve,
  23131. CatmullRomCurve3: CatmullRomCurve3,
  23132. CubicBezierCurve: CubicBezierCurve,
  23133. CubicBezierCurve3: CubicBezierCurve3,
  23134. EllipseCurve: EllipseCurve,
  23135. LineCurve: LineCurve,
  23136. LineCurve3: LineCurve3,
  23137. QuadraticBezierCurve: QuadraticBezierCurve,
  23138. QuadraticBezierCurve3: QuadraticBezierCurve3,
  23139. SplineCurve: SplineCurve
  23140. });
  23141. /**************************************************************
  23142. * Curved Path - a curve path is simply a array of connected
  23143. * curves, but retains the api of a curve
  23144. **************************************************************/
  23145. var CurvePath = /*#__PURE__*/function (_Curve) {
  23146. _inheritsLoose(CurvePath, _Curve);
  23147. function CurvePath() {
  23148. var _this;
  23149. _this = _Curve.call(this) || this;
  23150. _this.type = 'CurvePath';
  23151. _this.curves = [];
  23152. _this.autoClose = false; // Automatically closes the path
  23153. return _this;
  23154. }
  23155. var _proto = CurvePath.prototype;
  23156. _proto.add = function add(curve) {
  23157. this.curves.push(curve);
  23158. };
  23159. _proto.closePath = function closePath() {
  23160. // Add a line curve if start and end of lines are not connected
  23161. var startPoint = this.curves[0].getPoint(0);
  23162. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  23163. if (!startPoint.equals(endPoint)) {
  23164. this.curves.push(new LineCurve(endPoint, startPoint));
  23165. }
  23166. } // To get accurate point with reference to
  23167. // entire path distance at time t,
  23168. // following has to be done:
  23169. // 1. Length of each sub path have to be known
  23170. // 2. Locate and identify type of curve
  23171. // 3. Get t for the curve
  23172. // 4. Return curve.getPointAt(t')
  23173. ;
  23174. _proto.getPoint = function getPoint(t) {
  23175. var d = t * this.getLength();
  23176. var curveLengths = this.getCurveLengths();
  23177. var i = 0; // To think about boundaries points.
  23178. while (i < curveLengths.length) {
  23179. if (curveLengths[i] >= d) {
  23180. var diff = curveLengths[i] - d;
  23181. var curve = this.curves[i];
  23182. var segmentLength = curve.getLength();
  23183. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  23184. return curve.getPointAt(u);
  23185. }
  23186. i++;
  23187. }
  23188. return null; // loop where sum != 0, sum > d , sum+1 <d
  23189. } // We cannot use the default THREE.Curve getPoint() with getLength() because in
  23190. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  23191. // getPoint() depends on getLength
  23192. ;
  23193. _proto.getLength = function getLength() {
  23194. var lens = this.getCurveLengths();
  23195. return lens[lens.length - 1];
  23196. } // cacheLengths must be recalculated.
  23197. ;
  23198. _proto.updateArcLengths = function updateArcLengths() {
  23199. this.needsUpdate = true;
  23200. this.cacheLengths = null;
  23201. this.getCurveLengths();
  23202. } // Compute lengths and cache them
  23203. // We cannot overwrite getLengths() because UtoT mapping uses it.
  23204. ;
  23205. _proto.getCurveLengths = function getCurveLengths() {
  23206. // We use cache values if curves and cache array are same length
  23207. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  23208. return this.cacheLengths;
  23209. } // Get length of sub-curve
  23210. // Push sums into cached array
  23211. var lengths = [];
  23212. var sums = 0;
  23213. for (var i = 0, l = this.curves.length; i < l; i++) {
  23214. sums += this.curves[i].getLength();
  23215. lengths.push(sums);
  23216. }
  23217. this.cacheLengths = lengths;
  23218. return lengths;
  23219. };
  23220. _proto.getSpacedPoints = function getSpacedPoints(divisions) {
  23221. if (divisions === void 0) {
  23222. divisions = 40;
  23223. }
  23224. var points = [];
  23225. for (var i = 0; i <= divisions; i++) {
  23226. points.push(this.getPoint(i / divisions));
  23227. }
  23228. if (this.autoClose) {
  23229. points.push(points[0]);
  23230. }
  23231. return points;
  23232. };
  23233. _proto.getPoints = function getPoints(divisions) {
  23234. if (divisions === void 0) {
  23235. divisions = 12;
  23236. }
  23237. var points = [];
  23238. var last;
  23239. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  23240. var curve = curves[i];
  23241. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  23242. var pts = curve.getPoints(resolution);
  23243. for (var j = 0; j < pts.length; j++) {
  23244. var point = pts[j];
  23245. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  23246. points.push(point);
  23247. last = point;
  23248. }
  23249. }
  23250. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  23251. points.push(points[0]);
  23252. }
  23253. return points;
  23254. };
  23255. _proto.copy = function copy(source) {
  23256. _Curve.prototype.copy.call(this, source);
  23257. this.curves = [];
  23258. for (var i = 0, l = source.curves.length; i < l; i++) {
  23259. var curve = source.curves[i];
  23260. this.curves.push(curve.clone());
  23261. }
  23262. this.autoClose = source.autoClose;
  23263. return this;
  23264. };
  23265. _proto.toJSON = function toJSON() {
  23266. var data = _Curve.prototype.toJSON.call(this);
  23267. data.autoClose = this.autoClose;
  23268. data.curves = [];
  23269. for (var i = 0, l = this.curves.length; i < l; i++) {
  23270. var curve = this.curves[i];
  23271. data.curves.push(curve.toJSON());
  23272. }
  23273. return data;
  23274. };
  23275. _proto.fromJSON = function fromJSON(json) {
  23276. _Curve.prototype.fromJSON.call(this, json);
  23277. this.autoClose = json.autoClose;
  23278. this.curves = [];
  23279. for (var i = 0, l = json.curves.length; i < l; i++) {
  23280. var curve = json.curves[i];
  23281. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  23282. }
  23283. return this;
  23284. };
  23285. return CurvePath;
  23286. }(Curve);
  23287. var Path = /*#__PURE__*/function (_CurvePath) {
  23288. _inheritsLoose(Path, _CurvePath);
  23289. function Path(points) {
  23290. var _this;
  23291. _this = _CurvePath.call(this) || this;
  23292. _this.type = 'Path';
  23293. _this.currentPoint = new Vector2();
  23294. if (points) {
  23295. _this.setFromPoints(points);
  23296. }
  23297. return _this;
  23298. }
  23299. var _proto = Path.prototype;
  23300. _proto.setFromPoints = function setFromPoints(points) {
  23301. this.moveTo(points[0].x, points[0].y);
  23302. for (var i = 1, l = points.length; i < l; i++) {
  23303. this.lineTo(points[i].x, points[i].y);
  23304. }
  23305. return this;
  23306. };
  23307. _proto.moveTo = function moveTo(x, y) {
  23308. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  23309. return this;
  23310. };
  23311. _proto.lineTo = function lineTo(x, y) {
  23312. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  23313. this.curves.push(curve);
  23314. this.currentPoint.set(x, y);
  23315. return this;
  23316. };
  23317. _proto.quadraticCurveTo = function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  23318. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  23319. this.curves.push(curve);
  23320. this.currentPoint.set(aX, aY);
  23321. return this;
  23322. };
  23323. _proto.bezierCurveTo = function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  23324. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  23325. this.curves.push(curve);
  23326. this.currentPoint.set(aX, aY);
  23327. return this;
  23328. };
  23329. _proto.splineThru = function splineThru(pts
  23330. /*Array of Vector*/
  23331. ) {
  23332. var npts = [this.currentPoint.clone()].concat(pts);
  23333. var curve = new SplineCurve(npts);
  23334. this.curves.push(curve);
  23335. this.currentPoint.copy(pts[pts.length - 1]);
  23336. return this;
  23337. };
  23338. _proto.arc = function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23339. var x0 = this.currentPoint.x;
  23340. var y0 = this.currentPoint.y;
  23341. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  23342. return this;
  23343. };
  23344. _proto.absarc = function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23345. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  23346. return this;
  23347. };
  23348. _proto.ellipse = function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23349. var x0 = this.currentPoint.x;
  23350. var y0 = this.currentPoint.y;
  23351. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23352. return this;
  23353. };
  23354. _proto.absellipse = function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23355. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23356. if (this.curves.length > 0) {
  23357. // if a previous curve is present, attempt to join
  23358. var firstPoint = curve.getPoint(0);
  23359. if (!firstPoint.equals(this.currentPoint)) {
  23360. this.lineTo(firstPoint.x, firstPoint.y);
  23361. }
  23362. }
  23363. this.curves.push(curve);
  23364. var lastPoint = curve.getPoint(1);
  23365. this.currentPoint.copy(lastPoint);
  23366. return this;
  23367. };
  23368. _proto.copy = function copy(source) {
  23369. _CurvePath.prototype.copy.call(this, source);
  23370. this.currentPoint.copy(source.currentPoint);
  23371. return this;
  23372. };
  23373. _proto.toJSON = function toJSON() {
  23374. var data = _CurvePath.prototype.toJSON.call(this);
  23375. data.currentPoint = this.currentPoint.toArray();
  23376. return data;
  23377. };
  23378. _proto.fromJSON = function fromJSON(json) {
  23379. _CurvePath.prototype.fromJSON.call(this, json);
  23380. this.currentPoint.fromArray(json.currentPoint);
  23381. return this;
  23382. };
  23383. return Path;
  23384. }(CurvePath);
  23385. var Shape = /*#__PURE__*/function (_Path) {
  23386. _inheritsLoose(Shape, _Path);
  23387. function Shape(points) {
  23388. var _this;
  23389. _this = _Path.call(this, points) || this;
  23390. _this.uuid = MathUtils.generateUUID();
  23391. _this.type = 'Shape';
  23392. _this.holes = [];
  23393. return _this;
  23394. }
  23395. var _proto = Shape.prototype;
  23396. _proto.getPointsHoles = function getPointsHoles(divisions) {
  23397. var holesPts = [];
  23398. for (var i = 0, l = this.holes.length; i < l; i++) {
  23399. holesPts[i] = this.holes[i].getPoints(divisions);
  23400. }
  23401. return holesPts;
  23402. } // get points of shape and holes (keypoints based on segments parameter)
  23403. ;
  23404. _proto.extractPoints = function extractPoints(divisions) {
  23405. return {
  23406. shape: this.getPoints(divisions),
  23407. holes: this.getPointsHoles(divisions)
  23408. };
  23409. };
  23410. _proto.copy = function copy(source) {
  23411. _Path.prototype.copy.call(this, source);
  23412. this.holes = [];
  23413. for (var i = 0, l = source.holes.length; i < l; i++) {
  23414. var hole = source.holes[i];
  23415. this.holes.push(hole.clone());
  23416. }
  23417. return this;
  23418. };
  23419. _proto.toJSON = function toJSON() {
  23420. var data = _Path.prototype.toJSON.call(this);
  23421. data.uuid = this.uuid;
  23422. data.holes = [];
  23423. for (var i = 0, l = this.holes.length; i < l; i++) {
  23424. var hole = this.holes[i];
  23425. data.holes.push(hole.toJSON());
  23426. }
  23427. return data;
  23428. };
  23429. _proto.fromJSON = function fromJSON(json) {
  23430. _Path.prototype.fromJSON.call(this, json);
  23431. this.uuid = json.uuid;
  23432. this.holes = [];
  23433. for (var i = 0, l = json.holes.length; i < l; i++) {
  23434. var hole = json.holes[i];
  23435. this.holes.push(new Path().fromJSON(hole));
  23436. }
  23437. return this;
  23438. };
  23439. return Shape;
  23440. }(Path);
  23441. var Light = /*#__PURE__*/function (_Object3D) {
  23442. _inheritsLoose(Light, _Object3D);
  23443. function Light(color, intensity) {
  23444. var _this;
  23445. if (intensity === void 0) {
  23446. intensity = 1;
  23447. }
  23448. _this = _Object3D.call(this) || this;
  23449. _this.type = 'Light';
  23450. _this.color = new Color(color);
  23451. _this.intensity = intensity;
  23452. return _this;
  23453. }
  23454. var _proto = Light.prototype;
  23455. _proto.copy = function copy(source) {
  23456. _Object3D.prototype.copy.call(this, source);
  23457. this.color.copy(source.color);
  23458. this.intensity = source.intensity;
  23459. return this;
  23460. };
  23461. _proto.toJSON = function toJSON(meta) {
  23462. var data = _Object3D.prototype.toJSON.call(this, meta);
  23463. data.object.color = this.color.getHex();
  23464. data.object.intensity = this.intensity;
  23465. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  23466. if (this.distance !== undefined) data.object.distance = this.distance;
  23467. if (this.angle !== undefined) data.object.angle = this.angle;
  23468. if (this.decay !== undefined) data.object.decay = this.decay;
  23469. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  23470. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  23471. return data;
  23472. };
  23473. return Light;
  23474. }(Object3D);
  23475. Light.prototype.isLight = true;
  23476. var HemisphereLight = /*#__PURE__*/function (_Light) {
  23477. _inheritsLoose(HemisphereLight, _Light);
  23478. function HemisphereLight(skyColor, groundColor, intensity) {
  23479. var _this;
  23480. _this = _Light.call(this, skyColor, intensity) || this;
  23481. _this.type = 'HemisphereLight';
  23482. _this.position.copy(Object3D.DefaultUp);
  23483. _this.updateMatrix();
  23484. _this.groundColor = new Color(groundColor);
  23485. return _this;
  23486. }
  23487. var _proto = HemisphereLight.prototype;
  23488. _proto.copy = function copy(source) {
  23489. Light.prototype.copy.call(this, source);
  23490. this.groundColor.copy(source.groundColor);
  23491. return this;
  23492. };
  23493. return HemisphereLight;
  23494. }(Light);
  23495. HemisphereLight.prototype.isHemisphereLight = true;
  23496. var _projScreenMatrix = /*@__PURE__*/new Matrix4();
  23497. var _lightPositionWorld = /*@__PURE__*/new Vector3();
  23498. var _lookTarget = /*@__PURE__*/new Vector3();
  23499. var LightShadow = /*#__PURE__*/function () {
  23500. function LightShadow(camera) {
  23501. this.camera = camera;
  23502. this.bias = 0;
  23503. this.normalBias = 0;
  23504. this.radius = 1;
  23505. this.mapSize = new Vector2(512, 512);
  23506. this.map = null;
  23507. this.mapPass = null;
  23508. this.matrix = new Matrix4();
  23509. this.autoUpdate = true;
  23510. this.needsUpdate = false;
  23511. this._frustum = new Frustum();
  23512. this._frameExtents = new Vector2(1, 1);
  23513. this._viewportCount = 1;
  23514. this._viewports = [new Vector4(0, 0, 1, 1)];
  23515. }
  23516. var _proto = LightShadow.prototype;
  23517. _proto.getViewportCount = function getViewportCount() {
  23518. return this._viewportCount;
  23519. };
  23520. _proto.getFrustum = function getFrustum() {
  23521. return this._frustum;
  23522. };
  23523. _proto.updateMatrices = function updateMatrices(light) {
  23524. var shadowCamera = this.camera;
  23525. var shadowMatrix = this.matrix;
  23526. _lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23527. shadowCamera.position.copy(_lightPositionWorld);
  23528. _lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  23529. shadowCamera.lookAt(_lookTarget);
  23530. shadowCamera.updateMatrixWorld();
  23531. _projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  23532. this._frustum.setFromProjectionMatrix(_projScreenMatrix);
  23533. 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);
  23534. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  23535. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  23536. };
  23537. _proto.getViewport = function getViewport(viewportIndex) {
  23538. return this._viewports[viewportIndex];
  23539. };
  23540. _proto.getFrameExtents = function getFrameExtents() {
  23541. return this._frameExtents;
  23542. };
  23543. _proto.copy = function copy(source) {
  23544. this.camera = source.camera.clone();
  23545. this.bias = source.bias;
  23546. this.radius = source.radius;
  23547. this.mapSize.copy(source.mapSize);
  23548. return this;
  23549. };
  23550. _proto.clone = function clone() {
  23551. return new this.constructor().copy(this);
  23552. };
  23553. _proto.toJSON = function toJSON() {
  23554. var object = {};
  23555. if (this.bias !== 0) object.bias = this.bias;
  23556. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  23557. if (this.radius !== 1) object.radius = this.radius;
  23558. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  23559. object.camera = this.camera.toJSON(false).object;
  23560. delete object.camera.matrix;
  23561. return object;
  23562. };
  23563. return LightShadow;
  23564. }();
  23565. var SpotLightShadow = /*#__PURE__*/function (_LightShadow) {
  23566. _inheritsLoose(SpotLightShadow, _LightShadow);
  23567. function SpotLightShadow() {
  23568. var _this;
  23569. _this = _LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500)) || this;
  23570. _this.focus = 1;
  23571. return _this;
  23572. }
  23573. var _proto = SpotLightShadow.prototype;
  23574. _proto.updateMatrices = function updateMatrices(light) {
  23575. var camera = this.camera;
  23576. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23577. var aspect = this.mapSize.width / this.mapSize.height;
  23578. var far = light.distance || camera.far;
  23579. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  23580. camera.fov = fov;
  23581. camera.aspect = aspect;
  23582. camera.far = far;
  23583. camera.updateProjectionMatrix();
  23584. }
  23585. _LightShadow.prototype.updateMatrices.call(this, light);
  23586. };
  23587. return SpotLightShadow;
  23588. }(LightShadow);
  23589. SpotLightShadow.prototype.isSpotLightShadow = true;
  23590. var SpotLight = /*#__PURE__*/function (_Light) {
  23591. _inheritsLoose(SpotLight, _Light);
  23592. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  23593. var _this;
  23594. if (distance === void 0) {
  23595. distance = 0;
  23596. }
  23597. if (angle === void 0) {
  23598. angle = Math.PI / 3;
  23599. }
  23600. if (penumbra === void 0) {
  23601. penumbra = 0;
  23602. }
  23603. if (decay === void 0) {
  23604. decay = 1;
  23605. }
  23606. _this = _Light.call(this, color, intensity) || this;
  23607. _this.type = 'SpotLight';
  23608. _this.position.copy(Object3D.DefaultUp);
  23609. _this.updateMatrix();
  23610. _this.target = new Object3D();
  23611. _this.distance = distance;
  23612. _this.angle = angle;
  23613. _this.penumbra = penumbra;
  23614. _this.decay = decay; // for physically correct lights, should be 2.
  23615. _this.shadow = new SpotLightShadow();
  23616. return _this;
  23617. }
  23618. var _proto = SpotLight.prototype;
  23619. _proto.copy = function copy(source) {
  23620. _Light.prototype.copy.call(this, source);
  23621. this.distance = source.distance;
  23622. this.angle = source.angle;
  23623. this.penumbra = source.penumbra;
  23624. this.decay = source.decay;
  23625. this.target = source.target.clone();
  23626. this.shadow = source.shadow.clone();
  23627. return this;
  23628. };
  23629. _createClass(SpotLight, [{
  23630. key: "power",
  23631. get: function get() {
  23632. // intensity = power per solid angle.
  23633. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23634. return this.intensity * Math.PI;
  23635. },
  23636. set: function set(power) {
  23637. // intensity = power per solid angle.
  23638. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23639. this.intensity = power / Math.PI;
  23640. }
  23641. }]);
  23642. return SpotLight;
  23643. }(Light);
  23644. SpotLight.prototype.isSpotLight = true;
  23645. var _projScreenMatrix$1 = /*@__PURE__*/new Matrix4();
  23646. var _lightPositionWorld$1 = /*@__PURE__*/new Vector3();
  23647. var _lookTarget$1 = /*@__PURE__*/new Vector3();
  23648. var PointLightShadow = /*#__PURE__*/function (_LightShadow) {
  23649. _inheritsLoose(PointLightShadow, _LightShadow);
  23650. function PointLightShadow() {
  23651. var _this;
  23652. _this = _LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500)) || this;
  23653. _this._frameExtents = new Vector2(4, 2);
  23654. _this._viewportCount = 6;
  23655. _this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  23656. // following orientation:
  23657. //
  23658. // xzXZ
  23659. // y Y
  23660. //
  23661. // X - Positive x direction
  23662. // x - Negative x direction
  23663. // Y - Positive y direction
  23664. // y - Negative y direction
  23665. // Z - Positive z direction
  23666. // z - Negative z direction
  23667. // positive X
  23668. new Vector4(2, 1, 1, 1), // negative X
  23669. new Vector4(0, 1, 1, 1), // positive Z
  23670. new Vector4(3, 1, 1, 1), // negative Z
  23671. new Vector4(1, 1, 1, 1), // positive Y
  23672. new Vector4(3, 0, 1, 1), // negative Y
  23673. new Vector4(1, 0, 1, 1)];
  23674. _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)];
  23675. _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)];
  23676. return _this;
  23677. }
  23678. var _proto = PointLightShadow.prototype;
  23679. _proto.updateMatrices = function updateMatrices(light, viewportIndex) {
  23680. if (viewportIndex === void 0) {
  23681. viewportIndex = 0;
  23682. }
  23683. var camera = this.camera;
  23684. var shadowMatrix = this.matrix;
  23685. _lightPositionWorld$1.setFromMatrixPosition(light.matrixWorld);
  23686. camera.position.copy(_lightPositionWorld$1);
  23687. _lookTarget$1.copy(camera.position);
  23688. _lookTarget$1.add(this._cubeDirections[viewportIndex]);
  23689. camera.up.copy(this._cubeUps[viewportIndex]);
  23690. camera.lookAt(_lookTarget$1);
  23691. camera.updateMatrixWorld();
  23692. shadowMatrix.makeTranslation(-_lightPositionWorld$1.x, -_lightPositionWorld$1.y, -_lightPositionWorld$1.z);
  23693. _projScreenMatrix$1.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  23694. this._frustum.setFromProjectionMatrix(_projScreenMatrix$1);
  23695. };
  23696. return PointLightShadow;
  23697. }(LightShadow);
  23698. PointLightShadow.prototype.isPointLightShadow = true;
  23699. var PointLight = /*#__PURE__*/function (_Light) {
  23700. _inheritsLoose(PointLight, _Light);
  23701. function PointLight(color, intensity, distance, decay) {
  23702. var _this;
  23703. if (distance === void 0) {
  23704. distance = 0;
  23705. }
  23706. if (decay === void 0) {
  23707. decay = 1;
  23708. }
  23709. _this = _Light.call(this, color, intensity) || this;
  23710. _this.type = 'PointLight';
  23711. _this.distance = distance;
  23712. _this.decay = decay; // for physically correct lights, should be 2.
  23713. _this.shadow = new PointLightShadow();
  23714. return _this;
  23715. }
  23716. var _proto = PointLight.prototype;
  23717. _proto.copy = function copy(source) {
  23718. _Light.prototype.copy.call(this, source);
  23719. this.distance = source.distance;
  23720. this.decay = source.decay;
  23721. this.shadow = source.shadow.clone();
  23722. return this;
  23723. };
  23724. _createClass(PointLight, [{
  23725. key: "power",
  23726. get: function get() {
  23727. // intensity = power per solid angle.
  23728. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23729. return this.intensity * 4 * Math.PI;
  23730. },
  23731. set: function set(power) {
  23732. // intensity = power per solid angle.
  23733. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23734. this.intensity = power / (4 * Math.PI);
  23735. }
  23736. }]);
  23737. return PointLight;
  23738. }(Light);
  23739. PointLight.prototype.isPointLight = true;
  23740. var OrthographicCamera = /*#__PURE__*/function (_Camera) {
  23741. _inheritsLoose(OrthographicCamera, _Camera);
  23742. function OrthographicCamera(left, right, top, bottom, near, far) {
  23743. var _this;
  23744. if (left === void 0) {
  23745. left = -1;
  23746. }
  23747. if (right === void 0) {
  23748. right = 1;
  23749. }
  23750. if (top === void 0) {
  23751. top = 1;
  23752. }
  23753. if (bottom === void 0) {
  23754. bottom = -1;
  23755. }
  23756. if (near === void 0) {
  23757. near = 0.1;
  23758. }
  23759. if (far === void 0) {
  23760. far = 2000;
  23761. }
  23762. _this = _Camera.call(this) || this;
  23763. _this.type = 'OrthographicCamera';
  23764. _this.zoom = 1;
  23765. _this.view = null;
  23766. _this.left = left;
  23767. _this.right = right;
  23768. _this.top = top;
  23769. _this.bottom = bottom;
  23770. _this.near = near;
  23771. _this.far = far;
  23772. _this.updateProjectionMatrix();
  23773. return _this;
  23774. }
  23775. var _proto = OrthographicCamera.prototype;
  23776. _proto.copy = function copy(source, recursive) {
  23777. _Camera.prototype.copy.call(this, source, recursive);
  23778. this.left = source.left;
  23779. this.right = source.right;
  23780. this.top = source.top;
  23781. this.bottom = source.bottom;
  23782. this.near = source.near;
  23783. this.far = source.far;
  23784. this.zoom = source.zoom;
  23785. this.view = source.view === null ? null : Object.assign({}, source.view);
  23786. return this;
  23787. };
  23788. _proto.setViewOffset = function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  23789. if (this.view === null) {
  23790. this.view = {
  23791. enabled: true,
  23792. fullWidth: 1,
  23793. fullHeight: 1,
  23794. offsetX: 0,
  23795. offsetY: 0,
  23796. width: 1,
  23797. height: 1
  23798. };
  23799. }
  23800. this.view.enabled = true;
  23801. this.view.fullWidth = fullWidth;
  23802. this.view.fullHeight = fullHeight;
  23803. this.view.offsetX = x;
  23804. this.view.offsetY = y;
  23805. this.view.width = width;
  23806. this.view.height = height;
  23807. this.updateProjectionMatrix();
  23808. };
  23809. _proto.clearViewOffset = function clearViewOffset() {
  23810. if (this.view !== null) {
  23811. this.view.enabled = false;
  23812. }
  23813. this.updateProjectionMatrix();
  23814. };
  23815. _proto.updateProjectionMatrix = function updateProjectionMatrix() {
  23816. var dx = (this.right - this.left) / (2 * this.zoom);
  23817. var dy = (this.top - this.bottom) / (2 * this.zoom);
  23818. var cx = (this.right + this.left) / 2;
  23819. var cy = (this.top + this.bottom) / 2;
  23820. var left = cx - dx;
  23821. var right = cx + dx;
  23822. var top = cy + dy;
  23823. var bottom = cy - dy;
  23824. if (this.view !== null && this.view.enabled) {
  23825. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  23826. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  23827. left += scaleW * this.view.offsetX;
  23828. right = left + scaleW * this.view.width;
  23829. top -= scaleH * this.view.offsetY;
  23830. bottom = top - scaleH * this.view.height;
  23831. }
  23832. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  23833. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  23834. };
  23835. _proto.toJSON = function toJSON(meta) {
  23836. var data = Object3D.prototype.toJSON.call(this, meta);
  23837. data.object.zoom = this.zoom;
  23838. data.object.left = this.left;
  23839. data.object.right = this.right;
  23840. data.object.top = this.top;
  23841. data.object.bottom = this.bottom;
  23842. data.object.near = this.near;
  23843. data.object.far = this.far;
  23844. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  23845. return data;
  23846. };
  23847. return OrthographicCamera;
  23848. }(Camera);
  23849. OrthographicCamera.prototype.isOrthographicCamera = true;
  23850. var DirectionalLightShadow = /*#__PURE__*/function (_LightShadow) {
  23851. _inheritsLoose(DirectionalLightShadow, _LightShadow);
  23852. function DirectionalLightShadow() {
  23853. return _LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500)) || this;
  23854. }
  23855. return DirectionalLightShadow;
  23856. }(LightShadow);
  23857. DirectionalLightShadow.prototype.isDirectionalLightShadow = true;
  23858. var DirectionalLight = /*#__PURE__*/function (_Light) {
  23859. _inheritsLoose(DirectionalLight, _Light);
  23860. function DirectionalLight(color, intensity) {
  23861. var _this;
  23862. _this = _Light.call(this, color, intensity) || this;
  23863. _this.type = 'DirectionalLight';
  23864. _this.position.copy(Object3D.DefaultUp);
  23865. _this.updateMatrix();
  23866. _this.target = new Object3D();
  23867. _this.shadow = new DirectionalLightShadow();
  23868. return _this;
  23869. }
  23870. var _proto = DirectionalLight.prototype;
  23871. _proto.copy = function copy(source) {
  23872. _Light.prototype.copy.call(this, source);
  23873. this.target = source.target.clone();
  23874. this.shadow = source.shadow.clone();
  23875. return this;
  23876. };
  23877. return DirectionalLight;
  23878. }(Light);
  23879. DirectionalLight.prototype.isDirectionalLight = true;
  23880. var AmbientLight = /*#__PURE__*/function (_Light) {
  23881. _inheritsLoose(AmbientLight, _Light);
  23882. function AmbientLight(color, intensity) {
  23883. var _this;
  23884. _this = _Light.call(this, color, intensity) || this;
  23885. _this.type = 'AmbientLight';
  23886. return _this;
  23887. }
  23888. return AmbientLight;
  23889. }(Light);
  23890. AmbientLight.prototype.isAmbientLight = true;
  23891. var RectAreaLight = /*#__PURE__*/function (_Light) {
  23892. _inheritsLoose(RectAreaLight, _Light);
  23893. function RectAreaLight(color, intensity, width, height) {
  23894. var _this;
  23895. if (width === void 0) {
  23896. width = 10;
  23897. }
  23898. if (height === void 0) {
  23899. height = 10;
  23900. }
  23901. _this = _Light.call(this, color, intensity) || this;
  23902. _this.type = 'RectAreaLight';
  23903. _this.width = width;
  23904. _this.height = height;
  23905. return _this;
  23906. }
  23907. var _proto = RectAreaLight.prototype;
  23908. _proto.copy = function copy(source) {
  23909. _Light.prototype.copy.call(this, source);
  23910. this.width = source.width;
  23911. this.height = source.height;
  23912. return this;
  23913. };
  23914. _proto.toJSON = function toJSON(meta) {
  23915. var data = _Light.prototype.toJSON.call(this, meta);
  23916. data.object.width = this.width;
  23917. data.object.height = this.height;
  23918. return data;
  23919. };
  23920. return RectAreaLight;
  23921. }(Light);
  23922. RectAreaLight.prototype.isRectAreaLight = true;
  23923. /**
  23924. * Primary reference:
  23925. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23926. *
  23927. * Secondary reference:
  23928. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23929. */
  23930. // 3-band SH defined by 9 coefficients
  23931. var SphericalHarmonics3 = /*#__PURE__*/function () {
  23932. function SphericalHarmonics3() {
  23933. this.coefficients = [];
  23934. for (var i = 0; i < 9; i++) {
  23935. this.coefficients.push(new Vector3());
  23936. }
  23937. }
  23938. var _proto = SphericalHarmonics3.prototype;
  23939. _proto.set = function set(coefficients) {
  23940. for (var i = 0; i < 9; i++) {
  23941. this.coefficients[i].copy(coefficients[i]);
  23942. }
  23943. return this;
  23944. };
  23945. _proto.zero = function zero() {
  23946. for (var i = 0; i < 9; i++) {
  23947. this.coefficients[i].set(0, 0, 0);
  23948. }
  23949. return this;
  23950. } // get the radiance in the direction of the normal
  23951. // target is a Vector3
  23952. ;
  23953. _proto.getAt = function getAt(normal, target) {
  23954. // normal is assumed to be unit length
  23955. var x = normal.x,
  23956. y = normal.y,
  23957. z = normal.z;
  23958. var coeff = this.coefficients; // band 0
  23959. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  23960. target.addScaledVector(coeff[1], 0.488603 * y);
  23961. target.addScaledVector(coeff[2], 0.488603 * z);
  23962. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  23963. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  23964. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  23965. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  23966. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  23967. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  23968. return target;
  23969. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23970. // target is a Vector3
  23971. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23972. ;
  23973. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  23974. // normal is assumed to be unit length
  23975. var x = normal.x,
  23976. y = normal.y,
  23977. z = normal.z;
  23978. var coeff = this.coefficients; // band 0
  23979. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  23980. // band 1
  23981. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  23982. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  23983. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  23984. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  23985. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  23986. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  23987. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  23988. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  23989. return target;
  23990. };
  23991. _proto.add = function add(sh) {
  23992. for (var i = 0; i < 9; i++) {
  23993. this.coefficients[i].add(sh.coefficients[i]);
  23994. }
  23995. return this;
  23996. };
  23997. _proto.addScaledSH = function addScaledSH(sh, s) {
  23998. for (var i = 0; i < 9; i++) {
  23999. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  24000. }
  24001. return this;
  24002. };
  24003. _proto.scale = function scale(s) {
  24004. for (var i = 0; i < 9; i++) {
  24005. this.coefficients[i].multiplyScalar(s);
  24006. }
  24007. return this;
  24008. };
  24009. _proto.lerp = function lerp(sh, alpha) {
  24010. for (var i = 0; i < 9; i++) {
  24011. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  24012. }
  24013. return this;
  24014. };
  24015. _proto.equals = function equals(sh) {
  24016. for (var i = 0; i < 9; i++) {
  24017. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  24018. return false;
  24019. }
  24020. }
  24021. return true;
  24022. };
  24023. _proto.copy = function copy(sh) {
  24024. return this.set(sh.coefficients);
  24025. };
  24026. _proto.clone = function clone() {
  24027. return new this.constructor().copy(this);
  24028. };
  24029. _proto.fromArray = function fromArray(array, offset) {
  24030. if (offset === void 0) {
  24031. offset = 0;
  24032. }
  24033. var coefficients = this.coefficients;
  24034. for (var i = 0; i < 9; i++) {
  24035. coefficients[i].fromArray(array, offset + i * 3);
  24036. }
  24037. return this;
  24038. };
  24039. _proto.toArray = function toArray(array, offset) {
  24040. if (array === void 0) {
  24041. array = [];
  24042. }
  24043. if (offset === void 0) {
  24044. offset = 0;
  24045. }
  24046. var coefficients = this.coefficients;
  24047. for (var i = 0; i < 9; i++) {
  24048. coefficients[i].toArray(array, offset + i * 3);
  24049. }
  24050. return array;
  24051. } // evaluate the basis functions
  24052. // shBasis is an Array[ 9 ]
  24053. ;
  24054. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  24055. // normal is assumed to be unit length
  24056. var x = normal.x,
  24057. y = normal.y,
  24058. z = normal.z; // band 0
  24059. shBasis[0] = 0.282095; // band 1
  24060. shBasis[1] = 0.488603 * y;
  24061. shBasis[2] = 0.488603 * z;
  24062. shBasis[3] = 0.488603 * x; // band 2
  24063. shBasis[4] = 1.092548 * x * y;
  24064. shBasis[5] = 1.092548 * y * z;
  24065. shBasis[6] = 0.315392 * (3 * z * z - 1);
  24066. shBasis[7] = 1.092548 * x * z;
  24067. shBasis[8] = 0.546274 * (x * x - y * y);
  24068. };
  24069. return SphericalHarmonics3;
  24070. }();
  24071. SphericalHarmonics3.prototype.isSphericalHarmonics3 = true;
  24072. var LightProbe = /*#__PURE__*/function (_Light) {
  24073. _inheritsLoose(LightProbe, _Light);
  24074. function LightProbe(sh, intensity) {
  24075. var _this;
  24076. if (sh === void 0) {
  24077. sh = new SphericalHarmonics3();
  24078. }
  24079. if (intensity === void 0) {
  24080. intensity = 1;
  24081. }
  24082. _this = _Light.call(this, undefined, intensity) || this;
  24083. _this.sh = sh;
  24084. return _this;
  24085. }
  24086. var _proto = LightProbe.prototype;
  24087. _proto.copy = function copy(source) {
  24088. _Light.prototype.copy.call(this, source);
  24089. this.sh.copy(source.sh);
  24090. return this;
  24091. };
  24092. _proto.fromJSON = function fromJSON(json) {
  24093. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  24094. this.sh.fromArray(json.sh);
  24095. return this;
  24096. };
  24097. _proto.toJSON = function toJSON(meta) {
  24098. var data = _Light.prototype.toJSON.call(this, meta);
  24099. data.object.sh = this.sh.toArray();
  24100. return data;
  24101. };
  24102. return LightProbe;
  24103. }(Light);
  24104. LightProbe.prototype.isLightProbe = true;
  24105. var MaterialLoader = /*#__PURE__*/function (_Loader) {
  24106. _inheritsLoose(MaterialLoader, _Loader);
  24107. function MaterialLoader(manager) {
  24108. var _this;
  24109. _this = _Loader.call(this, manager) || this;
  24110. _this.textures = {};
  24111. return _this;
  24112. }
  24113. var _proto = MaterialLoader.prototype;
  24114. _proto.load = function load(url, onLoad, onProgress, onError) {
  24115. var scope = this;
  24116. var loader = new FileLoader(scope.manager);
  24117. loader.setPath(scope.path);
  24118. loader.setRequestHeader(scope.requestHeader);
  24119. loader.setWithCredentials(scope.withCredentials);
  24120. loader.load(url, function (text) {
  24121. try {
  24122. onLoad(scope.parse(JSON.parse(text)));
  24123. } catch (e) {
  24124. if (onError) {
  24125. onError(e);
  24126. } else {
  24127. console.error(e);
  24128. }
  24129. scope.manager.itemError(url);
  24130. }
  24131. }, onProgress, onError);
  24132. };
  24133. _proto.parse = function parse(json) {
  24134. var textures = this.textures;
  24135. function getTexture(name) {
  24136. if (textures[name] === undefined) {
  24137. console.warn('THREE.MaterialLoader: Undefined texture', name);
  24138. }
  24139. return textures[name];
  24140. }
  24141. var material = new Materials[json.type]();
  24142. if (json.uuid !== undefined) material.uuid = json.uuid;
  24143. if (json.name !== undefined) material.name = json.name;
  24144. if (json.color !== undefined && material.color !== undefined) material.color.setHex(json.color);
  24145. if (json.roughness !== undefined) material.roughness = json.roughness;
  24146. if (json.metalness !== undefined) material.metalness = json.metalness;
  24147. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  24148. if (json.emissive !== undefined && material.emissive !== undefined) material.emissive.setHex(json.emissive);
  24149. if (json.specular !== undefined && material.specular !== undefined) material.specular.setHex(json.specular);
  24150. if (json.shininess !== undefined) material.shininess = json.shininess;
  24151. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  24152. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  24153. if (json.fog !== undefined) material.fog = json.fog;
  24154. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  24155. if (json.blending !== undefined) material.blending = json.blending;
  24156. if (json.combine !== undefined) material.combine = json.combine;
  24157. if (json.side !== undefined) material.side = json.side;
  24158. if (json.opacity !== undefined) material.opacity = json.opacity;
  24159. if (json.transparent !== undefined) material.transparent = json.transparent;
  24160. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  24161. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  24162. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  24163. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  24164. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  24165. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  24166. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  24167. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  24168. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  24169. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  24170. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  24171. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  24172. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  24173. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  24174. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  24175. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  24176. if (json.rotation !== undefined) material.rotation = json.rotation;
  24177. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  24178. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  24179. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  24180. if (json.scale !== undefined) material.scale = json.scale;
  24181. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  24182. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  24183. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  24184. if (json.skinning !== undefined) material.skinning = json.skinning;
  24185. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  24186. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  24187. if (json.dithering !== undefined) material.dithering = json.dithering;
  24188. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  24189. if (json.visible !== undefined) material.visible = json.visible;
  24190. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  24191. if (json.userData !== undefined) material.userData = json.userData;
  24192. if (json.vertexColors !== undefined) {
  24193. if (typeof json.vertexColors === 'number') {
  24194. material.vertexColors = json.vertexColors > 0 ? true : false;
  24195. } else {
  24196. material.vertexColors = json.vertexColors;
  24197. }
  24198. } // Shader Material
  24199. if (json.uniforms !== undefined) {
  24200. for (var name in json.uniforms) {
  24201. var uniform = json.uniforms[name];
  24202. material.uniforms[name] = {};
  24203. switch (uniform.type) {
  24204. case 't':
  24205. material.uniforms[name].value = getTexture(uniform.value);
  24206. break;
  24207. case 'c':
  24208. material.uniforms[name].value = new Color().setHex(uniform.value);
  24209. break;
  24210. case 'v2':
  24211. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  24212. break;
  24213. case 'v3':
  24214. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  24215. break;
  24216. case 'v4':
  24217. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  24218. break;
  24219. case 'm3':
  24220. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  24221. break;
  24222. case 'm4':
  24223. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  24224. break;
  24225. default:
  24226. material.uniforms[name].value = uniform.value;
  24227. }
  24228. }
  24229. }
  24230. if (json.defines !== undefined) material.defines = json.defines;
  24231. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  24232. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  24233. if (json.extensions !== undefined) {
  24234. for (var key in json.extensions) {
  24235. material.extensions[key] = json.extensions[key];
  24236. }
  24237. } // Deprecated
  24238. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  24239. // for PointsMaterial
  24240. if (json.size !== undefined) material.size = json.size;
  24241. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  24242. if (json.map !== undefined) material.map = getTexture(json.map);
  24243. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  24244. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  24245. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  24246. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  24247. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  24248. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  24249. if (json.normalScale !== undefined) {
  24250. var normalScale = json.normalScale;
  24251. if (Array.isArray(normalScale) === false) {
  24252. // Blender exporter used to export a scalar. See #7459
  24253. normalScale = [normalScale, normalScale];
  24254. }
  24255. material.normalScale = new Vector2().fromArray(normalScale);
  24256. }
  24257. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  24258. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  24259. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  24260. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  24261. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  24262. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  24263. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  24264. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  24265. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  24266. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  24267. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  24268. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  24269. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  24270. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  24271. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  24272. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  24273. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  24274. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  24275. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  24276. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  24277. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  24278. if (json.transmission !== undefined) material.transmission = json.transmission;
  24279. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  24280. return material;
  24281. };
  24282. _proto.setTextures = function setTextures(value) {
  24283. this.textures = value;
  24284. return this;
  24285. };
  24286. return MaterialLoader;
  24287. }(Loader);
  24288. var LoaderUtils = {
  24289. decodeText: function decodeText(array) {
  24290. if (typeof TextDecoder !== 'undefined') {
  24291. return new TextDecoder().decode(array);
  24292. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  24293. // throws a "maximum call stack size exceeded" error for large arrays.
  24294. var s = '';
  24295. for (var i = 0, il = array.length; i < il; i++) {
  24296. // Implicitly assumes little-endian.
  24297. s += String.fromCharCode(array[i]);
  24298. }
  24299. try {
  24300. // merges multi-byte utf-8 characters.
  24301. return decodeURIComponent(escape(s));
  24302. } catch (e) {
  24303. // see #16358
  24304. return s;
  24305. }
  24306. },
  24307. extractUrlBase: function extractUrlBase(url) {
  24308. var index = url.lastIndexOf('/');
  24309. if (index === -1) return './';
  24310. return url.substr(0, index + 1);
  24311. }
  24312. };
  24313. function InstancedBufferGeometry() {
  24314. BufferGeometry.call(this);
  24315. this.type = 'InstancedBufferGeometry';
  24316. this.instanceCount = Infinity;
  24317. }
  24318. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  24319. constructor: InstancedBufferGeometry,
  24320. isInstancedBufferGeometry: true,
  24321. copy: function copy(source) {
  24322. BufferGeometry.prototype.copy.call(this, source);
  24323. this.instanceCount = source.instanceCount;
  24324. return this;
  24325. },
  24326. clone: function clone() {
  24327. return new this.constructor().copy(this);
  24328. },
  24329. toJSON: function toJSON() {
  24330. var data = BufferGeometry.prototype.toJSON.call(this);
  24331. data.instanceCount = this.instanceCount;
  24332. data.isInstancedBufferGeometry = true;
  24333. return data;
  24334. }
  24335. });
  24336. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  24337. if (typeof normalized === 'number') {
  24338. meshPerAttribute = normalized;
  24339. normalized = false;
  24340. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  24341. }
  24342. BufferAttribute.call(this, array, itemSize, normalized);
  24343. this.meshPerAttribute = meshPerAttribute || 1;
  24344. }
  24345. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  24346. constructor: InstancedBufferAttribute,
  24347. isInstancedBufferAttribute: true,
  24348. copy: function copy(source) {
  24349. BufferAttribute.prototype.copy.call(this, source);
  24350. this.meshPerAttribute = source.meshPerAttribute;
  24351. return this;
  24352. },
  24353. toJSON: function toJSON() {
  24354. var data = BufferAttribute.prototype.toJSON.call(this);
  24355. data.meshPerAttribute = this.meshPerAttribute;
  24356. data.isInstancedBufferAttribute = true;
  24357. return data;
  24358. }
  24359. });
  24360. var BufferGeometryLoader = /*#__PURE__*/function (_Loader) {
  24361. _inheritsLoose(BufferGeometryLoader, _Loader);
  24362. function BufferGeometryLoader(manager) {
  24363. return _Loader.call(this, manager) || this;
  24364. }
  24365. var _proto = BufferGeometryLoader.prototype;
  24366. _proto.load = function load(url, onLoad, onProgress, onError) {
  24367. var scope = this;
  24368. var loader = new FileLoader(scope.manager);
  24369. loader.setPath(scope.path);
  24370. loader.setRequestHeader(scope.requestHeader);
  24371. loader.setWithCredentials(scope.withCredentials);
  24372. loader.load(url, function (text) {
  24373. try {
  24374. onLoad(scope.parse(JSON.parse(text)));
  24375. } catch (e) {
  24376. if (onError) {
  24377. onError(e);
  24378. } else {
  24379. console.error(e);
  24380. }
  24381. scope.manager.itemError(url);
  24382. }
  24383. }, onProgress, onError);
  24384. };
  24385. _proto.parse = function parse(json) {
  24386. var interleavedBufferMap = {};
  24387. var arrayBufferMap = {};
  24388. function getInterleavedBuffer(json, uuid) {
  24389. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  24390. var interleavedBuffers = json.interleavedBuffers;
  24391. var interleavedBuffer = interleavedBuffers[uuid];
  24392. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  24393. var array = getTypedArray(interleavedBuffer.type, buffer);
  24394. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  24395. ib.uuid = interleavedBuffer.uuid;
  24396. interleavedBufferMap[uuid] = ib;
  24397. return ib;
  24398. }
  24399. function getArrayBuffer(json, uuid) {
  24400. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  24401. var arrayBuffers = json.arrayBuffers;
  24402. var arrayBuffer = arrayBuffers[uuid];
  24403. var ab = new Uint32Array(arrayBuffer).buffer;
  24404. arrayBufferMap[uuid] = ab;
  24405. return ab;
  24406. }
  24407. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24408. var index = json.data.index;
  24409. if (index !== undefined) {
  24410. var typedArray = getTypedArray(index.type, index.array);
  24411. geometry.setIndex(new BufferAttribute(typedArray, 1));
  24412. }
  24413. var attributes = json.data.attributes;
  24414. for (var key in attributes) {
  24415. var attribute = attributes[key];
  24416. var bufferAttribute = void 0;
  24417. if (attribute.isInterleavedBufferAttribute) {
  24418. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  24419. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  24420. } else {
  24421. var _typedArray = getTypedArray(attribute.type, attribute.array);
  24422. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24423. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  24424. }
  24425. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  24426. geometry.setAttribute(key, bufferAttribute);
  24427. }
  24428. var morphAttributes = json.data.morphAttributes;
  24429. if (morphAttributes) {
  24430. for (var _key in morphAttributes) {
  24431. var attributeArray = morphAttributes[_key];
  24432. var array = [];
  24433. for (var i = 0, il = attributeArray.length; i < il; i++) {
  24434. var _attribute = attributeArray[i];
  24435. var _bufferAttribute = void 0;
  24436. if (_attribute.isInterleavedBufferAttribute) {
  24437. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  24438. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  24439. } else {
  24440. var _typedArray2 = getTypedArray(_attribute.type, _attribute.array);
  24441. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  24442. }
  24443. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  24444. array.push(_bufferAttribute);
  24445. }
  24446. geometry.morphAttributes[_key] = array;
  24447. }
  24448. }
  24449. var morphTargetsRelative = json.data.morphTargetsRelative;
  24450. if (morphTargetsRelative) {
  24451. geometry.morphTargetsRelative = true;
  24452. }
  24453. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24454. if (groups !== undefined) {
  24455. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  24456. var group = groups[_i];
  24457. geometry.addGroup(group.start, group.count, group.materialIndex);
  24458. }
  24459. }
  24460. var boundingSphere = json.data.boundingSphere;
  24461. if (boundingSphere !== undefined) {
  24462. var center = new Vector3();
  24463. if (boundingSphere.center !== undefined) {
  24464. center.fromArray(boundingSphere.center);
  24465. }
  24466. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  24467. }
  24468. if (json.name) geometry.name = json.name;
  24469. if (json.userData) geometry.userData = json.userData;
  24470. return geometry;
  24471. };
  24472. return BufferGeometryLoader;
  24473. }(Loader);
  24474. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  24475. _inheritsLoose(ObjectLoader, _Loader);
  24476. function ObjectLoader(manager) {
  24477. return _Loader.call(this, manager) || this;
  24478. }
  24479. var _proto = ObjectLoader.prototype;
  24480. _proto.load = function load(url, onLoad, onProgress, onError) {
  24481. var scope = this;
  24482. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  24483. this.resourcePath = this.resourcePath || path;
  24484. var loader = new FileLoader(this.manager);
  24485. loader.setPath(this.path);
  24486. loader.setRequestHeader(this.requestHeader);
  24487. loader.setWithCredentials(this.withCredentials);
  24488. loader.load(url, function (text) {
  24489. var json = null;
  24490. try {
  24491. json = JSON.parse(text);
  24492. } catch (error) {
  24493. if (onError !== undefined) onError(error);
  24494. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  24495. return;
  24496. }
  24497. var metadata = json.metadata;
  24498. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  24499. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  24500. return;
  24501. }
  24502. scope.parse(json, onLoad);
  24503. }, onProgress, onError);
  24504. };
  24505. _proto.parse = function parse(json, onLoad) {
  24506. var animations = this.parseAnimations(json.animations);
  24507. var shapes = this.parseShapes(json.shapes);
  24508. var geometries = this.parseGeometries(json.geometries, shapes);
  24509. var images = this.parseImages(json.images, function () {
  24510. if (onLoad !== undefined) onLoad(object);
  24511. });
  24512. var textures = this.parseTextures(json.textures, images);
  24513. var materials = this.parseMaterials(json.materials, textures);
  24514. var object = this.parseObject(json.object, geometries, materials, animations);
  24515. var skeletons = this.parseSkeletons(json.skeletons, object);
  24516. this.bindSkeletons(object, skeletons); //
  24517. if (onLoad !== undefined) {
  24518. var hasImages = false;
  24519. for (var uuid in images) {
  24520. if (images[uuid] instanceof HTMLImageElement) {
  24521. hasImages = true;
  24522. break;
  24523. }
  24524. }
  24525. if (hasImages === false) onLoad(object);
  24526. }
  24527. return object;
  24528. };
  24529. _proto.parseShapes = function parseShapes(json) {
  24530. var shapes = {};
  24531. if (json !== undefined) {
  24532. for (var i = 0, l = json.length; i < l; i++) {
  24533. var shape = new Shape().fromJSON(json[i]);
  24534. shapes[shape.uuid] = shape;
  24535. }
  24536. }
  24537. return shapes;
  24538. };
  24539. _proto.parseSkeletons = function parseSkeletons(json, object) {
  24540. var skeletons = {};
  24541. var bones = {}; // generate bone lookup table
  24542. object.traverse(function (child) {
  24543. if (child.isBone) bones[child.uuid] = child;
  24544. }); // create skeletons
  24545. if (json !== undefined) {
  24546. for (var i = 0, l = json.length; i < l; i++) {
  24547. var skeleton = new Skeleton().fromJSON(json[i], bones);
  24548. skeletons[skeleton.uuid] = skeleton;
  24549. }
  24550. }
  24551. return skeletons;
  24552. };
  24553. _proto.parseGeometries = function parseGeometries(json, shapes) {
  24554. var geometries = {};
  24555. var geometryShapes;
  24556. if (json !== undefined) {
  24557. var bufferGeometryLoader = new BufferGeometryLoader();
  24558. for (var i = 0, l = json.length; i < l; i++) {
  24559. var geometry = void 0;
  24560. var data = json[i];
  24561. switch (data.type) {
  24562. case 'PlaneGeometry':
  24563. case 'PlaneBufferGeometry':
  24564. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  24565. break;
  24566. case 'BoxGeometry':
  24567. case 'BoxBufferGeometry':
  24568. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  24569. break;
  24570. case 'CircleGeometry':
  24571. case 'CircleBufferGeometry':
  24572. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  24573. break;
  24574. case 'CylinderGeometry':
  24575. case 'CylinderBufferGeometry':
  24576. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24577. break;
  24578. case 'ConeGeometry':
  24579. case 'ConeBufferGeometry':
  24580. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24581. break;
  24582. case 'SphereGeometry':
  24583. case 'SphereBufferGeometry':
  24584. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  24585. break;
  24586. case 'DodecahedronGeometry':
  24587. case 'DodecahedronBufferGeometry':
  24588. case 'IcosahedronGeometry':
  24589. case 'IcosahedronBufferGeometry':
  24590. case 'OctahedronGeometry':
  24591. case 'OctahedronBufferGeometry':
  24592. case 'TetrahedronGeometry':
  24593. case 'TetrahedronBufferGeometry':
  24594. geometry = new Geometries[data.type](data.radius, data.detail);
  24595. break;
  24596. case 'RingGeometry':
  24597. case 'RingBufferGeometry':
  24598. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  24599. break;
  24600. case 'TorusGeometry':
  24601. case 'TorusBufferGeometry':
  24602. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  24603. break;
  24604. case 'TorusKnotGeometry':
  24605. case 'TorusKnotBufferGeometry':
  24606. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  24607. break;
  24608. case 'TubeGeometry':
  24609. case 'TubeBufferGeometry':
  24610. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24611. // User defined curves or instances of CurvePath will not be deserialized.
  24612. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  24613. break;
  24614. case 'LatheGeometry':
  24615. case 'LatheBufferGeometry':
  24616. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  24617. break;
  24618. case 'PolyhedronGeometry':
  24619. case 'PolyhedronBufferGeometry':
  24620. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  24621. break;
  24622. case 'ShapeGeometry':
  24623. case 'ShapeBufferGeometry':
  24624. geometryShapes = [];
  24625. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  24626. var shape = shapes[data.shapes[j]];
  24627. geometryShapes.push(shape);
  24628. }
  24629. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  24630. break;
  24631. case 'ExtrudeGeometry':
  24632. case 'ExtrudeBufferGeometry':
  24633. geometryShapes = [];
  24634. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  24635. var _shape = shapes[data.shapes[_j]];
  24636. geometryShapes.push(_shape);
  24637. }
  24638. var extrudePath = data.options.extrudePath;
  24639. if (extrudePath !== undefined) {
  24640. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  24641. }
  24642. geometry = new Geometries[data.type](geometryShapes, data.options);
  24643. break;
  24644. case 'BufferGeometry':
  24645. case 'InstancedBufferGeometry':
  24646. geometry = bufferGeometryLoader.parse(data);
  24647. break;
  24648. case 'Geometry':
  24649. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  24650. break;
  24651. default:
  24652. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  24653. continue;
  24654. }
  24655. geometry.uuid = data.uuid;
  24656. if (data.name !== undefined) geometry.name = data.name;
  24657. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  24658. geometries[data.uuid] = geometry;
  24659. }
  24660. }
  24661. return geometries;
  24662. };
  24663. _proto.parseMaterials = function parseMaterials(json, textures) {
  24664. var cache = {}; // MultiMaterial
  24665. var materials = {};
  24666. if (json !== undefined) {
  24667. var loader = new MaterialLoader();
  24668. loader.setTextures(textures);
  24669. for (var i = 0, l = json.length; i < l; i++) {
  24670. var data = json[i];
  24671. if (data.type === 'MultiMaterial') {
  24672. // Deprecated
  24673. var array = [];
  24674. for (var j = 0; j < data.materials.length; j++) {
  24675. var material = data.materials[j];
  24676. if (cache[material.uuid] === undefined) {
  24677. cache[material.uuid] = loader.parse(material);
  24678. }
  24679. array.push(cache[material.uuid]);
  24680. }
  24681. materials[data.uuid] = array;
  24682. } else {
  24683. if (cache[data.uuid] === undefined) {
  24684. cache[data.uuid] = loader.parse(data);
  24685. }
  24686. materials[data.uuid] = cache[data.uuid];
  24687. }
  24688. }
  24689. }
  24690. return materials;
  24691. };
  24692. _proto.parseAnimations = function parseAnimations(json) {
  24693. var animations = {};
  24694. if (json !== undefined) {
  24695. for (var i = 0; i < json.length; i++) {
  24696. var data = json[i];
  24697. var clip = AnimationClip.parse(data);
  24698. animations[clip.uuid] = clip;
  24699. }
  24700. }
  24701. return animations;
  24702. };
  24703. _proto.parseImages = function parseImages(json, onLoad) {
  24704. var scope = this;
  24705. var images = {};
  24706. var loader;
  24707. function loadImage(url) {
  24708. scope.manager.itemStart(url);
  24709. return loader.load(url, function () {
  24710. scope.manager.itemEnd(url);
  24711. }, undefined, function () {
  24712. scope.manager.itemError(url);
  24713. scope.manager.itemEnd(url);
  24714. });
  24715. }
  24716. function deserializeImage(image) {
  24717. if (typeof image === 'string') {
  24718. var url = image;
  24719. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(url) ? url : scope.resourcePath + url;
  24720. return loadImage(path);
  24721. } else {
  24722. if (image.data) {
  24723. return {
  24724. data: getTypedArray(image.type, image.data),
  24725. width: image.width,
  24726. height: image.height
  24727. };
  24728. } else {
  24729. return null;
  24730. }
  24731. }
  24732. }
  24733. if (json !== undefined && json.length > 0) {
  24734. var manager = new LoadingManager(onLoad);
  24735. loader = new ImageLoader(manager);
  24736. loader.setCrossOrigin(this.crossOrigin);
  24737. for (var i = 0, il = json.length; i < il; i++) {
  24738. var image = json[i];
  24739. var url = image.url;
  24740. if (Array.isArray(url)) {
  24741. // load array of images e.g CubeTexture
  24742. images[image.uuid] = [];
  24743. for (var j = 0, jl = url.length; j < jl; j++) {
  24744. var currentUrl = url[j];
  24745. var deserializedImage = deserializeImage(currentUrl);
  24746. if (deserializedImage !== null) {
  24747. if (deserializedImage instanceof HTMLImageElement) {
  24748. images[image.uuid].push(deserializedImage);
  24749. } else {
  24750. // special case: handle array of data textures for cube textures
  24751. images[image.uuid].push(new DataTexture(deserializedImage.data, deserializedImage.width, deserializedImage.height));
  24752. }
  24753. }
  24754. }
  24755. } else {
  24756. // load single image
  24757. var _deserializedImage = deserializeImage(image.url);
  24758. if (_deserializedImage !== null) {
  24759. images[image.uuid] = _deserializedImage;
  24760. }
  24761. }
  24762. }
  24763. }
  24764. return images;
  24765. };
  24766. _proto.parseTextures = function parseTextures(json, images) {
  24767. function parseConstant(value, type) {
  24768. if (typeof value === 'number') return value;
  24769. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  24770. return type[value];
  24771. }
  24772. var textures = {};
  24773. if (json !== undefined) {
  24774. for (var i = 0, l = json.length; i < l; i++) {
  24775. var data = json[i];
  24776. if (data.image === undefined) {
  24777. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  24778. }
  24779. if (images[data.image] === undefined) {
  24780. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  24781. }
  24782. var texture = void 0;
  24783. var image = images[data.image];
  24784. if (Array.isArray(image)) {
  24785. texture = new CubeTexture(image);
  24786. if (image.length === 6) texture.needsUpdate = true;
  24787. } else {
  24788. if (image && image.data) {
  24789. texture = new DataTexture(image.data, image.width, image.height);
  24790. } else {
  24791. texture = new Texture(image);
  24792. }
  24793. if (image) texture.needsUpdate = true; // textures can have undefined image data
  24794. }
  24795. texture.uuid = data.uuid;
  24796. if (data.name !== undefined) texture.name = data.name;
  24797. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  24798. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  24799. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  24800. if (data.center !== undefined) texture.center.fromArray(data.center);
  24801. if (data.rotation !== undefined) texture.rotation = data.rotation;
  24802. if (data.wrap !== undefined) {
  24803. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  24804. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  24805. }
  24806. if (data.format !== undefined) texture.format = data.format;
  24807. if (data.type !== undefined) texture.type = data.type;
  24808. if (data.encoding !== undefined) texture.encoding = data.encoding;
  24809. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  24810. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  24811. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  24812. if (data.flipY !== undefined) texture.flipY = data.flipY;
  24813. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  24814. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  24815. textures[data.uuid] = texture;
  24816. }
  24817. }
  24818. return textures;
  24819. };
  24820. _proto.parseObject = function parseObject(data, geometries, materials, animations) {
  24821. var object;
  24822. function getGeometry(name) {
  24823. if (geometries[name] === undefined) {
  24824. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  24825. }
  24826. return geometries[name];
  24827. }
  24828. function getMaterial(name) {
  24829. if (name === undefined) return undefined;
  24830. if (Array.isArray(name)) {
  24831. var array = [];
  24832. for (var i = 0, l = name.length; i < l; i++) {
  24833. var uuid = name[i];
  24834. if (materials[uuid] === undefined) {
  24835. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  24836. }
  24837. array.push(materials[uuid]);
  24838. }
  24839. return array;
  24840. }
  24841. if (materials[name] === undefined) {
  24842. console.warn('THREE.ObjectLoader: Undefined material', name);
  24843. }
  24844. return materials[name];
  24845. }
  24846. var geometry, material;
  24847. switch (data.type) {
  24848. case 'Scene':
  24849. object = new Scene();
  24850. if (data.background !== undefined) {
  24851. if (Number.isInteger(data.background)) {
  24852. object.background = new Color(data.background);
  24853. }
  24854. }
  24855. if (data.fog !== undefined) {
  24856. if (data.fog.type === 'Fog') {
  24857. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  24858. } else if (data.fog.type === 'FogExp2') {
  24859. object.fog = new FogExp2(data.fog.color, data.fog.density);
  24860. }
  24861. }
  24862. break;
  24863. case 'PerspectiveCamera':
  24864. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  24865. if (data.focus !== undefined) object.focus = data.focus;
  24866. if (data.zoom !== undefined) object.zoom = data.zoom;
  24867. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  24868. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  24869. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24870. break;
  24871. case 'OrthographicCamera':
  24872. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  24873. if (data.zoom !== undefined) object.zoom = data.zoom;
  24874. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24875. break;
  24876. case 'AmbientLight':
  24877. object = new AmbientLight(data.color, data.intensity);
  24878. break;
  24879. case 'DirectionalLight':
  24880. object = new DirectionalLight(data.color, data.intensity);
  24881. break;
  24882. case 'PointLight':
  24883. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  24884. break;
  24885. case 'RectAreaLight':
  24886. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  24887. break;
  24888. case 'SpotLight':
  24889. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  24890. break;
  24891. case 'HemisphereLight':
  24892. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  24893. break;
  24894. case 'LightProbe':
  24895. object = new LightProbe().fromJSON(data);
  24896. break;
  24897. case 'SkinnedMesh':
  24898. geometry = getGeometry(data.geometry);
  24899. material = getMaterial(data.material);
  24900. object = new SkinnedMesh(geometry, material);
  24901. if (data.bindMode !== undefined) object.bindMode = data.bindMode;
  24902. if (data.bindMatrix !== undefined) object.bindMatrix.fromArray(data.bindMatrix);
  24903. if (data.skeleton !== undefined) object.skeleton = data.skeleton;
  24904. break;
  24905. case 'Mesh':
  24906. geometry = getGeometry(data.geometry);
  24907. material = getMaterial(data.material);
  24908. object = new Mesh(geometry, material);
  24909. break;
  24910. case 'InstancedMesh':
  24911. geometry = getGeometry(data.geometry);
  24912. material = getMaterial(data.material);
  24913. var count = data.count;
  24914. var instanceMatrix = data.instanceMatrix;
  24915. object = new InstancedMesh(geometry, material, count);
  24916. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  24917. break;
  24918. case 'LOD':
  24919. object = new LOD();
  24920. break;
  24921. case 'Line':
  24922. object = new Line(getGeometry(data.geometry), getMaterial(data.material));
  24923. break;
  24924. case 'LineLoop':
  24925. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  24926. break;
  24927. case 'LineSegments':
  24928. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  24929. break;
  24930. case 'PointCloud':
  24931. case 'Points':
  24932. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  24933. break;
  24934. case 'Sprite':
  24935. object = new Sprite(getMaterial(data.material));
  24936. break;
  24937. case 'Group':
  24938. object = new Group();
  24939. break;
  24940. case 'Bone':
  24941. object = new Bone();
  24942. break;
  24943. default:
  24944. object = new Object3D();
  24945. }
  24946. object.uuid = data.uuid;
  24947. if (data.name !== undefined) object.name = data.name;
  24948. if (data.matrix !== undefined) {
  24949. object.matrix.fromArray(data.matrix);
  24950. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24951. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  24952. } else {
  24953. if (data.position !== undefined) object.position.fromArray(data.position);
  24954. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  24955. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  24956. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  24957. }
  24958. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  24959. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  24960. if (data.shadow) {
  24961. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  24962. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  24963. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  24964. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  24965. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  24966. }
  24967. if (data.visible !== undefined) object.visible = data.visible;
  24968. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  24969. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  24970. if (data.userData !== undefined) object.userData = data.userData;
  24971. if (data.layers !== undefined) object.layers.mask = data.layers;
  24972. if (data.children !== undefined) {
  24973. var children = data.children;
  24974. for (var i = 0; i < children.length; i++) {
  24975. object.add(this.parseObject(children[i], geometries, materials, animations));
  24976. }
  24977. }
  24978. if (data.animations !== undefined) {
  24979. var objectAnimations = data.animations;
  24980. for (var _i = 0; _i < objectAnimations.length; _i++) {
  24981. var uuid = objectAnimations[_i];
  24982. object.animations.push(animations[uuid]);
  24983. }
  24984. }
  24985. if (data.type === 'LOD') {
  24986. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  24987. var levels = data.levels;
  24988. for (var l = 0; l < levels.length; l++) {
  24989. var level = levels[l];
  24990. var child = object.getObjectByProperty('uuid', level.object);
  24991. if (child !== undefined) {
  24992. object.addLevel(child, level.distance);
  24993. }
  24994. }
  24995. }
  24996. return object;
  24997. };
  24998. _proto.bindSkeletons = function bindSkeletons(object, skeletons) {
  24999. if (Object.keys(skeletons).length === 0) return;
  25000. object.traverse(function (child) {
  25001. if (child.isSkinnedMesh === true && child.skeleton !== undefined) {
  25002. var skeleton = skeletons[child.skeleton];
  25003. if (skeleton === undefined) {
  25004. console.warn('THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton);
  25005. } else {
  25006. child.bind(skeleton, child.bindMatrix);
  25007. }
  25008. }
  25009. });
  25010. }
  25011. /* DEPRECATED */
  25012. ;
  25013. _proto.setTexturePath = function setTexturePath(value) {
  25014. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  25015. return this.setResourcePath(value);
  25016. };
  25017. return ObjectLoader;
  25018. }(Loader);
  25019. var TEXTURE_MAPPING = {
  25020. UVMapping: UVMapping,
  25021. CubeReflectionMapping: CubeReflectionMapping,
  25022. CubeRefractionMapping: CubeRefractionMapping,
  25023. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  25024. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  25025. CubeUVReflectionMapping: CubeUVReflectionMapping,
  25026. CubeUVRefractionMapping: CubeUVRefractionMapping
  25027. };
  25028. var TEXTURE_WRAPPING = {
  25029. RepeatWrapping: RepeatWrapping,
  25030. ClampToEdgeWrapping: ClampToEdgeWrapping,
  25031. MirroredRepeatWrapping: MirroredRepeatWrapping
  25032. };
  25033. var TEXTURE_FILTER = {
  25034. NearestFilter: NearestFilter,
  25035. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  25036. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  25037. LinearFilter: LinearFilter,
  25038. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  25039. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  25040. };
  25041. function ImageBitmapLoader(manager) {
  25042. if (typeof createImageBitmap === 'undefined') {
  25043. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  25044. }
  25045. if (typeof fetch === 'undefined') {
  25046. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  25047. }
  25048. Loader.call(this, manager);
  25049. this.options = {
  25050. premultiplyAlpha: 'none'
  25051. };
  25052. }
  25053. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25054. constructor: ImageBitmapLoader,
  25055. isImageBitmapLoader: true,
  25056. setOptions: function setOptions(options) {
  25057. this.options = options;
  25058. return this;
  25059. },
  25060. load: function load(url, onLoad, onProgress, onError) {
  25061. if (url === undefined) url = '';
  25062. if (this.path !== undefined) url = this.path + url;
  25063. url = this.manager.resolveURL(url);
  25064. var scope = this;
  25065. var cached = Cache.get(url);
  25066. if (cached !== undefined) {
  25067. scope.manager.itemStart(url);
  25068. setTimeout(function () {
  25069. if (onLoad) onLoad(cached);
  25070. scope.manager.itemEnd(url);
  25071. }, 0);
  25072. return cached;
  25073. }
  25074. var fetchOptions = {};
  25075. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  25076. fetchOptions.headers = this.requestHeader;
  25077. fetch(url, fetchOptions).then(function (res) {
  25078. return res.blob();
  25079. }).then(function (blob) {
  25080. return createImageBitmap(blob, scope.options);
  25081. }).then(function (imageBitmap) {
  25082. Cache.add(url, imageBitmap);
  25083. if (onLoad) onLoad(imageBitmap);
  25084. scope.manager.itemEnd(url);
  25085. }).catch(function (e) {
  25086. if (onError) onError(e);
  25087. scope.manager.itemError(url);
  25088. scope.manager.itemEnd(url);
  25089. });
  25090. scope.manager.itemStart(url);
  25091. }
  25092. });
  25093. var ShapePath = /*#__PURE__*/function () {
  25094. function ShapePath() {
  25095. this.type = 'ShapePath';
  25096. this.color = new Color();
  25097. this.subPaths = [];
  25098. this.currentPath = null;
  25099. }
  25100. var _proto = ShapePath.prototype;
  25101. _proto.moveTo = function moveTo(x, y) {
  25102. this.currentPath = new Path();
  25103. this.subPaths.push(this.currentPath);
  25104. this.currentPath.moveTo(x, y);
  25105. return this;
  25106. };
  25107. _proto.lineTo = function lineTo(x, y) {
  25108. this.currentPath.lineTo(x, y);
  25109. return this;
  25110. };
  25111. _proto.quadraticCurveTo = function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  25112. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  25113. return this;
  25114. };
  25115. _proto.bezierCurveTo = function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  25116. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  25117. return this;
  25118. };
  25119. _proto.splineThru = function splineThru(pts) {
  25120. this.currentPath.splineThru(pts);
  25121. return this;
  25122. };
  25123. _proto.toShapes = function toShapes(isCCW, noHoles) {
  25124. function toShapesNoHoles(inSubpaths) {
  25125. var shapes = [];
  25126. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  25127. var _tmpPath = inSubpaths[i];
  25128. var _tmpShape = new Shape();
  25129. _tmpShape.curves = _tmpPath.curves;
  25130. shapes.push(_tmpShape);
  25131. }
  25132. return shapes;
  25133. }
  25134. function isPointInsidePolygon(inPt, inPolygon) {
  25135. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  25136. // toggling of inside/outside at every single! intersection point of an edge
  25137. // with the horizontal line through inPt, left of inPt
  25138. // not counting lowerY endpoints of edges and whole edges on that line
  25139. var inside = false;
  25140. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  25141. var edgeLowPt = inPolygon[p];
  25142. var edgeHighPt = inPolygon[q];
  25143. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  25144. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  25145. if (Math.abs(edgeDy) > Number.EPSILON) {
  25146. // not parallel
  25147. if (edgeDy < 0) {
  25148. edgeLowPt = inPolygon[q];
  25149. edgeDx = -edgeDx;
  25150. edgeHighPt = inPolygon[p];
  25151. edgeDy = -edgeDy;
  25152. }
  25153. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  25154. if (inPt.y === edgeLowPt.y) {
  25155. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  25156. // continue; // no intersection or edgeLowPt => doesn't count !!!
  25157. } else {
  25158. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  25159. if (perpEdge === 0) return true; // inPt is on contour ?
  25160. if (perpEdge < 0) continue;
  25161. inside = !inside; // true intersection left of inPt
  25162. }
  25163. } else {
  25164. // parallel or collinear
  25165. if (inPt.y !== edgeLowPt.y) continue; // parallel
  25166. // edge lies on the same horizontal line as inPt
  25167. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  25168. // continue;
  25169. }
  25170. }
  25171. return inside;
  25172. }
  25173. var isClockWise = ShapeUtils.isClockWise;
  25174. var subPaths = this.subPaths;
  25175. if (subPaths.length === 0) return [];
  25176. if (noHoles === true) return toShapesNoHoles(subPaths);
  25177. var solid, tmpPath, tmpShape;
  25178. var shapes = [];
  25179. if (subPaths.length === 1) {
  25180. tmpPath = subPaths[0];
  25181. tmpShape = new Shape();
  25182. tmpShape.curves = tmpPath.curves;
  25183. shapes.push(tmpShape);
  25184. return shapes;
  25185. }
  25186. var holesFirst = !isClockWise(subPaths[0].getPoints());
  25187. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  25188. var betterShapeHoles = [];
  25189. var newShapes = [];
  25190. var newShapeHoles = [];
  25191. var mainIdx = 0;
  25192. var tmpPoints;
  25193. newShapes[mainIdx] = undefined;
  25194. newShapeHoles[mainIdx] = [];
  25195. for (var i = 0, l = subPaths.length; i < l; i++) {
  25196. tmpPath = subPaths[i];
  25197. tmpPoints = tmpPath.getPoints();
  25198. solid = isClockWise(tmpPoints);
  25199. solid = isCCW ? !solid : solid;
  25200. if (solid) {
  25201. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  25202. newShapes[mainIdx] = {
  25203. s: new Shape(),
  25204. p: tmpPoints
  25205. };
  25206. newShapes[mainIdx].s.curves = tmpPath.curves;
  25207. if (holesFirst) mainIdx++;
  25208. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  25209. } else {
  25210. newShapeHoles[mainIdx].push({
  25211. h: tmpPath,
  25212. p: tmpPoints[0]
  25213. }); //console.log('ccw', i);
  25214. }
  25215. } // only Holes? -> probably all Shapes with wrong orientation
  25216. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  25217. if (newShapes.length > 1) {
  25218. var ambiguous = false;
  25219. var toChange = [];
  25220. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  25221. betterShapeHoles[sIdx] = [];
  25222. }
  25223. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  25224. var sho = newShapeHoles[_sIdx];
  25225. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  25226. var ho = sho[hIdx];
  25227. var hole_unassigned = true;
  25228. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  25229. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  25230. if (_sIdx !== s2Idx) toChange.push({
  25231. froms: _sIdx,
  25232. tos: s2Idx,
  25233. hole: hIdx
  25234. });
  25235. if (hole_unassigned) {
  25236. hole_unassigned = false;
  25237. betterShapeHoles[s2Idx].push(ho);
  25238. } else {
  25239. ambiguous = true;
  25240. }
  25241. }
  25242. }
  25243. if (hole_unassigned) {
  25244. betterShapeHoles[_sIdx].push(ho);
  25245. }
  25246. }
  25247. } // console.log("ambiguous: ", ambiguous);
  25248. if (toChange.length > 0) {
  25249. // console.log("to change: ", toChange);
  25250. if (!ambiguous) newShapeHoles = betterShapeHoles;
  25251. }
  25252. }
  25253. var tmpHoles;
  25254. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  25255. tmpShape = newShapes[_i].s;
  25256. shapes.push(tmpShape);
  25257. tmpHoles = newShapeHoles[_i];
  25258. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  25259. tmpShape.holes.push(tmpHoles[j].h);
  25260. }
  25261. } //console.log("shape", shapes);
  25262. return shapes;
  25263. };
  25264. return ShapePath;
  25265. }();
  25266. var Font = /*#__PURE__*/function () {
  25267. function Font(data) {
  25268. this.type = 'Font';
  25269. this.data = data;
  25270. }
  25271. var _proto = Font.prototype;
  25272. _proto.generateShapes = function generateShapes(text, size) {
  25273. if (size === void 0) {
  25274. size = 100;
  25275. }
  25276. var shapes = [];
  25277. var paths = createPaths(text, size, this.data);
  25278. for (var p = 0, pl = paths.length; p < pl; p++) {
  25279. Array.prototype.push.apply(shapes, paths[p].toShapes());
  25280. }
  25281. return shapes;
  25282. };
  25283. return Font;
  25284. }();
  25285. function createPaths(text, size, data) {
  25286. var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
  25287. var scale = size / data.resolution;
  25288. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  25289. var paths = [];
  25290. var offsetX = 0,
  25291. offsetY = 0;
  25292. for (var i = 0; i < chars.length; i++) {
  25293. var char = chars[i];
  25294. if (char === '\n') {
  25295. offsetX = 0;
  25296. offsetY -= line_height;
  25297. } else {
  25298. var ret = createPath(char, scale, offsetX, offsetY, data);
  25299. offsetX += ret.offsetX;
  25300. paths.push(ret.path);
  25301. }
  25302. }
  25303. return paths;
  25304. }
  25305. function createPath(char, scale, offsetX, offsetY, data) {
  25306. var glyph = data.glyphs[char] || data.glyphs['?'];
  25307. if (!glyph) {
  25308. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  25309. return;
  25310. }
  25311. var path = new ShapePath();
  25312. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  25313. if (glyph.o) {
  25314. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  25315. for (var i = 0, l = outline.length; i < l;) {
  25316. var action = outline[i++];
  25317. switch (action) {
  25318. case 'm':
  25319. // moveTo
  25320. x = outline[i++] * scale + offsetX;
  25321. y = outline[i++] * scale + offsetY;
  25322. path.moveTo(x, y);
  25323. break;
  25324. case 'l':
  25325. // lineTo
  25326. x = outline[i++] * scale + offsetX;
  25327. y = outline[i++] * scale + offsetY;
  25328. path.lineTo(x, y);
  25329. break;
  25330. case 'q':
  25331. // quadraticCurveTo
  25332. cpx = outline[i++] * scale + offsetX;
  25333. cpy = outline[i++] * scale + offsetY;
  25334. cpx1 = outline[i++] * scale + offsetX;
  25335. cpy1 = outline[i++] * scale + offsetY;
  25336. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  25337. break;
  25338. case 'b':
  25339. // bezierCurveTo
  25340. cpx = outline[i++] * scale + offsetX;
  25341. cpy = outline[i++] * scale + offsetY;
  25342. cpx1 = outline[i++] * scale + offsetX;
  25343. cpy1 = outline[i++] * scale + offsetY;
  25344. cpx2 = outline[i++] * scale + offsetX;
  25345. cpy2 = outline[i++] * scale + offsetY;
  25346. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  25347. break;
  25348. }
  25349. }
  25350. }
  25351. return {
  25352. offsetX: glyph.ha * scale,
  25353. path: path
  25354. };
  25355. }
  25356. Font.prototype.isFont = true;
  25357. var FontLoader = /*#__PURE__*/function (_Loader) {
  25358. _inheritsLoose(FontLoader, _Loader);
  25359. function FontLoader(manager) {
  25360. return _Loader.call(this, manager) || this;
  25361. }
  25362. var _proto = FontLoader.prototype;
  25363. _proto.load = function load(url, onLoad, onProgress, onError) {
  25364. var scope = this;
  25365. var loader = new FileLoader(this.manager);
  25366. loader.setPath(this.path);
  25367. loader.setRequestHeader(this.requestHeader);
  25368. loader.setWithCredentials(scope.withCredentials);
  25369. loader.load(url, function (text) {
  25370. var json;
  25371. try {
  25372. json = JSON.parse(text);
  25373. } catch (e) {
  25374. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  25375. json = JSON.parse(text.substring(65, text.length - 2));
  25376. }
  25377. var font = scope.parse(json);
  25378. if (onLoad) onLoad(font);
  25379. }, onProgress, onError);
  25380. };
  25381. _proto.parse = function parse(json) {
  25382. return new Font(json);
  25383. };
  25384. return FontLoader;
  25385. }(Loader);
  25386. var _context;
  25387. var AudioContext = {
  25388. getContext: function getContext() {
  25389. if (_context === undefined) {
  25390. _context = new (window.AudioContext || window.webkitAudioContext)();
  25391. }
  25392. return _context;
  25393. },
  25394. setContext: function setContext(value) {
  25395. _context = value;
  25396. }
  25397. };
  25398. var AudioLoader = /*#__PURE__*/function (_Loader) {
  25399. _inheritsLoose(AudioLoader, _Loader);
  25400. function AudioLoader(manager) {
  25401. return _Loader.call(this, manager) || this;
  25402. }
  25403. var _proto = AudioLoader.prototype;
  25404. _proto.load = function load(url, onLoad, onProgress, onError) {
  25405. var scope = this;
  25406. var loader = new FileLoader(this.manager);
  25407. loader.setResponseType('arraybuffer');
  25408. loader.setPath(this.path);
  25409. loader.setRequestHeader(this.requestHeader);
  25410. loader.setWithCredentials(this.withCredentials);
  25411. loader.load(url, function (buffer) {
  25412. try {
  25413. // Create a copy of the buffer. The `decodeAudioData` method
  25414. // detaches the buffer when complete, preventing reuse.
  25415. var bufferCopy = buffer.slice(0);
  25416. var context = AudioContext.getContext();
  25417. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  25418. onLoad(audioBuffer);
  25419. });
  25420. } catch (e) {
  25421. if (onError) {
  25422. onError(e);
  25423. } else {
  25424. console.error(e);
  25425. }
  25426. scope.manager.itemError(url);
  25427. }
  25428. }, onProgress, onError);
  25429. };
  25430. return AudioLoader;
  25431. }(Loader);
  25432. var HemisphereLightProbe = /*#__PURE__*/function (_LightProbe) {
  25433. _inheritsLoose(HemisphereLightProbe, _LightProbe);
  25434. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  25435. var _this;
  25436. if (intensity === void 0) {
  25437. intensity = 1;
  25438. }
  25439. _this = _LightProbe.call(this, undefined, intensity) || this;
  25440. var color1 = new Color().set(skyColor);
  25441. var color2 = new Color().set(groundColor);
  25442. var sky = new Vector3(color1.r, color1.g, color1.b);
  25443. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25444. var c0 = Math.sqrt(Math.PI);
  25445. var c1 = c0 * Math.sqrt(0.75);
  25446. _this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  25447. _this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  25448. return _this;
  25449. }
  25450. return HemisphereLightProbe;
  25451. }(LightProbe);
  25452. HemisphereLightProbe.prototype.isHemisphereLightProbe = true;
  25453. var AmbientLightProbe = /*#__PURE__*/function (_LightProbe) {
  25454. _inheritsLoose(AmbientLightProbe, _LightProbe);
  25455. function AmbientLightProbe(color, intensity) {
  25456. var _this;
  25457. if (intensity === void 0) {
  25458. intensity = 1;
  25459. }
  25460. _this = _LightProbe.call(this, undefined, intensity) || this;
  25461. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25462. _this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  25463. return _this;
  25464. }
  25465. return AmbientLightProbe;
  25466. }(LightProbe);
  25467. AmbientLightProbe.prototype.isAmbientLightProbe = true;
  25468. var _eyeRight = new Matrix4();
  25469. var _eyeLeft = new Matrix4();
  25470. var StereoCamera = /*#__PURE__*/function () {
  25471. function StereoCamera() {
  25472. this.type = 'StereoCamera';
  25473. this.aspect = 1;
  25474. this.eyeSep = 0.064;
  25475. this.cameraL = new PerspectiveCamera();
  25476. this.cameraL.layers.enable(1);
  25477. this.cameraL.matrixAutoUpdate = false;
  25478. this.cameraR = new PerspectiveCamera();
  25479. this.cameraR.layers.enable(2);
  25480. this.cameraR.matrixAutoUpdate = false;
  25481. this._cache = {
  25482. focus: null,
  25483. fov: null,
  25484. aspect: null,
  25485. near: null,
  25486. far: null,
  25487. zoom: null,
  25488. eyeSep: null
  25489. };
  25490. }
  25491. var _proto = StereoCamera.prototype;
  25492. _proto.update = function update(camera) {
  25493. var cache = this._cache;
  25494. 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;
  25495. if (needsUpdate) {
  25496. cache.focus = camera.focus;
  25497. cache.fov = camera.fov;
  25498. cache.aspect = camera.aspect * this.aspect;
  25499. cache.near = camera.near;
  25500. cache.far = camera.far;
  25501. cache.zoom = camera.zoom;
  25502. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  25503. // http://paulbourke.net/stereographics/stereorender/
  25504. var projectionMatrix = camera.projectionMatrix.clone();
  25505. var eyeSepHalf = cache.eyeSep / 2;
  25506. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25507. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  25508. var xmin, xmax; // translate xOffset
  25509. _eyeLeft.elements[12] = -eyeSepHalf;
  25510. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  25511. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  25512. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25513. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25514. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25515. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  25516. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  25517. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25518. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25519. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25520. this.cameraR.projectionMatrix.copy(projectionMatrix);
  25521. }
  25522. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  25523. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  25524. };
  25525. return StereoCamera;
  25526. }();
  25527. var Clock = /*#__PURE__*/function () {
  25528. function Clock(autoStart) {
  25529. this.autoStart = autoStart !== undefined ? autoStart : true;
  25530. this.startTime = 0;
  25531. this.oldTime = 0;
  25532. this.elapsedTime = 0;
  25533. this.running = false;
  25534. }
  25535. var _proto = Clock.prototype;
  25536. _proto.start = function start() {
  25537. this.startTime = now();
  25538. this.oldTime = this.startTime;
  25539. this.elapsedTime = 0;
  25540. this.running = true;
  25541. };
  25542. _proto.stop = function stop() {
  25543. this.getElapsedTime();
  25544. this.running = false;
  25545. this.autoStart = false;
  25546. };
  25547. _proto.getElapsedTime = function getElapsedTime() {
  25548. this.getDelta();
  25549. return this.elapsedTime;
  25550. };
  25551. _proto.getDelta = function getDelta() {
  25552. var diff = 0;
  25553. if (this.autoStart && !this.running) {
  25554. this.start();
  25555. return 0;
  25556. }
  25557. if (this.running) {
  25558. var newTime = now();
  25559. diff = (newTime - this.oldTime) / 1000;
  25560. this.oldTime = newTime;
  25561. this.elapsedTime += diff;
  25562. }
  25563. return diff;
  25564. };
  25565. return Clock;
  25566. }();
  25567. function now() {
  25568. return (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  25569. }
  25570. var _position$2 = /*@__PURE__*/new Vector3();
  25571. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  25572. var _scale$1 = /*@__PURE__*/new Vector3();
  25573. var _orientation = /*@__PURE__*/new Vector3();
  25574. var AudioListener = /*#__PURE__*/function (_Object3D) {
  25575. _inheritsLoose(AudioListener, _Object3D);
  25576. function AudioListener() {
  25577. var _this;
  25578. _this = _Object3D.call(this) || this;
  25579. _this.type = 'AudioListener';
  25580. _this.context = AudioContext.getContext();
  25581. _this.gain = _this.context.createGain();
  25582. _this.gain.connect(_this.context.destination);
  25583. _this.filter = null;
  25584. _this.timeDelta = 0; // private
  25585. _this._clock = new Clock();
  25586. return _this;
  25587. }
  25588. var _proto = AudioListener.prototype;
  25589. _proto.getInput = function getInput() {
  25590. return this.gain;
  25591. };
  25592. _proto.removeFilter = function removeFilter() {
  25593. if (this.filter !== null) {
  25594. this.gain.disconnect(this.filter);
  25595. this.filter.disconnect(this.context.destination);
  25596. this.gain.connect(this.context.destination);
  25597. this.filter = null;
  25598. }
  25599. return this;
  25600. };
  25601. _proto.getFilter = function getFilter() {
  25602. return this.filter;
  25603. };
  25604. _proto.setFilter = function setFilter(value) {
  25605. if (this.filter !== null) {
  25606. this.gain.disconnect(this.filter);
  25607. this.filter.disconnect(this.context.destination);
  25608. } else {
  25609. this.gain.disconnect(this.context.destination);
  25610. }
  25611. this.filter = value;
  25612. this.gain.connect(this.filter);
  25613. this.filter.connect(this.context.destination);
  25614. return this;
  25615. };
  25616. _proto.getMasterVolume = function getMasterVolume() {
  25617. return this.gain.gain.value;
  25618. };
  25619. _proto.setMasterVolume = function setMasterVolume(value) {
  25620. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25621. return this;
  25622. };
  25623. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25624. _Object3D.prototype.updateMatrixWorld.call(this, force);
  25625. var listener = this.context.listener;
  25626. var up = this.up;
  25627. this.timeDelta = this._clock.getDelta();
  25628. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  25629. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  25630. if (listener.positionX) {
  25631. // code path for Chrome (see #14393)
  25632. var endTime = this.context.currentTime + this.timeDelta;
  25633. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  25634. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  25635. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  25636. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  25637. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  25638. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  25639. listener.upX.linearRampToValueAtTime(up.x, endTime);
  25640. listener.upY.linearRampToValueAtTime(up.y, endTime);
  25641. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  25642. } else {
  25643. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  25644. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  25645. }
  25646. };
  25647. return AudioListener;
  25648. }(Object3D);
  25649. var Audio = /*#__PURE__*/function (_Object3D) {
  25650. _inheritsLoose(Audio, _Object3D);
  25651. function Audio(listener) {
  25652. var _this;
  25653. _this = _Object3D.call(this) || this;
  25654. _this.type = 'Audio';
  25655. _this.listener = listener;
  25656. _this.context = listener.context;
  25657. _this.gain = _this.context.createGain();
  25658. _this.gain.connect(listener.getInput());
  25659. _this.autoplay = false;
  25660. _this.buffer = null;
  25661. _this.detune = 0;
  25662. _this.loop = false;
  25663. _this.loopStart = 0;
  25664. _this.loopEnd = 0;
  25665. _this.offset = 0;
  25666. _this.duration = undefined;
  25667. _this.playbackRate = 1;
  25668. _this.isPlaying = false;
  25669. _this.hasPlaybackControl = true;
  25670. _this.source = null;
  25671. _this.sourceType = 'empty';
  25672. _this._startedAt = 0;
  25673. _this._progress = 0;
  25674. _this._connected = false;
  25675. _this.filters = [];
  25676. return _this;
  25677. }
  25678. var _proto = Audio.prototype;
  25679. _proto.getOutput = function getOutput() {
  25680. return this.gain;
  25681. };
  25682. _proto.setNodeSource = function setNodeSource(audioNode) {
  25683. this.hasPlaybackControl = false;
  25684. this.sourceType = 'audioNode';
  25685. this.source = audioNode;
  25686. this.connect();
  25687. return this;
  25688. };
  25689. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  25690. this.hasPlaybackControl = false;
  25691. this.sourceType = 'mediaNode';
  25692. this.source = this.context.createMediaElementSource(mediaElement);
  25693. this.connect();
  25694. return this;
  25695. };
  25696. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  25697. this.hasPlaybackControl = false;
  25698. this.sourceType = 'mediaStreamNode';
  25699. this.source = this.context.createMediaStreamSource(mediaStream);
  25700. this.connect();
  25701. return this;
  25702. };
  25703. _proto.setBuffer = function setBuffer(audioBuffer) {
  25704. this.buffer = audioBuffer;
  25705. this.sourceType = 'buffer';
  25706. if (this.autoplay) this.play();
  25707. return this;
  25708. };
  25709. _proto.play = function play(delay) {
  25710. if (delay === void 0) {
  25711. delay = 0;
  25712. }
  25713. if (this.isPlaying === true) {
  25714. console.warn('THREE.Audio: Audio is already playing.');
  25715. return;
  25716. }
  25717. if (this.hasPlaybackControl === false) {
  25718. console.warn('THREE.Audio: this Audio has no playback control.');
  25719. return;
  25720. }
  25721. this._startedAt = this.context.currentTime + delay;
  25722. var source = this.context.createBufferSource();
  25723. source.buffer = this.buffer;
  25724. source.loop = this.loop;
  25725. source.loopStart = this.loopStart;
  25726. source.loopEnd = this.loopEnd;
  25727. source.onended = this.onEnded.bind(this);
  25728. source.start(this._startedAt, this._progress + this.offset, this.duration);
  25729. this.isPlaying = true;
  25730. this.source = source;
  25731. this.setDetune(this.detune);
  25732. this.setPlaybackRate(this.playbackRate);
  25733. return this.connect();
  25734. };
  25735. _proto.pause = function pause() {
  25736. if (this.hasPlaybackControl === false) {
  25737. console.warn('THREE.Audio: this Audio has no playback control.');
  25738. return;
  25739. }
  25740. if (this.isPlaying === true) {
  25741. // update current progress
  25742. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  25743. if (this.loop === true) {
  25744. // ensure _progress does not exceed duration with looped audios
  25745. this._progress = this._progress % (this.duration || this.buffer.duration);
  25746. }
  25747. this.source.stop();
  25748. this.source.onended = null;
  25749. this.isPlaying = false;
  25750. }
  25751. return this;
  25752. };
  25753. _proto.stop = function stop() {
  25754. if (this.hasPlaybackControl === false) {
  25755. console.warn('THREE.Audio: this Audio has no playback control.');
  25756. return;
  25757. }
  25758. this._progress = 0;
  25759. this.source.stop();
  25760. this.source.onended = null;
  25761. this.isPlaying = false;
  25762. return this;
  25763. };
  25764. _proto.connect = function connect() {
  25765. if (this.filters.length > 0) {
  25766. this.source.connect(this.filters[0]);
  25767. for (var i = 1, l = this.filters.length; i < l; i++) {
  25768. this.filters[i - 1].connect(this.filters[i]);
  25769. }
  25770. this.filters[this.filters.length - 1].connect(this.getOutput());
  25771. } else {
  25772. this.source.connect(this.getOutput());
  25773. }
  25774. this._connected = true;
  25775. return this;
  25776. };
  25777. _proto.disconnect = function disconnect() {
  25778. if (this.filters.length > 0) {
  25779. this.source.disconnect(this.filters[0]);
  25780. for (var i = 1, l = this.filters.length; i < l; i++) {
  25781. this.filters[i - 1].disconnect(this.filters[i]);
  25782. }
  25783. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  25784. } else {
  25785. this.source.disconnect(this.getOutput());
  25786. }
  25787. this._connected = false;
  25788. return this;
  25789. };
  25790. _proto.getFilters = function getFilters() {
  25791. return this.filters;
  25792. };
  25793. _proto.setFilters = function setFilters(value) {
  25794. if (!value) value = [];
  25795. if (this._connected === true) {
  25796. this.disconnect();
  25797. this.filters = value.slice();
  25798. this.connect();
  25799. } else {
  25800. this.filters = value.slice();
  25801. }
  25802. return this;
  25803. };
  25804. _proto.setDetune = function setDetune(value) {
  25805. this.detune = value;
  25806. if (this.source.detune === undefined) return; // only set detune when available
  25807. if (this.isPlaying === true) {
  25808. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  25809. }
  25810. return this;
  25811. };
  25812. _proto.getDetune = function getDetune() {
  25813. return this.detune;
  25814. };
  25815. _proto.getFilter = function getFilter() {
  25816. return this.getFilters()[0];
  25817. };
  25818. _proto.setFilter = function setFilter(filter) {
  25819. return this.setFilters(filter ? [filter] : []);
  25820. };
  25821. _proto.setPlaybackRate = function setPlaybackRate(value) {
  25822. if (this.hasPlaybackControl === false) {
  25823. console.warn('THREE.Audio: this Audio has no playback control.');
  25824. return;
  25825. }
  25826. this.playbackRate = value;
  25827. if (this.isPlaying === true) {
  25828. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  25829. }
  25830. return this;
  25831. };
  25832. _proto.getPlaybackRate = function getPlaybackRate() {
  25833. return this.playbackRate;
  25834. };
  25835. _proto.onEnded = function onEnded() {
  25836. this.isPlaying = false;
  25837. };
  25838. _proto.getLoop = function getLoop() {
  25839. if (this.hasPlaybackControl === false) {
  25840. console.warn('THREE.Audio: this Audio has no playback control.');
  25841. return false;
  25842. }
  25843. return this.loop;
  25844. };
  25845. _proto.setLoop = function setLoop(value) {
  25846. if (this.hasPlaybackControl === false) {
  25847. console.warn('THREE.Audio: this Audio has no playback control.');
  25848. return;
  25849. }
  25850. this.loop = value;
  25851. if (this.isPlaying === true) {
  25852. this.source.loop = this.loop;
  25853. }
  25854. return this;
  25855. };
  25856. _proto.setLoopStart = function setLoopStart(value) {
  25857. this.loopStart = value;
  25858. return this;
  25859. };
  25860. _proto.setLoopEnd = function setLoopEnd(value) {
  25861. this.loopEnd = value;
  25862. return this;
  25863. };
  25864. _proto.getVolume = function getVolume() {
  25865. return this.gain.gain.value;
  25866. };
  25867. _proto.setVolume = function setVolume(value) {
  25868. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25869. return this;
  25870. };
  25871. return Audio;
  25872. }(Object3D);
  25873. var _position$3 = /*@__PURE__*/new Vector3();
  25874. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  25875. var _scale$2 = /*@__PURE__*/new Vector3();
  25876. var _orientation$1 = /*@__PURE__*/new Vector3();
  25877. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  25878. _inheritsLoose(PositionalAudio, _Audio);
  25879. function PositionalAudio(listener) {
  25880. var _this;
  25881. _this = _Audio.call(this, listener) || this;
  25882. _this.panner = _this.context.createPanner();
  25883. _this.panner.panningModel = 'HRTF';
  25884. _this.panner.connect(_this.gain);
  25885. return _this;
  25886. }
  25887. var _proto = PositionalAudio.prototype;
  25888. _proto.getOutput = function getOutput() {
  25889. return this.panner;
  25890. };
  25891. _proto.getRefDistance = function getRefDistance() {
  25892. return this.panner.refDistance;
  25893. };
  25894. _proto.setRefDistance = function setRefDistance(value) {
  25895. this.panner.refDistance = value;
  25896. return this;
  25897. };
  25898. _proto.getRolloffFactor = function getRolloffFactor() {
  25899. return this.panner.rolloffFactor;
  25900. };
  25901. _proto.setRolloffFactor = function setRolloffFactor(value) {
  25902. this.panner.rolloffFactor = value;
  25903. return this;
  25904. };
  25905. _proto.getDistanceModel = function getDistanceModel() {
  25906. return this.panner.distanceModel;
  25907. };
  25908. _proto.setDistanceModel = function setDistanceModel(value) {
  25909. this.panner.distanceModel = value;
  25910. return this;
  25911. };
  25912. _proto.getMaxDistance = function getMaxDistance() {
  25913. return this.panner.maxDistance;
  25914. };
  25915. _proto.setMaxDistance = function setMaxDistance(value) {
  25916. this.panner.maxDistance = value;
  25917. return this;
  25918. };
  25919. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  25920. this.panner.coneInnerAngle = coneInnerAngle;
  25921. this.panner.coneOuterAngle = coneOuterAngle;
  25922. this.panner.coneOuterGain = coneOuterGain;
  25923. return this;
  25924. };
  25925. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25926. _Audio.prototype.updateMatrixWorld.call(this, force);
  25927. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  25928. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  25929. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  25930. var panner = this.panner;
  25931. if (panner.positionX) {
  25932. // code path for Chrome and Firefox (see #14393)
  25933. var endTime = this.context.currentTime + this.listener.timeDelta;
  25934. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  25935. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  25936. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  25937. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  25938. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  25939. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  25940. } else {
  25941. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  25942. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  25943. }
  25944. };
  25945. return PositionalAudio;
  25946. }(Audio);
  25947. var AudioAnalyser = /*#__PURE__*/function () {
  25948. function AudioAnalyser(audio, fftSize) {
  25949. if (fftSize === void 0) {
  25950. fftSize = 2048;
  25951. }
  25952. this.analyser = audio.context.createAnalyser();
  25953. this.analyser.fftSize = fftSize;
  25954. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  25955. audio.getOutput().connect(this.analyser);
  25956. }
  25957. var _proto = AudioAnalyser.prototype;
  25958. _proto.getFrequencyData = function getFrequencyData() {
  25959. this.analyser.getByteFrequencyData(this.data);
  25960. return this.data;
  25961. };
  25962. _proto.getAverageFrequency = function getAverageFrequency() {
  25963. var value = 0;
  25964. var data = this.getFrequencyData();
  25965. for (var i = 0; i < data.length; i++) {
  25966. value += data[i];
  25967. }
  25968. return value / data.length;
  25969. };
  25970. return AudioAnalyser;
  25971. }();
  25972. function PropertyMixer(binding, typeName, valueSize) {
  25973. this.binding = binding;
  25974. this.valueSize = valueSize;
  25975. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  25976. //
  25977. // interpolators can use .buffer as their .result
  25978. // the data then goes to 'incoming'
  25979. //
  25980. // 'accu0' and 'accu1' are used frame-interleaved for
  25981. // the cumulative result and are compared to detect
  25982. // changes
  25983. //
  25984. // 'orig' stores the original state of the property
  25985. //
  25986. // 'add' is used for additive cumulative results
  25987. //
  25988. // 'work' is optional and is only present for quaternion types. It is used
  25989. // to store intermediate quaternion multiplication results
  25990. switch (typeName) {
  25991. case 'quaternion':
  25992. mixFunction = this._slerp;
  25993. mixFunctionAdditive = this._slerpAdditive;
  25994. setIdentity = this._setAdditiveIdentityQuaternion;
  25995. this.buffer = new Float64Array(valueSize * 6);
  25996. this._workIndex = 5;
  25997. break;
  25998. case 'string':
  25999. case 'bool':
  26000. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  26001. // additive is not relevant for non-numeric types
  26002. mixFunctionAdditive = this._select;
  26003. setIdentity = this._setAdditiveIdentityOther;
  26004. this.buffer = new Array(valueSize * 5);
  26005. break;
  26006. default:
  26007. mixFunction = this._lerp;
  26008. mixFunctionAdditive = this._lerpAdditive;
  26009. setIdentity = this._setAdditiveIdentityNumeric;
  26010. this.buffer = new Float64Array(valueSize * 5);
  26011. }
  26012. this._mixBufferRegion = mixFunction;
  26013. this._mixBufferRegionAdditive = mixFunctionAdditive;
  26014. this._setIdentity = setIdentity;
  26015. this._origIndex = 3;
  26016. this._addIndex = 4;
  26017. this.cumulativeWeight = 0;
  26018. this.cumulativeWeightAdditive = 0;
  26019. this.useCount = 0;
  26020. this.referenceCount = 0;
  26021. }
  26022. Object.assign(PropertyMixer.prototype, {
  26023. // accumulate data in the 'incoming' region into 'accu<i>'
  26024. accumulate: function accumulate(accuIndex, weight) {
  26025. // note: happily accumulating nothing when weight = 0, the caller knows
  26026. // the weight and shouldn't have made the call in the first place
  26027. var buffer = this.buffer,
  26028. stride = this.valueSize,
  26029. offset = accuIndex * stride + stride;
  26030. var currentWeight = this.cumulativeWeight;
  26031. if (currentWeight === 0) {
  26032. // accuN := incoming * weight
  26033. for (var i = 0; i !== stride; ++i) {
  26034. buffer[offset + i] = buffer[i];
  26035. }
  26036. currentWeight = weight;
  26037. } else {
  26038. // accuN := accuN + incoming * weight
  26039. currentWeight += weight;
  26040. var mix = weight / currentWeight;
  26041. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  26042. }
  26043. this.cumulativeWeight = currentWeight;
  26044. },
  26045. // accumulate data in the 'incoming' region into 'add'
  26046. accumulateAdditive: function accumulateAdditive(weight) {
  26047. var buffer = this.buffer,
  26048. stride = this.valueSize,
  26049. offset = stride * this._addIndex;
  26050. if (this.cumulativeWeightAdditive === 0) {
  26051. // add = identity
  26052. this._setIdentity();
  26053. } // add := add + incoming * weight
  26054. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  26055. this.cumulativeWeightAdditive += weight;
  26056. },
  26057. // apply the state of 'accu<i>' to the binding when accus differ
  26058. apply: function apply(accuIndex) {
  26059. var stride = this.valueSize,
  26060. buffer = this.buffer,
  26061. offset = accuIndex * stride + stride,
  26062. weight = this.cumulativeWeight,
  26063. weightAdditive = this.cumulativeWeightAdditive,
  26064. binding = this.binding;
  26065. this.cumulativeWeight = 0;
  26066. this.cumulativeWeightAdditive = 0;
  26067. if (weight < 1) {
  26068. // accuN := accuN + original * ( 1 - cumulativeWeight )
  26069. var originalValueOffset = stride * this._origIndex;
  26070. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  26071. }
  26072. if (weightAdditive > 0) {
  26073. // accuN := accuN + additive accuN
  26074. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  26075. }
  26076. for (var i = stride, e = stride + stride; i !== e; ++i) {
  26077. if (buffer[i] !== buffer[i + stride]) {
  26078. // value has changed -> update scene graph
  26079. binding.setValue(buffer, offset);
  26080. break;
  26081. }
  26082. }
  26083. },
  26084. // remember the state of the bound property and copy it to both accus
  26085. saveOriginalState: function saveOriginalState() {
  26086. var binding = this.binding;
  26087. var buffer = this.buffer,
  26088. stride = this.valueSize,
  26089. originalValueOffset = stride * this._origIndex;
  26090. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  26091. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  26092. buffer[i] = buffer[originalValueOffset + i % stride];
  26093. } // Add to identity for additive
  26094. this._setIdentity();
  26095. this.cumulativeWeight = 0;
  26096. this.cumulativeWeightAdditive = 0;
  26097. },
  26098. // apply the state previously taken via 'saveOriginalState' to the binding
  26099. restoreOriginalState: function restoreOriginalState() {
  26100. var originalValueOffset = this.valueSize * 3;
  26101. this.binding.setValue(this.buffer, originalValueOffset);
  26102. },
  26103. _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
  26104. var startIndex = this._addIndex * this.valueSize;
  26105. var endIndex = startIndex + this.valueSize;
  26106. for (var i = startIndex; i < endIndex; i++) {
  26107. this.buffer[i] = 0;
  26108. }
  26109. },
  26110. _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
  26111. this._setAdditiveIdentityNumeric();
  26112. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  26113. },
  26114. _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
  26115. var startIndex = this._origIndex * this.valueSize;
  26116. var targetIndex = this._addIndex * this.valueSize;
  26117. for (var i = 0; i < this.valueSize; i++) {
  26118. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  26119. }
  26120. },
  26121. // mix functions
  26122. _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
  26123. if (t >= 0.5) {
  26124. for (var i = 0; i !== stride; ++i) {
  26125. buffer[dstOffset + i] = buffer[srcOffset + i];
  26126. }
  26127. }
  26128. },
  26129. _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
  26130. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  26131. },
  26132. _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  26133. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  26134. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  26135. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  26136. },
  26137. _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  26138. var s = 1 - t;
  26139. for (var i = 0; i !== stride; ++i) {
  26140. var j = dstOffset + i;
  26141. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  26142. }
  26143. },
  26144. _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  26145. for (var i = 0; i !== stride; ++i) {
  26146. var j = dstOffset + i;
  26147. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  26148. }
  26149. }
  26150. });
  26151. // Characters [].:/ are reserved for track binding syntax.
  26152. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  26153. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  26154. // only latin characters, and the unicode \p{L} is not yet supported. So
  26155. // instead, we exclude reserved characters and match everything else.
  26156. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  26157. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  26158. // be matched to parse the rest of the track name.
  26159. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  26160. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  26161. // characters. Accessor may contain any character except closing bracket.
  26162. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  26163. // contain any non-bracket characters.
  26164. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  26165. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  26166. var _supportedObjectNames = ['material', 'materials', 'bones'];
  26167. function Composite(targetGroup, path, optionalParsedPath) {
  26168. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  26169. this._targetGroup = targetGroup;
  26170. this._bindings = targetGroup.subscribe_(path, parsedPath);
  26171. }
  26172. Object.assign(Composite.prototype, {
  26173. getValue: function getValue(array, offset) {
  26174. this.bind(); // bind all binding
  26175. var firstValidIndex = this._targetGroup.nCachedObjects_,
  26176. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  26177. if (binding !== undefined) binding.getValue(array, offset);
  26178. },
  26179. setValue: function setValue(array, offset) {
  26180. var bindings = this._bindings;
  26181. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26182. bindings[i].setValue(array, offset);
  26183. }
  26184. },
  26185. bind: function bind() {
  26186. var bindings = this._bindings;
  26187. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26188. bindings[i].bind();
  26189. }
  26190. },
  26191. unbind: function unbind() {
  26192. var bindings = this._bindings;
  26193. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26194. bindings[i].unbind();
  26195. }
  26196. }
  26197. });
  26198. function PropertyBinding(rootNode, path, parsedPath) {
  26199. this.path = path;
  26200. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  26201. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  26202. this.rootNode = rootNode;
  26203. }
  26204. Object.assign(PropertyBinding, {
  26205. Composite: Composite,
  26206. create: function create(root, path, parsedPath) {
  26207. if (!(root && root.isAnimationObjectGroup)) {
  26208. return new PropertyBinding(root, path, parsedPath);
  26209. } else {
  26210. return new PropertyBinding.Composite(root, path, parsedPath);
  26211. }
  26212. },
  26213. /**
  26214. * Replaces spaces with underscores and removes unsupported characters from
  26215. * node names, to ensure compatibility with parseTrackName().
  26216. *
  26217. * @param {string} name Node name to be sanitized.
  26218. * @return {string}
  26219. */
  26220. sanitizeNodeName: function sanitizeNodeName(name) {
  26221. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  26222. },
  26223. parseTrackName: function parseTrackName(trackName) {
  26224. var matches = _trackRe.exec(trackName);
  26225. if (!matches) {
  26226. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  26227. }
  26228. var results = {
  26229. // directoryName: matches[ 1 ], // (tschw) currently unused
  26230. nodeName: matches[2],
  26231. objectName: matches[3],
  26232. objectIndex: matches[4],
  26233. propertyName: matches[5],
  26234. // required
  26235. propertyIndex: matches[6]
  26236. };
  26237. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  26238. if (lastDot !== undefined && lastDot !== -1) {
  26239. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  26240. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  26241. // 'bar' could be the objectName, or part of a nodeName (which can
  26242. // include '.' characters).
  26243. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  26244. results.nodeName = results.nodeName.substring(0, lastDot);
  26245. results.objectName = objectName;
  26246. }
  26247. }
  26248. if (results.propertyName === null || results.propertyName.length === 0) {
  26249. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  26250. }
  26251. return results;
  26252. },
  26253. findNode: function findNode(root, nodeName) {
  26254. if (!nodeName || nodeName === '' || nodeName === '.' || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  26255. return root;
  26256. } // search into skeleton bones.
  26257. if (root.skeleton) {
  26258. var bone = root.skeleton.getBoneByName(nodeName);
  26259. if (bone !== undefined) {
  26260. return bone;
  26261. }
  26262. } // search into node subtree.
  26263. if (root.children) {
  26264. var searchNodeSubtree = function searchNodeSubtree(children) {
  26265. for (var i = 0; i < children.length; i++) {
  26266. var childNode = children[i];
  26267. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  26268. return childNode;
  26269. }
  26270. var result = searchNodeSubtree(childNode.children);
  26271. if (result) return result;
  26272. }
  26273. return null;
  26274. };
  26275. var subTreeNode = searchNodeSubtree(root.children);
  26276. if (subTreeNode) {
  26277. return subTreeNode;
  26278. }
  26279. }
  26280. return null;
  26281. }
  26282. });
  26283. Object.assign(PropertyBinding.prototype, {
  26284. // prototype, continued
  26285. // these are used to "bind" a nonexistent property
  26286. _getValue_unavailable: function _getValue_unavailable() {},
  26287. _setValue_unavailable: function _setValue_unavailable() {},
  26288. BindingType: {
  26289. Direct: 0,
  26290. EntireArray: 1,
  26291. ArrayElement: 2,
  26292. HasFromToArray: 3
  26293. },
  26294. Versioning: {
  26295. None: 0,
  26296. NeedsUpdate: 1,
  26297. MatrixWorldNeedsUpdate: 2
  26298. },
  26299. GetterByBindingType: [function getValue_direct(buffer, offset) {
  26300. buffer[offset] = this.node[this.propertyName];
  26301. }, function getValue_array(buffer, offset) {
  26302. var source = this.resolvedProperty;
  26303. for (var i = 0, n = source.length; i !== n; ++i) {
  26304. buffer[offset++] = source[i];
  26305. }
  26306. }, function getValue_arrayElement(buffer, offset) {
  26307. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  26308. }, function getValue_toArray(buffer, offset) {
  26309. this.resolvedProperty.toArray(buffer, offset);
  26310. }],
  26311. SetterByBindingTypeAndVersioning: [[// Direct
  26312. function setValue_direct(buffer, offset) {
  26313. this.targetObject[this.propertyName] = buffer[offset];
  26314. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  26315. this.targetObject[this.propertyName] = buffer[offset];
  26316. this.targetObject.needsUpdate = true;
  26317. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  26318. this.targetObject[this.propertyName] = buffer[offset];
  26319. this.targetObject.matrixWorldNeedsUpdate = true;
  26320. }], [// EntireArray
  26321. function setValue_array(buffer, offset) {
  26322. var dest = this.resolvedProperty;
  26323. for (var i = 0, n = dest.length; i !== n; ++i) {
  26324. dest[i] = buffer[offset++];
  26325. }
  26326. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  26327. var dest = this.resolvedProperty;
  26328. for (var i = 0, n = dest.length; i !== n; ++i) {
  26329. dest[i] = buffer[offset++];
  26330. }
  26331. this.targetObject.needsUpdate = true;
  26332. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  26333. var dest = this.resolvedProperty;
  26334. for (var i = 0, n = dest.length; i !== n; ++i) {
  26335. dest[i] = buffer[offset++];
  26336. }
  26337. this.targetObject.matrixWorldNeedsUpdate = true;
  26338. }], [// ArrayElement
  26339. function setValue_arrayElement(buffer, offset) {
  26340. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26341. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  26342. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26343. this.targetObject.needsUpdate = true;
  26344. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  26345. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26346. this.targetObject.matrixWorldNeedsUpdate = true;
  26347. }], [// HasToFromArray
  26348. function setValue_fromArray(buffer, offset) {
  26349. this.resolvedProperty.fromArray(buffer, offset);
  26350. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  26351. this.resolvedProperty.fromArray(buffer, offset);
  26352. this.targetObject.needsUpdate = true;
  26353. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  26354. this.resolvedProperty.fromArray(buffer, offset);
  26355. this.targetObject.matrixWorldNeedsUpdate = true;
  26356. }]],
  26357. getValue: function getValue_unbound(targetArray, offset) {
  26358. this.bind();
  26359. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  26360. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  26361. // prototype version of these methods with one that represents
  26362. // the bound state. When the property is not found, the methods
  26363. // become no-ops.
  26364. },
  26365. setValue: function getValue_unbound(sourceArray, offset) {
  26366. this.bind();
  26367. this.setValue(sourceArray, offset);
  26368. },
  26369. // create getter / setter pair for a property in the scene graph
  26370. bind: function bind() {
  26371. var targetObject = this.node;
  26372. var parsedPath = this.parsedPath;
  26373. var objectName = parsedPath.objectName;
  26374. var propertyName = parsedPath.propertyName;
  26375. var propertyIndex = parsedPath.propertyIndex;
  26376. if (!targetObject) {
  26377. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  26378. this.node = targetObject;
  26379. } // set fail state so we can just 'return' on error
  26380. this.getValue = this._getValue_unavailable;
  26381. this.setValue = this._setValue_unavailable; // ensure there is a value node
  26382. if (!targetObject) {
  26383. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  26384. return;
  26385. }
  26386. if (objectName) {
  26387. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  26388. switch (objectName) {
  26389. case 'materials':
  26390. if (!targetObject.material) {
  26391. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  26392. return;
  26393. }
  26394. if (!targetObject.material.materials) {
  26395. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  26396. return;
  26397. }
  26398. targetObject = targetObject.material.materials;
  26399. break;
  26400. case 'bones':
  26401. if (!targetObject.skeleton) {
  26402. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  26403. return;
  26404. } // potential future optimization: skip this if propertyIndex is already an integer
  26405. // and convert the integer string to a true integer.
  26406. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  26407. for (var i = 0; i < targetObject.length; i++) {
  26408. if (targetObject[i].name === objectIndex) {
  26409. objectIndex = i;
  26410. break;
  26411. }
  26412. }
  26413. break;
  26414. default:
  26415. if (targetObject[objectName] === undefined) {
  26416. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  26417. return;
  26418. }
  26419. targetObject = targetObject[objectName];
  26420. }
  26421. if (objectIndex !== undefined) {
  26422. if (targetObject[objectIndex] === undefined) {
  26423. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  26424. return;
  26425. }
  26426. targetObject = targetObject[objectIndex];
  26427. }
  26428. } // resolve property
  26429. var nodeProperty = targetObject[propertyName];
  26430. if (nodeProperty === undefined) {
  26431. var nodeName = parsedPath.nodeName;
  26432. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  26433. return;
  26434. } // determine versioning scheme
  26435. var versioning = this.Versioning.None;
  26436. this.targetObject = targetObject;
  26437. if (targetObject.needsUpdate !== undefined) {
  26438. // material
  26439. versioning = this.Versioning.NeedsUpdate;
  26440. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  26441. // node transform
  26442. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26443. } // determine how the property gets bound
  26444. var bindingType = this.BindingType.Direct;
  26445. if (propertyIndex !== undefined) {
  26446. // access a sub element of the property array (only primitives are supported right now)
  26447. if (propertyName === 'morphTargetInfluences') {
  26448. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26449. // support resolving morphTarget names into indices.
  26450. if (!targetObject.geometry) {
  26451. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  26452. return;
  26453. }
  26454. if (targetObject.geometry.isBufferGeometry) {
  26455. if (!targetObject.geometry.morphAttributes) {
  26456. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  26457. return;
  26458. }
  26459. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  26460. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  26461. }
  26462. } else {
  26463. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  26464. return;
  26465. }
  26466. }
  26467. bindingType = this.BindingType.ArrayElement;
  26468. this.resolvedProperty = nodeProperty;
  26469. this.propertyIndex = propertyIndex;
  26470. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  26471. // must use copy for Object3D.Euler/Quaternion
  26472. bindingType = this.BindingType.HasFromToArray;
  26473. this.resolvedProperty = nodeProperty;
  26474. } else if (Array.isArray(nodeProperty)) {
  26475. bindingType = this.BindingType.EntireArray;
  26476. this.resolvedProperty = nodeProperty;
  26477. } else {
  26478. this.propertyName = propertyName;
  26479. } // select getter / setter
  26480. this.getValue = this.GetterByBindingType[bindingType];
  26481. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  26482. },
  26483. unbind: function unbind() {
  26484. this.node = null; // back to the prototype version of getValue / setValue
  26485. // note: avoiding to mutate the shape of 'this' via 'delete'
  26486. this.getValue = this._getValue_unbound;
  26487. this.setValue = this._setValue_unbound;
  26488. }
  26489. }); // DECLARE ALIAS AFTER assign prototype
  26490. Object.assign(PropertyBinding.prototype, {
  26491. // initial state of these methods that calls 'bind'
  26492. _getValue_unbound: PropertyBinding.prototype.getValue,
  26493. _setValue_unbound: PropertyBinding.prototype.setValue
  26494. });
  26495. /**
  26496. *
  26497. * A group of objects that receives a shared animation state.
  26498. *
  26499. * Usage:
  26500. *
  26501. * - Add objects you would otherwise pass as 'root' to the
  26502. * constructor or the .clipAction method of AnimationMixer.
  26503. *
  26504. * - Instead pass this object as 'root'.
  26505. *
  26506. * - You can also add and remove objects later when the mixer
  26507. * is running.
  26508. *
  26509. * Note:
  26510. *
  26511. * Objects of this class appear as one object to the mixer,
  26512. * so cache control of the individual objects must be done
  26513. * on the group.
  26514. *
  26515. * Limitation:
  26516. *
  26517. * - The animated properties must be compatible among the
  26518. * all objects in the group.
  26519. *
  26520. * - A single property can either be controlled through a
  26521. * target group or directly, but not both.
  26522. */
  26523. function AnimationObjectGroup() {
  26524. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  26525. this._objects = Array.prototype.slice.call(arguments);
  26526. this.nCachedObjects_ = 0; // threshold
  26527. // note: read by PropertyBinding.Composite
  26528. var indices = {};
  26529. this._indicesByUUID = indices; // for bookkeeping
  26530. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26531. indices[arguments[i].uuid] = i;
  26532. }
  26533. this._paths = []; // inside: string
  26534. this._parsedPaths = []; // inside: { we don't care, here }
  26535. this._bindings = []; // inside: Array< PropertyBinding >
  26536. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26537. var scope = this;
  26538. this.stats = {
  26539. objects: {
  26540. get total() {
  26541. return scope._objects.length;
  26542. },
  26543. get inUse() {
  26544. return this.total - scope.nCachedObjects_;
  26545. }
  26546. },
  26547. get bindingsPerObject() {
  26548. return scope._bindings.length;
  26549. }
  26550. };
  26551. }
  26552. Object.assign(AnimationObjectGroup.prototype, {
  26553. isAnimationObjectGroup: true,
  26554. add: function add() {
  26555. var objects = this._objects,
  26556. indicesByUUID = this._indicesByUUID,
  26557. paths = this._paths,
  26558. parsedPaths = this._parsedPaths,
  26559. bindings = this._bindings,
  26560. nBindings = bindings.length;
  26561. var knownObject = undefined,
  26562. nObjects = objects.length,
  26563. nCachedObjects = this.nCachedObjects_;
  26564. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26565. var object = arguments[i],
  26566. uuid = object.uuid;
  26567. var index = indicesByUUID[uuid];
  26568. if (index === undefined) {
  26569. // unknown object -> add it to the ACTIVE region
  26570. index = nObjects++;
  26571. indicesByUUID[uuid] = index;
  26572. objects.push(object); // accounting is done, now do the same for all bindings
  26573. for (var j = 0, m = nBindings; j !== m; ++j) {
  26574. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  26575. }
  26576. } else if (index < nCachedObjects) {
  26577. knownObject = objects[index]; // move existing object to the ACTIVE region
  26578. var firstActiveIndex = --nCachedObjects,
  26579. lastCachedObject = objects[firstActiveIndex];
  26580. indicesByUUID[lastCachedObject.uuid] = index;
  26581. objects[index] = lastCachedObject;
  26582. indicesByUUID[uuid] = firstActiveIndex;
  26583. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  26584. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  26585. var bindingsForPath = bindings[_j],
  26586. lastCached = bindingsForPath[firstActiveIndex];
  26587. var binding = bindingsForPath[index];
  26588. bindingsForPath[index] = lastCached;
  26589. if (binding === undefined) {
  26590. // since we do not bother to create new bindings
  26591. // for objects that are cached, the binding may
  26592. // or may not exist
  26593. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  26594. }
  26595. bindingsForPath[firstActiveIndex] = binding;
  26596. }
  26597. } else if (objects[index] !== knownObject) {
  26598. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  26599. } // else the object is already where we want it to be
  26600. } // for arguments
  26601. this.nCachedObjects_ = nCachedObjects;
  26602. },
  26603. remove: function remove() {
  26604. var objects = this._objects,
  26605. indicesByUUID = this._indicesByUUID,
  26606. bindings = this._bindings,
  26607. nBindings = bindings.length;
  26608. var nCachedObjects = this.nCachedObjects_;
  26609. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26610. var object = arguments[i],
  26611. uuid = object.uuid,
  26612. index = indicesByUUID[uuid];
  26613. if (index !== undefined && index >= nCachedObjects) {
  26614. // move existing object into the CACHED region
  26615. var lastCachedIndex = nCachedObjects++,
  26616. firstActiveObject = objects[lastCachedIndex];
  26617. indicesByUUID[firstActiveObject.uuid] = index;
  26618. objects[index] = firstActiveObject;
  26619. indicesByUUID[uuid] = lastCachedIndex;
  26620. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  26621. for (var j = 0, m = nBindings; j !== m; ++j) {
  26622. var bindingsForPath = bindings[j],
  26623. firstActive = bindingsForPath[lastCachedIndex],
  26624. binding = bindingsForPath[index];
  26625. bindingsForPath[index] = firstActive;
  26626. bindingsForPath[lastCachedIndex] = binding;
  26627. }
  26628. }
  26629. } // for arguments
  26630. this.nCachedObjects_ = nCachedObjects;
  26631. },
  26632. // remove & forget
  26633. uncache: function uncache() {
  26634. var objects = this._objects,
  26635. indicesByUUID = this._indicesByUUID,
  26636. bindings = this._bindings,
  26637. nBindings = bindings.length;
  26638. var nCachedObjects = this.nCachedObjects_,
  26639. nObjects = objects.length;
  26640. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26641. var object = arguments[i],
  26642. uuid = object.uuid,
  26643. index = indicesByUUID[uuid];
  26644. if (index !== undefined) {
  26645. delete indicesByUUID[uuid];
  26646. if (index < nCachedObjects) {
  26647. // object is cached, shrink the CACHED region
  26648. var firstActiveIndex = --nCachedObjects,
  26649. lastCachedObject = objects[firstActiveIndex],
  26650. lastIndex = --nObjects,
  26651. lastObject = objects[lastIndex]; // last cached object takes this object's place
  26652. indicesByUUID[lastCachedObject.uuid] = index;
  26653. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  26654. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  26655. objects[firstActiveIndex] = lastObject;
  26656. objects.pop(); // accounting is done, now do the same for all bindings
  26657. for (var j = 0, m = nBindings; j !== m; ++j) {
  26658. var bindingsForPath = bindings[j],
  26659. lastCached = bindingsForPath[firstActiveIndex],
  26660. last = bindingsForPath[lastIndex];
  26661. bindingsForPath[index] = lastCached;
  26662. bindingsForPath[firstActiveIndex] = last;
  26663. bindingsForPath.pop();
  26664. }
  26665. } else {
  26666. // object is active, just swap with the last and pop
  26667. var _lastIndex = --nObjects,
  26668. _lastObject = objects[_lastIndex];
  26669. if (_lastIndex > 0) {
  26670. indicesByUUID[_lastObject.uuid] = index;
  26671. }
  26672. objects[index] = _lastObject;
  26673. objects.pop(); // accounting is done, now do the same for all bindings
  26674. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  26675. var _bindingsForPath = bindings[_j2];
  26676. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  26677. _bindingsForPath.pop();
  26678. }
  26679. } // cached or active
  26680. } // if object is known
  26681. } // for arguments
  26682. this.nCachedObjects_ = nCachedObjects;
  26683. },
  26684. // Internal interface used by befriended PropertyBinding.Composite:
  26685. subscribe_: function subscribe_(path, parsedPath) {
  26686. // returns an array of bindings for the given path that is changed
  26687. // according to the contained objects in the group
  26688. var indicesByPath = this._bindingsIndicesByPath;
  26689. var index = indicesByPath[path];
  26690. var bindings = this._bindings;
  26691. if (index !== undefined) return bindings[index];
  26692. var paths = this._paths,
  26693. parsedPaths = this._parsedPaths,
  26694. objects = this._objects,
  26695. nObjects = objects.length,
  26696. nCachedObjects = this.nCachedObjects_,
  26697. bindingsForPath = new Array(nObjects);
  26698. index = bindings.length;
  26699. indicesByPath[path] = index;
  26700. paths.push(path);
  26701. parsedPaths.push(parsedPath);
  26702. bindings.push(bindingsForPath);
  26703. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  26704. var object = objects[i];
  26705. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  26706. }
  26707. return bindingsForPath;
  26708. },
  26709. unsubscribe_: function unsubscribe_(path) {
  26710. // tells the group to forget about a property path and no longer
  26711. // update the array previously obtained with 'subscribe_'
  26712. var indicesByPath = this._bindingsIndicesByPath,
  26713. index = indicesByPath[path];
  26714. if (index !== undefined) {
  26715. var paths = this._paths,
  26716. parsedPaths = this._parsedPaths,
  26717. bindings = this._bindings,
  26718. lastBindingsIndex = bindings.length - 1,
  26719. lastBindings = bindings[lastBindingsIndex],
  26720. lastBindingsPath = path[lastBindingsIndex];
  26721. indicesByPath[lastBindingsPath] = index;
  26722. bindings[index] = lastBindings;
  26723. bindings.pop();
  26724. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  26725. parsedPaths.pop();
  26726. paths[index] = paths[lastBindingsIndex];
  26727. paths.pop();
  26728. }
  26729. }
  26730. });
  26731. var AnimationAction = /*#__PURE__*/function () {
  26732. function AnimationAction(mixer, clip, localRoot, blendMode) {
  26733. if (localRoot === void 0) {
  26734. localRoot = null;
  26735. }
  26736. if (blendMode === void 0) {
  26737. blendMode = clip.blendMode;
  26738. }
  26739. this._mixer = mixer;
  26740. this._clip = clip;
  26741. this._localRoot = localRoot;
  26742. this.blendMode = blendMode;
  26743. var tracks = clip.tracks,
  26744. nTracks = tracks.length,
  26745. interpolants = new Array(nTracks);
  26746. var interpolantSettings = {
  26747. endingStart: ZeroCurvatureEnding,
  26748. endingEnd: ZeroCurvatureEnding
  26749. };
  26750. for (var i = 0; i !== nTracks; ++i) {
  26751. var interpolant = tracks[i].createInterpolant(null);
  26752. interpolants[i] = interpolant;
  26753. interpolant.settings = interpolantSettings;
  26754. }
  26755. this._interpolantSettings = interpolantSettings;
  26756. this._interpolants = interpolants; // bound by the mixer
  26757. // inside: PropertyMixer (managed by the mixer)
  26758. this._propertyBindings = new Array(nTracks);
  26759. this._cacheIndex = null; // for the memory manager
  26760. this._byClipCacheIndex = null; // for the memory manager
  26761. this._timeScaleInterpolant = null;
  26762. this._weightInterpolant = null;
  26763. this.loop = LoopRepeat;
  26764. this._loopCount = -1; // global mixer time when the action is to be started
  26765. // it's set back to 'null' upon start of the action
  26766. this._startTime = null; // scaled local time of the action
  26767. // gets clamped or wrapped to 0..clip.duration according to loop
  26768. this.time = 0;
  26769. this.timeScale = 1;
  26770. this._effectiveTimeScale = 1;
  26771. this.weight = 1;
  26772. this._effectiveWeight = 1;
  26773. this.repetitions = Infinity; // no. of repetitions when looping
  26774. this.paused = false; // true -> zero effective time scale
  26775. this.enabled = true; // false -> zero effective weight
  26776. this.clampWhenFinished = false; // keep feeding the last frame?
  26777. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  26778. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  26779. } // State & Scheduling
  26780. var _proto = AnimationAction.prototype;
  26781. _proto.play = function play() {
  26782. this._mixer._activateAction(this);
  26783. return this;
  26784. };
  26785. _proto.stop = function stop() {
  26786. this._mixer._deactivateAction(this);
  26787. return this.reset();
  26788. };
  26789. _proto.reset = function reset() {
  26790. this.paused = false;
  26791. this.enabled = true;
  26792. this.time = 0; // restart clip
  26793. this._loopCount = -1; // forget previous loops
  26794. this._startTime = null; // forget scheduling
  26795. return this.stopFading().stopWarping();
  26796. };
  26797. _proto.isRunning = function isRunning() {
  26798. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  26799. } // return true when play has been called
  26800. ;
  26801. _proto.isScheduled = function isScheduled() {
  26802. return this._mixer._isActiveAction(this);
  26803. };
  26804. _proto.startAt = function startAt(time) {
  26805. this._startTime = time;
  26806. return this;
  26807. };
  26808. _proto.setLoop = function setLoop(mode, repetitions) {
  26809. this.loop = mode;
  26810. this.repetitions = repetitions;
  26811. return this;
  26812. } // Weight
  26813. // set the weight stopping any scheduled fading
  26814. // although .enabled = false yields an effective weight of zero, this
  26815. // method does *not* change .enabled, because it would be confusing
  26816. ;
  26817. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  26818. this.weight = weight; // note: same logic as when updated at runtime
  26819. this._effectiveWeight = this.enabled ? weight : 0;
  26820. return this.stopFading();
  26821. } // return the weight considering fading and .enabled
  26822. ;
  26823. _proto.getEffectiveWeight = function getEffectiveWeight() {
  26824. return this._effectiveWeight;
  26825. };
  26826. _proto.fadeIn = function fadeIn(duration) {
  26827. return this._scheduleFading(duration, 0, 1);
  26828. };
  26829. _proto.fadeOut = function fadeOut(duration) {
  26830. return this._scheduleFading(duration, 1, 0);
  26831. };
  26832. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  26833. fadeOutAction.fadeOut(duration);
  26834. this.fadeIn(duration);
  26835. if (warp) {
  26836. var fadeInDuration = this._clip.duration,
  26837. fadeOutDuration = fadeOutAction._clip.duration,
  26838. startEndRatio = fadeOutDuration / fadeInDuration,
  26839. endStartRatio = fadeInDuration / fadeOutDuration;
  26840. fadeOutAction.warp(1.0, startEndRatio, duration);
  26841. this.warp(endStartRatio, 1.0, duration);
  26842. }
  26843. return this;
  26844. };
  26845. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  26846. return fadeInAction.crossFadeFrom(this, duration, warp);
  26847. };
  26848. _proto.stopFading = function stopFading() {
  26849. var weightInterpolant = this._weightInterpolant;
  26850. if (weightInterpolant !== null) {
  26851. this._weightInterpolant = null;
  26852. this._mixer._takeBackControlInterpolant(weightInterpolant);
  26853. }
  26854. return this;
  26855. } // Time Scale Control
  26856. // set the time scale stopping any scheduled warping
  26857. // although .paused = true yields an effective time scale of zero, this
  26858. // method does *not* change .paused, because it would be confusing
  26859. ;
  26860. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  26861. this.timeScale = timeScale;
  26862. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26863. return this.stopWarping();
  26864. } // return the time scale considering warping and .paused
  26865. ;
  26866. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  26867. return this._effectiveTimeScale;
  26868. };
  26869. _proto.setDuration = function setDuration(duration) {
  26870. this.timeScale = this._clip.duration / duration;
  26871. return this.stopWarping();
  26872. };
  26873. _proto.syncWith = function syncWith(action) {
  26874. this.time = action.time;
  26875. this.timeScale = action.timeScale;
  26876. return this.stopWarping();
  26877. };
  26878. _proto.halt = function halt(duration) {
  26879. return this.warp(this._effectiveTimeScale, 0, duration);
  26880. };
  26881. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  26882. var mixer = this._mixer,
  26883. now = mixer.time,
  26884. timeScale = this.timeScale;
  26885. var interpolant = this._timeScaleInterpolant;
  26886. if (interpolant === null) {
  26887. interpolant = mixer._lendControlInterpolant();
  26888. this._timeScaleInterpolant = interpolant;
  26889. }
  26890. var times = interpolant.parameterPositions,
  26891. values = interpolant.sampleValues;
  26892. times[0] = now;
  26893. times[1] = now + duration;
  26894. values[0] = startTimeScale / timeScale;
  26895. values[1] = endTimeScale / timeScale;
  26896. return this;
  26897. };
  26898. _proto.stopWarping = function stopWarping() {
  26899. var timeScaleInterpolant = this._timeScaleInterpolant;
  26900. if (timeScaleInterpolant !== null) {
  26901. this._timeScaleInterpolant = null;
  26902. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  26903. }
  26904. return this;
  26905. } // Object Accessors
  26906. ;
  26907. _proto.getMixer = function getMixer() {
  26908. return this._mixer;
  26909. };
  26910. _proto.getClip = function getClip() {
  26911. return this._clip;
  26912. };
  26913. _proto.getRoot = function getRoot() {
  26914. return this._localRoot || this._mixer._root;
  26915. } // Interna
  26916. ;
  26917. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  26918. // called by the mixer
  26919. if (!this.enabled) {
  26920. // call ._updateWeight() to update ._effectiveWeight
  26921. this._updateWeight(time);
  26922. return;
  26923. }
  26924. var startTime = this._startTime;
  26925. if (startTime !== null) {
  26926. // check for scheduled start of action
  26927. var timeRunning = (time - startTime) * timeDirection;
  26928. if (timeRunning < 0 || timeDirection === 0) {
  26929. return; // yet to come / don't decide when delta = 0
  26930. } // start
  26931. this._startTime = null; // unschedule
  26932. deltaTime = timeDirection * timeRunning;
  26933. } // apply time scale and advance time
  26934. deltaTime *= this._updateTimeScale(time);
  26935. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  26936. // an effective weight of 0
  26937. var weight = this._updateWeight(time);
  26938. if (weight > 0) {
  26939. var _interpolants = this._interpolants;
  26940. var propertyMixers = this._propertyBindings;
  26941. switch (this.blendMode) {
  26942. case AdditiveAnimationBlendMode:
  26943. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  26944. _interpolants[j].evaluate(clipTime);
  26945. propertyMixers[j].accumulateAdditive(weight);
  26946. }
  26947. break;
  26948. case NormalAnimationBlendMode:
  26949. default:
  26950. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  26951. _interpolants[_j].evaluate(clipTime);
  26952. propertyMixers[_j].accumulate(accuIndex, weight);
  26953. }
  26954. }
  26955. }
  26956. };
  26957. _proto._updateWeight = function _updateWeight(time) {
  26958. var weight = 0;
  26959. if (this.enabled) {
  26960. weight = this.weight;
  26961. var interpolant = this._weightInterpolant;
  26962. if (interpolant !== null) {
  26963. var interpolantValue = interpolant.evaluate(time)[0];
  26964. weight *= interpolantValue;
  26965. if (time > interpolant.parameterPositions[1]) {
  26966. this.stopFading();
  26967. if (interpolantValue === 0) {
  26968. // faded out, disable
  26969. this.enabled = false;
  26970. }
  26971. }
  26972. }
  26973. }
  26974. this._effectiveWeight = weight;
  26975. return weight;
  26976. };
  26977. _proto._updateTimeScale = function _updateTimeScale(time) {
  26978. var timeScale = 0;
  26979. if (!this.paused) {
  26980. timeScale = this.timeScale;
  26981. var interpolant = this._timeScaleInterpolant;
  26982. if (interpolant !== null) {
  26983. var interpolantValue = interpolant.evaluate(time)[0];
  26984. timeScale *= interpolantValue;
  26985. if (time > interpolant.parameterPositions[1]) {
  26986. this.stopWarping();
  26987. if (timeScale === 0) {
  26988. // motion has halted, pause
  26989. this.paused = true;
  26990. } else {
  26991. // warp done - apply final time scale
  26992. this.timeScale = timeScale;
  26993. }
  26994. }
  26995. }
  26996. }
  26997. this._effectiveTimeScale = timeScale;
  26998. return timeScale;
  26999. };
  27000. _proto._updateTime = function _updateTime(deltaTime) {
  27001. var duration = this._clip.duration;
  27002. var loop = this.loop;
  27003. var time = this.time + deltaTime;
  27004. var loopCount = this._loopCount;
  27005. var pingPong = loop === LoopPingPong;
  27006. if (deltaTime === 0) {
  27007. if (loopCount === -1) return time;
  27008. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  27009. }
  27010. if (loop === LoopOnce) {
  27011. if (loopCount === -1) {
  27012. // just started
  27013. this._loopCount = 0;
  27014. this._setEndings(true, true, false);
  27015. }
  27016. handle_stop: {
  27017. if (time >= duration) {
  27018. time = duration;
  27019. } else if (time < 0) {
  27020. time = 0;
  27021. } else {
  27022. this.time = time;
  27023. break handle_stop;
  27024. }
  27025. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  27026. this.time = time;
  27027. this._mixer.dispatchEvent({
  27028. type: 'finished',
  27029. action: this,
  27030. direction: deltaTime < 0 ? -1 : 1
  27031. });
  27032. }
  27033. } else {
  27034. // repetitive Repeat or PingPong
  27035. if (loopCount === -1) {
  27036. // just started
  27037. if (deltaTime >= 0) {
  27038. loopCount = 0;
  27039. this._setEndings(true, this.repetitions === 0, pingPong);
  27040. } else {
  27041. // when looping in reverse direction, the initial
  27042. // transition through zero counts as a repetition,
  27043. // so leave loopCount at -1
  27044. this._setEndings(this.repetitions === 0, true, pingPong);
  27045. }
  27046. }
  27047. if (time >= duration || time < 0) {
  27048. // wrap around
  27049. var loopDelta = Math.floor(time / duration); // signed
  27050. time -= duration * loopDelta;
  27051. loopCount += Math.abs(loopDelta);
  27052. var pending = this.repetitions - loopCount;
  27053. if (pending <= 0) {
  27054. // have to stop (switch state, clamp time, fire event)
  27055. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  27056. time = deltaTime > 0 ? duration : 0;
  27057. this.time = time;
  27058. this._mixer.dispatchEvent({
  27059. type: 'finished',
  27060. action: this,
  27061. direction: deltaTime > 0 ? 1 : -1
  27062. });
  27063. } else {
  27064. // keep running
  27065. if (pending === 1) {
  27066. // entering the last round
  27067. var atStart = deltaTime < 0;
  27068. this._setEndings(atStart, !atStart, pingPong);
  27069. } else {
  27070. this._setEndings(false, false, pingPong);
  27071. }
  27072. this._loopCount = loopCount;
  27073. this.time = time;
  27074. this._mixer.dispatchEvent({
  27075. type: 'loop',
  27076. action: this,
  27077. loopDelta: loopDelta
  27078. });
  27079. }
  27080. } else {
  27081. this.time = time;
  27082. }
  27083. if (pingPong && (loopCount & 1) === 1) {
  27084. // invert time for the "pong round"
  27085. return duration - time;
  27086. }
  27087. }
  27088. return time;
  27089. };
  27090. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  27091. var settings = this._interpolantSettings;
  27092. if (pingPong) {
  27093. settings.endingStart = ZeroSlopeEnding;
  27094. settings.endingEnd = ZeroSlopeEnding;
  27095. } else {
  27096. // assuming for LoopOnce atStart == atEnd == true
  27097. if (atStart) {
  27098. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27099. } else {
  27100. settings.endingStart = WrapAroundEnding;
  27101. }
  27102. if (atEnd) {
  27103. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27104. } else {
  27105. settings.endingEnd = WrapAroundEnding;
  27106. }
  27107. }
  27108. };
  27109. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  27110. var mixer = this._mixer,
  27111. now = mixer.time;
  27112. var interpolant = this._weightInterpolant;
  27113. if (interpolant === null) {
  27114. interpolant = mixer._lendControlInterpolant();
  27115. this._weightInterpolant = interpolant;
  27116. }
  27117. var times = interpolant.parameterPositions,
  27118. values = interpolant.sampleValues;
  27119. times[0] = now;
  27120. values[0] = weightNow;
  27121. times[1] = now + duration;
  27122. values[1] = weightThen;
  27123. return this;
  27124. };
  27125. return AnimationAction;
  27126. }();
  27127. function AnimationMixer(root) {
  27128. this._root = root;
  27129. this._initMemoryManager();
  27130. this._accuIndex = 0;
  27131. this.time = 0;
  27132. this.timeScale = 1.0;
  27133. }
  27134. AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  27135. constructor: AnimationMixer,
  27136. _bindAction: function _bindAction(action, prototypeAction) {
  27137. var root = action._localRoot || this._root,
  27138. tracks = action._clip.tracks,
  27139. nTracks = tracks.length,
  27140. bindings = action._propertyBindings,
  27141. interpolants = action._interpolants,
  27142. rootUuid = root.uuid,
  27143. bindingsByRoot = this._bindingsByRootAndName;
  27144. var bindingsByName = bindingsByRoot[rootUuid];
  27145. if (bindingsByName === undefined) {
  27146. bindingsByName = {};
  27147. bindingsByRoot[rootUuid] = bindingsByName;
  27148. }
  27149. for (var i = 0; i !== nTracks; ++i) {
  27150. var track = tracks[i],
  27151. trackName = track.name;
  27152. var binding = bindingsByName[trackName];
  27153. if (binding !== undefined) {
  27154. bindings[i] = binding;
  27155. } else {
  27156. binding = bindings[i];
  27157. if (binding !== undefined) {
  27158. // existing binding, make sure the cache knows
  27159. if (binding._cacheIndex === null) {
  27160. ++binding.referenceCount;
  27161. this._addInactiveBinding(binding, rootUuid, trackName);
  27162. }
  27163. continue;
  27164. }
  27165. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  27166. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  27167. ++binding.referenceCount;
  27168. this._addInactiveBinding(binding, rootUuid, trackName);
  27169. bindings[i] = binding;
  27170. }
  27171. interpolants[i].resultBuffer = binding.buffer;
  27172. }
  27173. },
  27174. _activateAction: function _activateAction(action) {
  27175. if (!this._isActiveAction(action)) {
  27176. if (action._cacheIndex === null) {
  27177. // this action has been forgotten by the cache, but the user
  27178. // appears to be still using it -> rebind
  27179. var rootUuid = (action._localRoot || this._root).uuid,
  27180. clipUuid = action._clip.uuid,
  27181. actionsForClip = this._actionsByClip[clipUuid];
  27182. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  27183. this._addInactiveAction(action, clipUuid, rootUuid);
  27184. }
  27185. var bindings = action._propertyBindings; // increment reference counts / sort out state
  27186. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27187. var binding = bindings[i];
  27188. if (binding.useCount++ === 0) {
  27189. this._lendBinding(binding);
  27190. binding.saveOriginalState();
  27191. }
  27192. }
  27193. this._lendAction(action);
  27194. }
  27195. },
  27196. _deactivateAction: function _deactivateAction(action) {
  27197. if (this._isActiveAction(action)) {
  27198. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  27199. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27200. var binding = bindings[i];
  27201. if (--binding.useCount === 0) {
  27202. binding.restoreOriginalState();
  27203. this._takeBackBinding(binding);
  27204. }
  27205. }
  27206. this._takeBackAction(action);
  27207. }
  27208. },
  27209. // Memory manager
  27210. _initMemoryManager: function _initMemoryManager() {
  27211. this._actions = []; // 'nActiveActions' followed by inactive ones
  27212. this._nActiveActions = 0;
  27213. this._actionsByClip = {}; // inside:
  27214. // {
  27215. // knownActions: Array< AnimationAction > - used as prototypes
  27216. // actionByRoot: AnimationAction - lookup
  27217. // }
  27218. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  27219. this._nActiveBindings = 0;
  27220. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  27221. this._controlInterpolants = []; // same game as above
  27222. this._nActiveControlInterpolants = 0;
  27223. var scope = this;
  27224. this.stats = {
  27225. actions: {
  27226. get total() {
  27227. return scope._actions.length;
  27228. },
  27229. get inUse() {
  27230. return scope._nActiveActions;
  27231. }
  27232. },
  27233. bindings: {
  27234. get total() {
  27235. return scope._bindings.length;
  27236. },
  27237. get inUse() {
  27238. return scope._nActiveBindings;
  27239. }
  27240. },
  27241. controlInterpolants: {
  27242. get total() {
  27243. return scope._controlInterpolants.length;
  27244. },
  27245. get inUse() {
  27246. return scope._nActiveControlInterpolants;
  27247. }
  27248. }
  27249. };
  27250. },
  27251. // Memory management for AnimationAction objects
  27252. _isActiveAction: function _isActiveAction(action) {
  27253. var index = action._cacheIndex;
  27254. return index !== null && index < this._nActiveActions;
  27255. },
  27256. _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
  27257. var actions = this._actions,
  27258. actionsByClip = this._actionsByClip;
  27259. var actionsForClip = actionsByClip[clipUuid];
  27260. if (actionsForClip === undefined) {
  27261. actionsForClip = {
  27262. knownActions: [action],
  27263. actionByRoot: {}
  27264. };
  27265. action._byClipCacheIndex = 0;
  27266. actionsByClip[clipUuid] = actionsForClip;
  27267. } else {
  27268. var knownActions = actionsForClip.knownActions;
  27269. action._byClipCacheIndex = knownActions.length;
  27270. knownActions.push(action);
  27271. }
  27272. action._cacheIndex = actions.length;
  27273. actions.push(action);
  27274. actionsForClip.actionByRoot[rootUuid] = action;
  27275. },
  27276. _removeInactiveAction: function _removeInactiveAction(action) {
  27277. var actions = this._actions,
  27278. lastInactiveAction = actions[actions.length - 1],
  27279. cacheIndex = action._cacheIndex;
  27280. lastInactiveAction._cacheIndex = cacheIndex;
  27281. actions[cacheIndex] = lastInactiveAction;
  27282. actions.pop();
  27283. action._cacheIndex = null;
  27284. var clipUuid = action._clip.uuid,
  27285. actionsByClip = this._actionsByClip,
  27286. actionsForClip = actionsByClip[clipUuid],
  27287. knownActionsForClip = actionsForClip.knownActions,
  27288. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  27289. byClipCacheIndex = action._byClipCacheIndex;
  27290. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  27291. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  27292. knownActionsForClip.pop();
  27293. action._byClipCacheIndex = null;
  27294. var actionByRoot = actionsForClip.actionByRoot,
  27295. rootUuid = (action._localRoot || this._root).uuid;
  27296. delete actionByRoot[rootUuid];
  27297. if (knownActionsForClip.length === 0) {
  27298. delete actionsByClip[clipUuid];
  27299. }
  27300. this._removeInactiveBindingsForAction(action);
  27301. },
  27302. _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
  27303. var bindings = action._propertyBindings;
  27304. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27305. var binding = bindings[i];
  27306. if (--binding.referenceCount === 0) {
  27307. this._removeInactiveBinding(binding);
  27308. }
  27309. }
  27310. },
  27311. _lendAction: function _lendAction(action) {
  27312. // [ active actions | inactive actions ]
  27313. // [ active actions >| inactive actions ]
  27314. // s a
  27315. // <-swap->
  27316. // a s
  27317. var actions = this._actions,
  27318. prevIndex = action._cacheIndex,
  27319. lastActiveIndex = this._nActiveActions++,
  27320. firstInactiveAction = actions[lastActiveIndex];
  27321. action._cacheIndex = lastActiveIndex;
  27322. actions[lastActiveIndex] = action;
  27323. firstInactiveAction._cacheIndex = prevIndex;
  27324. actions[prevIndex] = firstInactiveAction;
  27325. },
  27326. _takeBackAction: function _takeBackAction(action) {
  27327. // [ active actions | inactive actions ]
  27328. // [ active actions |< inactive actions ]
  27329. // a s
  27330. // <-swap->
  27331. // s a
  27332. var actions = this._actions,
  27333. prevIndex = action._cacheIndex,
  27334. firstInactiveIndex = --this._nActiveActions,
  27335. lastActiveAction = actions[firstInactiveIndex];
  27336. action._cacheIndex = firstInactiveIndex;
  27337. actions[firstInactiveIndex] = action;
  27338. lastActiveAction._cacheIndex = prevIndex;
  27339. actions[prevIndex] = lastActiveAction;
  27340. },
  27341. // Memory management for PropertyMixer objects
  27342. _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
  27343. var bindingsByRoot = this._bindingsByRootAndName,
  27344. bindings = this._bindings;
  27345. var bindingByName = bindingsByRoot[rootUuid];
  27346. if (bindingByName === undefined) {
  27347. bindingByName = {};
  27348. bindingsByRoot[rootUuid] = bindingByName;
  27349. }
  27350. bindingByName[trackName] = binding;
  27351. binding._cacheIndex = bindings.length;
  27352. bindings.push(binding);
  27353. },
  27354. _removeInactiveBinding: function _removeInactiveBinding(binding) {
  27355. var bindings = this._bindings,
  27356. propBinding = binding.binding,
  27357. rootUuid = propBinding.rootNode.uuid,
  27358. trackName = propBinding.path,
  27359. bindingsByRoot = this._bindingsByRootAndName,
  27360. bindingByName = bindingsByRoot[rootUuid],
  27361. lastInactiveBinding = bindings[bindings.length - 1],
  27362. cacheIndex = binding._cacheIndex;
  27363. lastInactiveBinding._cacheIndex = cacheIndex;
  27364. bindings[cacheIndex] = lastInactiveBinding;
  27365. bindings.pop();
  27366. delete bindingByName[trackName];
  27367. if (Object.keys(bindingByName).length === 0) {
  27368. delete bindingsByRoot[rootUuid];
  27369. }
  27370. },
  27371. _lendBinding: function _lendBinding(binding) {
  27372. var bindings = this._bindings,
  27373. prevIndex = binding._cacheIndex,
  27374. lastActiveIndex = this._nActiveBindings++,
  27375. firstInactiveBinding = bindings[lastActiveIndex];
  27376. binding._cacheIndex = lastActiveIndex;
  27377. bindings[lastActiveIndex] = binding;
  27378. firstInactiveBinding._cacheIndex = prevIndex;
  27379. bindings[prevIndex] = firstInactiveBinding;
  27380. },
  27381. _takeBackBinding: function _takeBackBinding(binding) {
  27382. var bindings = this._bindings,
  27383. prevIndex = binding._cacheIndex,
  27384. firstInactiveIndex = --this._nActiveBindings,
  27385. lastActiveBinding = bindings[firstInactiveIndex];
  27386. binding._cacheIndex = firstInactiveIndex;
  27387. bindings[firstInactiveIndex] = binding;
  27388. lastActiveBinding._cacheIndex = prevIndex;
  27389. bindings[prevIndex] = lastActiveBinding;
  27390. },
  27391. // Memory management of Interpolants for weight and time scale
  27392. _lendControlInterpolant: function _lendControlInterpolant() {
  27393. var interpolants = this._controlInterpolants,
  27394. lastActiveIndex = this._nActiveControlInterpolants++;
  27395. var interpolant = interpolants[lastActiveIndex];
  27396. if (interpolant === undefined) {
  27397. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  27398. interpolant.__cacheIndex = lastActiveIndex;
  27399. interpolants[lastActiveIndex] = interpolant;
  27400. }
  27401. return interpolant;
  27402. },
  27403. _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
  27404. var interpolants = this._controlInterpolants,
  27405. prevIndex = interpolant.__cacheIndex,
  27406. firstInactiveIndex = --this._nActiveControlInterpolants,
  27407. lastActiveInterpolant = interpolants[firstInactiveIndex];
  27408. interpolant.__cacheIndex = firstInactiveIndex;
  27409. interpolants[firstInactiveIndex] = interpolant;
  27410. lastActiveInterpolant.__cacheIndex = prevIndex;
  27411. interpolants[prevIndex] = lastActiveInterpolant;
  27412. },
  27413. _controlInterpolantsResultBuffer: new Float32Array(1),
  27414. // return an action for a clip optionally using a custom root target
  27415. // object (this method allocates a lot of dynamic memory in case a
  27416. // previously unknown clip/root combination is specified)
  27417. clipAction: function clipAction(clip, optionalRoot, blendMode) {
  27418. var root = optionalRoot || this._root,
  27419. rootUuid = root.uuid;
  27420. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  27421. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  27422. var actionsForClip = this._actionsByClip[clipUuid];
  27423. var prototypeAction = null;
  27424. if (blendMode === undefined) {
  27425. if (clipObject !== null) {
  27426. blendMode = clipObject.blendMode;
  27427. } else {
  27428. blendMode = NormalAnimationBlendMode;
  27429. }
  27430. }
  27431. if (actionsForClip !== undefined) {
  27432. var existingAction = actionsForClip.actionByRoot[rootUuid];
  27433. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  27434. return existingAction;
  27435. } // we know the clip, so we don't have to parse all
  27436. // the bindings again but can just copy
  27437. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  27438. if (clipObject === null) clipObject = prototypeAction._clip;
  27439. } // clip must be known when specified via string
  27440. if (clipObject === null) return null; // allocate all resources required to run it
  27441. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  27442. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  27443. this._addInactiveAction(newAction, clipUuid, rootUuid);
  27444. return newAction;
  27445. },
  27446. // get an existing action
  27447. existingAction: function existingAction(clip, optionalRoot) {
  27448. var root = optionalRoot || this._root,
  27449. rootUuid = root.uuid,
  27450. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  27451. clipUuid = clipObject ? clipObject.uuid : clip,
  27452. actionsForClip = this._actionsByClip[clipUuid];
  27453. if (actionsForClip !== undefined) {
  27454. return actionsForClip.actionByRoot[rootUuid] || null;
  27455. }
  27456. return null;
  27457. },
  27458. // deactivates all previously scheduled actions
  27459. stopAllAction: function stopAllAction() {
  27460. var actions = this._actions,
  27461. nActions = this._nActiveActions;
  27462. for (var i = nActions - 1; i >= 0; --i) {
  27463. actions[i].stop();
  27464. }
  27465. return this;
  27466. },
  27467. // advance the time and update apply the animation
  27468. update: function update(deltaTime) {
  27469. deltaTime *= this.timeScale;
  27470. var actions = this._actions,
  27471. nActions = this._nActiveActions,
  27472. time = this.time += deltaTime,
  27473. timeDirection = Math.sign(deltaTime),
  27474. accuIndex = this._accuIndex ^= 1; // run active actions
  27475. for (var i = 0; i !== nActions; ++i) {
  27476. var action = actions[i];
  27477. action._update(time, deltaTime, timeDirection, accuIndex);
  27478. } // update scene graph
  27479. var bindings = this._bindings,
  27480. nBindings = this._nActiveBindings;
  27481. for (var _i = 0; _i !== nBindings; ++_i) {
  27482. bindings[_i].apply(accuIndex);
  27483. }
  27484. return this;
  27485. },
  27486. // Allows you to seek to a specific time in an animation.
  27487. setTime: function setTime(timeInSeconds) {
  27488. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27489. for (var i = 0; i < this._actions.length; i++) {
  27490. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27491. }
  27492. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  27493. },
  27494. // return this mixer's root target object
  27495. getRoot: function getRoot() {
  27496. return this._root;
  27497. },
  27498. // free all resources specific to a particular clip
  27499. uncacheClip: function uncacheClip(clip) {
  27500. var actions = this._actions,
  27501. clipUuid = clip.uuid,
  27502. actionsByClip = this._actionsByClip,
  27503. actionsForClip = actionsByClip[clipUuid];
  27504. if (actionsForClip !== undefined) {
  27505. // note: just calling _removeInactiveAction would mess up the
  27506. // iteration state and also require updating the state we can
  27507. // just throw away
  27508. var actionsToRemove = actionsForClip.knownActions;
  27509. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  27510. var action = actionsToRemove[i];
  27511. this._deactivateAction(action);
  27512. var cacheIndex = action._cacheIndex,
  27513. lastInactiveAction = actions[actions.length - 1];
  27514. action._cacheIndex = null;
  27515. action._byClipCacheIndex = null;
  27516. lastInactiveAction._cacheIndex = cacheIndex;
  27517. actions[cacheIndex] = lastInactiveAction;
  27518. actions.pop();
  27519. this._removeInactiveBindingsForAction(action);
  27520. }
  27521. delete actionsByClip[clipUuid];
  27522. }
  27523. },
  27524. // free all resources specific to a particular root target object
  27525. uncacheRoot: function uncacheRoot(root) {
  27526. var rootUuid = root.uuid,
  27527. actionsByClip = this._actionsByClip;
  27528. for (var clipUuid in actionsByClip) {
  27529. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  27530. action = actionByRoot[rootUuid];
  27531. if (action !== undefined) {
  27532. this._deactivateAction(action);
  27533. this._removeInactiveAction(action);
  27534. }
  27535. }
  27536. var bindingsByRoot = this._bindingsByRootAndName,
  27537. bindingByName = bindingsByRoot[rootUuid];
  27538. if (bindingByName !== undefined) {
  27539. for (var trackName in bindingByName) {
  27540. var binding = bindingByName[trackName];
  27541. binding.restoreOriginalState();
  27542. this._removeInactiveBinding(binding);
  27543. }
  27544. }
  27545. },
  27546. // remove a targeted clip from the cache
  27547. uncacheAction: function uncacheAction(clip, optionalRoot) {
  27548. var action = this.existingAction(clip, optionalRoot);
  27549. if (action !== null) {
  27550. this._deactivateAction(action);
  27551. this._removeInactiveAction(action);
  27552. }
  27553. }
  27554. });
  27555. var Uniform = /*#__PURE__*/function () {
  27556. function Uniform(value) {
  27557. if (typeof value === 'string') {
  27558. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  27559. value = arguments[1];
  27560. }
  27561. this.value = value;
  27562. }
  27563. var _proto = Uniform.prototype;
  27564. _proto.clone = function clone() {
  27565. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  27566. };
  27567. return Uniform;
  27568. }();
  27569. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27570. InterleavedBuffer.call(this, array, stride);
  27571. this.meshPerAttribute = meshPerAttribute || 1;
  27572. }
  27573. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27574. constructor: InstancedInterleavedBuffer,
  27575. isInstancedInterleavedBuffer: true,
  27576. copy: function copy(source) {
  27577. InterleavedBuffer.prototype.copy.call(this, source);
  27578. this.meshPerAttribute = source.meshPerAttribute;
  27579. return this;
  27580. },
  27581. clone: function clone(data) {
  27582. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27583. ib.meshPerAttribute = this.meshPerAttribute;
  27584. return ib;
  27585. },
  27586. toJSON: function toJSON(data) {
  27587. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27588. json.isInstancedInterleavedBuffer = true;
  27589. json.meshPerAttribute = this.meshPerAttribute;
  27590. return json;
  27591. }
  27592. });
  27593. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27594. this.buffer = buffer;
  27595. this.type = type;
  27596. this.itemSize = itemSize;
  27597. this.elementSize = elementSize;
  27598. this.count = count;
  27599. this.version = 0;
  27600. }
  27601. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27602. set: function set(value) {
  27603. if (value === true) this.version++;
  27604. }
  27605. });
  27606. Object.assign(GLBufferAttribute.prototype, {
  27607. isGLBufferAttribute: true,
  27608. setBuffer: function setBuffer(buffer) {
  27609. this.buffer = buffer;
  27610. return this;
  27611. },
  27612. setType: function setType(type, elementSize) {
  27613. this.type = type;
  27614. this.elementSize = elementSize;
  27615. return this;
  27616. },
  27617. setItemSize: function setItemSize(itemSize) {
  27618. this.itemSize = itemSize;
  27619. return this;
  27620. },
  27621. setCount: function setCount(count) {
  27622. this.count = count;
  27623. return this;
  27624. }
  27625. });
  27626. function Raycaster(origin, direction, near, far) {
  27627. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27628. this.near = near || 0;
  27629. this.far = far || Infinity;
  27630. this.camera = null;
  27631. this.layers = new Layers();
  27632. this.params = {
  27633. Mesh: {},
  27634. Line: {
  27635. threshold: 1
  27636. },
  27637. LOD: {},
  27638. Points: {
  27639. threshold: 1
  27640. },
  27641. Sprite: {}
  27642. };
  27643. Object.defineProperties(this.params, {
  27644. PointCloud: {
  27645. get: function get() {
  27646. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27647. return this.Points;
  27648. }
  27649. }
  27650. });
  27651. }
  27652. function ascSort(a, b) {
  27653. return a.distance - b.distance;
  27654. }
  27655. function _intersectObject(object, raycaster, intersects, recursive) {
  27656. if (object.layers.test(raycaster.layers)) {
  27657. object.raycast(raycaster, intersects);
  27658. }
  27659. if (recursive === true) {
  27660. var children = object.children;
  27661. for (var i = 0, l = children.length; i < l; i++) {
  27662. _intersectObject(children[i], raycaster, intersects, true);
  27663. }
  27664. }
  27665. }
  27666. Object.assign(Raycaster.prototype, {
  27667. set: function set(origin, direction) {
  27668. // direction is assumed to be normalized (for accurate distance calculations)
  27669. this.ray.set(origin, direction);
  27670. },
  27671. setFromCamera: function setFromCamera(coords, camera) {
  27672. if (camera && camera.isPerspectiveCamera) {
  27673. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27674. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27675. this.camera = camera;
  27676. } else if (camera && camera.isOrthographicCamera) {
  27677. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27678. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27679. this.camera = camera;
  27680. } else {
  27681. console.error('THREE.Raycaster: Unsupported camera type: ' + camera.type);
  27682. }
  27683. },
  27684. intersectObject: function intersectObject(object, recursive, optionalTarget) {
  27685. var intersects = optionalTarget || [];
  27686. _intersectObject(object, this, intersects, recursive);
  27687. intersects.sort(ascSort);
  27688. return intersects;
  27689. },
  27690. intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
  27691. var intersects = optionalTarget || [];
  27692. if (Array.isArray(objects) === false) {
  27693. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  27694. return intersects;
  27695. }
  27696. for (var i = 0, l = objects.length; i < l; i++) {
  27697. _intersectObject(objects[i], this, intersects, recursive);
  27698. }
  27699. intersects.sort(ascSort);
  27700. return intersects;
  27701. }
  27702. });
  27703. /**
  27704. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27705. *
  27706. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27707. * The azimuthal angle (theta) is measured from the positive z-axis.
  27708. */
  27709. var Spherical = /*#__PURE__*/function () {
  27710. function Spherical(radius, phi, theta) {
  27711. if (radius === void 0) {
  27712. radius = 1;
  27713. }
  27714. if (phi === void 0) {
  27715. phi = 0;
  27716. }
  27717. if (theta === void 0) {
  27718. theta = 0;
  27719. }
  27720. this.radius = radius;
  27721. this.phi = phi; // polar angle
  27722. this.theta = theta; // azimuthal angle
  27723. return this;
  27724. }
  27725. var _proto = Spherical.prototype;
  27726. _proto.set = function set(radius, phi, theta) {
  27727. this.radius = radius;
  27728. this.phi = phi;
  27729. this.theta = theta;
  27730. return this;
  27731. };
  27732. _proto.copy = function copy(other) {
  27733. this.radius = other.radius;
  27734. this.phi = other.phi;
  27735. this.theta = other.theta;
  27736. return this;
  27737. } // restrict phi to be betwee EPS and PI-EPS
  27738. ;
  27739. _proto.makeSafe = function makeSafe() {
  27740. var EPS = 0.000001;
  27741. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  27742. return this;
  27743. };
  27744. _proto.setFromVector3 = function setFromVector3(v) {
  27745. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27746. };
  27747. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27748. this.radius = Math.sqrt(x * x + y * y + z * z);
  27749. if (this.radius === 0) {
  27750. this.theta = 0;
  27751. this.phi = 0;
  27752. } else {
  27753. this.theta = Math.atan2(x, z);
  27754. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  27755. }
  27756. return this;
  27757. };
  27758. _proto.clone = function clone() {
  27759. return new this.constructor().copy(this);
  27760. };
  27761. return Spherical;
  27762. }();
  27763. /**
  27764. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27765. */
  27766. var Cylindrical = /*#__PURE__*/function () {
  27767. function Cylindrical(radius, theta, y) {
  27768. if (radius === void 0) {
  27769. radius = 1;
  27770. }
  27771. if (theta === void 0) {
  27772. theta = 0;
  27773. }
  27774. if (y === void 0) {
  27775. y = 0;
  27776. }
  27777. this.radius = radius; // distance from the origin to a point in the x-z plane
  27778. this.theta = theta; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27779. this.y = y; // height above the x-z plane
  27780. return this;
  27781. }
  27782. var _proto = Cylindrical.prototype;
  27783. _proto.set = function set(radius, theta, y) {
  27784. this.radius = radius;
  27785. this.theta = theta;
  27786. this.y = y;
  27787. return this;
  27788. };
  27789. _proto.copy = function copy(other) {
  27790. this.radius = other.radius;
  27791. this.theta = other.theta;
  27792. this.y = other.y;
  27793. return this;
  27794. };
  27795. _proto.setFromVector3 = function setFromVector3(v) {
  27796. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27797. };
  27798. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27799. this.radius = Math.sqrt(x * x + z * z);
  27800. this.theta = Math.atan2(x, z);
  27801. this.y = y;
  27802. return this;
  27803. };
  27804. _proto.clone = function clone() {
  27805. return new this.constructor().copy(this);
  27806. };
  27807. return Cylindrical;
  27808. }();
  27809. var _vector$8 = /*@__PURE__*/new Vector2();
  27810. var Box2 = /*#__PURE__*/function () {
  27811. function Box2(min, max) {
  27812. if (min === void 0) {
  27813. min = new Vector2(+Infinity, +Infinity);
  27814. }
  27815. if (max === void 0) {
  27816. max = new Vector2(-Infinity, -Infinity);
  27817. }
  27818. this.min = min;
  27819. this.max = max;
  27820. }
  27821. var _proto = Box2.prototype;
  27822. _proto.set = function set(min, max) {
  27823. this.min.copy(min);
  27824. this.max.copy(max);
  27825. return this;
  27826. };
  27827. _proto.setFromPoints = function setFromPoints(points) {
  27828. this.makeEmpty();
  27829. for (var i = 0, il = points.length; i < il; i++) {
  27830. this.expandByPoint(points[i]);
  27831. }
  27832. return this;
  27833. };
  27834. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  27835. var halfSize = _vector$8.copy(size).multiplyScalar(0.5);
  27836. this.min.copy(center).sub(halfSize);
  27837. this.max.copy(center).add(halfSize);
  27838. return this;
  27839. };
  27840. _proto.clone = function clone() {
  27841. return new this.constructor().copy(this);
  27842. };
  27843. _proto.copy = function copy(box) {
  27844. this.min.copy(box.min);
  27845. this.max.copy(box.max);
  27846. return this;
  27847. };
  27848. _proto.makeEmpty = function makeEmpty() {
  27849. this.min.x = this.min.y = +Infinity;
  27850. this.max.x = this.max.y = -Infinity;
  27851. return this;
  27852. };
  27853. _proto.isEmpty = function isEmpty() {
  27854. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27855. return this.max.x < this.min.x || this.max.y < this.min.y;
  27856. };
  27857. _proto.getCenter = function getCenter(target) {
  27858. if (target === undefined) {
  27859. console.warn('THREE.Box2: .getCenter() target is now required');
  27860. target = new Vector2();
  27861. }
  27862. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  27863. };
  27864. _proto.getSize = function getSize(target) {
  27865. if (target === undefined) {
  27866. console.warn('THREE.Box2: .getSize() target is now required');
  27867. target = new Vector2();
  27868. }
  27869. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  27870. };
  27871. _proto.expandByPoint = function expandByPoint(point) {
  27872. this.min.min(point);
  27873. this.max.max(point);
  27874. return this;
  27875. };
  27876. _proto.expandByVector = function expandByVector(vector) {
  27877. this.min.sub(vector);
  27878. this.max.add(vector);
  27879. return this;
  27880. };
  27881. _proto.expandByScalar = function expandByScalar(scalar) {
  27882. this.min.addScalar(-scalar);
  27883. this.max.addScalar(scalar);
  27884. return this;
  27885. };
  27886. _proto.containsPoint = function containsPoint(point) {
  27887. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  27888. };
  27889. _proto.containsBox = function containsBox(box) {
  27890. 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;
  27891. };
  27892. _proto.getParameter = function getParameter(point, target) {
  27893. // This can potentially have a divide by zero if the box
  27894. // has a size dimension of 0.
  27895. if (target === undefined) {
  27896. console.warn('THREE.Box2: .getParameter() target is now required');
  27897. target = new Vector2();
  27898. }
  27899. 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));
  27900. };
  27901. _proto.intersectsBox = function intersectsBox(box) {
  27902. // using 4 splitting planes to rule out intersections
  27903. 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;
  27904. };
  27905. _proto.clampPoint = function clampPoint(point, target) {
  27906. if (target === undefined) {
  27907. console.warn('THREE.Box2: .clampPoint() target is now required');
  27908. target = new Vector2();
  27909. }
  27910. return target.copy(point).clamp(this.min, this.max);
  27911. };
  27912. _proto.distanceToPoint = function distanceToPoint(point) {
  27913. var clampedPoint = _vector$8.copy(point).clamp(this.min, this.max);
  27914. return clampedPoint.sub(point).length();
  27915. };
  27916. _proto.intersect = function intersect(box) {
  27917. this.min.max(box.min);
  27918. this.max.min(box.max);
  27919. return this;
  27920. };
  27921. _proto.union = function union(box) {
  27922. this.min.min(box.min);
  27923. this.max.max(box.max);
  27924. return this;
  27925. };
  27926. _proto.translate = function translate(offset) {
  27927. this.min.add(offset);
  27928. this.max.add(offset);
  27929. return this;
  27930. };
  27931. _proto.equals = function equals(box) {
  27932. return box.min.equals(this.min) && box.max.equals(this.max);
  27933. };
  27934. return Box2;
  27935. }();
  27936. Box2.prototype.isBox2 = true;
  27937. var _startP = /*@__PURE__*/new Vector3();
  27938. var _startEnd = /*@__PURE__*/new Vector3();
  27939. var Line3 = /*#__PURE__*/function () {
  27940. function Line3(start, end) {
  27941. if (start === void 0) {
  27942. start = new Vector3();
  27943. }
  27944. if (end === void 0) {
  27945. end = new Vector3();
  27946. }
  27947. this.start = start;
  27948. this.end = end;
  27949. }
  27950. var _proto = Line3.prototype;
  27951. _proto.set = function set(start, end) {
  27952. this.start.copy(start);
  27953. this.end.copy(end);
  27954. return this;
  27955. };
  27956. _proto.copy = function copy(line) {
  27957. this.start.copy(line.start);
  27958. this.end.copy(line.end);
  27959. return this;
  27960. };
  27961. _proto.getCenter = function getCenter(target) {
  27962. if (target === undefined) {
  27963. console.warn('THREE.Line3: .getCenter() target is now required');
  27964. target = new Vector3();
  27965. }
  27966. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  27967. };
  27968. _proto.delta = function delta(target) {
  27969. if (target === undefined) {
  27970. console.warn('THREE.Line3: .delta() target is now required');
  27971. target = new Vector3();
  27972. }
  27973. return target.subVectors(this.end, this.start);
  27974. };
  27975. _proto.distanceSq = function distanceSq() {
  27976. return this.start.distanceToSquared(this.end);
  27977. };
  27978. _proto.distance = function distance() {
  27979. return this.start.distanceTo(this.end);
  27980. };
  27981. _proto.at = function at(t, target) {
  27982. if (target === undefined) {
  27983. console.warn('THREE.Line3: .at() target is now required');
  27984. target = new Vector3();
  27985. }
  27986. return this.delta(target).multiplyScalar(t).add(this.start);
  27987. };
  27988. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  27989. _startP.subVectors(point, this.start);
  27990. _startEnd.subVectors(this.end, this.start);
  27991. var startEnd2 = _startEnd.dot(_startEnd);
  27992. var startEnd_startP = _startEnd.dot(_startP);
  27993. var t = startEnd_startP / startEnd2;
  27994. if (clampToLine) {
  27995. t = MathUtils.clamp(t, 0, 1);
  27996. }
  27997. return t;
  27998. };
  27999. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  28000. var t = this.closestPointToPointParameter(point, clampToLine);
  28001. if (target === undefined) {
  28002. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  28003. target = new Vector3();
  28004. }
  28005. return this.delta(target).multiplyScalar(t).add(this.start);
  28006. };
  28007. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  28008. this.start.applyMatrix4(matrix);
  28009. this.end.applyMatrix4(matrix);
  28010. return this;
  28011. };
  28012. _proto.equals = function equals(line) {
  28013. return line.start.equals(this.start) && line.end.equals(this.end);
  28014. };
  28015. _proto.clone = function clone() {
  28016. return new this.constructor().copy(this);
  28017. };
  28018. return Line3;
  28019. }();
  28020. function ImmediateRenderObject(material) {
  28021. Object3D.call(this);
  28022. this.material = material;
  28023. this.render = function ()
  28024. /* renderCallback */
  28025. {};
  28026. this.hasPositions = false;
  28027. this.hasNormals = false;
  28028. this.hasColors = false;
  28029. this.hasUvs = false;
  28030. this.positionArray = null;
  28031. this.normalArray = null;
  28032. this.colorArray = null;
  28033. this.uvArray = null;
  28034. this.count = 0;
  28035. }
  28036. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  28037. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  28038. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  28039. var _vector$9 = /*@__PURE__*/new Vector3();
  28040. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  28041. _inheritsLoose(SpotLightHelper, _Object3D);
  28042. function SpotLightHelper(light, color) {
  28043. var _this;
  28044. _this = _Object3D.call(this) || this;
  28045. _this.light = light;
  28046. _this.light.updateMatrixWorld();
  28047. _this.matrix = light.matrixWorld;
  28048. _this.matrixAutoUpdate = false;
  28049. _this.color = color;
  28050. var geometry = new BufferGeometry();
  28051. 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];
  28052. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  28053. var p1 = i / l * Math.PI * 2;
  28054. var p2 = j / l * Math.PI * 2;
  28055. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  28056. }
  28057. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28058. var material = new LineBasicMaterial({
  28059. fog: false,
  28060. toneMapped: false
  28061. });
  28062. _this.cone = new LineSegments(geometry, material);
  28063. _this.add(_this.cone);
  28064. _this.update();
  28065. return _this;
  28066. }
  28067. var _proto = SpotLightHelper.prototype;
  28068. _proto.dispose = function dispose() {
  28069. this.cone.geometry.dispose();
  28070. this.cone.material.dispose();
  28071. };
  28072. _proto.update = function update() {
  28073. this.light.updateMatrixWorld();
  28074. var coneLength = this.light.distance ? this.light.distance : 1000;
  28075. var coneWidth = coneLength * Math.tan(this.light.angle);
  28076. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  28077. _vector$9.setFromMatrixPosition(this.light.target.matrixWorld);
  28078. this.cone.lookAt(_vector$9);
  28079. if (this.color !== undefined) {
  28080. this.cone.material.color.set(this.color);
  28081. } else {
  28082. this.cone.material.color.copy(this.light.color);
  28083. }
  28084. };
  28085. return SpotLightHelper;
  28086. }(Object3D);
  28087. var _vector$a = /*@__PURE__*/new Vector3();
  28088. var _boneMatrix = /*@__PURE__*/new Matrix4();
  28089. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  28090. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  28091. _inheritsLoose(SkeletonHelper, _LineSegments);
  28092. function SkeletonHelper(object) {
  28093. var _this;
  28094. var bones = getBoneList(object);
  28095. var geometry = new BufferGeometry();
  28096. var vertices = [];
  28097. var colors = [];
  28098. var color1 = new Color(0, 0, 1);
  28099. var color2 = new Color(0, 1, 0);
  28100. for (var i = 0; i < bones.length; i++) {
  28101. var bone = bones[i];
  28102. if (bone.parent && bone.parent.isBone) {
  28103. vertices.push(0, 0, 0);
  28104. vertices.push(0, 0, 0);
  28105. colors.push(color1.r, color1.g, color1.b);
  28106. colors.push(color2.r, color2.g, color2.b);
  28107. }
  28108. }
  28109. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28110. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28111. var material = new LineBasicMaterial({
  28112. vertexColors: true,
  28113. depthTest: false,
  28114. depthWrite: false,
  28115. toneMapped: false,
  28116. transparent: true
  28117. });
  28118. _this = _LineSegments.call(this, geometry, material) || this;
  28119. _this.type = 'SkeletonHelper';
  28120. _this.isSkeletonHelper = true;
  28121. _this.root = object;
  28122. _this.bones = bones;
  28123. _this.matrix = object.matrixWorld;
  28124. _this.matrixAutoUpdate = false;
  28125. return _this;
  28126. }
  28127. var _proto = SkeletonHelper.prototype;
  28128. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28129. var bones = this.bones;
  28130. var geometry = this.geometry;
  28131. var position = geometry.getAttribute('position');
  28132. _matrixWorldInv.copy(this.root.matrixWorld).invert();
  28133. for (var i = 0, j = 0; i < bones.length; i++) {
  28134. var bone = bones[i];
  28135. if (bone.parent && bone.parent.isBone) {
  28136. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  28137. _vector$a.setFromMatrixPosition(_boneMatrix);
  28138. position.setXYZ(j, _vector$a.x, _vector$a.y, _vector$a.z);
  28139. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  28140. _vector$a.setFromMatrixPosition(_boneMatrix);
  28141. position.setXYZ(j + 1, _vector$a.x, _vector$a.y, _vector$a.z);
  28142. j += 2;
  28143. }
  28144. }
  28145. geometry.getAttribute('position').needsUpdate = true;
  28146. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28147. };
  28148. return SkeletonHelper;
  28149. }(LineSegments);
  28150. function getBoneList(object) {
  28151. var boneList = [];
  28152. if (object && object.isBone) {
  28153. boneList.push(object);
  28154. }
  28155. for (var i = 0; i < object.children.length; i++) {
  28156. boneList.push.apply(boneList, getBoneList(object.children[i]));
  28157. }
  28158. return boneList;
  28159. }
  28160. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  28161. _inheritsLoose(PointLightHelper, _Mesh);
  28162. function PointLightHelper(light, sphereSize, color) {
  28163. var _this;
  28164. var geometry = new SphereGeometry(sphereSize, 4, 2);
  28165. var material = new MeshBasicMaterial({
  28166. wireframe: true,
  28167. fog: false,
  28168. toneMapped: false
  28169. });
  28170. _this = _Mesh.call(this, geometry, material) || this;
  28171. _this.light = light;
  28172. _this.light.updateMatrixWorld();
  28173. _this.color = color;
  28174. _this.type = 'PointLightHelper';
  28175. _this.matrix = _this.light.matrixWorld;
  28176. _this.matrixAutoUpdate = false;
  28177. _this.update();
  28178. /*
  28179. // TODO: delete this comment?
  28180. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  28181. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  28182. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  28183. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  28184. const d = light.distance;
  28185. if ( d === 0.0 ) {
  28186. this.lightDistance.visible = false;
  28187. } else {
  28188. this.lightDistance.scale.set( d, d, d );
  28189. }
  28190. this.add( this.lightDistance );
  28191. */
  28192. return _this;
  28193. }
  28194. var _proto = PointLightHelper.prototype;
  28195. _proto.dispose = function dispose() {
  28196. this.geometry.dispose();
  28197. this.material.dispose();
  28198. };
  28199. _proto.update = function update() {
  28200. if (this.color !== undefined) {
  28201. this.material.color.set(this.color);
  28202. } else {
  28203. this.material.color.copy(this.light.color);
  28204. }
  28205. /*
  28206. const d = this.light.distance;
  28207. if ( d === 0.0 ) {
  28208. this.lightDistance.visible = false;
  28209. } else {
  28210. this.lightDistance.visible = true;
  28211. this.lightDistance.scale.set( d, d, d );
  28212. }
  28213. */
  28214. };
  28215. return PointLightHelper;
  28216. }(Mesh);
  28217. var _vector$b = /*@__PURE__*/new Vector3();
  28218. var _color1 = /*@__PURE__*/new Color();
  28219. var _color2 = /*@__PURE__*/new Color();
  28220. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  28221. _inheritsLoose(HemisphereLightHelper, _Object3D);
  28222. function HemisphereLightHelper(light, size, color) {
  28223. var _this;
  28224. _this = _Object3D.call(this) || this;
  28225. _this.light = light;
  28226. _this.light.updateMatrixWorld();
  28227. _this.matrix = light.matrixWorld;
  28228. _this.matrixAutoUpdate = false;
  28229. _this.color = color;
  28230. var geometry = new OctahedronGeometry(size);
  28231. geometry.rotateY(Math.PI * 0.5);
  28232. _this.material = new MeshBasicMaterial({
  28233. wireframe: true,
  28234. fog: false,
  28235. toneMapped: false
  28236. });
  28237. if (_this.color === undefined) _this.material.vertexColors = true;
  28238. var position = geometry.getAttribute('position');
  28239. var colors = new Float32Array(position.count * 3);
  28240. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  28241. _this.add(new Mesh(geometry, _this.material));
  28242. _this.update();
  28243. return _this;
  28244. }
  28245. var _proto = HemisphereLightHelper.prototype;
  28246. _proto.dispose = function dispose() {
  28247. this.children[0].geometry.dispose();
  28248. this.children[0].material.dispose();
  28249. };
  28250. _proto.update = function update() {
  28251. var mesh = this.children[0];
  28252. if (this.color !== undefined) {
  28253. this.material.color.set(this.color);
  28254. } else {
  28255. var colors = mesh.geometry.getAttribute('color');
  28256. _color1.copy(this.light.color);
  28257. _color2.copy(this.light.groundColor);
  28258. for (var i = 0, l = colors.count; i < l; i++) {
  28259. var color = i < l / 2 ? _color1 : _color2;
  28260. colors.setXYZ(i, color.r, color.g, color.b);
  28261. }
  28262. colors.needsUpdate = true;
  28263. }
  28264. mesh.lookAt(_vector$b.setFromMatrixPosition(this.light.matrixWorld).negate());
  28265. };
  28266. return HemisphereLightHelper;
  28267. }(Object3D);
  28268. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  28269. _inheritsLoose(GridHelper, _LineSegments);
  28270. function GridHelper(size, divisions, color1, color2) {
  28271. var _this;
  28272. if (size === void 0) {
  28273. size = 10;
  28274. }
  28275. if (divisions === void 0) {
  28276. divisions = 10;
  28277. }
  28278. if (color1 === void 0) {
  28279. color1 = 0x444444;
  28280. }
  28281. if (color2 === void 0) {
  28282. color2 = 0x888888;
  28283. }
  28284. color1 = new Color(color1);
  28285. color2 = new Color(color2);
  28286. var center = divisions / 2;
  28287. var step = size / divisions;
  28288. var halfSize = size / 2;
  28289. var vertices = [],
  28290. colors = [];
  28291. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  28292. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  28293. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  28294. var color = i === center ? color1 : color2;
  28295. color.toArray(colors, j);
  28296. j += 3;
  28297. color.toArray(colors, j);
  28298. j += 3;
  28299. color.toArray(colors, j);
  28300. j += 3;
  28301. color.toArray(colors, j);
  28302. j += 3;
  28303. }
  28304. var geometry = new BufferGeometry();
  28305. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28306. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28307. var material = new LineBasicMaterial({
  28308. vertexColors: true,
  28309. toneMapped: false
  28310. });
  28311. _this = _LineSegments.call(this, geometry, material) || this;
  28312. _this.type = 'GridHelper';
  28313. return _this;
  28314. }
  28315. return GridHelper;
  28316. }(LineSegments);
  28317. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  28318. _inheritsLoose(PolarGridHelper, _LineSegments);
  28319. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  28320. var _this;
  28321. if (radius === void 0) {
  28322. radius = 10;
  28323. }
  28324. if (radials === void 0) {
  28325. radials = 16;
  28326. }
  28327. if (circles === void 0) {
  28328. circles = 8;
  28329. }
  28330. if (divisions === void 0) {
  28331. divisions = 64;
  28332. }
  28333. if (color1 === void 0) {
  28334. color1 = 0x444444;
  28335. }
  28336. if (color2 === void 0) {
  28337. color2 = 0x888888;
  28338. }
  28339. color1 = new Color(color1);
  28340. color2 = new Color(color2);
  28341. var vertices = [];
  28342. var colors = []; // create the radials
  28343. for (var i = 0; i <= radials; i++) {
  28344. var v = i / radials * (Math.PI * 2);
  28345. var x = Math.sin(v) * radius;
  28346. var z = Math.cos(v) * radius;
  28347. vertices.push(0, 0, 0);
  28348. vertices.push(x, 0, z);
  28349. var color = i & 1 ? color1 : color2;
  28350. colors.push(color.r, color.g, color.b);
  28351. colors.push(color.r, color.g, color.b);
  28352. } // create the circles
  28353. for (var _i = 0; _i <= circles; _i++) {
  28354. var _color = _i & 1 ? color1 : color2;
  28355. var r = radius - radius / circles * _i;
  28356. for (var j = 0; j < divisions; j++) {
  28357. // first vertex
  28358. var _v = j / divisions * (Math.PI * 2);
  28359. var _x = Math.sin(_v) * r;
  28360. var _z = Math.cos(_v) * r;
  28361. vertices.push(_x, 0, _z);
  28362. colors.push(_color.r, _color.g, _color.b); // second vertex
  28363. _v = (j + 1) / divisions * (Math.PI * 2);
  28364. _x = Math.sin(_v) * r;
  28365. _z = Math.cos(_v) * r;
  28366. vertices.push(_x, 0, _z);
  28367. colors.push(_color.r, _color.g, _color.b);
  28368. }
  28369. }
  28370. var geometry = new BufferGeometry();
  28371. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28372. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28373. var material = new LineBasicMaterial({
  28374. vertexColors: true,
  28375. toneMapped: false
  28376. });
  28377. _this = _LineSegments.call(this, geometry, material) || this;
  28378. _this.type = 'PolarGridHelper';
  28379. return _this;
  28380. }
  28381. return PolarGridHelper;
  28382. }(LineSegments);
  28383. var _v1$6 = /*@__PURE__*/new Vector3();
  28384. var _v2$3 = /*@__PURE__*/new Vector3();
  28385. var _v3$1 = /*@__PURE__*/new Vector3();
  28386. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  28387. _inheritsLoose(DirectionalLightHelper, _Object3D);
  28388. function DirectionalLightHelper(light, size, color) {
  28389. var _this;
  28390. _this = _Object3D.call(this) || this;
  28391. _this.light = light;
  28392. _this.light.updateMatrixWorld();
  28393. _this.matrix = light.matrixWorld;
  28394. _this.matrixAutoUpdate = false;
  28395. _this.color = color;
  28396. if (size === undefined) size = 1;
  28397. var geometry = new BufferGeometry();
  28398. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  28399. var material = new LineBasicMaterial({
  28400. fog: false,
  28401. toneMapped: false
  28402. });
  28403. _this.lightPlane = new Line(geometry, material);
  28404. _this.add(_this.lightPlane);
  28405. geometry = new BufferGeometry();
  28406. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  28407. _this.targetLine = new Line(geometry, material);
  28408. _this.add(_this.targetLine);
  28409. _this.update();
  28410. return _this;
  28411. }
  28412. var _proto = DirectionalLightHelper.prototype;
  28413. _proto.dispose = function dispose() {
  28414. this.lightPlane.geometry.dispose();
  28415. this.lightPlane.material.dispose();
  28416. this.targetLine.geometry.dispose();
  28417. this.targetLine.material.dispose();
  28418. };
  28419. _proto.update = function update() {
  28420. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  28421. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  28422. _v3$1.subVectors(_v2$3, _v1$6);
  28423. this.lightPlane.lookAt(_v2$3);
  28424. if (this.color !== undefined) {
  28425. this.lightPlane.material.color.set(this.color);
  28426. this.targetLine.material.color.set(this.color);
  28427. } else {
  28428. this.lightPlane.material.color.copy(this.light.color);
  28429. this.targetLine.material.color.copy(this.light.color);
  28430. }
  28431. this.targetLine.lookAt(_v2$3);
  28432. this.targetLine.scale.z = _v3$1.length();
  28433. };
  28434. return DirectionalLightHelper;
  28435. }(Object3D);
  28436. var _vector$c = /*@__PURE__*/new Vector3();
  28437. var _camera = /*@__PURE__*/new Camera();
  28438. /**
  28439. * - shows frustum, line of sight and up of the camera
  28440. * - suitable for fast updates
  28441. * - based on frustum visualization in lightgl.js shadowmap example
  28442. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28443. */
  28444. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  28445. _inheritsLoose(CameraHelper, _LineSegments);
  28446. function CameraHelper(camera) {
  28447. var _this;
  28448. var geometry = new BufferGeometry();
  28449. var material = new LineBasicMaterial({
  28450. color: 0xffffff,
  28451. vertexColors: true,
  28452. toneMapped: false
  28453. });
  28454. var vertices = [];
  28455. var colors = [];
  28456. var pointMap = {}; // colors
  28457. var colorFrustum = new Color(0xffaa00);
  28458. var colorCone = new Color(0xff0000);
  28459. var colorUp = new Color(0x00aaff);
  28460. var colorTarget = new Color(0xffffff);
  28461. var colorCross = new Color(0x333333); // near
  28462. addLine('n1', 'n2', colorFrustum);
  28463. addLine('n2', 'n4', colorFrustum);
  28464. addLine('n4', 'n3', colorFrustum);
  28465. addLine('n3', 'n1', colorFrustum); // far
  28466. addLine('f1', 'f2', colorFrustum);
  28467. addLine('f2', 'f4', colorFrustum);
  28468. addLine('f4', 'f3', colorFrustum);
  28469. addLine('f3', 'f1', colorFrustum); // sides
  28470. addLine('n1', 'f1', colorFrustum);
  28471. addLine('n2', 'f2', colorFrustum);
  28472. addLine('n3', 'f3', colorFrustum);
  28473. addLine('n4', 'f4', colorFrustum); // cone
  28474. addLine('p', 'n1', colorCone);
  28475. addLine('p', 'n2', colorCone);
  28476. addLine('p', 'n3', colorCone);
  28477. addLine('p', 'n4', colorCone); // up
  28478. addLine('u1', 'u2', colorUp);
  28479. addLine('u2', 'u3', colorUp);
  28480. addLine('u3', 'u1', colorUp); // target
  28481. addLine('c', 't', colorTarget);
  28482. addLine('p', 'c', colorCross); // cross
  28483. addLine('cn1', 'cn2', colorCross);
  28484. addLine('cn3', 'cn4', colorCross);
  28485. addLine('cf1', 'cf2', colorCross);
  28486. addLine('cf3', 'cf4', colorCross);
  28487. function addLine(a, b, color) {
  28488. addPoint(a, color);
  28489. addPoint(b, color);
  28490. }
  28491. function addPoint(id, color) {
  28492. vertices.push(0, 0, 0);
  28493. colors.push(color.r, color.g, color.b);
  28494. if (pointMap[id] === undefined) {
  28495. pointMap[id] = [];
  28496. }
  28497. pointMap[id].push(vertices.length / 3 - 1);
  28498. }
  28499. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28500. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28501. _this = _LineSegments.call(this, geometry, material) || this;
  28502. _this.type = 'CameraHelper';
  28503. _this.camera = camera;
  28504. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  28505. _this.matrix = camera.matrixWorld;
  28506. _this.matrixAutoUpdate = false;
  28507. _this.pointMap = pointMap;
  28508. _this.update();
  28509. return _this;
  28510. }
  28511. var _proto = CameraHelper.prototype;
  28512. _proto.update = function update() {
  28513. var geometry = this.geometry;
  28514. var pointMap = this.pointMap;
  28515. var w = 1,
  28516. h = 1; // we need just camera projection matrix inverse
  28517. // world matrix must be identity
  28518. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  28519. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  28520. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  28521. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  28522. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  28523. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  28524. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  28525. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  28526. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  28527. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  28528. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  28529. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  28530. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  28531. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  28532. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  28533. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  28534. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  28535. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  28536. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  28537. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  28538. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  28539. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  28540. geometry.getAttribute('position').needsUpdate = true;
  28541. };
  28542. return CameraHelper;
  28543. }(LineSegments);
  28544. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  28545. _vector$c.set(x, y, z).unproject(camera);
  28546. var points = pointMap[point];
  28547. if (points !== undefined) {
  28548. var position = geometry.getAttribute('position');
  28549. for (var i = 0, l = points.length; i < l; i++) {
  28550. position.setXYZ(points[i], _vector$c.x, _vector$c.y, _vector$c.z);
  28551. }
  28552. }
  28553. }
  28554. var _box$3 = /*@__PURE__*/new Box3();
  28555. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  28556. _inheritsLoose(BoxHelper, _LineSegments);
  28557. function BoxHelper(object, color) {
  28558. var _this;
  28559. if (color === void 0) {
  28560. color = 0xffff00;
  28561. }
  28562. 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]);
  28563. var positions = new Float32Array(8 * 3);
  28564. var geometry = new BufferGeometry();
  28565. geometry.setIndex(new BufferAttribute(indices, 1));
  28566. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28567. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28568. color: color,
  28569. toneMapped: false
  28570. })) || this;
  28571. _this.object = object;
  28572. _this.type = 'BoxHelper';
  28573. _this.matrixAutoUpdate = false;
  28574. _this.update();
  28575. return _this;
  28576. }
  28577. var _proto = BoxHelper.prototype;
  28578. _proto.update = function update(object) {
  28579. if (object !== undefined) {
  28580. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28581. }
  28582. if (this.object !== undefined) {
  28583. _box$3.setFromObject(this.object);
  28584. }
  28585. if (_box$3.isEmpty()) return;
  28586. var min = _box$3.min;
  28587. var max = _box$3.max;
  28588. /*
  28589. 5____4
  28590. 1/___0/|
  28591. | 6__|_7
  28592. 2/___3/
  28593. 0: max.x, max.y, max.z
  28594. 1: min.x, max.y, max.z
  28595. 2: min.x, min.y, max.z
  28596. 3: max.x, min.y, max.z
  28597. 4: max.x, max.y, min.z
  28598. 5: min.x, max.y, min.z
  28599. 6: min.x, min.y, min.z
  28600. 7: max.x, min.y, min.z
  28601. */
  28602. var position = this.geometry.attributes.position;
  28603. var array = position.array;
  28604. array[0] = max.x;
  28605. array[1] = max.y;
  28606. array[2] = max.z;
  28607. array[3] = min.x;
  28608. array[4] = max.y;
  28609. array[5] = max.z;
  28610. array[6] = min.x;
  28611. array[7] = min.y;
  28612. array[8] = max.z;
  28613. array[9] = max.x;
  28614. array[10] = min.y;
  28615. array[11] = max.z;
  28616. array[12] = max.x;
  28617. array[13] = max.y;
  28618. array[14] = min.z;
  28619. array[15] = min.x;
  28620. array[16] = max.y;
  28621. array[17] = min.z;
  28622. array[18] = min.x;
  28623. array[19] = min.y;
  28624. array[20] = min.z;
  28625. array[21] = max.x;
  28626. array[22] = min.y;
  28627. array[23] = min.z;
  28628. position.needsUpdate = true;
  28629. this.geometry.computeBoundingSphere();
  28630. };
  28631. _proto.setFromObject = function setFromObject(object) {
  28632. this.object = object;
  28633. this.update();
  28634. return this;
  28635. };
  28636. _proto.copy = function copy(source) {
  28637. LineSegments.prototype.copy.call(this, source);
  28638. this.object = source.object;
  28639. return this;
  28640. };
  28641. return BoxHelper;
  28642. }(LineSegments);
  28643. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28644. _inheritsLoose(Box3Helper, _LineSegments);
  28645. function Box3Helper(box, color) {
  28646. var _this;
  28647. if (color === void 0) {
  28648. color = 0xffff00;
  28649. }
  28650. 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]);
  28651. 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];
  28652. var geometry = new BufferGeometry();
  28653. geometry.setIndex(new BufferAttribute(indices, 1));
  28654. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28655. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28656. color: color,
  28657. toneMapped: false
  28658. })) || this;
  28659. _this.box = box;
  28660. _this.type = 'Box3Helper';
  28661. _this.geometry.computeBoundingSphere();
  28662. return _this;
  28663. }
  28664. var _proto = Box3Helper.prototype;
  28665. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28666. var box = this.box;
  28667. if (box.isEmpty()) return;
  28668. box.getCenter(this.position);
  28669. box.getSize(this.scale);
  28670. this.scale.multiplyScalar(0.5);
  28671. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28672. };
  28673. return Box3Helper;
  28674. }(LineSegments);
  28675. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28676. _inheritsLoose(PlaneHelper, _Line);
  28677. function PlaneHelper(plane, size, hex) {
  28678. var _this;
  28679. if (size === void 0) {
  28680. size = 1;
  28681. }
  28682. if (hex === void 0) {
  28683. hex = 0xffff00;
  28684. }
  28685. var color = hex;
  28686. 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];
  28687. var geometry = new BufferGeometry();
  28688. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28689. geometry.computeBoundingSphere();
  28690. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28691. color: color,
  28692. toneMapped: false
  28693. })) || this;
  28694. _this.type = 'PlaneHelper';
  28695. _this.plane = plane;
  28696. _this.size = size;
  28697. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28698. var geometry2 = new BufferGeometry();
  28699. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28700. geometry2.computeBoundingSphere();
  28701. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28702. color: color,
  28703. opacity: 0.2,
  28704. transparent: true,
  28705. depthWrite: false,
  28706. toneMapped: false
  28707. })));
  28708. return _this;
  28709. }
  28710. var _proto = PlaneHelper.prototype;
  28711. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28712. var scale = -this.plane.constant;
  28713. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28714. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28715. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28716. this.lookAt(this.plane.normal);
  28717. _Line.prototype.updateMatrixWorld.call(this, force);
  28718. };
  28719. return PlaneHelper;
  28720. }(Line);
  28721. var _axis = /*@__PURE__*/new Vector3();
  28722. var _lineGeometry, _coneGeometry;
  28723. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28724. _inheritsLoose(ArrowHelper, _Object3D);
  28725. // dir is assumed to be normalized
  28726. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28727. var _this;
  28728. if (dir === void 0) {
  28729. dir = new Vector3(0, 0, 1);
  28730. }
  28731. if (origin === void 0) {
  28732. origin = new Vector3(0, 0, 0);
  28733. }
  28734. if (length === void 0) {
  28735. length = 1;
  28736. }
  28737. if (color === void 0) {
  28738. color = 0xffff00;
  28739. }
  28740. if (headLength === void 0) {
  28741. headLength = length * 0.2;
  28742. }
  28743. if (headWidth === void 0) {
  28744. headWidth = headLength * 0.2;
  28745. }
  28746. _this = _Object3D.call(this) || this;
  28747. _this.type = 'ArrowHelper';
  28748. if (_lineGeometry === undefined) {
  28749. _lineGeometry = new BufferGeometry();
  28750. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28751. _coneGeometry = new CylinderGeometry(0, 0.5, 1, 5, 1);
  28752. _coneGeometry.translate(0, -0.5, 0);
  28753. }
  28754. _this.position.copy(origin);
  28755. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28756. color: color,
  28757. toneMapped: false
  28758. }));
  28759. _this.line.matrixAutoUpdate = false;
  28760. _this.add(_this.line);
  28761. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  28762. color: color,
  28763. toneMapped: false
  28764. }));
  28765. _this.cone.matrixAutoUpdate = false;
  28766. _this.add(_this.cone);
  28767. _this.setDirection(dir);
  28768. _this.setLength(length, headLength, headWidth);
  28769. return _this;
  28770. }
  28771. var _proto = ArrowHelper.prototype;
  28772. _proto.setDirection = function setDirection(dir) {
  28773. // dir is assumed to be normalized
  28774. if (dir.y > 0.99999) {
  28775. this.quaternion.set(0, 0, 0, 1);
  28776. } else if (dir.y < -0.99999) {
  28777. this.quaternion.set(1, 0, 0, 0);
  28778. } else {
  28779. _axis.set(dir.z, 0, -dir.x).normalize();
  28780. var radians = Math.acos(dir.y);
  28781. this.quaternion.setFromAxisAngle(_axis, radians);
  28782. }
  28783. };
  28784. _proto.setLength = function setLength(length, headLength, headWidth) {
  28785. if (headLength === void 0) {
  28786. headLength = length * 0.2;
  28787. }
  28788. if (headWidth === void 0) {
  28789. headWidth = headLength * 0.2;
  28790. }
  28791. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  28792. this.line.updateMatrix();
  28793. this.cone.scale.set(headWidth, headLength, headWidth);
  28794. this.cone.position.y = length;
  28795. this.cone.updateMatrix();
  28796. };
  28797. _proto.setColor = function setColor(color) {
  28798. this.line.material.color.set(color);
  28799. this.cone.material.color.set(color);
  28800. };
  28801. _proto.copy = function copy(source) {
  28802. _Object3D.prototype.copy.call(this, source, false);
  28803. this.line.copy(source.line);
  28804. this.cone.copy(source.cone);
  28805. return this;
  28806. };
  28807. return ArrowHelper;
  28808. }(Object3D);
  28809. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  28810. _inheritsLoose(AxesHelper, _LineSegments);
  28811. function AxesHelper(size) {
  28812. var _this;
  28813. if (size === void 0) {
  28814. size = 1;
  28815. }
  28816. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  28817. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  28818. var geometry = new BufferGeometry();
  28819. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28820. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28821. var material = new LineBasicMaterial({
  28822. vertexColors: true,
  28823. toneMapped: false
  28824. });
  28825. _this = _LineSegments.call(this, geometry, material) || this;
  28826. _this.type = 'AxesHelper';
  28827. return _this;
  28828. }
  28829. return AxesHelper;
  28830. }(LineSegments);
  28831. var _floatView = new Float32Array(1);
  28832. var _int32View = new Int32Array(_floatView.buffer);
  28833. var DataUtils = {
  28834. // Converts float32 to float16 (stored as uint16 value).
  28835. toHalfFloat: function toHalfFloat(val) {
  28836. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  28837. /* This method is faster than the OpenEXR implementation (very often
  28838. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  28839. * by James Tursa?s half-precision code. */
  28840. _floatView[0] = val;
  28841. var x = _int32View[0];
  28842. var bits = x >> 16 & 0x8000;
  28843. /* Get the sign */
  28844. var m = x >> 12 & 0x07ff;
  28845. /* Keep one extra bit for rounding */
  28846. var e = x >> 23 & 0xff;
  28847. /* Using int is faster here */
  28848. /* If zero, or denormal, or exponent underflows too much for a denormal
  28849. * half, return signed zero. */
  28850. if (e < 103) return bits;
  28851. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  28852. if (e > 142) {
  28853. bits |= 0x7c00;
  28854. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  28855. * not Inf, so make sure we set one mantissa bit too. */
  28856. bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;
  28857. return bits;
  28858. }
  28859. /* If exponent underflows but not too much, return a denormal */
  28860. if (e < 113) {
  28861. m |= 0x0800;
  28862. /* Extra rounding may overflow and set mantissa to 0 and exponent
  28863. * to 1, which is OK. */
  28864. bits |= (m >> 114 - e) + (m >> 113 - e & 1);
  28865. return bits;
  28866. }
  28867. bits |= e - 112 << 10 | m >> 1;
  28868. /* Extra rounding. An overflow will set mantissa to 0 and increment
  28869. * the exponent, which is OK. */
  28870. bits += m & 1;
  28871. return bits;
  28872. }
  28873. };
  28874. var _ENCODINGS;
  28875. var LOD_MIN = 4;
  28876. var LOD_MAX = 8;
  28877. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  28878. // chosen to approximate a Trowbridge-Reitz distribution function times the
  28879. // geometric shadowing function. These sigma values squared must match the
  28880. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  28881. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  28882. 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
  28883. // samples and exit early, but not recompile the shader.
  28884. var MAX_SAMPLES = 20;
  28885. 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);
  28886. var backgroundMaterial = new MeshBasicMaterial({
  28887. side: BackSide,
  28888. depthWrite: false,
  28889. depthTest: false
  28890. });
  28891. var backgroundBox = new Mesh(new BoxGeometry(), backgroundMaterial);
  28892. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  28893. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  28894. _lodPlanes = _createPlanes2._lodPlanes,
  28895. _sizeLods = _createPlanes2._sizeLods,
  28896. _sigmas = _createPlanes2._sigmas;
  28897. var _clearColor = /*@__PURE__*/new Color();
  28898. var _oldTarget = null; // Golden Ratio
  28899. var PHI = (1 + Math.sqrt(5)) / 2;
  28900. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  28901. // same axis), used as axis directions evenly spread on a sphere.
  28902. 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)];
  28903. /**
  28904. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28905. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28906. * blur to be quickly accessed based on material roughness. It is packed into a
  28907. * special CubeUV format that allows us to perform custom interpolation so that
  28908. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  28909. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  28910. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  28911. * higher roughness levels. In this way we maintain resolution to smoothly
  28912. * interpolate diffuse lighting while limiting sampling computation.
  28913. */
  28914. function convertLinearToRGBE(color) {
  28915. var maxComponent = Math.max(color.r, color.g, color.b);
  28916. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  28917. color.multiplyScalar(Math.pow(2.0, -fExp));
  28918. var alpha = (fExp + 128.0) / 255.0;
  28919. return alpha;
  28920. }
  28921. var PMREMGenerator = /*#__PURE__*/function () {
  28922. function PMREMGenerator(renderer) {
  28923. this._renderer = renderer;
  28924. this._pingPongRenderTarget = null;
  28925. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  28926. this._equirectShader = null;
  28927. this._cubemapShader = null;
  28928. this._compileMaterial(this._blurMaterial);
  28929. }
  28930. /**
  28931. * Generates a PMREM from a supplied Scene, which can be faster than using an
  28932. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  28933. * in radians to be applied to the scene before PMREM generation. Optional near
  28934. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  28935. * is placed at the origin).
  28936. */
  28937. var _proto = PMREMGenerator.prototype;
  28938. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  28939. if (sigma === void 0) {
  28940. sigma = 0;
  28941. }
  28942. if (near === void 0) {
  28943. near = 0.1;
  28944. }
  28945. if (far === void 0) {
  28946. far = 100;
  28947. }
  28948. _oldTarget = this._renderer.getRenderTarget();
  28949. var cubeUVRenderTarget = this._allocateTargets();
  28950. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  28951. if (sigma > 0) {
  28952. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  28953. }
  28954. this._applyPMREM(cubeUVRenderTarget);
  28955. this._cleanup(cubeUVRenderTarget);
  28956. return cubeUVRenderTarget;
  28957. }
  28958. /**
  28959. * Generates a PMREM from an equirectangular texture, which can be either LDR
  28960. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  28961. * as this matches best with the 256 x 256 cubemap output.
  28962. */
  28963. ;
  28964. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  28965. return this._fromTexture(equirectangular);
  28966. }
  28967. /**
  28968. * Generates a PMREM from an cubemap texture, which can be either LDR
  28969. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  28970. * as this matches best with the 256 x 256 cubemap output.
  28971. */
  28972. ;
  28973. _proto.fromCubemap = function fromCubemap(cubemap) {
  28974. return this._fromTexture(cubemap);
  28975. }
  28976. /**
  28977. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  28978. * your texture's network fetch for increased concurrency.
  28979. */
  28980. ;
  28981. _proto.compileCubemapShader = function compileCubemapShader() {
  28982. if (this._cubemapShader === null) {
  28983. this._cubemapShader = _getCubemapShader();
  28984. this._compileMaterial(this._cubemapShader);
  28985. }
  28986. }
  28987. /**
  28988. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  28989. * your texture's network fetch for increased concurrency.
  28990. */
  28991. ;
  28992. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  28993. if (this._equirectShader === null) {
  28994. this._equirectShader = _getEquirectShader();
  28995. this._compileMaterial(this._equirectShader);
  28996. }
  28997. }
  28998. /**
  28999. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  29000. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  29001. * one of them will cause any others to also become unusable.
  29002. */
  29003. ;
  29004. _proto.dispose = function dispose() {
  29005. this._blurMaterial.dispose();
  29006. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  29007. if (this._equirectShader !== null) this._equirectShader.dispose();
  29008. for (var i = 0; i < _lodPlanes.length; i++) {
  29009. _lodPlanes[i].dispose();
  29010. }
  29011. } // private interface
  29012. ;
  29013. _proto._cleanup = function _cleanup(outputTarget) {
  29014. this._pingPongRenderTarget.dispose();
  29015. this._renderer.setRenderTarget(_oldTarget);
  29016. outputTarget.scissorTest = false;
  29017. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  29018. };
  29019. _proto._fromTexture = function _fromTexture(texture) {
  29020. _oldTarget = this._renderer.getRenderTarget();
  29021. var cubeUVRenderTarget = this._allocateTargets(texture);
  29022. this._textureToCubeUV(texture, cubeUVRenderTarget);
  29023. this._applyPMREM(cubeUVRenderTarget);
  29024. this._cleanup(cubeUVRenderTarget);
  29025. return cubeUVRenderTarget;
  29026. };
  29027. _proto._allocateTargets = function _allocateTargets(texture) {
  29028. // warning: null texture is valid
  29029. var params = {
  29030. magFilter: NearestFilter,
  29031. minFilter: NearestFilter,
  29032. generateMipmaps: false,
  29033. type: UnsignedByteType,
  29034. format: RGBEFormat,
  29035. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  29036. depthBuffer: false
  29037. };
  29038. var cubeUVRenderTarget = _createRenderTarget(params);
  29039. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  29040. this._pingPongRenderTarget = _createRenderTarget(params);
  29041. return cubeUVRenderTarget;
  29042. };
  29043. _proto._compileMaterial = function _compileMaterial(material) {
  29044. var tmpMesh = new Mesh(_lodPlanes[0], material);
  29045. this._renderer.compile(tmpMesh, _flatCamera);
  29046. };
  29047. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  29048. var fov = 90;
  29049. var aspect = 1;
  29050. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  29051. var upSign = [1, -1, 1, 1, 1, 1];
  29052. var forwardSign = [1, 1, 1, -1, -1, -1];
  29053. var renderer = this._renderer;
  29054. var originalAutoClear = renderer.autoClear;
  29055. var outputEncoding = renderer.outputEncoding;
  29056. var toneMapping = renderer.toneMapping;
  29057. renderer.getClearColor(_clearColor);
  29058. renderer.toneMapping = NoToneMapping;
  29059. renderer.outputEncoding = LinearEncoding;
  29060. renderer.autoClear = false;
  29061. var useSolidColor = false;
  29062. var background = scene.background;
  29063. if (background) {
  29064. if (background.isColor) {
  29065. backgroundMaterial.color.copy(background).convertSRGBToLinear();
  29066. scene.background = null;
  29067. var alpha = convertLinearToRGBE(backgroundMaterial.color);
  29068. backgroundMaterial.opacity = alpha;
  29069. useSolidColor = true;
  29070. }
  29071. } else {
  29072. backgroundMaterial.color.copy(_clearColor).convertSRGBToLinear();
  29073. var _alpha = convertLinearToRGBE(backgroundMaterial.color);
  29074. backgroundMaterial.opacity = _alpha;
  29075. useSolidColor = true;
  29076. }
  29077. for (var i = 0; i < 6; i++) {
  29078. var col = i % 3;
  29079. if (col == 0) {
  29080. cubeCamera.up.set(0, upSign[i], 0);
  29081. cubeCamera.lookAt(forwardSign[i], 0, 0);
  29082. } else if (col == 1) {
  29083. cubeCamera.up.set(0, 0, upSign[i]);
  29084. cubeCamera.lookAt(0, forwardSign[i], 0);
  29085. } else {
  29086. cubeCamera.up.set(0, upSign[i], 0);
  29087. cubeCamera.lookAt(0, 0, forwardSign[i]);
  29088. }
  29089. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  29090. renderer.setRenderTarget(cubeUVRenderTarget);
  29091. if (useSolidColor) {
  29092. renderer.render(backgroundBox, cubeCamera);
  29093. }
  29094. renderer.render(scene, cubeCamera);
  29095. }
  29096. renderer.toneMapping = toneMapping;
  29097. renderer.outputEncoding = outputEncoding;
  29098. renderer.autoClear = originalAutoClear;
  29099. };
  29100. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  29101. var renderer = this._renderer;
  29102. if (texture.isCubeTexture) {
  29103. if (this._cubemapShader == null) {
  29104. this._cubemapShader = _getCubemapShader();
  29105. }
  29106. } else {
  29107. if (this._equirectShader == null) {
  29108. this._equirectShader = _getEquirectShader();
  29109. }
  29110. }
  29111. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  29112. var mesh = new Mesh(_lodPlanes[0], material);
  29113. var uniforms = material.uniforms;
  29114. uniforms['envMap'].value = texture;
  29115. if (!texture.isCubeTexture) {
  29116. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  29117. }
  29118. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  29119. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  29120. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  29121. renderer.setRenderTarget(cubeUVRenderTarget);
  29122. renderer.render(mesh, _flatCamera);
  29123. };
  29124. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  29125. var renderer = this._renderer;
  29126. var autoClear = renderer.autoClear;
  29127. renderer.autoClear = false;
  29128. for (var i = 1; i < TOTAL_LODS; i++) {
  29129. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  29130. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  29131. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  29132. }
  29133. renderer.autoClear = autoClear;
  29134. }
  29135. /**
  29136. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  29137. * vertically and horizontally, but this breaks down on a cube. Here we apply
  29138. * the blur latitudinally (around the poles), and then longitudinally (towards
  29139. * the poles) to approximate the orthogonally-separable blur. It is least
  29140. * accurate at the poles, but still does a decent job.
  29141. */
  29142. ;
  29143. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  29144. var pingPongRenderTarget = this._pingPongRenderTarget;
  29145. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  29146. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  29147. };
  29148. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  29149. var renderer = this._renderer;
  29150. var blurMaterial = this._blurMaterial;
  29151. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  29152. console.error('blur direction must be either latitudinal or longitudinal!');
  29153. } // Number of standard deviations at which to cut off the discrete approximation.
  29154. var STANDARD_DEVIATIONS = 3;
  29155. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  29156. var blurUniforms = blurMaterial.uniforms;
  29157. var pixels = _sizeLods[lodIn] - 1;
  29158. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  29159. var sigmaPixels = sigmaRadians / radiansPerPixel;
  29160. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  29161. if (samples > MAX_SAMPLES) {
  29162. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  29163. }
  29164. var weights = [];
  29165. var sum = 0;
  29166. for (var i = 0; i < MAX_SAMPLES; ++i) {
  29167. var _x = i / sigmaPixels;
  29168. var weight = Math.exp(-_x * _x / 2);
  29169. weights.push(weight);
  29170. if (i == 0) {
  29171. sum += weight;
  29172. } else if (i < samples) {
  29173. sum += 2 * weight;
  29174. }
  29175. }
  29176. for (var _i = 0; _i < weights.length; _i++) {
  29177. weights[_i] = weights[_i] / sum;
  29178. }
  29179. blurUniforms['envMap'].value = targetIn.texture;
  29180. blurUniforms['samples'].value = samples;
  29181. blurUniforms['weights'].value = weights;
  29182. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  29183. if (poleAxis) {
  29184. blurUniforms['poleAxis'].value = poleAxis;
  29185. }
  29186. blurUniforms['dTheta'].value = radiansPerPixel;
  29187. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  29188. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  29189. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  29190. var outputSize = _sizeLods[lodOut];
  29191. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  29192. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  29193. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  29194. renderer.setRenderTarget(targetOut);
  29195. renderer.render(blurMesh, _flatCamera);
  29196. };
  29197. return PMREMGenerator;
  29198. }();
  29199. function _isLDR(texture) {
  29200. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  29201. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  29202. }
  29203. function _createPlanes() {
  29204. var _lodPlanes = [];
  29205. var _sizeLods = [];
  29206. var _sigmas = [];
  29207. var lod = LOD_MAX;
  29208. for (var i = 0; i < TOTAL_LODS; i++) {
  29209. var sizeLod = Math.pow(2, lod);
  29210. _sizeLods.push(sizeLod);
  29211. var sigma = 1.0 / sizeLod;
  29212. if (i > LOD_MAX - LOD_MIN) {
  29213. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  29214. } else if (i == 0) {
  29215. sigma = 0;
  29216. }
  29217. _sigmas.push(sigma);
  29218. var texelSize = 1.0 / (sizeLod - 1);
  29219. var min = -texelSize / 2;
  29220. var max = 1 + texelSize / 2;
  29221. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  29222. var cubeFaces = 6;
  29223. var vertices = 6;
  29224. var positionSize = 3;
  29225. var uvSize = 2;
  29226. var faceIndexSize = 1;
  29227. var position = new Float32Array(positionSize * vertices * cubeFaces);
  29228. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  29229. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  29230. for (var face = 0; face < cubeFaces; face++) {
  29231. var x = face % 3 * 2 / 3 - 1;
  29232. var y = face > 2 ? 0 : -1;
  29233. 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];
  29234. position.set(coordinates, positionSize * vertices * face);
  29235. uv.set(uv1, uvSize * vertices * face);
  29236. var fill = [face, face, face, face, face, face];
  29237. faceIndex.set(fill, faceIndexSize * vertices * face);
  29238. }
  29239. var planes = new BufferGeometry();
  29240. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  29241. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  29242. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  29243. _lodPlanes.push(planes);
  29244. if (lod > LOD_MIN) {
  29245. lod--;
  29246. }
  29247. }
  29248. return {
  29249. _lodPlanes: _lodPlanes,
  29250. _sizeLods: _sizeLods,
  29251. _sigmas: _sigmas
  29252. };
  29253. }
  29254. function _createRenderTarget(params) {
  29255. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  29256. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  29257. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  29258. cubeUVRenderTarget.scissorTest = true;
  29259. return cubeUVRenderTarget;
  29260. }
  29261. function _setViewport(target, x, y, width, height) {
  29262. target.viewport.set(x, y, width, height);
  29263. target.scissor.set(x, y, width, height);
  29264. }
  29265. function _getBlurShader(maxSamples) {
  29266. var weights = new Float32Array(maxSamples);
  29267. var poleAxis = new Vector3(0, 1, 0);
  29268. var shaderMaterial = new RawShaderMaterial({
  29269. name: 'SphericalGaussianBlur',
  29270. defines: {
  29271. 'n': maxSamples
  29272. },
  29273. uniforms: {
  29274. 'envMap': {
  29275. value: null
  29276. },
  29277. 'samples': {
  29278. value: 1
  29279. },
  29280. 'weights': {
  29281. value: weights
  29282. },
  29283. 'latitudinal': {
  29284. value: false
  29285. },
  29286. 'dTheta': {
  29287. value: 0
  29288. },
  29289. 'mipInt': {
  29290. value: 0
  29291. },
  29292. 'poleAxis': {
  29293. value: poleAxis
  29294. },
  29295. 'inputEncoding': {
  29296. value: ENCODINGS[LinearEncoding]
  29297. },
  29298. 'outputEncoding': {
  29299. value: ENCODINGS[LinearEncoding]
  29300. }
  29301. },
  29302. vertexShader: _getCommonVertexShader(),
  29303. fragmentShader:
  29304. /* glsl */
  29305. "\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",
  29306. blending: NoBlending,
  29307. depthTest: false,
  29308. depthWrite: false
  29309. });
  29310. return shaderMaterial;
  29311. }
  29312. function _getEquirectShader() {
  29313. var texelSize = new Vector2(1, 1);
  29314. var shaderMaterial = new RawShaderMaterial({
  29315. name: 'EquirectangularToCubeUV',
  29316. uniforms: {
  29317. 'envMap': {
  29318. value: null
  29319. },
  29320. 'texelSize': {
  29321. value: texelSize
  29322. },
  29323. 'inputEncoding': {
  29324. value: ENCODINGS[LinearEncoding]
  29325. },
  29326. 'outputEncoding': {
  29327. value: ENCODINGS[LinearEncoding]
  29328. }
  29329. },
  29330. vertexShader: _getCommonVertexShader(),
  29331. fragmentShader:
  29332. /* glsl */
  29333. "\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",
  29334. blending: NoBlending,
  29335. depthTest: false,
  29336. depthWrite: false
  29337. });
  29338. return shaderMaterial;
  29339. }
  29340. function _getCubemapShader() {
  29341. var shaderMaterial = new RawShaderMaterial({
  29342. name: 'CubemapToCubeUV',
  29343. uniforms: {
  29344. 'envMap': {
  29345. value: null
  29346. },
  29347. 'inputEncoding': {
  29348. value: ENCODINGS[LinearEncoding]
  29349. },
  29350. 'outputEncoding': {
  29351. value: ENCODINGS[LinearEncoding]
  29352. }
  29353. },
  29354. vertexShader: _getCommonVertexShader(),
  29355. fragmentShader:
  29356. /* glsl */
  29357. "\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",
  29358. blending: NoBlending,
  29359. depthTest: false,
  29360. depthWrite: false
  29361. });
  29362. return shaderMaterial;
  29363. }
  29364. function _getCommonVertexShader() {
  29365. return (
  29366. /* glsl */
  29367. "\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"
  29368. );
  29369. }
  29370. function _getEncodings() {
  29371. return (
  29372. /* glsl */
  29373. "\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"
  29374. );
  29375. }
  29376. var LineStrip = 0;
  29377. var LinePieces = 1;
  29378. var NoColors = 0;
  29379. var FaceColors = 1;
  29380. var VertexColors = 2;
  29381. function MeshFaceMaterial(materials) {
  29382. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  29383. return materials;
  29384. }
  29385. function MultiMaterial(materials) {
  29386. if (materials === void 0) {
  29387. materials = [];
  29388. }
  29389. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  29390. materials.isMultiMaterial = true;
  29391. materials.materials = materials;
  29392. materials.clone = function () {
  29393. return materials.slice();
  29394. };
  29395. return materials;
  29396. }
  29397. function PointCloud(geometry, material) {
  29398. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  29399. return new Points(geometry, material);
  29400. }
  29401. function Particle(material) {
  29402. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  29403. return new Sprite(material);
  29404. }
  29405. function ParticleSystem(geometry, material) {
  29406. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  29407. return new Points(geometry, material);
  29408. }
  29409. function PointCloudMaterial(parameters) {
  29410. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  29411. return new PointsMaterial(parameters);
  29412. }
  29413. function ParticleBasicMaterial(parameters) {
  29414. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  29415. return new PointsMaterial(parameters);
  29416. }
  29417. function ParticleSystemMaterial(parameters) {
  29418. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  29419. return new PointsMaterial(parameters);
  29420. }
  29421. function Vertex(x, y, z) {
  29422. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  29423. return new Vector3(x, y, z);
  29424. } //
  29425. function DynamicBufferAttribute(array, itemSize) {
  29426. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  29427. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  29428. }
  29429. function Int8Attribute(array, itemSize) {
  29430. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  29431. return new Int8BufferAttribute(array, itemSize);
  29432. }
  29433. function Uint8Attribute(array, itemSize) {
  29434. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  29435. return new Uint8BufferAttribute(array, itemSize);
  29436. }
  29437. function Uint8ClampedAttribute(array, itemSize) {
  29438. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  29439. return new Uint8ClampedBufferAttribute(array, itemSize);
  29440. }
  29441. function Int16Attribute(array, itemSize) {
  29442. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  29443. return new Int16BufferAttribute(array, itemSize);
  29444. }
  29445. function Uint16Attribute(array, itemSize) {
  29446. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  29447. return new Uint16BufferAttribute(array, itemSize);
  29448. }
  29449. function Int32Attribute(array, itemSize) {
  29450. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  29451. return new Int32BufferAttribute(array, itemSize);
  29452. }
  29453. function Uint32Attribute(array, itemSize) {
  29454. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  29455. return new Uint32BufferAttribute(array, itemSize);
  29456. }
  29457. function Float32Attribute(array, itemSize) {
  29458. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  29459. return new Float32BufferAttribute(array, itemSize);
  29460. }
  29461. function Float64Attribute(array, itemSize) {
  29462. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  29463. return new Float64BufferAttribute(array, itemSize);
  29464. } //
  29465. Curve.create = function (construct, getPoint) {
  29466. console.log('THREE.Curve.create() has been deprecated');
  29467. construct.prototype = Object.create(Curve.prototype);
  29468. construct.prototype.constructor = construct;
  29469. construct.prototype.getPoint = getPoint;
  29470. return construct;
  29471. }; //
  29472. Object.assign(Path.prototype, {
  29473. fromPoints: function fromPoints(points) {
  29474. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  29475. return this.setFromPoints(points);
  29476. }
  29477. }); //
  29478. function AxisHelper(size) {
  29479. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  29480. return new AxesHelper(size);
  29481. }
  29482. function BoundingBoxHelper(object, color) {
  29483. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  29484. return new BoxHelper(object, color);
  29485. }
  29486. function EdgesHelper(object, hex) {
  29487. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  29488. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  29489. color: hex !== undefined ? hex : 0xffffff
  29490. }));
  29491. }
  29492. GridHelper.prototype.setColors = function () {
  29493. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  29494. };
  29495. SkeletonHelper.prototype.update = function () {
  29496. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  29497. };
  29498. function WireframeHelper(object, hex) {
  29499. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  29500. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  29501. color: hex !== undefined ? hex : 0xffffff
  29502. }));
  29503. } //
  29504. Object.assign(Loader.prototype, {
  29505. extractUrlBase: function extractUrlBase(url) {
  29506. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  29507. return LoaderUtils.extractUrlBase(url);
  29508. }
  29509. });
  29510. Loader.Handlers = {
  29511. add: function add()
  29512. /* regex, loader */
  29513. {
  29514. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  29515. },
  29516. get: function get()
  29517. /* file */
  29518. {
  29519. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  29520. }
  29521. };
  29522. function XHRLoader(manager) {
  29523. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  29524. return new FileLoader(manager);
  29525. }
  29526. function BinaryTextureLoader(manager) {
  29527. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  29528. return new DataTextureLoader(manager);
  29529. } //
  29530. Object.assign(Box2.prototype, {
  29531. center: function center(optionalTarget) {
  29532. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  29533. return this.getCenter(optionalTarget);
  29534. },
  29535. empty: function empty() {
  29536. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  29537. return this.isEmpty();
  29538. },
  29539. isIntersectionBox: function isIntersectionBox(box) {
  29540. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  29541. return this.intersectsBox(box);
  29542. },
  29543. size: function size(optionalTarget) {
  29544. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  29545. return this.getSize(optionalTarget);
  29546. }
  29547. });
  29548. Object.assign(Box3.prototype, {
  29549. center: function center(optionalTarget) {
  29550. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  29551. return this.getCenter(optionalTarget);
  29552. },
  29553. empty: function empty() {
  29554. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  29555. return this.isEmpty();
  29556. },
  29557. isIntersectionBox: function isIntersectionBox(box) {
  29558. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  29559. return this.intersectsBox(box);
  29560. },
  29561. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29562. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29563. return this.intersectsSphere(sphere);
  29564. },
  29565. size: function size(optionalTarget) {
  29566. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  29567. return this.getSize(optionalTarget);
  29568. }
  29569. });
  29570. Object.assign(Sphere.prototype, {
  29571. empty: function empty() {
  29572. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  29573. return this.isEmpty();
  29574. }
  29575. });
  29576. Frustum.prototype.setFromMatrix = function (m) {
  29577. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  29578. return this.setFromProjectionMatrix(m);
  29579. };
  29580. Line3.prototype.center = function (optionalTarget) {
  29581. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  29582. return this.getCenter(optionalTarget);
  29583. };
  29584. Object.assign(MathUtils, {
  29585. random16: function random16() {
  29586. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  29587. return Math.random();
  29588. },
  29589. nearestPowerOfTwo: function nearestPowerOfTwo(value) {
  29590. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  29591. return MathUtils.floorPowerOfTwo(value);
  29592. },
  29593. nextPowerOfTwo: function nextPowerOfTwo(value) {
  29594. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29595. return MathUtils.ceilPowerOfTwo(value);
  29596. }
  29597. });
  29598. Object.assign(Matrix3.prototype, {
  29599. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29600. console.warn('THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29601. return this.toArray(array, offset);
  29602. },
  29603. multiplyVector3: function multiplyVector3(vector) {
  29604. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29605. return vector.applyMatrix3(this);
  29606. },
  29607. multiplyVector3Array: function multiplyVector3Array()
  29608. /* a */
  29609. {
  29610. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29611. },
  29612. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29613. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29614. return attribute.applyMatrix3(this);
  29615. },
  29616. applyToVector3Array: function applyToVector3Array()
  29617. /* array, offset, length */
  29618. {
  29619. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29620. },
  29621. getInverse: function getInverse(matrix) {
  29622. console.warn('THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29623. return this.copy(matrix).invert();
  29624. }
  29625. });
  29626. Object.assign(Matrix4.prototype, {
  29627. extractPosition: function extractPosition(m) {
  29628. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29629. return this.copyPosition(m);
  29630. },
  29631. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29632. console.warn('THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29633. return this.toArray(array, offset);
  29634. },
  29635. getPosition: function getPosition() {
  29636. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29637. return new Vector3().setFromMatrixColumn(this, 3);
  29638. },
  29639. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  29640. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29641. return this.makeRotationFromQuaternion(q);
  29642. },
  29643. multiplyToArray: function multiplyToArray() {
  29644. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29645. },
  29646. multiplyVector3: function multiplyVector3(vector) {
  29647. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29648. return vector.applyMatrix4(this);
  29649. },
  29650. multiplyVector4: function multiplyVector4(vector) {
  29651. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29652. return vector.applyMatrix4(this);
  29653. },
  29654. multiplyVector3Array: function multiplyVector3Array()
  29655. /* a */
  29656. {
  29657. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29658. },
  29659. rotateAxis: function rotateAxis(v) {
  29660. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29661. v.transformDirection(this);
  29662. },
  29663. crossVector: function crossVector(vector) {
  29664. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29665. return vector.applyMatrix4(this);
  29666. },
  29667. translate: function translate() {
  29668. console.error('THREE.Matrix4: .translate() has been removed.');
  29669. },
  29670. rotateX: function rotateX() {
  29671. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29672. },
  29673. rotateY: function rotateY() {
  29674. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29675. },
  29676. rotateZ: function rotateZ() {
  29677. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29678. },
  29679. rotateByAxis: function rotateByAxis() {
  29680. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29681. },
  29682. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29683. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29684. return attribute.applyMatrix4(this);
  29685. },
  29686. applyToVector3Array: function applyToVector3Array()
  29687. /* array, offset, length */
  29688. {
  29689. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29690. },
  29691. makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
  29692. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29693. return this.makePerspective(left, right, top, bottom, near, far);
  29694. },
  29695. getInverse: function getInverse(matrix) {
  29696. console.warn('THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29697. return this.copy(matrix).invert();
  29698. }
  29699. });
  29700. Plane.prototype.isIntersectionLine = function (line) {
  29701. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29702. return this.intersectsLine(line);
  29703. };
  29704. Object.assign(Quaternion.prototype, {
  29705. multiplyVector3: function multiplyVector3(vector) {
  29706. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29707. return vector.applyQuaternion(this);
  29708. },
  29709. inverse: function inverse() {
  29710. console.warn('THREE.Quaternion: .inverse() has been renamed to invert().');
  29711. return this.invert();
  29712. }
  29713. });
  29714. Object.assign(Ray.prototype, {
  29715. isIntersectionBox: function isIntersectionBox(box) {
  29716. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29717. return this.intersectsBox(box);
  29718. },
  29719. isIntersectionPlane: function isIntersectionPlane(plane) {
  29720. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29721. return this.intersectsPlane(plane);
  29722. },
  29723. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29724. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29725. return this.intersectsSphere(sphere);
  29726. }
  29727. });
  29728. Object.assign(Triangle.prototype, {
  29729. area: function area() {
  29730. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  29731. return this.getArea();
  29732. },
  29733. barycoordFromPoint: function barycoordFromPoint(point, target) {
  29734. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29735. return this.getBarycoord(point, target);
  29736. },
  29737. midpoint: function midpoint(target) {
  29738. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  29739. return this.getMidpoint(target);
  29740. },
  29741. normal: function normal(target) {
  29742. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29743. return this.getNormal(target);
  29744. },
  29745. plane: function plane(target) {
  29746. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  29747. return this.getPlane(target);
  29748. }
  29749. });
  29750. Object.assign(Triangle, {
  29751. barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
  29752. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29753. return Triangle.getBarycoord(point, a, b, c, target);
  29754. },
  29755. normal: function normal(a, b, c, target) {
  29756. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29757. return Triangle.getNormal(a, b, c, target);
  29758. }
  29759. });
  29760. Object.assign(Shape.prototype, {
  29761. extractAllPoints: function extractAllPoints(divisions) {
  29762. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  29763. return this.extractPoints(divisions);
  29764. },
  29765. extrude: function extrude(options) {
  29766. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  29767. return new ExtrudeGeometry(this, options);
  29768. },
  29769. makeGeometry: function makeGeometry(options) {
  29770. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  29771. return new ShapeGeometry(this, options);
  29772. }
  29773. });
  29774. Object.assign(Vector2.prototype, {
  29775. fromAttribute: function fromAttribute(attribute, index, offset) {
  29776. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29777. return this.fromBufferAttribute(attribute, index, offset);
  29778. },
  29779. distanceToManhattan: function distanceToManhattan(v) {
  29780. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29781. return this.manhattanDistanceTo(v);
  29782. },
  29783. lengthManhattan: function lengthManhattan() {
  29784. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  29785. return this.manhattanLength();
  29786. }
  29787. });
  29788. Object.assign(Vector3.prototype, {
  29789. setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
  29790. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  29791. },
  29792. setEulerFromQuaternion: function setEulerFromQuaternion() {
  29793. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  29794. },
  29795. getPositionFromMatrix: function getPositionFromMatrix(m) {
  29796. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  29797. return this.setFromMatrixPosition(m);
  29798. },
  29799. getScaleFromMatrix: function getScaleFromMatrix(m) {
  29800. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  29801. return this.setFromMatrixScale(m);
  29802. },
  29803. getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
  29804. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  29805. return this.setFromMatrixColumn(matrix, index);
  29806. },
  29807. applyProjection: function applyProjection(m) {
  29808. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  29809. return this.applyMatrix4(m);
  29810. },
  29811. fromAttribute: function fromAttribute(attribute, index, offset) {
  29812. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29813. return this.fromBufferAttribute(attribute, index, offset);
  29814. },
  29815. distanceToManhattan: function distanceToManhattan(v) {
  29816. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29817. return this.manhattanDistanceTo(v);
  29818. },
  29819. lengthManhattan: function lengthManhattan() {
  29820. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  29821. return this.manhattanLength();
  29822. }
  29823. });
  29824. Object.assign(Vector4.prototype, {
  29825. fromAttribute: function fromAttribute(attribute, index, offset) {
  29826. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29827. return this.fromBufferAttribute(attribute, index, offset);
  29828. },
  29829. lengthManhattan: function lengthManhattan() {
  29830. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  29831. return this.manhattanLength();
  29832. }
  29833. }); //
  29834. Object.assign(Object3D.prototype, {
  29835. getChildByName: function getChildByName(name) {
  29836. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  29837. return this.getObjectByName(name);
  29838. },
  29839. renderDepth: function renderDepth() {
  29840. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  29841. },
  29842. translate: function translate(distance, axis) {
  29843. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  29844. return this.translateOnAxis(axis, distance);
  29845. },
  29846. getWorldRotation: function getWorldRotation() {
  29847. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  29848. },
  29849. applyMatrix: function applyMatrix(matrix) {
  29850. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  29851. return this.applyMatrix4(matrix);
  29852. }
  29853. });
  29854. Object.defineProperties(Object3D.prototype, {
  29855. eulerOrder: {
  29856. get: function get() {
  29857. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29858. return this.rotation.order;
  29859. },
  29860. set: function set(value) {
  29861. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29862. this.rotation.order = value;
  29863. }
  29864. },
  29865. useQuaternion: {
  29866. get: function get() {
  29867. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29868. },
  29869. set: function set() {
  29870. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29871. }
  29872. }
  29873. });
  29874. Object.assign(Mesh.prototype, {
  29875. setDrawMode: function setDrawMode() {
  29876. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29877. }
  29878. });
  29879. Object.defineProperties(Mesh.prototype, {
  29880. drawMode: {
  29881. get: function get() {
  29882. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  29883. return TrianglesDrawMode;
  29884. },
  29885. set: function set() {
  29886. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29887. }
  29888. }
  29889. });
  29890. Object.defineProperties(LOD.prototype, {
  29891. objects: {
  29892. get: function get() {
  29893. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  29894. return this.levels;
  29895. }
  29896. }
  29897. });
  29898. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  29899. get: function get() {
  29900. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29901. },
  29902. set: function set() {
  29903. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29904. }
  29905. });
  29906. SkinnedMesh.prototype.initBones = function () {
  29907. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  29908. };
  29909. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  29910. get: function get() {
  29911. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29912. return this.arcLengthDivisions;
  29913. },
  29914. set: function set(value) {
  29915. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29916. this.arcLengthDivisions = value;
  29917. }
  29918. }); //
  29919. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  29920. console.warn('THREE.PerspectiveCamera.setLens is deprecated. ' + 'Use .setFocalLength and .filmGauge for a photographic setup.');
  29921. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  29922. this.setFocalLength(focalLength);
  29923. }; //
  29924. Object.defineProperties(Light.prototype, {
  29925. onlyShadow: {
  29926. set: function set() {
  29927. console.warn('THREE.Light: .onlyShadow has been removed.');
  29928. }
  29929. },
  29930. shadowCameraFov: {
  29931. set: function set(value) {
  29932. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  29933. this.shadow.camera.fov = value;
  29934. }
  29935. },
  29936. shadowCameraLeft: {
  29937. set: function set(value) {
  29938. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  29939. this.shadow.camera.left = value;
  29940. }
  29941. },
  29942. shadowCameraRight: {
  29943. set: function set(value) {
  29944. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  29945. this.shadow.camera.right = value;
  29946. }
  29947. },
  29948. shadowCameraTop: {
  29949. set: function set(value) {
  29950. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  29951. this.shadow.camera.top = value;
  29952. }
  29953. },
  29954. shadowCameraBottom: {
  29955. set: function set(value) {
  29956. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  29957. this.shadow.camera.bottom = value;
  29958. }
  29959. },
  29960. shadowCameraNear: {
  29961. set: function set(value) {
  29962. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  29963. this.shadow.camera.near = value;
  29964. }
  29965. },
  29966. shadowCameraFar: {
  29967. set: function set(value) {
  29968. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  29969. this.shadow.camera.far = value;
  29970. }
  29971. },
  29972. shadowCameraVisible: {
  29973. set: function set() {
  29974. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  29975. }
  29976. },
  29977. shadowBias: {
  29978. set: function set(value) {
  29979. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  29980. this.shadow.bias = value;
  29981. }
  29982. },
  29983. shadowDarkness: {
  29984. set: function set() {
  29985. console.warn('THREE.Light: .shadowDarkness has been removed.');
  29986. }
  29987. },
  29988. shadowMapWidth: {
  29989. set: function set(value) {
  29990. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  29991. this.shadow.mapSize.width = value;
  29992. }
  29993. },
  29994. shadowMapHeight: {
  29995. set: function set(value) {
  29996. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  29997. this.shadow.mapSize.height = value;
  29998. }
  29999. }
  30000. }); //
  30001. Object.defineProperties(BufferAttribute.prototype, {
  30002. length: {
  30003. get: function get() {
  30004. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  30005. return this.array.length;
  30006. }
  30007. },
  30008. dynamic: {
  30009. get: function get() {
  30010. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  30011. return this.usage === DynamicDrawUsage;
  30012. },
  30013. set: function set()
  30014. /* value */
  30015. {
  30016. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  30017. this.setUsage(DynamicDrawUsage);
  30018. }
  30019. }
  30020. });
  30021. Object.assign(BufferAttribute.prototype, {
  30022. setDynamic: function setDynamic(value) {
  30023. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  30024. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  30025. return this;
  30026. },
  30027. copyIndicesArray: function copyIndicesArray()
  30028. /* indices */
  30029. {
  30030. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  30031. },
  30032. setArray: function setArray()
  30033. /* array */
  30034. {
  30035. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  30036. }
  30037. });
  30038. Object.assign(BufferGeometry.prototype, {
  30039. addIndex: function addIndex(index) {
  30040. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  30041. this.setIndex(index);
  30042. },
  30043. addAttribute: function addAttribute(name, attribute) {
  30044. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  30045. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  30046. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  30047. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  30048. }
  30049. if (name === 'index') {
  30050. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  30051. this.setIndex(attribute);
  30052. return this;
  30053. }
  30054. return this.setAttribute(name, attribute);
  30055. },
  30056. addDrawCall: function addDrawCall(start, count, indexOffset) {
  30057. if (indexOffset !== undefined) {
  30058. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  30059. }
  30060. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  30061. this.addGroup(start, count);
  30062. },
  30063. clearDrawCalls: function clearDrawCalls() {
  30064. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  30065. this.clearGroups();
  30066. },
  30067. computeOffsets: function computeOffsets() {
  30068. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  30069. },
  30070. removeAttribute: function removeAttribute(name) {
  30071. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  30072. return this.deleteAttribute(name);
  30073. },
  30074. applyMatrix: function applyMatrix(matrix) {
  30075. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  30076. return this.applyMatrix4(matrix);
  30077. }
  30078. });
  30079. Object.defineProperties(BufferGeometry.prototype, {
  30080. drawcalls: {
  30081. get: function get() {
  30082. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  30083. return this.groups;
  30084. }
  30085. },
  30086. offsets: {
  30087. get: function get() {
  30088. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  30089. return this.groups;
  30090. }
  30091. }
  30092. });
  30093. Object.defineProperties(InstancedBufferGeometry.prototype, {
  30094. maxInstancedCount: {
  30095. get: function get() {
  30096. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  30097. return this.instanceCount;
  30098. },
  30099. set: function set(value) {
  30100. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  30101. this.instanceCount = value;
  30102. }
  30103. }
  30104. });
  30105. Object.defineProperties(Raycaster.prototype, {
  30106. linePrecision: {
  30107. get: function get() {
  30108. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  30109. return this.params.Line.threshold;
  30110. },
  30111. set: function set(value) {
  30112. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  30113. this.params.Line.threshold = value;
  30114. }
  30115. }
  30116. });
  30117. Object.defineProperties(InterleavedBuffer.prototype, {
  30118. dynamic: {
  30119. get: function get() {
  30120. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  30121. return this.usage === DynamicDrawUsage;
  30122. },
  30123. set: function set(value) {
  30124. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  30125. this.setUsage(value);
  30126. }
  30127. }
  30128. });
  30129. Object.assign(InterleavedBuffer.prototype, {
  30130. setDynamic: function setDynamic(value) {
  30131. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  30132. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  30133. return this;
  30134. },
  30135. setArray: function setArray()
  30136. /* array */
  30137. {
  30138. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  30139. }
  30140. }); //
  30141. Object.assign(ExtrudeGeometry.prototype, {
  30142. getArrays: function getArrays() {
  30143. console.error('THREE.ExtrudeGeometry: .getArrays() has been removed.');
  30144. },
  30145. addShapeList: function addShapeList() {
  30146. console.error('THREE.ExtrudeGeometry: .addShapeList() has been removed.');
  30147. },
  30148. addShape: function addShape() {
  30149. console.error('THREE.ExtrudeGeometry: .addShape() has been removed.');
  30150. }
  30151. }); //
  30152. Object.assign(Scene.prototype, {
  30153. dispose: function dispose() {
  30154. console.error('THREE.Scene: .dispose() has been removed.');
  30155. }
  30156. }); //
  30157. Object.defineProperties(Uniform.prototype, {
  30158. dynamic: {
  30159. set: function set() {
  30160. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  30161. }
  30162. },
  30163. onUpdate: {
  30164. value: function value() {
  30165. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  30166. return this;
  30167. }
  30168. }
  30169. }); //
  30170. Object.defineProperties(Material.prototype, {
  30171. wrapAround: {
  30172. get: function get() {
  30173. console.warn('THREE.Material: .wrapAround has been removed.');
  30174. },
  30175. set: function set() {
  30176. console.warn('THREE.Material: .wrapAround has been removed.');
  30177. }
  30178. },
  30179. overdraw: {
  30180. get: function get() {
  30181. console.warn('THREE.Material: .overdraw has been removed.');
  30182. },
  30183. set: function set() {
  30184. console.warn('THREE.Material: .overdraw has been removed.');
  30185. }
  30186. },
  30187. wrapRGB: {
  30188. get: function get() {
  30189. console.warn('THREE.Material: .wrapRGB has been removed.');
  30190. return new Color();
  30191. }
  30192. },
  30193. shading: {
  30194. get: function get() {
  30195. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  30196. },
  30197. set: function set(value) {
  30198. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  30199. this.flatShading = value === FlatShading;
  30200. }
  30201. },
  30202. stencilMask: {
  30203. get: function get() {
  30204. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30205. return this.stencilFuncMask;
  30206. },
  30207. set: function set(value) {
  30208. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30209. this.stencilFuncMask = value;
  30210. }
  30211. }
  30212. });
  30213. Object.defineProperties(MeshPhongMaterial.prototype, {
  30214. metal: {
  30215. get: function get() {
  30216. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  30217. return false;
  30218. },
  30219. set: function set() {
  30220. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  30221. }
  30222. }
  30223. });
  30224. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  30225. transparency: {
  30226. get: function get() {
  30227. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30228. return this.transmission;
  30229. },
  30230. set: function set(value) {
  30231. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30232. this.transmission = value;
  30233. }
  30234. }
  30235. });
  30236. Object.defineProperties(ShaderMaterial.prototype, {
  30237. derivatives: {
  30238. get: function get() {
  30239. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30240. return this.extensions.derivatives;
  30241. },
  30242. set: function set(value) {
  30243. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30244. this.extensions.derivatives = value;
  30245. }
  30246. }
  30247. }); //
  30248. Object.assign(WebGLRenderer.prototype, {
  30249. clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
  30250. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  30251. this.setRenderTarget(renderTarget);
  30252. this.clear(color, depth, stencil);
  30253. },
  30254. animate: function animate(callback) {
  30255. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  30256. this.setAnimationLoop(callback);
  30257. },
  30258. getCurrentRenderTarget: function getCurrentRenderTarget() {
  30259. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  30260. return this.getRenderTarget();
  30261. },
  30262. getMaxAnisotropy: function getMaxAnisotropy() {
  30263. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  30264. return this.capabilities.getMaxAnisotropy();
  30265. },
  30266. getPrecision: function getPrecision() {
  30267. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  30268. return this.capabilities.precision;
  30269. },
  30270. resetGLState: function resetGLState() {
  30271. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  30272. return this.state.reset();
  30273. },
  30274. supportsFloatTextures: function supportsFloatTextures() {
  30275. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  30276. return this.extensions.get('OES_texture_float');
  30277. },
  30278. supportsHalfFloatTextures: function supportsHalfFloatTextures() {
  30279. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  30280. return this.extensions.get('OES_texture_half_float');
  30281. },
  30282. supportsStandardDerivatives: function supportsStandardDerivatives() {
  30283. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  30284. return this.extensions.get('OES_standard_derivatives');
  30285. },
  30286. supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
  30287. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  30288. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  30289. },
  30290. supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
  30291. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  30292. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  30293. },
  30294. supportsBlendMinMax: function supportsBlendMinMax() {
  30295. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  30296. return this.extensions.get('EXT_blend_minmax');
  30297. },
  30298. supportsVertexTextures: function supportsVertexTextures() {
  30299. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  30300. return this.capabilities.vertexTextures;
  30301. },
  30302. supportsInstancedArrays: function supportsInstancedArrays() {
  30303. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  30304. return this.extensions.get('ANGLE_instanced_arrays');
  30305. },
  30306. enableScissorTest: function enableScissorTest(boolean) {
  30307. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  30308. this.setScissorTest(boolean);
  30309. },
  30310. initMaterial: function initMaterial() {
  30311. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  30312. },
  30313. addPrePlugin: function addPrePlugin() {
  30314. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  30315. },
  30316. addPostPlugin: function addPostPlugin() {
  30317. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  30318. },
  30319. updateShadowMap: function updateShadowMap() {
  30320. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  30321. },
  30322. setFaceCulling: function setFaceCulling() {
  30323. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  30324. },
  30325. allocTextureUnit: function allocTextureUnit() {
  30326. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  30327. },
  30328. setTexture: function setTexture() {
  30329. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  30330. },
  30331. setTexture2D: function setTexture2D() {
  30332. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  30333. },
  30334. setTextureCube: function setTextureCube() {
  30335. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  30336. },
  30337. getActiveMipMapLevel: function getActiveMipMapLevel() {
  30338. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  30339. return this.getActiveMipmapLevel();
  30340. }
  30341. });
  30342. Object.defineProperties(WebGLRenderer.prototype, {
  30343. shadowMapEnabled: {
  30344. get: function get() {
  30345. return this.shadowMap.enabled;
  30346. },
  30347. set: function set(value) {
  30348. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  30349. this.shadowMap.enabled = value;
  30350. }
  30351. },
  30352. shadowMapType: {
  30353. get: function get() {
  30354. return this.shadowMap.type;
  30355. },
  30356. set: function set(value) {
  30357. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  30358. this.shadowMap.type = value;
  30359. }
  30360. },
  30361. shadowMapCullFace: {
  30362. get: function get() {
  30363. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30364. return undefined;
  30365. },
  30366. set: function set()
  30367. /* value */
  30368. {
  30369. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30370. }
  30371. },
  30372. context: {
  30373. get: function get() {
  30374. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  30375. return this.getContext();
  30376. }
  30377. },
  30378. vr: {
  30379. get: function get() {
  30380. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  30381. return this.xr;
  30382. }
  30383. },
  30384. gammaInput: {
  30385. get: function get() {
  30386. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30387. return false;
  30388. },
  30389. set: function set() {
  30390. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30391. }
  30392. },
  30393. gammaOutput: {
  30394. get: function get() {
  30395. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30396. return false;
  30397. },
  30398. set: function set(value) {
  30399. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30400. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  30401. }
  30402. },
  30403. toneMappingWhitePoint: {
  30404. get: function get() {
  30405. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30406. return 1.0;
  30407. },
  30408. set: function set() {
  30409. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30410. }
  30411. }
  30412. });
  30413. Object.defineProperties(WebGLShadowMap.prototype, {
  30414. cullFace: {
  30415. get: function get() {
  30416. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30417. return undefined;
  30418. },
  30419. set: function set()
  30420. /* cullFace */
  30421. {
  30422. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30423. }
  30424. },
  30425. renderReverseSided: {
  30426. get: function get() {
  30427. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30428. return undefined;
  30429. },
  30430. set: function set() {
  30431. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30432. }
  30433. },
  30434. renderSingleSided: {
  30435. get: function get() {
  30436. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30437. return undefined;
  30438. },
  30439. set: function set() {
  30440. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30441. }
  30442. }
  30443. });
  30444. function WebGLRenderTargetCube(width, height, options) {
  30445. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  30446. return new WebGLCubeRenderTarget(width, options);
  30447. } //
  30448. Object.defineProperties(WebGLRenderTarget.prototype, {
  30449. wrapS: {
  30450. get: function get() {
  30451. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30452. return this.texture.wrapS;
  30453. },
  30454. set: function set(value) {
  30455. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30456. this.texture.wrapS = value;
  30457. }
  30458. },
  30459. wrapT: {
  30460. get: function get() {
  30461. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30462. return this.texture.wrapT;
  30463. },
  30464. set: function set(value) {
  30465. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30466. this.texture.wrapT = value;
  30467. }
  30468. },
  30469. magFilter: {
  30470. get: function get() {
  30471. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30472. return this.texture.magFilter;
  30473. },
  30474. set: function set(value) {
  30475. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30476. this.texture.magFilter = value;
  30477. }
  30478. },
  30479. minFilter: {
  30480. get: function get() {
  30481. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30482. return this.texture.minFilter;
  30483. },
  30484. set: function set(value) {
  30485. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30486. this.texture.minFilter = value;
  30487. }
  30488. },
  30489. anisotropy: {
  30490. get: function get() {
  30491. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30492. return this.texture.anisotropy;
  30493. },
  30494. set: function set(value) {
  30495. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30496. this.texture.anisotropy = value;
  30497. }
  30498. },
  30499. offset: {
  30500. get: function get() {
  30501. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30502. return this.texture.offset;
  30503. },
  30504. set: function set(value) {
  30505. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30506. this.texture.offset = value;
  30507. }
  30508. },
  30509. repeat: {
  30510. get: function get() {
  30511. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30512. return this.texture.repeat;
  30513. },
  30514. set: function set(value) {
  30515. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30516. this.texture.repeat = value;
  30517. }
  30518. },
  30519. format: {
  30520. get: function get() {
  30521. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30522. return this.texture.format;
  30523. },
  30524. set: function set(value) {
  30525. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30526. this.texture.format = value;
  30527. }
  30528. },
  30529. type: {
  30530. get: function get() {
  30531. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30532. return this.texture.type;
  30533. },
  30534. set: function set(value) {
  30535. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30536. this.texture.type = value;
  30537. }
  30538. },
  30539. generateMipmaps: {
  30540. get: function get() {
  30541. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30542. return this.texture.generateMipmaps;
  30543. },
  30544. set: function set(value) {
  30545. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30546. this.texture.generateMipmaps = value;
  30547. }
  30548. }
  30549. }); //
  30550. Object.defineProperties(Audio.prototype, {
  30551. load: {
  30552. value: function value(file) {
  30553. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  30554. var scope = this;
  30555. var audioLoader = new AudioLoader();
  30556. audioLoader.load(file, function (buffer) {
  30557. scope.setBuffer(buffer);
  30558. });
  30559. return this;
  30560. }
  30561. },
  30562. startTime: {
  30563. set: function set() {
  30564. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  30565. }
  30566. }
  30567. });
  30568. AudioAnalyser.prototype.getData = function () {
  30569. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  30570. return this.getFrequencyData();
  30571. }; //
  30572. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  30573. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  30574. return this.update(renderer, scene);
  30575. };
  30576. CubeCamera.prototype.clear = function (renderer, color, depth, stencil) {
  30577. console.warn('THREE.CubeCamera: .clear() is now .renderTarget.clear().');
  30578. return this.renderTarget.clear(renderer, color, depth, stencil);
  30579. };
  30580. ImageUtils.crossOrigin = undefined;
  30581. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30582. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30583. var loader = new TextureLoader();
  30584. loader.setCrossOrigin(this.crossOrigin);
  30585. var texture = loader.load(url, onLoad, undefined, onError);
  30586. if (mapping) texture.mapping = mapping;
  30587. return texture;
  30588. };
  30589. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30590. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30591. var loader = new CubeTextureLoader();
  30592. loader.setCrossOrigin(this.crossOrigin);
  30593. var texture = loader.load(urls, onLoad, undefined, onError);
  30594. if (mapping) texture.mapping = mapping;
  30595. return texture;
  30596. };
  30597. ImageUtils.loadCompressedTexture = function () {
  30598. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30599. };
  30600. ImageUtils.loadCompressedTextureCube = function () {
  30601. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30602. }; //
  30603. function CanvasRenderer() {
  30604. console.error('THREE.CanvasRenderer has been removed');
  30605. } //
  30606. function JSONLoader() {
  30607. console.error('THREE.JSONLoader has been removed.');
  30608. } //
  30609. var SceneUtils = {
  30610. createMultiMaterialObject: function createMultiMaterialObject()
  30611. /* geometry, materials */
  30612. {
  30613. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30614. },
  30615. detach: function detach()
  30616. /* child, parent, scene */
  30617. {
  30618. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30619. },
  30620. attach: function attach()
  30621. /* child, scene, parent */
  30622. {
  30623. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30624. }
  30625. }; //
  30626. function LensFlare() {
  30627. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30628. }
  30629. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30630. /* eslint-disable no-undef */
  30631. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30632. detail: {
  30633. revision: REVISION
  30634. }
  30635. }));
  30636. /* eslint-enable no-undef */
  30637. }
  30638. if (typeof window !== 'undefined') {
  30639. if (window.__THREE__) {
  30640. console.warn('WARNING: Multiple instances of Three.js being imported.');
  30641. } else {
  30642. window.__THREE__ = REVISION;
  30643. }
  30644. }
  30645. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30646. exports.AddEquation = AddEquation;
  30647. exports.AddOperation = AddOperation;
  30648. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30649. exports.AdditiveBlending = AdditiveBlending;
  30650. exports.AlphaFormat = AlphaFormat;
  30651. exports.AlwaysDepth = AlwaysDepth;
  30652. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30653. exports.AmbientLight = AmbientLight;
  30654. exports.AmbientLightProbe = AmbientLightProbe;
  30655. exports.AnimationClip = AnimationClip;
  30656. exports.AnimationLoader = AnimationLoader;
  30657. exports.AnimationMixer = AnimationMixer;
  30658. exports.AnimationObjectGroup = AnimationObjectGroup;
  30659. exports.AnimationUtils = AnimationUtils;
  30660. exports.ArcCurve = ArcCurve;
  30661. exports.ArrayCamera = ArrayCamera;
  30662. exports.ArrowHelper = ArrowHelper;
  30663. exports.Audio = Audio;
  30664. exports.AudioAnalyser = AudioAnalyser;
  30665. exports.AudioContext = AudioContext;
  30666. exports.AudioListener = AudioListener;
  30667. exports.AudioLoader = AudioLoader;
  30668. exports.AxesHelper = AxesHelper;
  30669. exports.AxisHelper = AxisHelper;
  30670. exports.BackSide = BackSide;
  30671. exports.BasicDepthPacking = BasicDepthPacking;
  30672. exports.BasicShadowMap = BasicShadowMap;
  30673. exports.BinaryTextureLoader = BinaryTextureLoader;
  30674. exports.Bone = Bone;
  30675. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30676. exports.BoundingBoxHelper = BoundingBoxHelper;
  30677. exports.Box2 = Box2;
  30678. exports.Box3 = Box3;
  30679. exports.Box3Helper = Box3Helper;
  30680. exports.BoxBufferGeometry = BoxGeometry;
  30681. exports.BoxGeometry = BoxGeometry;
  30682. exports.BoxHelper = BoxHelper;
  30683. exports.BufferAttribute = BufferAttribute;
  30684. exports.BufferGeometry = BufferGeometry;
  30685. exports.BufferGeometryLoader = BufferGeometryLoader;
  30686. exports.ByteType = ByteType;
  30687. exports.Cache = Cache;
  30688. exports.Camera = Camera;
  30689. exports.CameraHelper = CameraHelper;
  30690. exports.CanvasRenderer = CanvasRenderer;
  30691. exports.CanvasTexture = CanvasTexture;
  30692. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30693. exports.CineonToneMapping = CineonToneMapping;
  30694. exports.CircleBufferGeometry = CircleGeometry;
  30695. exports.CircleGeometry = CircleGeometry;
  30696. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30697. exports.Clock = Clock;
  30698. exports.Color = Color;
  30699. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30700. exports.CompressedTexture = CompressedTexture;
  30701. exports.CompressedTextureLoader = CompressedTextureLoader;
  30702. exports.ConeBufferGeometry = ConeGeometry;
  30703. exports.ConeGeometry = ConeGeometry;
  30704. exports.CubeCamera = CubeCamera;
  30705. exports.CubeReflectionMapping = CubeReflectionMapping;
  30706. exports.CubeRefractionMapping = CubeRefractionMapping;
  30707. exports.CubeTexture = CubeTexture;
  30708. exports.CubeTextureLoader = CubeTextureLoader;
  30709. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  30710. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  30711. exports.CubicBezierCurve = CubicBezierCurve;
  30712. exports.CubicBezierCurve3 = CubicBezierCurve3;
  30713. exports.CubicInterpolant = CubicInterpolant;
  30714. exports.CullFaceBack = CullFaceBack;
  30715. exports.CullFaceFront = CullFaceFront;
  30716. exports.CullFaceFrontBack = CullFaceFrontBack;
  30717. exports.CullFaceNone = CullFaceNone;
  30718. exports.Curve = Curve;
  30719. exports.CurvePath = CurvePath;
  30720. exports.CustomBlending = CustomBlending;
  30721. exports.CustomToneMapping = CustomToneMapping;
  30722. exports.CylinderBufferGeometry = CylinderGeometry;
  30723. exports.CylinderGeometry = CylinderGeometry;
  30724. exports.Cylindrical = Cylindrical;
  30725. exports.DataTexture = DataTexture;
  30726. exports.DataTexture2DArray = DataTexture2DArray;
  30727. exports.DataTexture3D = DataTexture3D;
  30728. exports.DataTextureLoader = DataTextureLoader;
  30729. exports.DataUtils = DataUtils;
  30730. exports.DecrementStencilOp = DecrementStencilOp;
  30731. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  30732. exports.DefaultLoadingManager = DefaultLoadingManager;
  30733. exports.DepthFormat = DepthFormat;
  30734. exports.DepthStencilFormat = DepthStencilFormat;
  30735. exports.DepthTexture = DepthTexture;
  30736. exports.DirectionalLight = DirectionalLight;
  30737. exports.DirectionalLightHelper = DirectionalLightHelper;
  30738. exports.DiscreteInterpolant = DiscreteInterpolant;
  30739. exports.DodecahedronBufferGeometry = DodecahedronGeometry;
  30740. exports.DodecahedronGeometry = DodecahedronGeometry;
  30741. exports.DoubleSide = DoubleSide;
  30742. exports.DstAlphaFactor = DstAlphaFactor;
  30743. exports.DstColorFactor = DstColorFactor;
  30744. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  30745. exports.DynamicCopyUsage = DynamicCopyUsage;
  30746. exports.DynamicDrawUsage = DynamicDrawUsage;
  30747. exports.DynamicReadUsage = DynamicReadUsage;
  30748. exports.EdgesGeometry = EdgesGeometry;
  30749. exports.EdgesHelper = EdgesHelper;
  30750. exports.EllipseCurve = EllipseCurve;
  30751. exports.EqualDepth = EqualDepth;
  30752. exports.EqualStencilFunc = EqualStencilFunc;
  30753. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  30754. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  30755. exports.Euler = Euler;
  30756. exports.EventDispatcher = EventDispatcher;
  30757. exports.ExtrudeBufferGeometry = ExtrudeGeometry;
  30758. exports.ExtrudeGeometry = ExtrudeGeometry;
  30759. exports.FaceColors = FaceColors;
  30760. exports.FileLoader = FileLoader;
  30761. exports.FlatShading = FlatShading;
  30762. exports.Float16BufferAttribute = Float16BufferAttribute;
  30763. exports.Float32Attribute = Float32Attribute;
  30764. exports.Float32BufferAttribute = Float32BufferAttribute;
  30765. exports.Float64Attribute = Float64Attribute;
  30766. exports.Float64BufferAttribute = Float64BufferAttribute;
  30767. exports.FloatType = FloatType;
  30768. exports.Fog = Fog;
  30769. exports.FogExp2 = FogExp2;
  30770. exports.Font = Font;
  30771. exports.FontLoader = FontLoader;
  30772. exports.FrontSide = FrontSide;
  30773. exports.Frustum = Frustum;
  30774. exports.GLBufferAttribute = GLBufferAttribute;
  30775. exports.GLSL1 = GLSL1;
  30776. exports.GLSL3 = GLSL3;
  30777. exports.GammaEncoding = GammaEncoding;
  30778. exports.GreaterDepth = GreaterDepth;
  30779. exports.GreaterEqualDepth = GreaterEqualDepth;
  30780. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  30781. exports.GreaterStencilFunc = GreaterStencilFunc;
  30782. exports.GridHelper = GridHelper;
  30783. exports.Group = Group;
  30784. exports.HalfFloatType = HalfFloatType;
  30785. exports.HemisphereLight = HemisphereLight;
  30786. exports.HemisphereLightHelper = HemisphereLightHelper;
  30787. exports.HemisphereLightProbe = HemisphereLightProbe;
  30788. exports.IcosahedronBufferGeometry = IcosahedronGeometry;
  30789. exports.IcosahedronGeometry = IcosahedronGeometry;
  30790. exports.ImageBitmapLoader = ImageBitmapLoader;
  30791. exports.ImageLoader = ImageLoader;
  30792. exports.ImageUtils = ImageUtils;
  30793. exports.ImmediateRenderObject = ImmediateRenderObject;
  30794. exports.IncrementStencilOp = IncrementStencilOp;
  30795. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  30796. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  30797. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  30798. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  30799. exports.InstancedMesh = InstancedMesh;
  30800. exports.Int16Attribute = Int16Attribute;
  30801. exports.Int16BufferAttribute = Int16BufferAttribute;
  30802. exports.Int32Attribute = Int32Attribute;
  30803. exports.Int32BufferAttribute = Int32BufferAttribute;
  30804. exports.Int8Attribute = Int8Attribute;
  30805. exports.Int8BufferAttribute = Int8BufferAttribute;
  30806. exports.IntType = IntType;
  30807. exports.InterleavedBuffer = InterleavedBuffer;
  30808. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  30809. exports.Interpolant = Interpolant;
  30810. exports.InterpolateDiscrete = InterpolateDiscrete;
  30811. exports.InterpolateLinear = InterpolateLinear;
  30812. exports.InterpolateSmooth = InterpolateSmooth;
  30813. exports.InvertStencilOp = InvertStencilOp;
  30814. exports.JSONLoader = JSONLoader;
  30815. exports.KeepStencilOp = KeepStencilOp;
  30816. exports.KeyframeTrack = KeyframeTrack;
  30817. exports.LOD = LOD;
  30818. exports.LatheBufferGeometry = LatheGeometry;
  30819. exports.LatheGeometry = LatheGeometry;
  30820. exports.Layers = Layers;
  30821. exports.LensFlare = LensFlare;
  30822. exports.LessDepth = LessDepth;
  30823. exports.LessEqualDepth = LessEqualDepth;
  30824. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  30825. exports.LessStencilFunc = LessStencilFunc;
  30826. exports.Light = Light;
  30827. exports.LightProbe = LightProbe;
  30828. exports.Line = Line;
  30829. exports.Line3 = Line3;
  30830. exports.LineBasicMaterial = LineBasicMaterial;
  30831. exports.LineCurve = LineCurve;
  30832. exports.LineCurve3 = LineCurve3;
  30833. exports.LineDashedMaterial = LineDashedMaterial;
  30834. exports.LineLoop = LineLoop;
  30835. exports.LinePieces = LinePieces;
  30836. exports.LineSegments = LineSegments;
  30837. exports.LineStrip = LineStrip;
  30838. exports.LinearEncoding = LinearEncoding;
  30839. exports.LinearFilter = LinearFilter;
  30840. exports.LinearInterpolant = LinearInterpolant;
  30841. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  30842. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  30843. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  30844. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  30845. exports.LinearToneMapping = LinearToneMapping;
  30846. exports.Loader = Loader;
  30847. exports.LoaderUtils = LoaderUtils;
  30848. exports.LoadingManager = LoadingManager;
  30849. exports.LogLuvEncoding = LogLuvEncoding;
  30850. exports.LoopOnce = LoopOnce;
  30851. exports.LoopPingPong = LoopPingPong;
  30852. exports.LoopRepeat = LoopRepeat;
  30853. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  30854. exports.LuminanceFormat = LuminanceFormat;
  30855. exports.MOUSE = MOUSE;
  30856. exports.Material = Material;
  30857. exports.MaterialLoader = MaterialLoader;
  30858. exports.Math = MathUtils;
  30859. exports.MathUtils = MathUtils;
  30860. exports.Matrix3 = Matrix3;
  30861. exports.Matrix4 = Matrix4;
  30862. exports.MaxEquation = MaxEquation;
  30863. exports.Mesh = Mesh;
  30864. exports.MeshBasicMaterial = MeshBasicMaterial;
  30865. exports.MeshDepthMaterial = MeshDepthMaterial;
  30866. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  30867. exports.MeshFaceMaterial = MeshFaceMaterial;
  30868. exports.MeshLambertMaterial = MeshLambertMaterial;
  30869. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  30870. exports.MeshNormalMaterial = MeshNormalMaterial;
  30871. exports.MeshPhongMaterial = MeshPhongMaterial;
  30872. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  30873. exports.MeshStandardMaterial = MeshStandardMaterial;
  30874. exports.MeshToonMaterial = MeshToonMaterial;
  30875. exports.MinEquation = MinEquation;
  30876. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  30877. exports.MixOperation = MixOperation;
  30878. exports.MultiMaterial = MultiMaterial;
  30879. exports.MultiplyBlending = MultiplyBlending;
  30880. exports.MultiplyOperation = MultiplyOperation;
  30881. exports.NearestFilter = NearestFilter;
  30882. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  30883. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  30884. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  30885. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  30886. exports.NeverDepth = NeverDepth;
  30887. exports.NeverStencilFunc = NeverStencilFunc;
  30888. exports.NoBlending = NoBlending;
  30889. exports.NoColors = NoColors;
  30890. exports.NoToneMapping = NoToneMapping;
  30891. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  30892. exports.NormalBlending = NormalBlending;
  30893. exports.NotEqualDepth = NotEqualDepth;
  30894. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  30895. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  30896. exports.Object3D = Object3D;
  30897. exports.ObjectLoader = ObjectLoader;
  30898. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  30899. exports.OctahedronBufferGeometry = OctahedronGeometry;
  30900. exports.OctahedronGeometry = OctahedronGeometry;
  30901. exports.OneFactor = OneFactor;
  30902. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  30903. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  30904. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  30905. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  30906. exports.OrthographicCamera = OrthographicCamera;
  30907. exports.PCFShadowMap = PCFShadowMap;
  30908. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  30909. exports.PMREMGenerator = PMREMGenerator;
  30910. exports.ParametricBufferGeometry = ParametricGeometry;
  30911. exports.ParametricGeometry = ParametricGeometry;
  30912. exports.Particle = Particle;
  30913. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  30914. exports.ParticleSystem = ParticleSystem;
  30915. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  30916. exports.Path = Path;
  30917. exports.PerspectiveCamera = PerspectiveCamera;
  30918. exports.Plane = Plane;
  30919. exports.PlaneBufferGeometry = PlaneGeometry;
  30920. exports.PlaneGeometry = PlaneGeometry;
  30921. exports.PlaneHelper = PlaneHelper;
  30922. exports.PointCloud = PointCloud;
  30923. exports.PointCloudMaterial = PointCloudMaterial;
  30924. exports.PointLight = PointLight;
  30925. exports.PointLightHelper = PointLightHelper;
  30926. exports.Points = Points;
  30927. exports.PointsMaterial = PointsMaterial;
  30928. exports.PolarGridHelper = PolarGridHelper;
  30929. exports.PolyhedronBufferGeometry = PolyhedronGeometry;
  30930. exports.PolyhedronGeometry = PolyhedronGeometry;
  30931. exports.PositionalAudio = PositionalAudio;
  30932. exports.PropertyBinding = PropertyBinding;
  30933. exports.PropertyMixer = PropertyMixer;
  30934. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  30935. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  30936. exports.Quaternion = Quaternion;
  30937. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  30938. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  30939. exports.REVISION = REVISION;
  30940. exports.RGBADepthPacking = RGBADepthPacking;
  30941. exports.RGBAFormat = RGBAFormat;
  30942. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  30943. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  30944. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  30945. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  30946. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  30947. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  30948. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  30949. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  30950. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  30951. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  30952. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  30953. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  30954. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  30955. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  30956. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  30957. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  30958. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  30959. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  30960. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  30961. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  30962. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  30963. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  30964. exports.RGBDEncoding = RGBDEncoding;
  30965. exports.RGBEEncoding = RGBEEncoding;
  30966. exports.RGBEFormat = RGBEFormat;
  30967. exports.RGBFormat = RGBFormat;
  30968. exports.RGBIntegerFormat = RGBIntegerFormat;
  30969. exports.RGBM16Encoding = RGBM16Encoding;
  30970. exports.RGBM7Encoding = RGBM7Encoding;
  30971. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  30972. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  30973. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  30974. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  30975. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  30976. exports.RGFormat = RGFormat;
  30977. exports.RGIntegerFormat = RGIntegerFormat;
  30978. exports.RawShaderMaterial = RawShaderMaterial;
  30979. exports.Ray = Ray;
  30980. exports.Raycaster = Raycaster;
  30981. exports.RectAreaLight = RectAreaLight;
  30982. exports.RedFormat = RedFormat;
  30983. exports.RedIntegerFormat = RedIntegerFormat;
  30984. exports.ReinhardToneMapping = ReinhardToneMapping;
  30985. exports.RepeatWrapping = RepeatWrapping;
  30986. exports.ReplaceStencilOp = ReplaceStencilOp;
  30987. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  30988. exports.RingBufferGeometry = RingGeometry;
  30989. exports.RingGeometry = RingGeometry;
  30990. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  30991. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  30992. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  30993. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  30994. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  30995. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  30996. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  30997. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  30998. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  30999. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  31000. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  31001. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  31002. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  31003. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  31004. exports.Scene = Scene;
  31005. exports.SceneUtils = SceneUtils;
  31006. exports.ShaderChunk = ShaderChunk;
  31007. exports.ShaderLib = ShaderLib;
  31008. exports.ShaderMaterial = ShaderMaterial;
  31009. exports.ShadowMaterial = ShadowMaterial;
  31010. exports.Shape = Shape;
  31011. exports.ShapeBufferGeometry = ShapeGeometry;
  31012. exports.ShapeGeometry = ShapeGeometry;
  31013. exports.ShapePath = ShapePath;
  31014. exports.ShapeUtils = ShapeUtils;
  31015. exports.ShortType = ShortType;
  31016. exports.Skeleton = Skeleton;
  31017. exports.SkeletonHelper = SkeletonHelper;
  31018. exports.SkinnedMesh = SkinnedMesh;
  31019. exports.SmoothShading = SmoothShading;
  31020. exports.Sphere = Sphere;
  31021. exports.SphereBufferGeometry = SphereGeometry;
  31022. exports.SphereGeometry = SphereGeometry;
  31023. exports.Spherical = Spherical;
  31024. exports.SphericalHarmonics3 = SphericalHarmonics3;
  31025. exports.SplineCurve = SplineCurve;
  31026. exports.SpotLight = SpotLight;
  31027. exports.SpotLightHelper = SpotLightHelper;
  31028. exports.Sprite = Sprite;
  31029. exports.SpriteMaterial = SpriteMaterial;
  31030. exports.SrcAlphaFactor = SrcAlphaFactor;
  31031. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  31032. exports.SrcColorFactor = SrcColorFactor;
  31033. exports.StaticCopyUsage = StaticCopyUsage;
  31034. exports.StaticDrawUsage = StaticDrawUsage;
  31035. exports.StaticReadUsage = StaticReadUsage;
  31036. exports.StereoCamera = StereoCamera;
  31037. exports.StreamCopyUsage = StreamCopyUsage;
  31038. exports.StreamDrawUsage = StreamDrawUsage;
  31039. exports.StreamReadUsage = StreamReadUsage;
  31040. exports.StringKeyframeTrack = StringKeyframeTrack;
  31041. exports.SubtractEquation = SubtractEquation;
  31042. exports.SubtractiveBlending = SubtractiveBlending;
  31043. exports.TOUCH = TOUCH;
  31044. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  31045. exports.TetrahedronBufferGeometry = TetrahedronGeometry;
  31046. exports.TetrahedronGeometry = TetrahedronGeometry;
  31047. exports.TextBufferGeometry = TextGeometry;
  31048. exports.TextGeometry = TextGeometry;
  31049. exports.Texture = Texture;
  31050. exports.TextureLoader = TextureLoader;
  31051. exports.TorusBufferGeometry = TorusGeometry;
  31052. exports.TorusGeometry = TorusGeometry;
  31053. exports.TorusKnotBufferGeometry = TorusKnotGeometry;
  31054. exports.TorusKnotGeometry = TorusKnotGeometry;
  31055. exports.Triangle = Triangle;
  31056. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  31057. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  31058. exports.TrianglesDrawMode = TrianglesDrawMode;
  31059. exports.TubeBufferGeometry = TubeGeometry;
  31060. exports.TubeGeometry = TubeGeometry;
  31061. exports.UVMapping = UVMapping;
  31062. exports.Uint16Attribute = Uint16Attribute;
  31063. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  31064. exports.Uint32Attribute = Uint32Attribute;
  31065. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  31066. exports.Uint8Attribute = Uint8Attribute;
  31067. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  31068. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  31069. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  31070. exports.Uniform = Uniform;
  31071. exports.UniformsLib = UniformsLib;
  31072. exports.UniformsUtils = UniformsUtils;
  31073. exports.UnsignedByteType = UnsignedByteType;
  31074. exports.UnsignedInt248Type = UnsignedInt248Type;
  31075. exports.UnsignedIntType = UnsignedIntType;
  31076. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  31077. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  31078. exports.UnsignedShort565Type = UnsignedShort565Type;
  31079. exports.UnsignedShortType = UnsignedShortType;
  31080. exports.VSMShadowMap = VSMShadowMap;
  31081. exports.Vector2 = Vector2;
  31082. exports.Vector3 = Vector3;
  31083. exports.Vector4 = Vector4;
  31084. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  31085. exports.Vertex = Vertex;
  31086. exports.VertexColors = VertexColors;
  31087. exports.VideoTexture = VideoTexture;
  31088. exports.WebGL1Renderer = WebGL1Renderer;
  31089. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  31090. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  31091. exports.WebGLRenderTarget = WebGLRenderTarget;
  31092. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  31093. exports.WebGLRenderer = WebGLRenderer;
  31094. exports.WebGLUtils = WebGLUtils;
  31095. exports.WireframeGeometry = WireframeGeometry;
  31096. exports.WireframeHelper = WireframeHelper;
  31097. exports.WrapAroundEnding = WrapAroundEnding;
  31098. exports.XHRLoader = XHRLoader;
  31099. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  31100. exports.ZeroFactor = ZeroFactor;
  31101. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  31102. exports.ZeroStencilOp = ZeroStencilOp;
  31103. exports.sRGBEncoding = sRGBEncoding;
  31104. Object.defineProperty(exports, '__esModule', { value: true });
  31105. })));