three.js 1.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359
  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 = '125';
  650. var MOUSE = {
  651. LEFT: 0,
  652. MIDDLE: 1,
  653. RIGHT: 2,
  654. ROTATE: 0,
  655. DOLLY: 1,
  656. PAN: 2
  657. };
  658. var TOUCH = {
  659. ROTATE: 0,
  660. PAN: 1,
  661. DOLLY_PAN: 2,
  662. DOLLY_ROTATE: 3
  663. };
  664. var CullFaceNone = 0;
  665. var CullFaceBack = 1;
  666. var CullFaceFront = 2;
  667. var CullFaceFrontBack = 3;
  668. var BasicShadowMap = 0;
  669. var PCFShadowMap = 1;
  670. var PCFSoftShadowMap = 2;
  671. var VSMShadowMap = 3;
  672. var FrontSide = 0;
  673. var BackSide = 1;
  674. var DoubleSide = 2;
  675. var FlatShading = 1;
  676. var SmoothShading = 2;
  677. var NoBlending = 0;
  678. var NormalBlending = 1;
  679. var AdditiveBlending = 2;
  680. var SubtractiveBlending = 3;
  681. var MultiplyBlending = 4;
  682. var CustomBlending = 5;
  683. var AddEquation = 100;
  684. var SubtractEquation = 101;
  685. var ReverseSubtractEquation = 102;
  686. var MinEquation = 103;
  687. var MaxEquation = 104;
  688. var ZeroFactor = 200;
  689. var OneFactor = 201;
  690. var SrcColorFactor = 202;
  691. var OneMinusSrcColorFactor = 203;
  692. var SrcAlphaFactor = 204;
  693. var OneMinusSrcAlphaFactor = 205;
  694. var DstAlphaFactor = 206;
  695. var OneMinusDstAlphaFactor = 207;
  696. var DstColorFactor = 208;
  697. var OneMinusDstColorFactor = 209;
  698. var SrcAlphaSaturateFactor = 210;
  699. var NeverDepth = 0;
  700. var AlwaysDepth = 1;
  701. var LessDepth = 2;
  702. var LessEqualDepth = 3;
  703. var EqualDepth = 4;
  704. var GreaterEqualDepth = 5;
  705. var GreaterDepth = 6;
  706. var NotEqualDepth = 7;
  707. var MultiplyOperation = 0;
  708. var MixOperation = 1;
  709. var AddOperation = 2;
  710. var NoToneMapping = 0;
  711. var LinearToneMapping = 1;
  712. var ReinhardToneMapping = 2;
  713. var CineonToneMapping = 3;
  714. var ACESFilmicToneMapping = 4;
  715. var CustomToneMapping = 5;
  716. var UVMapping = 300;
  717. var CubeReflectionMapping = 301;
  718. var CubeRefractionMapping = 302;
  719. var EquirectangularReflectionMapping = 303;
  720. var EquirectangularRefractionMapping = 304;
  721. var CubeUVReflectionMapping = 306;
  722. var CubeUVRefractionMapping = 307;
  723. var RepeatWrapping = 1000;
  724. var ClampToEdgeWrapping = 1001;
  725. var MirroredRepeatWrapping = 1002;
  726. var NearestFilter = 1003;
  727. var NearestMipmapNearestFilter = 1004;
  728. var NearestMipMapNearestFilter = 1004;
  729. var NearestMipmapLinearFilter = 1005;
  730. var NearestMipMapLinearFilter = 1005;
  731. var LinearFilter = 1006;
  732. var LinearMipmapNearestFilter = 1007;
  733. var LinearMipMapNearestFilter = 1007;
  734. var LinearMipmapLinearFilter = 1008;
  735. var LinearMipMapLinearFilter = 1008;
  736. var UnsignedByteType = 1009;
  737. var ByteType = 1010;
  738. var ShortType = 1011;
  739. var UnsignedShortType = 1012;
  740. var IntType = 1013;
  741. var UnsignedIntType = 1014;
  742. var FloatType = 1015;
  743. var HalfFloatType = 1016;
  744. var UnsignedShort4444Type = 1017;
  745. var UnsignedShort5551Type = 1018;
  746. var UnsignedShort565Type = 1019;
  747. var UnsignedInt248Type = 1020;
  748. var AlphaFormat = 1021;
  749. var RGBFormat = 1022;
  750. var RGBAFormat = 1023;
  751. var LuminanceFormat = 1024;
  752. var LuminanceAlphaFormat = 1025;
  753. var RGBEFormat = RGBAFormat;
  754. var DepthFormat = 1026;
  755. var DepthStencilFormat = 1027;
  756. var RedFormat = 1028;
  757. var RedIntegerFormat = 1029;
  758. var RGFormat = 1030;
  759. var RGIntegerFormat = 1031;
  760. var RGBIntegerFormat = 1032;
  761. var RGBAIntegerFormat = 1033;
  762. var RGB_S3TC_DXT1_Format = 33776;
  763. var RGBA_S3TC_DXT1_Format = 33777;
  764. var RGBA_S3TC_DXT3_Format = 33778;
  765. var RGBA_S3TC_DXT5_Format = 33779;
  766. var RGB_PVRTC_4BPPV1_Format = 35840;
  767. var RGB_PVRTC_2BPPV1_Format = 35841;
  768. var RGBA_PVRTC_4BPPV1_Format = 35842;
  769. var RGBA_PVRTC_2BPPV1_Format = 35843;
  770. var RGB_ETC1_Format = 36196;
  771. var RGB_ETC2_Format = 37492;
  772. var RGBA_ETC2_EAC_Format = 37496;
  773. var RGBA_ASTC_4x4_Format = 37808;
  774. var RGBA_ASTC_5x4_Format = 37809;
  775. var RGBA_ASTC_5x5_Format = 37810;
  776. var RGBA_ASTC_6x5_Format = 37811;
  777. var RGBA_ASTC_6x6_Format = 37812;
  778. var RGBA_ASTC_8x5_Format = 37813;
  779. var RGBA_ASTC_8x6_Format = 37814;
  780. var RGBA_ASTC_8x8_Format = 37815;
  781. var RGBA_ASTC_10x5_Format = 37816;
  782. var RGBA_ASTC_10x6_Format = 37817;
  783. var RGBA_ASTC_10x8_Format = 37818;
  784. var RGBA_ASTC_10x10_Format = 37819;
  785. var RGBA_ASTC_12x10_Format = 37820;
  786. var RGBA_ASTC_12x12_Format = 37821;
  787. var RGBA_BPTC_Format = 36492;
  788. var SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  789. var SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  790. var SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  791. var SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  792. var SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  793. var SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  794. var SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  795. var SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  796. var SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  797. var SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  798. var SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  799. var SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  800. var SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  801. var SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  802. var LoopOnce = 2200;
  803. var LoopRepeat = 2201;
  804. var LoopPingPong = 2202;
  805. var InterpolateDiscrete = 2300;
  806. var InterpolateLinear = 2301;
  807. var InterpolateSmooth = 2302;
  808. var ZeroCurvatureEnding = 2400;
  809. var ZeroSlopeEnding = 2401;
  810. var WrapAroundEnding = 2402;
  811. var NormalAnimationBlendMode = 2500;
  812. var AdditiveAnimationBlendMode = 2501;
  813. var TrianglesDrawMode = 0;
  814. var TriangleStripDrawMode = 1;
  815. var TriangleFanDrawMode = 2;
  816. var LinearEncoding = 3000;
  817. var sRGBEncoding = 3001;
  818. var GammaEncoding = 3007;
  819. var RGBEEncoding = 3002;
  820. var LogLuvEncoding = 3003;
  821. var RGBM7Encoding = 3004;
  822. var RGBM16Encoding = 3005;
  823. var RGBDEncoding = 3006;
  824. var BasicDepthPacking = 3200;
  825. var RGBADepthPacking = 3201;
  826. var TangentSpaceNormalMap = 0;
  827. var ObjectSpaceNormalMap = 1;
  828. var ZeroStencilOp = 0;
  829. var KeepStencilOp = 7680;
  830. var ReplaceStencilOp = 7681;
  831. var IncrementStencilOp = 7682;
  832. var DecrementStencilOp = 7683;
  833. var IncrementWrapStencilOp = 34055;
  834. var DecrementWrapStencilOp = 34056;
  835. var InvertStencilOp = 5386;
  836. var NeverStencilFunc = 512;
  837. var LessStencilFunc = 513;
  838. var EqualStencilFunc = 514;
  839. var LessEqualStencilFunc = 515;
  840. var GreaterStencilFunc = 516;
  841. var NotEqualStencilFunc = 517;
  842. var GreaterEqualStencilFunc = 518;
  843. var AlwaysStencilFunc = 519;
  844. var StaticDrawUsage = 35044;
  845. var DynamicDrawUsage = 35048;
  846. var StreamDrawUsage = 35040;
  847. var StaticReadUsage = 35045;
  848. var DynamicReadUsage = 35049;
  849. var StreamReadUsage = 35041;
  850. var StaticCopyUsage = 35046;
  851. var DynamicCopyUsage = 35050;
  852. var StreamCopyUsage = 35042;
  853. var GLSL1 = '100';
  854. var GLSL3 = '300 es';
  855. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  856. try {
  857. var info = gen[key](arg);
  858. var value = info.value;
  859. } catch (error) {
  860. reject(error);
  861. return;
  862. }
  863. if (info.done) {
  864. resolve(value);
  865. } else {
  866. Promise.resolve(value).then(_next, _throw);
  867. }
  868. }
  869. function _asyncToGenerator(fn) {
  870. return function () {
  871. var self = this,
  872. args = arguments;
  873. return new Promise(function (resolve, reject) {
  874. var gen = fn.apply(self, args);
  875. function _next(value) {
  876. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
  877. }
  878. function _throw(err) {
  879. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
  880. }
  881. _next(undefined);
  882. });
  883. };
  884. }
  885. function _defineProperties(target, props) {
  886. for (var i = 0; i < props.length; i++) {
  887. var descriptor = props[i];
  888. descriptor.enumerable = descriptor.enumerable || false;
  889. descriptor.configurable = true;
  890. if ("value" in descriptor) descriptor.writable = true;
  891. Object.defineProperty(target, descriptor.key, descriptor);
  892. }
  893. }
  894. function _createClass(Constructor, protoProps, staticProps) {
  895. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  896. if (staticProps) _defineProperties(Constructor, staticProps);
  897. return Constructor;
  898. }
  899. function _inheritsLoose(subClass, superClass) {
  900. subClass.prototype = Object.create(superClass.prototype);
  901. subClass.prototype.constructor = subClass;
  902. subClass.__proto__ = superClass;
  903. }
  904. function _assertThisInitialized(self) {
  905. if (self === void 0) {
  906. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  907. }
  908. return self;
  909. }
  910. function _unsupportedIterableToArray(o, minLen) {
  911. if (!o) return;
  912. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  913. var n = Object.prototype.toString.call(o).slice(8, -1);
  914. if (n === "Object" && o.constructor) n = o.constructor.name;
  915. if (n === "Map" || n === "Set") return Array.from(o);
  916. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  917. }
  918. function _arrayLikeToArray(arr, len) {
  919. if (len == null || len > arr.length) len = arr.length;
  920. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  921. return arr2;
  922. }
  923. function _createForOfIteratorHelperLoose(o, allowArrayLike) {
  924. var it;
  925. if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
  926. if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  927. if (it) o = it;
  928. var i = 0;
  929. return function () {
  930. if (i >= o.length) return {
  931. done: true
  932. };
  933. return {
  934. done: false,
  935. value: o[i++]
  936. };
  937. };
  938. }
  939. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  940. }
  941. it = o[Symbol.iterator]();
  942. return it.next.bind(it);
  943. }
  944. /**
  945. * https://github.com/mrdoob/eventdispatcher.js/
  946. */
  947. function EventDispatcher() {}
  948. Object.assign(EventDispatcher.prototype, {
  949. addEventListener: function addEventListener(type, listener) {
  950. if (this._listeners === undefined) this._listeners = {};
  951. var listeners = this._listeners;
  952. if (listeners[type] === undefined) {
  953. listeners[type] = [];
  954. }
  955. if (listeners[type].indexOf(listener) === -1) {
  956. listeners[type].push(listener);
  957. }
  958. },
  959. hasEventListener: function hasEventListener(type, listener) {
  960. if (this._listeners === undefined) return false;
  961. var listeners = this._listeners;
  962. return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
  963. },
  964. removeEventListener: function removeEventListener(type, listener) {
  965. if (this._listeners === undefined) return;
  966. var listeners = this._listeners;
  967. var listenerArray = listeners[type];
  968. if (listenerArray !== undefined) {
  969. var index = listenerArray.indexOf(listener);
  970. if (index !== -1) {
  971. listenerArray.splice(index, 1);
  972. }
  973. }
  974. },
  975. dispatchEvent: function dispatchEvent(event) {
  976. if (this._listeners === undefined) return;
  977. var listeners = this._listeners;
  978. var listenerArray = listeners[event.type];
  979. if (listenerArray !== undefined) {
  980. event.target = this; // Make a copy, in case listeners are removed while iterating.
  981. var array = listenerArray.slice(0);
  982. for (var i = 0, l = array.length; i < l; i++) {
  983. array[i].call(this, event);
  984. }
  985. }
  986. }
  987. });
  988. var _lut = [];
  989. for (var i = 0; i < 256; i++) {
  990. _lut[i] = (i < 16 ? '0' : '') + i.toString(16);
  991. }
  992. var _seed = 1234567;
  993. var MathUtils = {
  994. DEG2RAD: Math.PI / 180,
  995. RAD2DEG: 180 / Math.PI,
  996. generateUUID: function generateUUID() {
  997. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  998. var d0 = Math.random() * 0xffffffff | 0;
  999. var d1 = Math.random() * 0xffffffff | 0;
  1000. var d2 = Math.random() * 0xffffffff | 0;
  1001. var d3 = Math.random() * 0xffffffff | 0;
  1002. var uuid = _lut[d0 & 0xff] + _lut[d0 >> 8 & 0xff] + _lut[d0 >> 16 & 0xff] + _lut[d0 >> 24 & 0xff] + '-' + _lut[d1 & 0xff] + _lut[d1 >> 8 & 0xff] + '-' + _lut[d1 >> 16 & 0x0f | 0x40] + _lut[d1 >> 24 & 0xff] + '-' + _lut[d2 & 0x3f | 0x80] + _lut[d2 >> 8 & 0xff] + '-' + _lut[d2 >> 16 & 0xff] + _lut[d2 >> 24 & 0xff] + _lut[d3 & 0xff] + _lut[d3 >> 8 & 0xff] + _lut[d3 >> 16 & 0xff] + _lut[d3 >> 24 & 0xff]; // .toUpperCase() here flattens concatenated strings to save heap memory space.
  1003. return uuid.toUpperCase();
  1004. },
  1005. clamp: function clamp(value, min, max) {
  1006. return Math.max(min, Math.min(max, value));
  1007. },
  1008. // compute euclidian modulo of m % n
  1009. // https://en.wikipedia.org/wiki/Modulo_operation
  1010. euclideanModulo: function euclideanModulo(n, m) {
  1011. return (n % m + m) % m;
  1012. },
  1013. // Linear mapping from range <a1, a2> to range <b1, b2>
  1014. mapLinear: function mapLinear(x, a1, a2, b1, b2) {
  1015. return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
  1016. },
  1017. // https://en.wikipedia.org/wiki/Linear_interpolation
  1018. lerp: function lerp(x, y, t) {
  1019. return (1 - t) * x + t * y;
  1020. },
  1021. // http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/
  1022. damp: function damp(x, y, lambda, dt) {
  1023. return MathUtils.lerp(x, y, 1 - Math.exp(-lambda * dt));
  1024. },
  1025. // https://www.desmos.com/calculator/vcsjnyz7x4
  1026. pingpong: function pingpong(x, length) {
  1027. if (length === void 0) {
  1028. length = 1;
  1029. }
  1030. return length - Math.abs(MathUtils.euclideanModulo(x, length * 2) - length);
  1031. },
  1032. // http://en.wikipedia.org/wiki/Smoothstep
  1033. smoothstep: function smoothstep(x, min, max) {
  1034. if (x <= min) return 0;
  1035. if (x >= max) return 1;
  1036. x = (x - min) / (max - min);
  1037. return x * x * (3 - 2 * x);
  1038. },
  1039. smootherstep: function smootherstep(x, min, max) {
  1040. if (x <= min) return 0;
  1041. if (x >= max) return 1;
  1042. x = (x - min) / (max - min);
  1043. return x * x * x * (x * (x * 6 - 15) + 10);
  1044. },
  1045. // Random integer from <low, high> interval
  1046. randInt: function randInt(low, high) {
  1047. return low + Math.floor(Math.random() * (high - low + 1));
  1048. },
  1049. // Random float from <low, high> interval
  1050. randFloat: function randFloat(low, high) {
  1051. return low + Math.random() * (high - low);
  1052. },
  1053. // Random float from <-range/2, range/2> interval
  1054. randFloatSpread: function randFloatSpread(range) {
  1055. return range * (0.5 - Math.random());
  1056. },
  1057. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  1058. seededRandom: function seededRandom(s) {
  1059. if (s !== undefined) _seed = s % 2147483647; // Park-Miller algorithm
  1060. _seed = _seed * 16807 % 2147483647;
  1061. return (_seed - 1) / 2147483646;
  1062. },
  1063. degToRad: function degToRad(degrees) {
  1064. return degrees * MathUtils.DEG2RAD;
  1065. },
  1066. radToDeg: function radToDeg(radians) {
  1067. return radians * MathUtils.RAD2DEG;
  1068. },
  1069. isPowerOfTwo: function isPowerOfTwo(value) {
  1070. return (value & value - 1) === 0 && value !== 0;
  1071. },
  1072. ceilPowerOfTwo: function ceilPowerOfTwo(value) {
  1073. return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
  1074. },
  1075. floorPowerOfTwo: function floorPowerOfTwo(value) {
  1076. return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
  1077. },
  1078. setQuaternionFromProperEuler: function setQuaternionFromProperEuler(q, a, b, c, order) {
  1079. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  1080. // rotations are applied to the axes in the order specified by 'order'
  1081. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  1082. // angles are in radians
  1083. var cos = Math.cos;
  1084. var sin = Math.sin;
  1085. var c2 = cos(b / 2);
  1086. var s2 = sin(b / 2);
  1087. var c13 = cos((a + c) / 2);
  1088. var s13 = sin((a + c) / 2);
  1089. var c1_3 = cos((a - c) / 2);
  1090. var s1_3 = sin((a - c) / 2);
  1091. var c3_1 = cos((c - a) / 2);
  1092. var s3_1 = sin((c - a) / 2);
  1093. switch (order) {
  1094. case 'XYX':
  1095. q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
  1096. break;
  1097. case 'YZY':
  1098. q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
  1099. break;
  1100. case 'ZXZ':
  1101. q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
  1102. break;
  1103. case 'XZX':
  1104. q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
  1105. break;
  1106. case 'YXY':
  1107. q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
  1108. break;
  1109. case 'ZYZ':
  1110. q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
  1111. break;
  1112. default:
  1113. console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order);
  1114. }
  1115. }
  1116. };
  1117. var Vector2 = /*#__PURE__*/function () {
  1118. function Vector2(x, y) {
  1119. if (x === void 0) {
  1120. x = 0;
  1121. }
  1122. if (y === void 0) {
  1123. y = 0;
  1124. }
  1125. Object.defineProperty(this, 'isVector2', {
  1126. value: true
  1127. });
  1128. this.x = x;
  1129. this.y = y;
  1130. }
  1131. var _proto = Vector2.prototype;
  1132. _proto.set = function set(x, y) {
  1133. this.x = x;
  1134. this.y = y;
  1135. return this;
  1136. };
  1137. _proto.setScalar = function setScalar(scalar) {
  1138. this.x = scalar;
  1139. this.y = scalar;
  1140. return this;
  1141. };
  1142. _proto.setX = function setX(x) {
  1143. this.x = x;
  1144. return this;
  1145. };
  1146. _proto.setY = function setY(y) {
  1147. this.y = y;
  1148. return this;
  1149. };
  1150. _proto.setComponent = function setComponent(index, value) {
  1151. switch (index) {
  1152. case 0:
  1153. this.x = value;
  1154. break;
  1155. case 1:
  1156. this.y = value;
  1157. break;
  1158. default:
  1159. throw new Error('index is out of range: ' + index);
  1160. }
  1161. return this;
  1162. };
  1163. _proto.getComponent = function getComponent(index) {
  1164. switch (index) {
  1165. case 0:
  1166. return this.x;
  1167. case 1:
  1168. return this.y;
  1169. default:
  1170. throw new Error('index is out of range: ' + index);
  1171. }
  1172. };
  1173. _proto.clone = function clone() {
  1174. return new this.constructor(this.x, this.y);
  1175. };
  1176. _proto.copy = function copy(v) {
  1177. this.x = v.x;
  1178. this.y = v.y;
  1179. return this;
  1180. };
  1181. _proto.add = function add(v, w) {
  1182. if (w !== undefined) {
  1183. console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1184. return this.addVectors(v, w);
  1185. }
  1186. this.x += v.x;
  1187. this.y += v.y;
  1188. return this;
  1189. };
  1190. _proto.addScalar = function addScalar(s) {
  1191. this.x += s;
  1192. this.y += s;
  1193. return this;
  1194. };
  1195. _proto.addVectors = function addVectors(a, b) {
  1196. this.x = a.x + b.x;
  1197. this.y = a.y + b.y;
  1198. return this;
  1199. };
  1200. _proto.addScaledVector = function addScaledVector(v, s) {
  1201. this.x += v.x * s;
  1202. this.y += v.y * s;
  1203. return this;
  1204. };
  1205. _proto.sub = function sub(v, w) {
  1206. if (w !== undefined) {
  1207. console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  1208. return this.subVectors(v, w);
  1209. }
  1210. this.x -= v.x;
  1211. this.y -= v.y;
  1212. return this;
  1213. };
  1214. _proto.subScalar = function subScalar(s) {
  1215. this.x -= s;
  1216. this.y -= s;
  1217. return this;
  1218. };
  1219. _proto.subVectors = function subVectors(a, b) {
  1220. this.x = a.x - b.x;
  1221. this.y = a.y - b.y;
  1222. return this;
  1223. };
  1224. _proto.multiply = function multiply(v) {
  1225. this.x *= v.x;
  1226. this.y *= v.y;
  1227. return this;
  1228. };
  1229. _proto.multiplyScalar = function multiplyScalar(scalar) {
  1230. this.x *= scalar;
  1231. this.y *= scalar;
  1232. return this;
  1233. };
  1234. _proto.divide = function divide(v) {
  1235. this.x /= v.x;
  1236. this.y /= v.y;
  1237. return this;
  1238. };
  1239. _proto.divideScalar = function divideScalar(scalar) {
  1240. return this.multiplyScalar(1 / scalar);
  1241. };
  1242. _proto.applyMatrix3 = function applyMatrix3(m) {
  1243. var x = this.x,
  1244. y = this.y;
  1245. var e = m.elements;
  1246. this.x = e[0] * x + e[3] * y + e[6];
  1247. this.y = e[1] * x + e[4] * y + e[7];
  1248. return this;
  1249. };
  1250. _proto.min = function min(v) {
  1251. this.x = Math.min(this.x, v.x);
  1252. this.y = Math.min(this.y, v.y);
  1253. return this;
  1254. };
  1255. _proto.max = function max(v) {
  1256. this.x = Math.max(this.x, v.x);
  1257. this.y = Math.max(this.y, v.y);
  1258. return this;
  1259. };
  1260. _proto.clamp = function clamp(min, max) {
  1261. // assumes min < max, componentwise
  1262. this.x = Math.max(min.x, Math.min(max.x, this.x));
  1263. this.y = Math.max(min.y, Math.min(max.y, this.y));
  1264. return this;
  1265. };
  1266. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  1267. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  1268. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  1269. return this;
  1270. };
  1271. _proto.clampLength = function clampLength(min, max) {
  1272. var length = this.length();
  1273. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  1274. };
  1275. _proto.floor = function floor() {
  1276. this.x = Math.floor(this.x);
  1277. this.y = Math.floor(this.y);
  1278. return this;
  1279. };
  1280. _proto.ceil = function ceil() {
  1281. this.x = Math.ceil(this.x);
  1282. this.y = Math.ceil(this.y);
  1283. return this;
  1284. };
  1285. _proto.round = function round() {
  1286. this.x = Math.round(this.x);
  1287. this.y = Math.round(this.y);
  1288. return this;
  1289. };
  1290. _proto.roundToZero = function roundToZero() {
  1291. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  1292. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  1293. return this;
  1294. };
  1295. _proto.negate = function negate() {
  1296. this.x = -this.x;
  1297. this.y = -this.y;
  1298. return this;
  1299. };
  1300. _proto.dot = function dot(v) {
  1301. return this.x * v.x + this.y * v.y;
  1302. };
  1303. _proto.cross = function cross(v) {
  1304. return this.x * v.y - this.y * v.x;
  1305. };
  1306. _proto.lengthSq = function lengthSq() {
  1307. return this.x * this.x + this.y * this.y;
  1308. };
  1309. _proto.length = function length() {
  1310. return Math.sqrt(this.x * this.x + this.y * this.y);
  1311. };
  1312. _proto.manhattanLength = function manhattanLength() {
  1313. return Math.abs(this.x) + Math.abs(this.y);
  1314. };
  1315. _proto.normalize = function normalize() {
  1316. return this.divideScalar(this.length() || 1);
  1317. };
  1318. _proto.angle = function angle() {
  1319. // computes the angle in radians with respect to the positive x-axis
  1320. var angle = Math.atan2(-this.y, -this.x) + Math.PI;
  1321. return angle;
  1322. };
  1323. _proto.distanceTo = function distanceTo(v) {
  1324. return Math.sqrt(this.distanceToSquared(v));
  1325. };
  1326. _proto.distanceToSquared = function distanceToSquared(v) {
  1327. var dx = this.x - v.x,
  1328. dy = this.y - v.y;
  1329. return dx * dx + dy * dy;
  1330. };
  1331. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  1332. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
  1333. };
  1334. _proto.setLength = function setLength(length) {
  1335. return this.normalize().multiplyScalar(length);
  1336. };
  1337. _proto.lerp = function lerp(v, alpha) {
  1338. this.x += (v.x - this.x) * alpha;
  1339. this.y += (v.y - this.y) * alpha;
  1340. return this;
  1341. };
  1342. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  1343. this.x = v1.x + (v2.x - v1.x) * alpha;
  1344. this.y = v1.y + (v2.y - v1.y) * alpha;
  1345. return this;
  1346. };
  1347. _proto.equals = function equals(v) {
  1348. return v.x === this.x && v.y === this.y;
  1349. };
  1350. _proto.fromArray = function fromArray(array, offset) {
  1351. if (offset === void 0) {
  1352. offset = 0;
  1353. }
  1354. this.x = array[offset];
  1355. this.y = array[offset + 1];
  1356. return this;
  1357. };
  1358. _proto.toArray = function toArray(array, offset) {
  1359. if (array === void 0) {
  1360. array = [];
  1361. }
  1362. if (offset === void 0) {
  1363. offset = 0;
  1364. }
  1365. array[offset] = this.x;
  1366. array[offset + 1] = this.y;
  1367. return array;
  1368. };
  1369. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  1370. if (offset !== undefined) {
  1371. console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
  1372. }
  1373. this.x = attribute.getX(index);
  1374. this.y = attribute.getY(index);
  1375. return this;
  1376. };
  1377. _proto.rotateAround = function rotateAround(center, angle) {
  1378. var c = Math.cos(angle),
  1379. s = Math.sin(angle);
  1380. var x = this.x - center.x;
  1381. var y = this.y - center.y;
  1382. this.x = x * c - y * s + center.x;
  1383. this.y = x * s + y * c + center.y;
  1384. return this;
  1385. };
  1386. _proto.random = function random() {
  1387. this.x = Math.random();
  1388. this.y = Math.random();
  1389. return this;
  1390. };
  1391. _createClass(Vector2, [{
  1392. key: "width",
  1393. get: function get() {
  1394. return this.x;
  1395. },
  1396. set: function set(value) {
  1397. this.x = value;
  1398. }
  1399. }, {
  1400. key: "height",
  1401. get: function get() {
  1402. return this.y;
  1403. },
  1404. set: function set(value) {
  1405. this.y = value;
  1406. }
  1407. }]);
  1408. return Vector2;
  1409. }();
  1410. var Matrix3 = /*#__PURE__*/function () {
  1411. function Matrix3() {
  1412. Object.defineProperty(this, 'isMatrix3', {
  1413. value: true
  1414. });
  1415. this.elements = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  1416. if (arguments.length > 0) {
  1417. console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');
  1418. }
  1419. }
  1420. var _proto = Matrix3.prototype;
  1421. _proto.set = function set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
  1422. var te = this.elements;
  1423. te[0] = n11;
  1424. te[1] = n21;
  1425. te[2] = n31;
  1426. te[3] = n12;
  1427. te[4] = n22;
  1428. te[5] = n32;
  1429. te[6] = n13;
  1430. te[7] = n23;
  1431. te[8] = n33;
  1432. return this;
  1433. };
  1434. _proto.identity = function identity() {
  1435. this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
  1436. return this;
  1437. };
  1438. _proto.clone = function clone() {
  1439. return new this.constructor().fromArray(this.elements);
  1440. };
  1441. _proto.copy = function copy(m) {
  1442. var te = this.elements;
  1443. var me = m.elements;
  1444. te[0] = me[0];
  1445. te[1] = me[1];
  1446. te[2] = me[2];
  1447. te[3] = me[3];
  1448. te[4] = me[4];
  1449. te[5] = me[5];
  1450. te[6] = me[6];
  1451. te[7] = me[7];
  1452. te[8] = me[8];
  1453. return this;
  1454. };
  1455. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  1456. xAxis.setFromMatrix3Column(this, 0);
  1457. yAxis.setFromMatrix3Column(this, 1);
  1458. zAxis.setFromMatrix3Column(this, 2);
  1459. return this;
  1460. };
  1461. _proto.setFromMatrix4 = function setFromMatrix4(m) {
  1462. var me = m.elements;
  1463. this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
  1464. return this;
  1465. };
  1466. _proto.multiply = function multiply(m) {
  1467. return this.multiplyMatrices(this, m);
  1468. };
  1469. _proto.premultiply = function premultiply(m) {
  1470. return this.multiplyMatrices(m, this);
  1471. };
  1472. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  1473. var ae = a.elements;
  1474. var be = b.elements;
  1475. var te = this.elements;
  1476. var a11 = ae[0],
  1477. a12 = ae[3],
  1478. a13 = ae[6];
  1479. var a21 = ae[1],
  1480. a22 = ae[4],
  1481. a23 = ae[7];
  1482. var a31 = ae[2],
  1483. a32 = ae[5],
  1484. a33 = ae[8];
  1485. var b11 = be[0],
  1486. b12 = be[3],
  1487. b13 = be[6];
  1488. var b21 = be[1],
  1489. b22 = be[4],
  1490. b23 = be[7];
  1491. var b31 = be[2],
  1492. b32 = be[5],
  1493. b33 = be[8];
  1494. te[0] = a11 * b11 + a12 * b21 + a13 * b31;
  1495. te[3] = a11 * b12 + a12 * b22 + a13 * b32;
  1496. te[6] = a11 * b13 + a12 * b23 + a13 * b33;
  1497. te[1] = a21 * b11 + a22 * b21 + a23 * b31;
  1498. te[4] = a21 * b12 + a22 * b22 + a23 * b32;
  1499. te[7] = a21 * b13 + a22 * b23 + a23 * b33;
  1500. te[2] = a31 * b11 + a32 * b21 + a33 * b31;
  1501. te[5] = a31 * b12 + a32 * b22 + a33 * b32;
  1502. te[8] = a31 * b13 + a32 * b23 + a33 * b33;
  1503. return this;
  1504. };
  1505. _proto.multiplyScalar = function multiplyScalar(s) {
  1506. var te = this.elements;
  1507. te[0] *= s;
  1508. te[3] *= s;
  1509. te[6] *= s;
  1510. te[1] *= s;
  1511. te[4] *= s;
  1512. te[7] *= s;
  1513. te[2] *= s;
  1514. te[5] *= s;
  1515. te[8] *= s;
  1516. return this;
  1517. };
  1518. _proto.determinant = function determinant() {
  1519. var te = this.elements;
  1520. var a = te[0],
  1521. b = te[1],
  1522. c = te[2],
  1523. d = te[3],
  1524. e = te[4],
  1525. f = te[5],
  1526. g = te[6],
  1527. h = te[7],
  1528. i = te[8];
  1529. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  1530. };
  1531. _proto.invert = function invert() {
  1532. var te = this.elements,
  1533. n11 = te[0],
  1534. n21 = te[1],
  1535. n31 = te[2],
  1536. n12 = te[3],
  1537. n22 = te[4],
  1538. n32 = te[5],
  1539. n13 = te[6],
  1540. n23 = te[7],
  1541. n33 = te[8],
  1542. t11 = n33 * n22 - n32 * n23,
  1543. t12 = n32 * n13 - n33 * n12,
  1544. t13 = n23 * n12 - n22 * n13,
  1545. det = n11 * t11 + n21 * t12 + n31 * t13;
  1546. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
  1547. var detInv = 1 / det;
  1548. te[0] = t11 * detInv;
  1549. te[1] = (n31 * n23 - n33 * n21) * detInv;
  1550. te[2] = (n32 * n21 - n31 * n22) * detInv;
  1551. te[3] = t12 * detInv;
  1552. te[4] = (n33 * n11 - n31 * n13) * detInv;
  1553. te[5] = (n31 * n12 - n32 * n11) * detInv;
  1554. te[6] = t13 * detInv;
  1555. te[7] = (n21 * n13 - n23 * n11) * detInv;
  1556. te[8] = (n22 * n11 - n21 * n12) * detInv;
  1557. return this;
  1558. };
  1559. _proto.transpose = function transpose() {
  1560. var tmp;
  1561. var m = this.elements;
  1562. tmp = m[1];
  1563. m[1] = m[3];
  1564. m[3] = tmp;
  1565. tmp = m[2];
  1566. m[2] = m[6];
  1567. m[6] = tmp;
  1568. tmp = m[5];
  1569. m[5] = m[7];
  1570. m[7] = tmp;
  1571. return this;
  1572. };
  1573. _proto.getNormalMatrix = function getNormalMatrix(matrix4) {
  1574. return this.setFromMatrix4(matrix4).copy(this).invert().transpose();
  1575. };
  1576. _proto.transposeIntoArray = function transposeIntoArray(r) {
  1577. var m = this.elements;
  1578. r[0] = m[0];
  1579. r[1] = m[3];
  1580. r[2] = m[6];
  1581. r[3] = m[1];
  1582. r[4] = m[4];
  1583. r[5] = m[7];
  1584. r[6] = m[2];
  1585. r[7] = m[5];
  1586. r[8] = m[8];
  1587. return this;
  1588. };
  1589. _proto.setUvTransform = function setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
  1590. var c = Math.cos(rotation);
  1591. var s = Math.sin(rotation);
  1592. this.set(sx * c, sx * s, -sx * (c * cx + s * cy) + cx + tx, -sy * s, sy * c, -sy * (-s * cx + c * cy) + cy + ty, 0, 0, 1);
  1593. return this;
  1594. };
  1595. _proto.scale = function scale(sx, sy) {
  1596. var te = this.elements;
  1597. te[0] *= sx;
  1598. te[3] *= sx;
  1599. te[6] *= sx;
  1600. te[1] *= sy;
  1601. te[4] *= sy;
  1602. te[7] *= sy;
  1603. return this;
  1604. };
  1605. _proto.rotate = function rotate(theta) {
  1606. var c = Math.cos(theta);
  1607. var s = Math.sin(theta);
  1608. var te = this.elements;
  1609. var a11 = te[0],
  1610. a12 = te[3],
  1611. a13 = te[6];
  1612. var a21 = te[1],
  1613. a22 = te[4],
  1614. a23 = te[7];
  1615. te[0] = c * a11 + s * a21;
  1616. te[3] = c * a12 + s * a22;
  1617. te[6] = c * a13 + s * a23;
  1618. te[1] = -s * a11 + c * a21;
  1619. te[4] = -s * a12 + c * a22;
  1620. te[7] = -s * a13 + c * a23;
  1621. return this;
  1622. };
  1623. _proto.translate = function translate(tx, ty) {
  1624. var te = this.elements;
  1625. te[0] += tx * te[2];
  1626. te[3] += tx * te[5];
  1627. te[6] += tx * te[8];
  1628. te[1] += ty * te[2];
  1629. te[4] += ty * te[5];
  1630. te[7] += ty * te[8];
  1631. return this;
  1632. };
  1633. _proto.equals = function equals(matrix) {
  1634. var te = this.elements;
  1635. var me = matrix.elements;
  1636. for (var i = 0; i < 9; i++) {
  1637. if (te[i] !== me[i]) return false;
  1638. }
  1639. return true;
  1640. };
  1641. _proto.fromArray = function fromArray(array, offset) {
  1642. if (offset === void 0) {
  1643. offset = 0;
  1644. }
  1645. for (var i = 0; i < 9; i++) {
  1646. this.elements[i] = array[i + offset];
  1647. }
  1648. return this;
  1649. };
  1650. _proto.toArray = function toArray(array, offset) {
  1651. if (array === void 0) {
  1652. array = [];
  1653. }
  1654. if (offset === void 0) {
  1655. offset = 0;
  1656. }
  1657. var te = this.elements;
  1658. array[offset] = te[0];
  1659. array[offset + 1] = te[1];
  1660. array[offset + 2] = te[2];
  1661. array[offset + 3] = te[3];
  1662. array[offset + 4] = te[4];
  1663. array[offset + 5] = te[5];
  1664. array[offset + 6] = te[6];
  1665. array[offset + 7] = te[7];
  1666. array[offset + 8] = te[8];
  1667. return array;
  1668. };
  1669. return Matrix3;
  1670. }();
  1671. var _canvas;
  1672. var ImageUtils = {
  1673. getDataURL: function getDataURL(image) {
  1674. if (/^data:/i.test(image.src)) {
  1675. return image.src;
  1676. }
  1677. if (typeof HTMLCanvasElement == 'undefined') {
  1678. return image.src;
  1679. }
  1680. var canvas;
  1681. if (image instanceof HTMLCanvasElement) {
  1682. canvas = image;
  1683. } else {
  1684. if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  1685. _canvas.width = image.width;
  1686. _canvas.height = image.height;
  1687. var context = _canvas.getContext('2d');
  1688. if (image instanceof ImageData) {
  1689. context.putImageData(image, 0, 0);
  1690. } else {
  1691. context.drawImage(image, 0, 0, image.width, image.height);
  1692. }
  1693. canvas = _canvas;
  1694. }
  1695. if (canvas.width > 2048 || canvas.height > 2048) {
  1696. return canvas.toDataURL('image/jpeg', 0.6);
  1697. } else {
  1698. return canvas.toDataURL('image/png');
  1699. }
  1700. }
  1701. };
  1702. var textureId = 0;
  1703. function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  1704. if (image === void 0) {
  1705. image = Texture.DEFAULT_IMAGE;
  1706. }
  1707. if (mapping === void 0) {
  1708. mapping = Texture.DEFAULT_MAPPING;
  1709. }
  1710. if (wrapS === void 0) {
  1711. wrapS = ClampToEdgeWrapping;
  1712. }
  1713. if (wrapT === void 0) {
  1714. wrapT = ClampToEdgeWrapping;
  1715. }
  1716. if (magFilter === void 0) {
  1717. magFilter = LinearFilter;
  1718. }
  1719. if (minFilter === void 0) {
  1720. minFilter = LinearMipmapLinearFilter;
  1721. }
  1722. if (format === void 0) {
  1723. format = RGBAFormat;
  1724. }
  1725. if (type === void 0) {
  1726. type = UnsignedByteType;
  1727. }
  1728. if (anisotropy === void 0) {
  1729. anisotropy = 1;
  1730. }
  1731. if (encoding === void 0) {
  1732. encoding = LinearEncoding;
  1733. }
  1734. Object.defineProperty(this, 'id', {
  1735. value: textureId++
  1736. });
  1737. this.uuid = MathUtils.generateUUID();
  1738. this.name = '';
  1739. this.image = image;
  1740. this.mipmaps = [];
  1741. this.mapping = mapping;
  1742. this.wrapS = wrapS;
  1743. this.wrapT = wrapT;
  1744. this.magFilter = magFilter;
  1745. this.minFilter = minFilter;
  1746. this.anisotropy = anisotropy;
  1747. this.format = format;
  1748. this.internalFormat = null;
  1749. this.type = type;
  1750. this.offset = new Vector2(0, 0);
  1751. this.repeat = new Vector2(1, 1);
  1752. this.center = new Vector2(0, 0);
  1753. this.rotation = 0;
  1754. this.matrixAutoUpdate = true;
  1755. this.matrix = new Matrix3();
  1756. this.generateMipmaps = true;
  1757. this.premultiplyAlpha = false;
  1758. this.flipY = true;
  1759. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1760. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1761. //
  1762. // Also changing the encoding after already used by a Material will not automatically make the Material
  1763. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1764. this.encoding = encoding;
  1765. this.version = 0;
  1766. this.onUpdate = null;
  1767. }
  1768. Texture.DEFAULT_IMAGE = undefined;
  1769. Texture.DEFAULT_MAPPING = UVMapping;
  1770. Texture.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1771. constructor: Texture,
  1772. isTexture: true,
  1773. updateMatrix: function updateMatrix() {
  1774. this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  1775. },
  1776. clone: function clone() {
  1777. return new this.constructor().copy(this);
  1778. },
  1779. copy: function copy(source) {
  1780. this.name = source.name;
  1781. this.image = source.image;
  1782. this.mipmaps = source.mipmaps.slice(0);
  1783. this.mapping = source.mapping;
  1784. this.wrapS = source.wrapS;
  1785. this.wrapT = source.wrapT;
  1786. this.magFilter = source.magFilter;
  1787. this.minFilter = source.minFilter;
  1788. this.anisotropy = source.anisotropy;
  1789. this.format = source.format;
  1790. this.internalFormat = source.internalFormat;
  1791. this.type = source.type;
  1792. this.offset.copy(source.offset);
  1793. this.repeat.copy(source.repeat);
  1794. this.center.copy(source.center);
  1795. this.rotation = source.rotation;
  1796. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1797. this.matrix.copy(source.matrix);
  1798. this.generateMipmaps = source.generateMipmaps;
  1799. this.premultiplyAlpha = source.premultiplyAlpha;
  1800. this.flipY = source.flipY;
  1801. this.unpackAlignment = source.unpackAlignment;
  1802. this.encoding = source.encoding;
  1803. return this;
  1804. },
  1805. toJSON: function toJSON(meta) {
  1806. var isRootObject = meta === undefined || typeof meta === 'string';
  1807. if (!isRootObject && meta.textures[this.uuid] !== undefined) {
  1808. return meta.textures[this.uuid];
  1809. }
  1810. var output = {
  1811. metadata: {
  1812. version: 4.5,
  1813. type: 'Texture',
  1814. generator: 'Texture.toJSON'
  1815. },
  1816. uuid: this.uuid,
  1817. name: this.name,
  1818. mapping: this.mapping,
  1819. repeat: [this.repeat.x, this.repeat.y],
  1820. offset: [this.offset.x, this.offset.y],
  1821. center: [this.center.x, this.center.y],
  1822. rotation: this.rotation,
  1823. wrap: [this.wrapS, this.wrapT],
  1824. format: this.format,
  1825. type: this.type,
  1826. encoding: this.encoding,
  1827. minFilter: this.minFilter,
  1828. magFilter: this.magFilter,
  1829. anisotropy: this.anisotropy,
  1830. flipY: this.flipY,
  1831. premultiplyAlpha: this.premultiplyAlpha,
  1832. unpackAlignment: this.unpackAlignment
  1833. };
  1834. if (this.image !== undefined) {
  1835. // TODO: Move to THREE.Image
  1836. var image = this.image;
  1837. if (image.uuid === undefined) {
  1838. image.uuid = MathUtils.generateUUID(); // UGH
  1839. }
  1840. if (!isRootObject && meta.images[image.uuid] === undefined) {
  1841. var url;
  1842. if (Array.isArray(image)) {
  1843. // process array of images e.g. CubeTexture
  1844. url = [];
  1845. for (var i = 0, l = image.length; i < l; i++) {
  1846. // check cube texture with data textures
  1847. if (image[i].isDataTexture) {
  1848. url.push(serializeImage(image[i].image));
  1849. } else {
  1850. url.push(serializeImage(image[i]));
  1851. }
  1852. }
  1853. } else {
  1854. // process single image
  1855. url = serializeImage(image);
  1856. }
  1857. meta.images[image.uuid] = {
  1858. uuid: image.uuid,
  1859. url: url
  1860. };
  1861. }
  1862. output.image = image.uuid;
  1863. }
  1864. if (!isRootObject) {
  1865. meta.textures[this.uuid] = output;
  1866. }
  1867. return output;
  1868. },
  1869. dispose: function dispose() {
  1870. this.dispatchEvent({
  1871. type: 'dispose'
  1872. });
  1873. },
  1874. transformUv: function transformUv(uv) {
  1875. if (this.mapping !== UVMapping) return uv;
  1876. uv.applyMatrix3(this.matrix);
  1877. if (uv.x < 0 || uv.x > 1) {
  1878. switch (this.wrapS) {
  1879. case RepeatWrapping:
  1880. uv.x = uv.x - Math.floor(uv.x);
  1881. break;
  1882. case ClampToEdgeWrapping:
  1883. uv.x = uv.x < 0 ? 0 : 1;
  1884. break;
  1885. case MirroredRepeatWrapping:
  1886. if (Math.abs(Math.floor(uv.x) % 2) === 1) {
  1887. uv.x = Math.ceil(uv.x) - uv.x;
  1888. } else {
  1889. uv.x = uv.x - Math.floor(uv.x);
  1890. }
  1891. break;
  1892. }
  1893. }
  1894. if (uv.y < 0 || uv.y > 1) {
  1895. switch (this.wrapT) {
  1896. case RepeatWrapping:
  1897. uv.y = uv.y - Math.floor(uv.y);
  1898. break;
  1899. case ClampToEdgeWrapping:
  1900. uv.y = uv.y < 0 ? 0 : 1;
  1901. break;
  1902. case MirroredRepeatWrapping:
  1903. if (Math.abs(Math.floor(uv.y) % 2) === 1) {
  1904. uv.y = Math.ceil(uv.y) - uv.y;
  1905. } else {
  1906. uv.y = uv.y - Math.floor(uv.y);
  1907. }
  1908. break;
  1909. }
  1910. }
  1911. if (this.flipY) {
  1912. uv.y = 1 - uv.y;
  1913. }
  1914. return uv;
  1915. }
  1916. });
  1917. Object.defineProperty(Texture.prototype, 'needsUpdate', {
  1918. set: function set(value) {
  1919. if (value === true) this.version++;
  1920. }
  1921. });
  1922. function serializeImage(image) {
  1923. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  1924. // default images
  1925. return ImageUtils.getDataURL(image);
  1926. } else {
  1927. if (image.data) {
  1928. // images of DataTexture
  1929. return {
  1930. data: Array.prototype.slice.call(image.data),
  1931. width: image.width,
  1932. height: image.height,
  1933. type: image.data.constructor.name
  1934. };
  1935. } else {
  1936. console.warn('THREE.Texture: Unable to serialize Texture.');
  1937. return {};
  1938. }
  1939. }
  1940. }
  1941. var Vector4 = /*#__PURE__*/function () {
  1942. function Vector4(x, y, z, w) {
  1943. if (x === void 0) {
  1944. x = 0;
  1945. }
  1946. if (y === void 0) {
  1947. y = 0;
  1948. }
  1949. if (z === void 0) {
  1950. z = 0;
  1951. }
  1952. if (w === void 0) {
  1953. w = 1;
  1954. }
  1955. Object.defineProperty(this, 'isVector4', {
  1956. value: true
  1957. });
  1958. this.x = x;
  1959. this.y = y;
  1960. this.z = z;
  1961. this.w = w;
  1962. }
  1963. var _proto = Vector4.prototype;
  1964. _proto.set = function set(x, y, z, w) {
  1965. this.x = x;
  1966. this.y = y;
  1967. this.z = z;
  1968. this.w = w;
  1969. return this;
  1970. };
  1971. _proto.setScalar = function setScalar(scalar) {
  1972. this.x = scalar;
  1973. this.y = scalar;
  1974. this.z = scalar;
  1975. this.w = scalar;
  1976. return this;
  1977. };
  1978. _proto.setX = function setX(x) {
  1979. this.x = x;
  1980. return this;
  1981. };
  1982. _proto.setY = function setY(y) {
  1983. this.y = y;
  1984. return this;
  1985. };
  1986. _proto.setZ = function setZ(z) {
  1987. this.z = z;
  1988. return this;
  1989. };
  1990. _proto.setW = function setW(w) {
  1991. this.w = w;
  1992. return this;
  1993. };
  1994. _proto.setComponent = function setComponent(index, value) {
  1995. switch (index) {
  1996. case 0:
  1997. this.x = value;
  1998. break;
  1999. case 1:
  2000. this.y = value;
  2001. break;
  2002. case 2:
  2003. this.z = value;
  2004. break;
  2005. case 3:
  2006. this.w = value;
  2007. break;
  2008. default:
  2009. throw new Error('index is out of range: ' + index);
  2010. }
  2011. return this;
  2012. };
  2013. _proto.getComponent = function getComponent(index) {
  2014. switch (index) {
  2015. case 0:
  2016. return this.x;
  2017. case 1:
  2018. return this.y;
  2019. case 2:
  2020. return this.z;
  2021. case 3:
  2022. return this.w;
  2023. default:
  2024. throw new Error('index is out of range: ' + index);
  2025. }
  2026. };
  2027. _proto.clone = function clone() {
  2028. return new this.constructor(this.x, this.y, this.z, this.w);
  2029. };
  2030. _proto.copy = function copy(v) {
  2031. this.x = v.x;
  2032. this.y = v.y;
  2033. this.z = v.z;
  2034. this.w = v.w !== undefined ? v.w : 1;
  2035. return this;
  2036. };
  2037. _proto.add = function add(v, w) {
  2038. if (w !== undefined) {
  2039. console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2040. return this.addVectors(v, w);
  2041. }
  2042. this.x += v.x;
  2043. this.y += v.y;
  2044. this.z += v.z;
  2045. this.w += v.w;
  2046. return this;
  2047. };
  2048. _proto.addScalar = function addScalar(s) {
  2049. this.x += s;
  2050. this.y += s;
  2051. this.z += s;
  2052. this.w += s;
  2053. return this;
  2054. };
  2055. _proto.addVectors = function addVectors(a, b) {
  2056. this.x = a.x + b.x;
  2057. this.y = a.y + b.y;
  2058. this.z = a.z + b.z;
  2059. this.w = a.w + b.w;
  2060. return this;
  2061. };
  2062. _proto.addScaledVector = function addScaledVector(v, s) {
  2063. this.x += v.x * s;
  2064. this.y += v.y * s;
  2065. this.z += v.z * s;
  2066. this.w += v.w * s;
  2067. return this;
  2068. };
  2069. _proto.sub = function sub(v, w) {
  2070. if (w !== undefined) {
  2071. console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2072. return this.subVectors(v, w);
  2073. }
  2074. this.x -= v.x;
  2075. this.y -= v.y;
  2076. this.z -= v.z;
  2077. this.w -= v.w;
  2078. return this;
  2079. };
  2080. _proto.subScalar = function subScalar(s) {
  2081. this.x -= s;
  2082. this.y -= s;
  2083. this.z -= s;
  2084. this.w -= s;
  2085. return this;
  2086. };
  2087. _proto.subVectors = function subVectors(a, b) {
  2088. this.x = a.x - b.x;
  2089. this.y = a.y - b.y;
  2090. this.z = a.z - b.z;
  2091. this.w = a.w - b.w;
  2092. return this;
  2093. };
  2094. _proto.multiply = function multiply(v) {
  2095. this.x *= v.x;
  2096. this.y *= v.y;
  2097. this.z *= v.z;
  2098. this.w *= v.w;
  2099. return this;
  2100. };
  2101. _proto.multiplyScalar = function multiplyScalar(scalar) {
  2102. this.x *= scalar;
  2103. this.y *= scalar;
  2104. this.z *= scalar;
  2105. this.w *= scalar;
  2106. return this;
  2107. };
  2108. _proto.applyMatrix4 = function applyMatrix4(m) {
  2109. var x = this.x,
  2110. y = this.y,
  2111. z = this.z,
  2112. w = this.w;
  2113. var e = m.elements;
  2114. this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
  2115. this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
  2116. this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
  2117. this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
  2118. return this;
  2119. };
  2120. _proto.divideScalar = function divideScalar(scalar) {
  2121. return this.multiplyScalar(1 / scalar);
  2122. };
  2123. _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
  2124. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2125. // q is assumed to be normalized
  2126. this.w = 2 * Math.acos(q.w);
  2127. var s = Math.sqrt(1 - q.w * q.w);
  2128. if (s < 0.0001) {
  2129. this.x = 1;
  2130. this.y = 0;
  2131. this.z = 0;
  2132. } else {
  2133. this.x = q.x / s;
  2134. this.y = q.y / s;
  2135. this.z = q.z / s;
  2136. }
  2137. return this;
  2138. };
  2139. _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
  2140. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2141. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2142. var angle, x, y, z; // variables for result
  2143. var epsilon = 0.01,
  2144. // margin to allow for rounding errors
  2145. epsilon2 = 0.1,
  2146. // margin to distinguish between 0 and 180 degrees
  2147. te = m.elements,
  2148. m11 = te[0],
  2149. m12 = te[4],
  2150. m13 = te[8],
  2151. m21 = te[1],
  2152. m22 = te[5],
  2153. m23 = te[9],
  2154. m31 = te[2],
  2155. m32 = te[6],
  2156. m33 = te[10];
  2157. if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
  2158. // singularity found
  2159. // first check for identity matrix which must have +1 for all terms
  2160. // in leading diagonal and zero in other terms
  2161. if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
  2162. // this singularity is identity matrix so angle = 0
  2163. this.set(1, 0, 0, 0);
  2164. return this; // zero angle, arbitrary axis
  2165. } // otherwise this singularity is angle = 180
  2166. angle = Math.PI;
  2167. var xx = (m11 + 1) / 2;
  2168. var yy = (m22 + 1) / 2;
  2169. var zz = (m33 + 1) / 2;
  2170. var xy = (m12 + m21) / 4;
  2171. var xz = (m13 + m31) / 4;
  2172. var yz = (m23 + m32) / 4;
  2173. if (xx > yy && xx > zz) {
  2174. // m11 is the largest diagonal term
  2175. if (xx < epsilon) {
  2176. x = 0;
  2177. y = 0.707106781;
  2178. z = 0.707106781;
  2179. } else {
  2180. x = Math.sqrt(xx);
  2181. y = xy / x;
  2182. z = xz / x;
  2183. }
  2184. } else if (yy > zz) {
  2185. // m22 is the largest diagonal term
  2186. if (yy < epsilon) {
  2187. x = 0.707106781;
  2188. y = 0;
  2189. z = 0.707106781;
  2190. } else {
  2191. y = Math.sqrt(yy);
  2192. x = xy / y;
  2193. z = yz / y;
  2194. }
  2195. } else {
  2196. // m33 is the largest diagonal term so base result on this
  2197. if (zz < epsilon) {
  2198. x = 0.707106781;
  2199. y = 0.707106781;
  2200. z = 0;
  2201. } else {
  2202. z = Math.sqrt(zz);
  2203. x = xz / z;
  2204. y = yz / z;
  2205. }
  2206. }
  2207. this.set(x, y, z, angle);
  2208. return this; // return 180 deg rotation
  2209. } // as we have reached here there are no singularities so we can handle normally
  2210. var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
  2211. if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2212. // caught by singularity test above, but I've left it in just in case
  2213. this.x = (m32 - m23) / s;
  2214. this.y = (m13 - m31) / s;
  2215. this.z = (m21 - m12) / s;
  2216. this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
  2217. return this;
  2218. };
  2219. _proto.min = function min(v) {
  2220. this.x = Math.min(this.x, v.x);
  2221. this.y = Math.min(this.y, v.y);
  2222. this.z = Math.min(this.z, v.z);
  2223. this.w = Math.min(this.w, v.w);
  2224. return this;
  2225. };
  2226. _proto.max = function max(v) {
  2227. this.x = Math.max(this.x, v.x);
  2228. this.y = Math.max(this.y, v.y);
  2229. this.z = Math.max(this.z, v.z);
  2230. this.w = Math.max(this.w, v.w);
  2231. return this;
  2232. };
  2233. _proto.clamp = function clamp(min, max) {
  2234. // assumes min < max, componentwise
  2235. this.x = Math.max(min.x, Math.min(max.x, this.x));
  2236. this.y = Math.max(min.y, Math.min(max.y, this.y));
  2237. this.z = Math.max(min.z, Math.min(max.z, this.z));
  2238. this.w = Math.max(min.w, Math.min(max.w, this.w));
  2239. return this;
  2240. };
  2241. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  2242. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  2243. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  2244. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  2245. this.w = Math.max(minVal, Math.min(maxVal, this.w));
  2246. return this;
  2247. };
  2248. _proto.clampLength = function clampLength(min, max) {
  2249. var length = this.length();
  2250. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  2251. };
  2252. _proto.floor = function floor() {
  2253. this.x = Math.floor(this.x);
  2254. this.y = Math.floor(this.y);
  2255. this.z = Math.floor(this.z);
  2256. this.w = Math.floor(this.w);
  2257. return this;
  2258. };
  2259. _proto.ceil = function ceil() {
  2260. this.x = Math.ceil(this.x);
  2261. this.y = Math.ceil(this.y);
  2262. this.z = Math.ceil(this.z);
  2263. this.w = Math.ceil(this.w);
  2264. return this;
  2265. };
  2266. _proto.round = function round() {
  2267. this.x = Math.round(this.x);
  2268. this.y = Math.round(this.y);
  2269. this.z = Math.round(this.z);
  2270. this.w = Math.round(this.w);
  2271. return this;
  2272. };
  2273. _proto.roundToZero = function roundToZero() {
  2274. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  2275. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  2276. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  2277. this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
  2278. return this;
  2279. };
  2280. _proto.negate = function negate() {
  2281. this.x = -this.x;
  2282. this.y = -this.y;
  2283. this.z = -this.z;
  2284. this.w = -this.w;
  2285. return this;
  2286. };
  2287. _proto.dot = function dot(v) {
  2288. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2289. };
  2290. _proto.lengthSq = function lengthSq() {
  2291. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2292. };
  2293. _proto.length = function length() {
  2294. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  2295. };
  2296. _proto.manhattanLength = function manhattanLength() {
  2297. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  2298. };
  2299. _proto.normalize = function normalize() {
  2300. return this.divideScalar(this.length() || 1);
  2301. };
  2302. _proto.setLength = function setLength(length) {
  2303. return this.normalize().multiplyScalar(length);
  2304. };
  2305. _proto.lerp = function lerp(v, alpha) {
  2306. this.x += (v.x - this.x) * alpha;
  2307. this.y += (v.y - this.y) * alpha;
  2308. this.z += (v.z - this.z) * alpha;
  2309. this.w += (v.w - this.w) * alpha;
  2310. return this;
  2311. };
  2312. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  2313. this.x = v1.x + (v2.x - v1.x) * alpha;
  2314. this.y = v1.y + (v2.y - v1.y) * alpha;
  2315. this.z = v1.z + (v2.z - v1.z) * alpha;
  2316. this.w = v1.w + (v2.w - v1.w) * alpha;
  2317. return this;
  2318. };
  2319. _proto.equals = function equals(v) {
  2320. return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
  2321. };
  2322. _proto.fromArray = function fromArray(array, offset) {
  2323. if (offset === void 0) {
  2324. offset = 0;
  2325. }
  2326. this.x = array[offset];
  2327. this.y = array[offset + 1];
  2328. this.z = array[offset + 2];
  2329. this.w = array[offset + 3];
  2330. return this;
  2331. };
  2332. _proto.toArray = function toArray(array, offset) {
  2333. if (array === void 0) {
  2334. array = [];
  2335. }
  2336. if (offset === void 0) {
  2337. offset = 0;
  2338. }
  2339. array[offset] = this.x;
  2340. array[offset + 1] = this.y;
  2341. array[offset + 2] = this.z;
  2342. array[offset + 3] = this.w;
  2343. return array;
  2344. };
  2345. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  2346. if (offset !== undefined) {
  2347. console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
  2348. }
  2349. this.x = attribute.getX(index);
  2350. this.y = attribute.getY(index);
  2351. this.z = attribute.getZ(index);
  2352. this.w = attribute.getW(index);
  2353. return this;
  2354. };
  2355. _proto.random = function random() {
  2356. this.x = Math.random();
  2357. this.y = Math.random();
  2358. this.z = Math.random();
  2359. this.w = Math.random();
  2360. return this;
  2361. };
  2362. _createClass(Vector4, [{
  2363. key: "width",
  2364. get: function get() {
  2365. return this.z;
  2366. },
  2367. set: function set(value) {
  2368. this.z = value;
  2369. }
  2370. }, {
  2371. key: "height",
  2372. get: function get() {
  2373. return this.w;
  2374. },
  2375. set: function set(value) {
  2376. this.w = value;
  2377. }
  2378. }]);
  2379. return Vector4;
  2380. }();
  2381. /*
  2382. In options, we can specify:
  2383. * Texture parameters for an auto-generated target texture
  2384. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2385. */
  2386. var WebGLRenderTarget = /*#__PURE__*/function (_EventDispatcher) {
  2387. _inheritsLoose(WebGLRenderTarget, _EventDispatcher);
  2388. function WebGLRenderTarget(width, height, options) {
  2389. var _this;
  2390. _this = _EventDispatcher.call(this) || this;
  2391. Object.defineProperty(_assertThisInitialized(_this), 'isWebGLRenderTarget', {
  2392. value: true
  2393. });
  2394. _this.width = width;
  2395. _this.height = height;
  2396. _this.scissor = new Vector4(0, 0, width, height);
  2397. _this.scissorTest = false;
  2398. _this.viewport = new Vector4(0, 0, width, height);
  2399. options = options || {};
  2400. _this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  2401. _this.texture.image = {};
  2402. _this.texture.image.width = width;
  2403. _this.texture.image.height = height;
  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.setSize = function setSize(width, height) {
  2413. if (this.width !== width || this.height !== height) {
  2414. this.width = width;
  2415. this.height = height;
  2416. this.texture.image.width = width;
  2417. this.texture.image.height = height;
  2418. this.dispose();
  2419. }
  2420. this.viewport.set(0, 0, width, height);
  2421. this.scissor.set(0, 0, width, height);
  2422. };
  2423. _proto.clone = function clone() {
  2424. return new this.constructor().copy(this);
  2425. };
  2426. _proto.copy = function copy(source) {
  2427. this.width = source.width;
  2428. this.height = source.height;
  2429. this.viewport.copy(source.viewport);
  2430. this.texture = source.texture.clone();
  2431. this.depthBuffer = source.depthBuffer;
  2432. this.stencilBuffer = source.stencilBuffer;
  2433. this.depthTexture = source.depthTexture;
  2434. return this;
  2435. };
  2436. _proto.dispose = function dispose() {
  2437. this.dispatchEvent({
  2438. type: 'dispose'
  2439. });
  2440. };
  2441. return WebGLRenderTarget;
  2442. }(EventDispatcher);
  2443. var WebGLMultisampleRenderTarget = /*#__PURE__*/function (_WebGLRenderTarget) {
  2444. _inheritsLoose(WebGLMultisampleRenderTarget, _WebGLRenderTarget);
  2445. function WebGLMultisampleRenderTarget(width, height, options) {
  2446. var _this;
  2447. _this = _WebGLRenderTarget.call(this, width, height, options) || this;
  2448. Object.defineProperty(_assertThisInitialized(_this), 'isWebGLMultisampleRenderTarget', {
  2449. value: true
  2450. });
  2451. _this.samples = 4;
  2452. return _this;
  2453. }
  2454. var _proto = WebGLMultisampleRenderTarget.prototype;
  2455. _proto.copy = function copy(source) {
  2456. _WebGLRenderTarget.prototype.copy.call(this, source);
  2457. this.samples = source.samples;
  2458. return this;
  2459. };
  2460. return WebGLMultisampleRenderTarget;
  2461. }(WebGLRenderTarget);
  2462. var Quaternion = /*#__PURE__*/function () {
  2463. function Quaternion(x, y, z, w) {
  2464. if (x === void 0) {
  2465. x = 0;
  2466. }
  2467. if (y === void 0) {
  2468. y = 0;
  2469. }
  2470. if (z === void 0) {
  2471. z = 0;
  2472. }
  2473. if (w === void 0) {
  2474. w = 1;
  2475. }
  2476. Object.defineProperty(this, 'isQuaternion', {
  2477. value: true
  2478. });
  2479. this._x = x;
  2480. this._y = y;
  2481. this._z = z;
  2482. this._w = w;
  2483. }
  2484. Quaternion.slerp = function slerp(qa, qb, qm, t) {
  2485. return qm.copy(qa).slerp(qb, t);
  2486. };
  2487. Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
  2488. // fuzz-free, array-based Quaternion SLERP operation
  2489. var x0 = src0[srcOffset0 + 0],
  2490. y0 = src0[srcOffset0 + 1],
  2491. z0 = src0[srcOffset0 + 2],
  2492. w0 = src0[srcOffset0 + 3];
  2493. var x1 = src1[srcOffset1 + 0],
  2494. y1 = src1[srcOffset1 + 1],
  2495. z1 = src1[srcOffset1 + 2],
  2496. w1 = src1[srcOffset1 + 3];
  2497. if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
  2498. var s = 1 - t;
  2499. var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  2500. dir = cos >= 0 ? 1 : -1,
  2501. sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
  2502. if (sqrSin > Number.EPSILON) {
  2503. var sin = Math.sqrt(sqrSin),
  2504. len = Math.atan2(sin, cos * dir);
  2505. s = Math.sin(s * len) / sin;
  2506. t = Math.sin(t * len) / sin;
  2507. }
  2508. var tDir = t * dir;
  2509. x0 = x0 * s + x1 * tDir;
  2510. y0 = y0 * s + y1 * tDir;
  2511. z0 = z0 * s + z1 * tDir;
  2512. w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
  2513. if (s === 1 - t) {
  2514. var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
  2515. x0 *= f;
  2516. y0 *= f;
  2517. z0 *= f;
  2518. w0 *= f;
  2519. }
  2520. }
  2521. dst[dstOffset] = x0;
  2522. dst[dstOffset + 1] = y0;
  2523. dst[dstOffset + 2] = z0;
  2524. dst[dstOffset + 3] = w0;
  2525. };
  2526. Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
  2527. var x0 = src0[srcOffset0];
  2528. var y0 = src0[srcOffset0 + 1];
  2529. var z0 = src0[srcOffset0 + 2];
  2530. var w0 = src0[srcOffset0 + 3];
  2531. var x1 = src1[srcOffset1];
  2532. var y1 = src1[srcOffset1 + 1];
  2533. var z1 = src1[srcOffset1 + 2];
  2534. var w1 = src1[srcOffset1 + 3];
  2535. dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  2536. dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  2537. dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  2538. dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  2539. return dst;
  2540. };
  2541. var _proto = Quaternion.prototype;
  2542. _proto.set = function set(x, y, z, w) {
  2543. this._x = x;
  2544. this._y = y;
  2545. this._z = z;
  2546. this._w = w;
  2547. this._onChangeCallback();
  2548. return this;
  2549. };
  2550. _proto.clone = function clone() {
  2551. return new this.constructor(this._x, this._y, this._z, this._w);
  2552. };
  2553. _proto.copy = function copy(quaternion) {
  2554. this._x = quaternion.x;
  2555. this._y = quaternion.y;
  2556. this._z = quaternion.z;
  2557. this._w = quaternion.w;
  2558. this._onChangeCallback();
  2559. return this;
  2560. };
  2561. _proto.setFromEuler = function setFromEuler(euler, update) {
  2562. if (!(euler && euler.isEuler)) {
  2563. throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
  2564. }
  2565. var x = euler._x,
  2566. y = euler._y,
  2567. z = euler._z,
  2568. order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
  2569. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  2570. // content/SpinCalc.m
  2571. var cos = Math.cos;
  2572. var sin = Math.sin;
  2573. var c1 = cos(x / 2);
  2574. var c2 = cos(y / 2);
  2575. var c3 = cos(z / 2);
  2576. var s1 = sin(x / 2);
  2577. var s2 = sin(y / 2);
  2578. var s3 = sin(z / 2);
  2579. switch (order) {
  2580. case 'XYZ':
  2581. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2582. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2583. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2584. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2585. break;
  2586. case 'YXZ':
  2587. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2588. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2589. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2590. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2591. break;
  2592. case 'ZXY':
  2593. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2594. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2595. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2596. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2597. break;
  2598. case 'ZYX':
  2599. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2600. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2601. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2602. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2603. break;
  2604. case 'YZX':
  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 'XZY':
  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. default:
  2617. console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
  2618. }
  2619. if (update !== false) this._onChangeCallback();
  2620. return this;
  2621. };
  2622. _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
  2623. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  2624. // assumes axis is normalized
  2625. var halfAngle = angle / 2,
  2626. s = Math.sin(halfAngle);
  2627. this._x = axis.x * s;
  2628. this._y = axis.y * s;
  2629. this._z = axis.z * s;
  2630. this._w = Math.cos(halfAngle);
  2631. this._onChangeCallback();
  2632. return this;
  2633. };
  2634. _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
  2635. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  2636. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2637. var te = m.elements,
  2638. m11 = te[0],
  2639. m12 = te[4],
  2640. m13 = te[8],
  2641. m21 = te[1],
  2642. m22 = te[5],
  2643. m23 = te[9],
  2644. m31 = te[2],
  2645. m32 = te[6],
  2646. m33 = te[10],
  2647. trace = m11 + m22 + m33;
  2648. if (trace > 0) {
  2649. var s = 0.5 / Math.sqrt(trace + 1.0);
  2650. this._w = 0.25 / s;
  2651. this._x = (m32 - m23) * s;
  2652. this._y = (m13 - m31) * s;
  2653. this._z = (m21 - m12) * s;
  2654. } else if (m11 > m22 && m11 > m33) {
  2655. var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  2656. this._w = (m32 - m23) / _s;
  2657. this._x = 0.25 * _s;
  2658. this._y = (m12 + m21) / _s;
  2659. this._z = (m13 + m31) / _s;
  2660. } else if (m22 > m33) {
  2661. var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  2662. this._w = (m13 - m31) / _s2;
  2663. this._x = (m12 + m21) / _s2;
  2664. this._y = 0.25 * _s2;
  2665. this._z = (m23 + m32) / _s2;
  2666. } else {
  2667. var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  2668. this._w = (m21 - m12) / _s3;
  2669. this._x = (m13 + m31) / _s3;
  2670. this._y = (m23 + m32) / _s3;
  2671. this._z = 0.25 * _s3;
  2672. }
  2673. this._onChangeCallback();
  2674. return this;
  2675. };
  2676. _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
  2677. // assumes direction vectors vFrom and vTo are normalized
  2678. var EPS = 0.000001;
  2679. var r = vFrom.dot(vTo) + 1;
  2680. if (r < EPS) {
  2681. r = 0;
  2682. if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
  2683. this._x = -vFrom.y;
  2684. this._y = vFrom.x;
  2685. this._z = 0;
  2686. this._w = r;
  2687. } else {
  2688. this._x = 0;
  2689. this._y = -vFrom.z;
  2690. this._z = vFrom.y;
  2691. this._w = r;
  2692. }
  2693. } else {
  2694. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  2695. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  2696. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  2697. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  2698. this._w = r;
  2699. }
  2700. return this.normalize();
  2701. };
  2702. _proto.angleTo = function angleTo(q) {
  2703. return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
  2704. };
  2705. _proto.rotateTowards = function rotateTowards(q, step) {
  2706. var angle = this.angleTo(q);
  2707. if (angle === 0) return this;
  2708. var t = Math.min(1, step / angle);
  2709. this.slerp(q, t);
  2710. return this;
  2711. };
  2712. _proto.identity = function identity() {
  2713. return this.set(0, 0, 0, 1);
  2714. };
  2715. _proto.invert = function invert() {
  2716. // quaternion is assumed to have unit length
  2717. return this.conjugate();
  2718. };
  2719. _proto.conjugate = function conjugate() {
  2720. this._x *= -1;
  2721. this._y *= -1;
  2722. this._z *= -1;
  2723. this._onChangeCallback();
  2724. return this;
  2725. };
  2726. _proto.dot = function dot(v) {
  2727. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  2728. };
  2729. _proto.lengthSq = function lengthSq() {
  2730. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  2731. };
  2732. _proto.length = function length() {
  2733. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  2734. };
  2735. _proto.normalize = function normalize() {
  2736. var l = this.length();
  2737. if (l === 0) {
  2738. this._x = 0;
  2739. this._y = 0;
  2740. this._z = 0;
  2741. this._w = 1;
  2742. } else {
  2743. l = 1 / l;
  2744. this._x = this._x * l;
  2745. this._y = this._y * l;
  2746. this._z = this._z * l;
  2747. this._w = this._w * l;
  2748. }
  2749. this._onChangeCallback();
  2750. return this;
  2751. };
  2752. _proto.multiply = function multiply(q, p) {
  2753. if (p !== undefined) {
  2754. console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
  2755. return this.multiplyQuaternions(q, p);
  2756. }
  2757. return this.multiplyQuaternions(this, q);
  2758. };
  2759. _proto.premultiply = function premultiply(q) {
  2760. return this.multiplyQuaternions(q, this);
  2761. };
  2762. _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
  2763. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2764. var qax = a._x,
  2765. qay = a._y,
  2766. qaz = a._z,
  2767. qaw = a._w;
  2768. var qbx = b._x,
  2769. qby = b._y,
  2770. qbz = b._z,
  2771. qbw = b._w;
  2772. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2773. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2774. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2775. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2776. this._onChangeCallback();
  2777. return this;
  2778. };
  2779. _proto.slerp = function slerp(qb, t) {
  2780. if (t === 0) return this;
  2781. if (t === 1) return this.copy(qb);
  2782. var x = this._x,
  2783. y = this._y,
  2784. z = this._z,
  2785. w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2786. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2787. if (cosHalfTheta < 0) {
  2788. this._w = -qb._w;
  2789. this._x = -qb._x;
  2790. this._y = -qb._y;
  2791. this._z = -qb._z;
  2792. cosHalfTheta = -cosHalfTheta;
  2793. } else {
  2794. this.copy(qb);
  2795. }
  2796. if (cosHalfTheta >= 1.0) {
  2797. this._w = w;
  2798. this._x = x;
  2799. this._y = y;
  2800. this._z = z;
  2801. return this;
  2802. }
  2803. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2804. if (sqrSinHalfTheta <= Number.EPSILON) {
  2805. var s = 1 - t;
  2806. this._w = s * w + t * this._w;
  2807. this._x = s * x + t * this._x;
  2808. this._y = s * y + t * this._y;
  2809. this._z = s * z + t * this._z;
  2810. this.normalize();
  2811. this._onChangeCallback();
  2812. return this;
  2813. }
  2814. var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
  2815. var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
  2816. var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
  2817. ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
  2818. this._w = w * ratioA + this._w * ratioB;
  2819. this._x = x * ratioA + this._x * ratioB;
  2820. this._y = y * ratioA + this._y * ratioB;
  2821. this._z = z * ratioA + this._z * ratioB;
  2822. this._onChangeCallback();
  2823. return this;
  2824. };
  2825. _proto.equals = function equals(quaternion) {
  2826. return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
  2827. };
  2828. _proto.fromArray = function fromArray(array, offset) {
  2829. if (offset === void 0) {
  2830. offset = 0;
  2831. }
  2832. this._x = array[offset];
  2833. this._y = array[offset + 1];
  2834. this._z = array[offset + 2];
  2835. this._w = array[offset + 3];
  2836. this._onChangeCallback();
  2837. return this;
  2838. };
  2839. _proto.toArray = function toArray(array, offset) {
  2840. if (array === void 0) {
  2841. array = [];
  2842. }
  2843. if (offset === void 0) {
  2844. offset = 0;
  2845. }
  2846. array[offset] = this._x;
  2847. array[offset + 1] = this._y;
  2848. array[offset + 2] = this._z;
  2849. array[offset + 3] = this._w;
  2850. return array;
  2851. };
  2852. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  2853. this._x = attribute.getX(index);
  2854. this._y = attribute.getY(index);
  2855. this._z = attribute.getZ(index);
  2856. this._w = attribute.getW(index);
  2857. return this;
  2858. };
  2859. _proto._onChange = function _onChange(callback) {
  2860. this._onChangeCallback = callback;
  2861. return this;
  2862. };
  2863. _proto._onChangeCallback = function _onChangeCallback() {};
  2864. _createClass(Quaternion, [{
  2865. key: "x",
  2866. get: function get() {
  2867. return this._x;
  2868. },
  2869. set: function set(value) {
  2870. this._x = value;
  2871. this._onChangeCallback();
  2872. }
  2873. }, {
  2874. key: "y",
  2875. get: function get() {
  2876. return this._y;
  2877. },
  2878. set: function set(value) {
  2879. this._y = value;
  2880. this._onChangeCallback();
  2881. }
  2882. }, {
  2883. key: "z",
  2884. get: function get() {
  2885. return this._z;
  2886. },
  2887. set: function set(value) {
  2888. this._z = value;
  2889. this._onChangeCallback();
  2890. }
  2891. }, {
  2892. key: "w",
  2893. get: function get() {
  2894. return this._w;
  2895. },
  2896. set: function set(value) {
  2897. this._w = value;
  2898. this._onChangeCallback();
  2899. }
  2900. }]);
  2901. return Quaternion;
  2902. }();
  2903. var Vector3 = /*#__PURE__*/function () {
  2904. function Vector3(x, y, z) {
  2905. if (x === void 0) {
  2906. x = 0;
  2907. }
  2908. if (y === void 0) {
  2909. y = 0;
  2910. }
  2911. if (z === void 0) {
  2912. z = 0;
  2913. }
  2914. Object.defineProperty(this, 'isVector3', {
  2915. value: true
  2916. });
  2917. this.x = x;
  2918. this.y = y;
  2919. this.z = z;
  2920. }
  2921. var _proto = Vector3.prototype;
  2922. _proto.set = function set(x, y, z) {
  2923. if (z === undefined) z = this.z; // sprite.scale.set(x,y)
  2924. this.x = x;
  2925. this.y = y;
  2926. this.z = z;
  2927. return this;
  2928. };
  2929. _proto.setScalar = function setScalar(scalar) {
  2930. this.x = scalar;
  2931. this.y = scalar;
  2932. this.z = scalar;
  2933. return this;
  2934. };
  2935. _proto.setX = function setX(x) {
  2936. this.x = x;
  2937. return this;
  2938. };
  2939. _proto.setY = function setY(y) {
  2940. this.y = y;
  2941. return this;
  2942. };
  2943. _proto.setZ = function setZ(z) {
  2944. this.z = z;
  2945. return this;
  2946. };
  2947. _proto.setComponent = function setComponent(index, value) {
  2948. switch (index) {
  2949. case 0:
  2950. this.x = value;
  2951. break;
  2952. case 1:
  2953. this.y = value;
  2954. break;
  2955. case 2:
  2956. this.z = value;
  2957. break;
  2958. default:
  2959. throw new Error('index is out of range: ' + index);
  2960. }
  2961. return this;
  2962. };
  2963. _proto.getComponent = function getComponent(index) {
  2964. switch (index) {
  2965. case 0:
  2966. return this.x;
  2967. case 1:
  2968. return this.y;
  2969. case 2:
  2970. return this.z;
  2971. default:
  2972. throw new Error('index is out of range: ' + index);
  2973. }
  2974. };
  2975. _proto.clone = function clone() {
  2976. return new this.constructor(this.x, this.y, this.z);
  2977. };
  2978. _proto.copy = function copy(v) {
  2979. this.x = v.x;
  2980. this.y = v.y;
  2981. this.z = v.z;
  2982. return this;
  2983. };
  2984. _proto.add = function add(v, w) {
  2985. if (w !== undefined) {
  2986. console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2987. return this.addVectors(v, w);
  2988. }
  2989. this.x += v.x;
  2990. this.y += v.y;
  2991. this.z += v.z;
  2992. return this;
  2993. };
  2994. _proto.addScalar = function addScalar(s) {
  2995. this.x += s;
  2996. this.y += s;
  2997. this.z += s;
  2998. return this;
  2999. };
  3000. _proto.addVectors = function addVectors(a, b) {
  3001. this.x = a.x + b.x;
  3002. this.y = a.y + b.y;
  3003. this.z = a.z + b.z;
  3004. return this;
  3005. };
  3006. _proto.addScaledVector = function addScaledVector(v, s) {
  3007. this.x += v.x * s;
  3008. this.y += v.y * s;
  3009. this.z += v.z * s;
  3010. return this;
  3011. };
  3012. _proto.sub = function sub(v, w) {
  3013. if (w !== undefined) {
  3014. console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  3015. return this.subVectors(v, w);
  3016. }
  3017. this.x -= v.x;
  3018. this.y -= v.y;
  3019. this.z -= v.z;
  3020. return this;
  3021. };
  3022. _proto.subScalar = function subScalar(s) {
  3023. this.x -= s;
  3024. this.y -= s;
  3025. this.z -= s;
  3026. return this;
  3027. };
  3028. _proto.subVectors = function subVectors(a, b) {
  3029. this.x = a.x - b.x;
  3030. this.y = a.y - b.y;
  3031. this.z = a.z - b.z;
  3032. return this;
  3033. };
  3034. _proto.multiply = function multiply(v, w) {
  3035. if (w !== undefined) {
  3036. console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
  3037. return this.multiplyVectors(v, w);
  3038. }
  3039. this.x *= v.x;
  3040. this.y *= v.y;
  3041. this.z *= v.z;
  3042. return this;
  3043. };
  3044. _proto.multiplyScalar = function multiplyScalar(scalar) {
  3045. this.x *= scalar;
  3046. this.y *= scalar;
  3047. this.z *= scalar;
  3048. return this;
  3049. };
  3050. _proto.multiplyVectors = function multiplyVectors(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.applyEuler = function applyEuler(euler) {
  3057. if (!(euler && euler.isEuler)) {
  3058. console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
  3059. }
  3060. return this.applyQuaternion(_quaternion.setFromEuler(euler));
  3061. };
  3062. _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
  3063. return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
  3064. };
  3065. _proto.applyMatrix3 = function applyMatrix3(m) {
  3066. var x = this.x,
  3067. y = this.y,
  3068. z = this.z;
  3069. var e = m.elements;
  3070. this.x = e[0] * x + e[3] * y + e[6] * z;
  3071. this.y = e[1] * x + e[4] * y + e[7] * z;
  3072. this.z = e[2] * x + e[5] * y + e[8] * z;
  3073. return this;
  3074. };
  3075. _proto.applyNormalMatrix = function applyNormalMatrix(m) {
  3076. return this.applyMatrix3(m).normalize();
  3077. };
  3078. _proto.applyMatrix4 = function applyMatrix4(m) {
  3079. var x = this.x,
  3080. y = this.y,
  3081. z = this.z;
  3082. var e = m.elements;
  3083. var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
  3084. this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
  3085. this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
  3086. this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
  3087. return this;
  3088. };
  3089. _proto.applyQuaternion = function applyQuaternion(q) {
  3090. var x = this.x,
  3091. y = this.y,
  3092. z = this.z;
  3093. var qx = q.x,
  3094. qy = q.y,
  3095. qz = q.z,
  3096. qw = q.w; // calculate quat * vector
  3097. var ix = qw * x + qy * z - qz * y;
  3098. var iy = qw * y + qz * x - qx * z;
  3099. var iz = qw * z + qx * y - qy * x;
  3100. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  3101. this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  3102. this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  3103. this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  3104. return this;
  3105. };
  3106. _proto.project = function project(camera) {
  3107. return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
  3108. };
  3109. _proto.unproject = function unproject(camera) {
  3110. return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
  3111. };
  3112. _proto.transformDirection = function transformDirection(m) {
  3113. // input: THREE.Matrix4 affine matrix
  3114. // vector interpreted as a direction
  3115. var x = this.x,
  3116. y = this.y,
  3117. z = this.z;
  3118. var e = m.elements;
  3119. this.x = e[0] * x + e[4] * y + e[8] * z;
  3120. this.y = e[1] * x + e[5] * y + e[9] * z;
  3121. this.z = e[2] * x + e[6] * y + e[10] * z;
  3122. return this.normalize();
  3123. };
  3124. _proto.divide = function divide(v) {
  3125. this.x /= v.x;
  3126. this.y /= v.y;
  3127. this.z /= v.z;
  3128. return this;
  3129. };
  3130. _proto.divideScalar = function divideScalar(scalar) {
  3131. return this.multiplyScalar(1 / scalar);
  3132. };
  3133. _proto.min = function min(v) {
  3134. this.x = Math.min(this.x, v.x);
  3135. this.y = Math.min(this.y, v.y);
  3136. this.z = Math.min(this.z, v.z);
  3137. return this;
  3138. };
  3139. _proto.max = function max(v) {
  3140. this.x = Math.max(this.x, v.x);
  3141. this.y = Math.max(this.y, v.y);
  3142. this.z = Math.max(this.z, v.z);
  3143. return this;
  3144. };
  3145. _proto.clamp = function clamp(min, max) {
  3146. // assumes min < max, componentwise
  3147. this.x = Math.max(min.x, Math.min(max.x, this.x));
  3148. this.y = Math.max(min.y, Math.min(max.y, this.y));
  3149. this.z = Math.max(min.z, Math.min(max.z, this.z));
  3150. return this;
  3151. };
  3152. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  3153. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  3154. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  3155. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  3156. return this;
  3157. };
  3158. _proto.clampLength = function clampLength(min, max) {
  3159. var length = this.length();
  3160. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  3161. };
  3162. _proto.floor = function floor() {
  3163. this.x = Math.floor(this.x);
  3164. this.y = Math.floor(this.y);
  3165. this.z = Math.floor(this.z);
  3166. return this;
  3167. };
  3168. _proto.ceil = function ceil() {
  3169. this.x = Math.ceil(this.x);
  3170. this.y = Math.ceil(this.y);
  3171. this.z = Math.ceil(this.z);
  3172. return this;
  3173. };
  3174. _proto.round = function round() {
  3175. this.x = Math.round(this.x);
  3176. this.y = Math.round(this.y);
  3177. this.z = Math.round(this.z);
  3178. return this;
  3179. };
  3180. _proto.roundToZero = function roundToZero() {
  3181. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  3182. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  3183. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  3184. return this;
  3185. };
  3186. _proto.negate = function negate() {
  3187. this.x = -this.x;
  3188. this.y = -this.y;
  3189. this.z = -this.z;
  3190. return this;
  3191. };
  3192. _proto.dot = function dot(v) {
  3193. return this.x * v.x + this.y * v.y + this.z * v.z;
  3194. } // TODO lengthSquared?
  3195. ;
  3196. _proto.lengthSq = function lengthSq() {
  3197. return this.x * this.x + this.y * this.y + this.z * this.z;
  3198. };
  3199. _proto.length = function length() {
  3200. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  3201. };
  3202. _proto.manhattanLength = function manhattanLength() {
  3203. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  3204. };
  3205. _proto.normalize = function normalize() {
  3206. return this.divideScalar(this.length() || 1);
  3207. };
  3208. _proto.setLength = function setLength(length) {
  3209. return this.normalize().multiplyScalar(length);
  3210. };
  3211. _proto.lerp = function lerp(v, alpha) {
  3212. this.x += (v.x - this.x) * alpha;
  3213. this.y += (v.y - this.y) * alpha;
  3214. this.z += (v.z - this.z) * alpha;
  3215. return this;
  3216. };
  3217. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  3218. this.x = v1.x + (v2.x - v1.x) * alpha;
  3219. this.y = v1.y + (v2.y - v1.y) * alpha;
  3220. this.z = v1.z + (v2.z - v1.z) * alpha;
  3221. return this;
  3222. };
  3223. _proto.cross = function cross(v, w) {
  3224. if (w !== undefined) {
  3225. console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
  3226. return this.crossVectors(v, w);
  3227. }
  3228. return this.crossVectors(this, v);
  3229. };
  3230. _proto.crossVectors = function crossVectors(a, b) {
  3231. var ax = a.x,
  3232. ay = a.y,
  3233. az = a.z;
  3234. var bx = b.x,
  3235. by = b.y,
  3236. bz = b.z;
  3237. this.x = ay * bz - az * by;
  3238. this.y = az * bx - ax * bz;
  3239. this.z = ax * by - ay * bx;
  3240. return this;
  3241. };
  3242. _proto.projectOnVector = function projectOnVector(v) {
  3243. var denominator = v.lengthSq();
  3244. if (denominator === 0) return this.set(0, 0, 0);
  3245. var scalar = v.dot(this) / denominator;
  3246. return this.copy(v).multiplyScalar(scalar);
  3247. };
  3248. _proto.projectOnPlane = function projectOnPlane(planeNormal) {
  3249. _vector.copy(this).projectOnVector(planeNormal);
  3250. return this.sub(_vector);
  3251. };
  3252. _proto.reflect = function reflect(normal) {
  3253. // reflect incident vector off plane orthogonal to normal
  3254. // normal is assumed to have unit length
  3255. return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
  3256. };
  3257. _proto.angleTo = function angleTo(v) {
  3258. var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
  3259. if (denominator === 0) return Math.PI / 2;
  3260. var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
  3261. return Math.acos(MathUtils.clamp(theta, -1, 1));
  3262. };
  3263. _proto.distanceTo = function distanceTo(v) {
  3264. return Math.sqrt(this.distanceToSquared(v));
  3265. };
  3266. _proto.distanceToSquared = function distanceToSquared(v) {
  3267. var dx = this.x - v.x,
  3268. dy = this.y - v.y,
  3269. dz = this.z - v.z;
  3270. return dx * dx + dy * dy + dz * dz;
  3271. };
  3272. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  3273. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
  3274. };
  3275. _proto.setFromSpherical = function setFromSpherical(s) {
  3276. return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
  3277. };
  3278. _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
  3279. var sinPhiRadius = Math.sin(phi) * radius;
  3280. this.x = sinPhiRadius * Math.sin(theta);
  3281. this.y = Math.cos(phi) * radius;
  3282. this.z = sinPhiRadius * Math.cos(theta);
  3283. return this;
  3284. };
  3285. _proto.setFromCylindrical = function setFromCylindrical(c) {
  3286. return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
  3287. };
  3288. _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
  3289. this.x = radius * Math.sin(theta);
  3290. this.y = y;
  3291. this.z = radius * Math.cos(theta);
  3292. return this;
  3293. };
  3294. _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
  3295. var e = m.elements;
  3296. this.x = e[12];
  3297. this.y = e[13];
  3298. this.z = e[14];
  3299. return this;
  3300. };
  3301. _proto.setFromMatrixScale = function setFromMatrixScale(m) {
  3302. var sx = this.setFromMatrixColumn(m, 0).length();
  3303. var sy = this.setFromMatrixColumn(m, 1).length();
  3304. var sz = this.setFromMatrixColumn(m, 2).length();
  3305. this.x = sx;
  3306. this.y = sy;
  3307. this.z = sz;
  3308. return this;
  3309. };
  3310. _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
  3311. return this.fromArray(m.elements, index * 4);
  3312. };
  3313. _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
  3314. return this.fromArray(m.elements, index * 3);
  3315. };
  3316. _proto.equals = function equals(v) {
  3317. return v.x === this.x && v.y === this.y && v.z === this.z;
  3318. };
  3319. _proto.fromArray = function fromArray(array, offset) {
  3320. if (offset === void 0) {
  3321. offset = 0;
  3322. }
  3323. this.x = array[offset];
  3324. this.y = array[offset + 1];
  3325. this.z = array[offset + 2];
  3326. return this;
  3327. };
  3328. _proto.toArray = function toArray(array, offset) {
  3329. if (array === void 0) {
  3330. array = [];
  3331. }
  3332. if (offset === void 0) {
  3333. offset = 0;
  3334. }
  3335. array[offset] = this.x;
  3336. array[offset + 1] = this.y;
  3337. array[offset + 2] = this.z;
  3338. return array;
  3339. };
  3340. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  3341. if (offset !== undefined) {
  3342. console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
  3343. }
  3344. this.x = attribute.getX(index);
  3345. this.y = attribute.getY(index);
  3346. this.z = attribute.getZ(index);
  3347. return this;
  3348. };
  3349. _proto.random = function random() {
  3350. this.x = Math.random();
  3351. this.y = Math.random();
  3352. this.z = Math.random();
  3353. return this;
  3354. };
  3355. return Vector3;
  3356. }();
  3357. var _vector = /*@__PURE__*/new Vector3();
  3358. var _quaternion = /*@__PURE__*/new Quaternion();
  3359. var Box3 = /*#__PURE__*/function () {
  3360. function Box3(min, max) {
  3361. Object.defineProperty(this, 'isBox3', {
  3362. value: true
  3363. });
  3364. this.min = min !== undefined ? min : new Vector3(+Infinity, +Infinity, +Infinity);
  3365. this.max = max !== undefined ? max : new Vector3(-Infinity, -Infinity, -Infinity);
  3366. }
  3367. var _proto = Box3.prototype;
  3368. _proto.set = function set(min, max) {
  3369. this.min.copy(min);
  3370. this.max.copy(max);
  3371. return this;
  3372. };
  3373. _proto.setFromArray = function setFromArray(array) {
  3374. var minX = +Infinity;
  3375. var minY = +Infinity;
  3376. var minZ = +Infinity;
  3377. var maxX = -Infinity;
  3378. var maxY = -Infinity;
  3379. var maxZ = -Infinity;
  3380. for (var i = 0, l = array.length; i < l; i += 3) {
  3381. var x = array[i];
  3382. var y = array[i + 1];
  3383. var z = array[i + 2];
  3384. if (x < minX) minX = x;
  3385. if (y < minY) minY = y;
  3386. if (z < minZ) minZ = z;
  3387. if (x > maxX) maxX = x;
  3388. if (y > maxY) maxY = y;
  3389. if (z > maxZ) maxZ = z;
  3390. }
  3391. this.min.set(minX, minY, minZ);
  3392. this.max.set(maxX, maxY, maxZ);
  3393. return this;
  3394. };
  3395. _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
  3396. var minX = +Infinity;
  3397. var minY = +Infinity;
  3398. var minZ = +Infinity;
  3399. var maxX = -Infinity;
  3400. var maxY = -Infinity;
  3401. var maxZ = -Infinity;
  3402. for (var i = 0, l = attribute.count; i < l; i++) {
  3403. var x = attribute.getX(i);
  3404. var y = attribute.getY(i);
  3405. var z = attribute.getZ(i);
  3406. if (x < minX) minX = x;
  3407. if (y < minY) minY = y;
  3408. if (z < minZ) minZ = z;
  3409. if (x > maxX) maxX = x;
  3410. if (y > maxY) maxY = y;
  3411. if (z > maxZ) maxZ = z;
  3412. }
  3413. this.min.set(minX, minY, minZ);
  3414. this.max.set(maxX, maxY, maxZ);
  3415. return this;
  3416. };
  3417. _proto.setFromPoints = function setFromPoints(points) {
  3418. this.makeEmpty();
  3419. for (var i = 0, il = points.length; i < il; i++) {
  3420. this.expandByPoint(points[i]);
  3421. }
  3422. return this;
  3423. };
  3424. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  3425. var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
  3426. this.min.copy(center).sub(halfSize);
  3427. this.max.copy(center).add(halfSize);
  3428. return this;
  3429. };
  3430. _proto.setFromObject = function setFromObject(object) {
  3431. this.makeEmpty();
  3432. return this.expandByObject(object);
  3433. };
  3434. _proto.clone = function clone() {
  3435. return new this.constructor().copy(this);
  3436. };
  3437. _proto.copy = function copy(box) {
  3438. this.min.copy(box.min);
  3439. this.max.copy(box.max);
  3440. return this;
  3441. };
  3442. _proto.makeEmpty = function makeEmpty() {
  3443. this.min.x = this.min.y = this.min.z = +Infinity;
  3444. this.max.x = this.max.y = this.max.z = -Infinity;
  3445. return this;
  3446. };
  3447. _proto.isEmpty = function isEmpty() {
  3448. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3449. return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  3450. };
  3451. _proto.getCenter = function getCenter(target) {
  3452. if (target === undefined) {
  3453. console.warn('THREE.Box3: .getCenter() target is now required');
  3454. target = new Vector3();
  3455. }
  3456. return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  3457. };
  3458. _proto.getSize = function getSize(target) {
  3459. if (target === undefined) {
  3460. console.warn('THREE.Box3: .getSize() target is now required');
  3461. target = new Vector3();
  3462. }
  3463. return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
  3464. };
  3465. _proto.expandByPoint = function expandByPoint(point) {
  3466. this.min.min(point);
  3467. this.max.max(point);
  3468. return this;
  3469. };
  3470. _proto.expandByVector = function expandByVector(vector) {
  3471. this.min.sub(vector);
  3472. this.max.add(vector);
  3473. return this;
  3474. };
  3475. _proto.expandByScalar = function expandByScalar(scalar) {
  3476. this.min.addScalar(-scalar);
  3477. this.max.addScalar(scalar);
  3478. return this;
  3479. };
  3480. _proto.expandByObject = function expandByObject(object) {
  3481. // Computes the world-axis-aligned bounding box of an object (including its children),
  3482. // accounting for both the object's, and children's, world transforms
  3483. object.updateWorldMatrix(false, false);
  3484. var geometry = object.geometry;
  3485. if (geometry !== undefined) {
  3486. if (geometry.boundingBox === null) {
  3487. geometry.computeBoundingBox();
  3488. }
  3489. _box.copy(geometry.boundingBox);
  3490. _box.applyMatrix4(object.matrixWorld);
  3491. this.union(_box);
  3492. }
  3493. var children = object.children;
  3494. for (var i = 0, l = children.length; i < l; i++) {
  3495. this.expandByObject(children[i]);
  3496. }
  3497. return this;
  3498. };
  3499. _proto.containsPoint = function containsPoint(point) {
  3500. 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;
  3501. };
  3502. _proto.containsBox = function containsBox(box) {
  3503. 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;
  3504. };
  3505. _proto.getParameter = function getParameter(point, target) {
  3506. // This can potentially have a divide by zero if the box
  3507. // has a size dimension of 0.
  3508. if (target === undefined) {
  3509. console.warn('THREE.Box3: .getParameter() target is now required');
  3510. target = new Vector3();
  3511. }
  3512. 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));
  3513. };
  3514. _proto.intersectsBox = function intersectsBox(box) {
  3515. // using 6 splitting planes to rule out intersections.
  3516. 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;
  3517. };
  3518. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3519. // Find the point on the AABB closest to the sphere center.
  3520. this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
  3521. return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
  3522. };
  3523. _proto.intersectsPlane = function intersectsPlane(plane) {
  3524. // We compute the minimum and maximum dot product values. If those values
  3525. // are on the same side (back or front) of the plane, then there is no intersection.
  3526. var min, max;
  3527. if (plane.normal.x > 0) {
  3528. min = plane.normal.x * this.min.x;
  3529. max = plane.normal.x * this.max.x;
  3530. } else {
  3531. min = plane.normal.x * this.max.x;
  3532. max = plane.normal.x * this.min.x;
  3533. }
  3534. if (plane.normal.y > 0) {
  3535. min += plane.normal.y * this.min.y;
  3536. max += plane.normal.y * this.max.y;
  3537. } else {
  3538. min += plane.normal.y * this.max.y;
  3539. max += plane.normal.y * this.min.y;
  3540. }
  3541. if (plane.normal.z > 0) {
  3542. min += plane.normal.z * this.min.z;
  3543. max += plane.normal.z * this.max.z;
  3544. } else {
  3545. min += plane.normal.z * this.max.z;
  3546. max += plane.normal.z * this.min.z;
  3547. }
  3548. return min <= -plane.constant && max >= -plane.constant;
  3549. };
  3550. _proto.intersectsTriangle = function intersectsTriangle(triangle) {
  3551. if (this.isEmpty()) {
  3552. return false;
  3553. } // compute box center and extents
  3554. this.getCenter(_center);
  3555. _extents.subVectors(this.max, _center); // translate triangle to aabb origin
  3556. _v0.subVectors(triangle.a, _center);
  3557. _v1.subVectors(triangle.b, _center);
  3558. _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
  3559. _f0.subVectors(_v1, _v0);
  3560. _f1.subVectors(_v2, _v1);
  3561. _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
  3562. // 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
  3563. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3564. 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];
  3565. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  3566. return false;
  3567. } // test 3 face normals from the aabb
  3568. axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  3569. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  3570. return false;
  3571. } // finally testing the face normal of the triangle
  3572. // use already existing triangle edge vectors here
  3573. _triangleNormal.crossVectors(_f0, _f1);
  3574. axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
  3575. return satForAxes(axes, _v0, _v1, _v2, _extents);
  3576. };
  3577. _proto.clampPoint = function clampPoint(point, target) {
  3578. if (target === undefined) {
  3579. console.warn('THREE.Box3: .clampPoint() target is now required');
  3580. target = new Vector3();
  3581. }
  3582. return target.copy(point).clamp(this.min, this.max);
  3583. };
  3584. _proto.distanceToPoint = function distanceToPoint(point) {
  3585. var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
  3586. return clampedPoint.sub(point).length();
  3587. };
  3588. _proto.getBoundingSphere = function getBoundingSphere(target) {
  3589. if (target === undefined) {
  3590. console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
  3591. }
  3592. this.getCenter(target.center);
  3593. target.radius = this.getSize(_vector$1).length() * 0.5;
  3594. return target;
  3595. };
  3596. _proto.intersect = function intersect(box) {
  3597. this.min.max(box.min);
  3598. 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.
  3599. if (this.isEmpty()) this.makeEmpty();
  3600. return this;
  3601. };
  3602. _proto.union = function union(box) {
  3603. this.min.min(box.min);
  3604. this.max.max(box.max);
  3605. return this;
  3606. };
  3607. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3608. // transform of empty box is an empty box.
  3609. if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  3610. _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
  3611. _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
  3612. _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
  3613. _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
  3614. _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
  3615. _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
  3616. _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
  3617. _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
  3618. this.setFromPoints(_points);
  3619. return this;
  3620. };
  3621. _proto.translate = function translate(offset) {
  3622. this.min.add(offset);
  3623. this.max.add(offset);
  3624. return this;
  3625. };
  3626. _proto.equals = function equals(box) {
  3627. return box.min.equals(this.min) && box.max.equals(this.max);
  3628. };
  3629. return Box3;
  3630. }();
  3631. function satForAxes(axes, v0, v1, v2, extents) {
  3632. for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
  3633. _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
  3634. 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
  3635. var p0 = v0.dot(_testAxis);
  3636. var p1 = v1.dot(_testAxis);
  3637. var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
  3638. if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
  3639. // points of the projected triangle are outside the projected half-length of the aabb
  3640. // the axis is seperating and we can exit
  3641. return false;
  3642. }
  3643. }
  3644. return true;
  3645. }
  3646. 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()];
  3647. var _vector$1 = /*@__PURE__*/new Vector3();
  3648. var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
  3649. var _v0 = /*@__PURE__*/new Vector3();
  3650. var _v1 = /*@__PURE__*/new Vector3();
  3651. var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
  3652. var _f0 = /*@__PURE__*/new Vector3();
  3653. var _f1 = /*@__PURE__*/new Vector3();
  3654. var _f2 = /*@__PURE__*/new Vector3();
  3655. var _center = /*@__PURE__*/new Vector3();
  3656. var _extents = /*@__PURE__*/new Vector3();
  3657. var _triangleNormal = /*@__PURE__*/new Vector3();
  3658. var _testAxis = /*@__PURE__*/new Vector3();
  3659. var _box$1 = /*@__PURE__*/new Box3();
  3660. var Sphere = /*#__PURE__*/function () {
  3661. function Sphere(center, radius) {
  3662. this.center = center !== undefined ? center : new Vector3();
  3663. this.radius = radius !== undefined ? radius : -1;
  3664. }
  3665. var _proto = Sphere.prototype;
  3666. _proto.set = function set(center, radius) {
  3667. this.center.copy(center);
  3668. this.radius = radius;
  3669. return this;
  3670. };
  3671. _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
  3672. var center = this.center;
  3673. if (optionalCenter !== undefined) {
  3674. center.copy(optionalCenter);
  3675. } else {
  3676. _box$1.setFromPoints(points).getCenter(center);
  3677. }
  3678. var maxRadiusSq = 0;
  3679. for (var i = 0, il = points.length; i < il; i++) {
  3680. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
  3681. }
  3682. this.radius = Math.sqrt(maxRadiusSq);
  3683. return this;
  3684. };
  3685. _proto.clone = function clone() {
  3686. return new this.constructor().copy(this);
  3687. };
  3688. _proto.copy = function copy(sphere) {
  3689. this.center.copy(sphere.center);
  3690. this.radius = sphere.radius;
  3691. return this;
  3692. };
  3693. _proto.isEmpty = function isEmpty() {
  3694. return this.radius < 0;
  3695. };
  3696. _proto.makeEmpty = function makeEmpty() {
  3697. this.center.set(0, 0, 0);
  3698. this.radius = -1;
  3699. return this;
  3700. };
  3701. _proto.containsPoint = function containsPoint(point) {
  3702. return point.distanceToSquared(this.center) <= this.radius * this.radius;
  3703. };
  3704. _proto.distanceToPoint = function distanceToPoint(point) {
  3705. return point.distanceTo(this.center) - this.radius;
  3706. };
  3707. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3708. var radiusSum = this.radius + sphere.radius;
  3709. return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
  3710. };
  3711. _proto.intersectsBox = function intersectsBox(box) {
  3712. return box.intersectsSphere(this);
  3713. };
  3714. _proto.intersectsPlane = function intersectsPlane(plane) {
  3715. return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
  3716. };
  3717. _proto.clampPoint = function clampPoint(point, target) {
  3718. var deltaLengthSq = this.center.distanceToSquared(point);
  3719. if (target === undefined) {
  3720. console.warn('THREE.Sphere: .clampPoint() target is now required');
  3721. target = new Vector3();
  3722. }
  3723. target.copy(point);
  3724. if (deltaLengthSq > this.radius * this.radius) {
  3725. target.sub(this.center).normalize();
  3726. target.multiplyScalar(this.radius).add(this.center);
  3727. }
  3728. return target;
  3729. };
  3730. _proto.getBoundingBox = function getBoundingBox(target) {
  3731. if (target === undefined) {
  3732. console.warn('THREE.Sphere: .getBoundingBox() target is now required');
  3733. target = new Box3();
  3734. }
  3735. if (this.isEmpty()) {
  3736. // Empty sphere produces empty bounding box
  3737. target.makeEmpty();
  3738. return target;
  3739. }
  3740. target.set(this.center, this.center);
  3741. target.expandByScalar(this.radius);
  3742. return target;
  3743. };
  3744. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3745. this.center.applyMatrix4(matrix);
  3746. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3747. return this;
  3748. };
  3749. _proto.translate = function translate(offset) {
  3750. this.center.add(offset);
  3751. return this;
  3752. };
  3753. _proto.equals = function equals(sphere) {
  3754. return sphere.center.equals(this.center) && sphere.radius === this.radius;
  3755. };
  3756. return Sphere;
  3757. }();
  3758. var _vector$2 = /*@__PURE__*/new Vector3();
  3759. var _segCenter = /*@__PURE__*/new Vector3();
  3760. var _segDir = /*@__PURE__*/new Vector3();
  3761. var _diff = /*@__PURE__*/new Vector3();
  3762. var _edge1 = /*@__PURE__*/new Vector3();
  3763. var _edge2 = /*@__PURE__*/new Vector3();
  3764. var _normal = /*@__PURE__*/new Vector3();
  3765. var Ray = /*#__PURE__*/function () {
  3766. function Ray(origin, direction) {
  3767. this.origin = origin !== undefined ? origin : new Vector3();
  3768. this.direction = direction !== undefined ? direction : new Vector3(0, 0, -1);
  3769. }
  3770. var _proto = Ray.prototype;
  3771. _proto.set = function set(origin, direction) {
  3772. this.origin.copy(origin);
  3773. this.direction.copy(direction);
  3774. return this;
  3775. };
  3776. _proto.clone = function clone() {
  3777. return new this.constructor().copy(this);
  3778. };
  3779. _proto.copy = function copy(ray) {
  3780. this.origin.copy(ray.origin);
  3781. this.direction.copy(ray.direction);
  3782. return this;
  3783. };
  3784. _proto.at = function at(t, target) {
  3785. if (target === undefined) {
  3786. console.warn('THREE.Ray: .at() target is now required');
  3787. target = new Vector3();
  3788. }
  3789. return target.copy(this.direction).multiplyScalar(t).add(this.origin);
  3790. };
  3791. _proto.lookAt = function lookAt(v) {
  3792. this.direction.copy(v).sub(this.origin).normalize();
  3793. return this;
  3794. };
  3795. _proto.recast = function recast(t) {
  3796. this.origin.copy(this.at(t, _vector$2));
  3797. return this;
  3798. };
  3799. _proto.closestPointToPoint = function closestPointToPoint(point, target) {
  3800. if (target === undefined) {
  3801. console.warn('THREE.Ray: .closestPointToPoint() target is now required');
  3802. target = new Vector3();
  3803. }
  3804. target.subVectors(point, this.origin);
  3805. var directionDistance = target.dot(this.direction);
  3806. if (directionDistance < 0) {
  3807. return target.copy(this.origin);
  3808. }
  3809. return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3810. };
  3811. _proto.distanceToPoint = function distanceToPoint(point) {
  3812. return Math.sqrt(this.distanceSqToPoint(point));
  3813. };
  3814. _proto.distanceSqToPoint = function distanceSqToPoint(point) {
  3815. var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
  3816. if (directionDistance < 0) {
  3817. return this.origin.distanceToSquared(point);
  3818. }
  3819. _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3820. return _vector$2.distanceToSquared(point);
  3821. };
  3822. _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
  3823. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3824. // It returns the min distance between the ray and the segment
  3825. // defined by v0 and v1
  3826. // It can also set two optional targets :
  3827. // - The closest point on the ray
  3828. // - The closest point on the segment
  3829. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
  3830. _segDir.copy(v1).sub(v0).normalize();
  3831. _diff.copy(this.origin).sub(_segCenter);
  3832. var segExtent = v0.distanceTo(v1) * 0.5;
  3833. var a01 = -this.direction.dot(_segDir);
  3834. var b0 = _diff.dot(this.direction);
  3835. var b1 = -_diff.dot(_segDir);
  3836. var c = _diff.lengthSq();
  3837. var det = Math.abs(1 - a01 * a01);
  3838. var s0, s1, sqrDist, extDet;
  3839. if (det > 0) {
  3840. // The ray and segment are not parallel.
  3841. s0 = a01 * b1 - b0;
  3842. s1 = a01 * b0 - b1;
  3843. extDet = segExtent * det;
  3844. if (s0 >= 0) {
  3845. if (s1 >= -extDet) {
  3846. if (s1 <= extDet) {
  3847. // region 0
  3848. // Minimum at interior points of ray and segment.
  3849. var invDet = 1 / det;
  3850. s0 *= invDet;
  3851. s1 *= invDet;
  3852. sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
  3853. } else {
  3854. // region 1
  3855. s1 = segExtent;
  3856. s0 = Math.max(0, -(a01 * s1 + b0));
  3857. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3858. }
  3859. } else {
  3860. // region 5
  3861. s1 = -segExtent;
  3862. s0 = Math.max(0, -(a01 * s1 + b0));
  3863. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3864. }
  3865. } else {
  3866. if (s1 <= -extDet) {
  3867. // region 4
  3868. s0 = Math.max(0, -(-a01 * segExtent + b0));
  3869. s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3870. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3871. } else if (s1 <= extDet) {
  3872. // region 3
  3873. s0 = 0;
  3874. s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
  3875. sqrDist = s1 * (s1 + 2 * b1) + c;
  3876. } else {
  3877. // region 2
  3878. s0 = Math.max(0, -(a01 * segExtent + b0));
  3879. s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3880. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3881. }
  3882. }
  3883. } else {
  3884. // Ray and segment are parallel.
  3885. s1 = a01 > 0 ? -segExtent : segExtent;
  3886. s0 = Math.max(0, -(a01 * s1 + b0));
  3887. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3888. }
  3889. if (optionalPointOnRay) {
  3890. optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
  3891. }
  3892. if (optionalPointOnSegment) {
  3893. optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
  3894. }
  3895. return sqrDist;
  3896. };
  3897. _proto.intersectSphere = function intersectSphere(sphere, target) {
  3898. _vector$2.subVectors(sphere.center, this.origin);
  3899. var tca = _vector$2.dot(this.direction);
  3900. var d2 = _vector$2.dot(_vector$2) - tca * tca;
  3901. var radius2 = sphere.radius * sphere.radius;
  3902. if (d2 > radius2) return null;
  3903. var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
  3904. var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
  3905. var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
  3906. if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
  3907. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3908. // in order to always return an intersect point that is in front of the ray.
  3909. 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
  3910. return this.at(t0, target);
  3911. };
  3912. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3913. return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
  3914. };
  3915. _proto.distanceToPlane = function distanceToPlane(plane) {
  3916. var denominator = plane.normal.dot(this.direction);
  3917. if (denominator === 0) {
  3918. // line is coplanar, return origin
  3919. if (plane.distanceToPoint(this.origin) === 0) {
  3920. return 0;
  3921. } // Null is preferable to undefined since undefined means.... it is undefined
  3922. return null;
  3923. }
  3924. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
  3925. return t >= 0 ? t : null;
  3926. };
  3927. _proto.intersectPlane = function intersectPlane(plane, target) {
  3928. var t = this.distanceToPlane(plane);
  3929. if (t === null) {
  3930. return null;
  3931. }
  3932. return this.at(t, target);
  3933. };
  3934. _proto.intersectsPlane = function intersectsPlane(plane) {
  3935. // check if the ray lies on the plane first
  3936. var distToPoint = plane.distanceToPoint(this.origin);
  3937. if (distToPoint === 0) {
  3938. return true;
  3939. }
  3940. var denominator = plane.normal.dot(this.direction);
  3941. if (denominator * distToPoint < 0) {
  3942. return true;
  3943. } // ray origin is behind the plane (and is pointing behind it)
  3944. return false;
  3945. };
  3946. _proto.intersectBox = function intersectBox(box, target) {
  3947. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3948. var invdirx = 1 / this.direction.x,
  3949. invdiry = 1 / this.direction.y,
  3950. invdirz = 1 / this.direction.z;
  3951. var origin = this.origin;
  3952. if (invdirx >= 0) {
  3953. tmin = (box.min.x - origin.x) * invdirx;
  3954. tmax = (box.max.x - origin.x) * invdirx;
  3955. } else {
  3956. tmin = (box.max.x - origin.x) * invdirx;
  3957. tmax = (box.min.x - origin.x) * invdirx;
  3958. }
  3959. if (invdiry >= 0) {
  3960. tymin = (box.min.y - origin.y) * invdiry;
  3961. tymax = (box.max.y - origin.y) * invdiry;
  3962. } else {
  3963. tymin = (box.max.y - origin.y) * invdiry;
  3964. tymax = (box.min.y - origin.y) * invdiry;
  3965. }
  3966. if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
  3967. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3968. if (tymin > tmin || tmin !== tmin) tmin = tymin;
  3969. if (tymax < tmax || tmax !== tmax) tmax = tymax;
  3970. if (invdirz >= 0) {
  3971. tzmin = (box.min.z - origin.z) * invdirz;
  3972. tzmax = (box.max.z - origin.z) * invdirz;
  3973. } else {
  3974. tzmin = (box.max.z - origin.z) * invdirz;
  3975. tzmax = (box.min.z - origin.z) * invdirz;
  3976. }
  3977. if (tmin > tzmax || tzmin > tmax) return null;
  3978. if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
  3979. if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
  3980. if (tmax < 0) return null;
  3981. return this.at(tmin >= 0 ? tmin : tmax, target);
  3982. };
  3983. _proto.intersectsBox = function intersectsBox(box) {
  3984. return this.intersectBox(box, _vector$2) !== null;
  3985. };
  3986. _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
  3987. // Compute the offset origin, edges, and normal.
  3988. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3989. _edge1.subVectors(b, a);
  3990. _edge2.subVectors(c, a);
  3991. _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3992. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3993. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3994. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3995. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3996. var DdN = this.direction.dot(_normal);
  3997. var sign;
  3998. if (DdN > 0) {
  3999. if (backfaceCulling) return null;
  4000. sign = 1;
  4001. } else if (DdN < 0) {
  4002. sign = -1;
  4003. DdN = -DdN;
  4004. } else {
  4005. return null;
  4006. }
  4007. _diff.subVectors(this.origin, a);
  4008. var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
  4009. if (DdQxE2 < 0) {
  4010. return null;
  4011. }
  4012. var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
  4013. if (DdE1xQ < 0) {
  4014. return null;
  4015. } // b1+b2 > 1, no intersection
  4016. if (DdQxE2 + DdE1xQ > DdN) {
  4017. return null;
  4018. } // Line intersects triangle, check if ray does.
  4019. var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
  4020. if (QdN < 0) {
  4021. return null;
  4022. } // Ray intersects triangle.
  4023. return this.at(QdN / DdN, target);
  4024. };
  4025. _proto.applyMatrix4 = function applyMatrix4(matrix4) {
  4026. this.origin.applyMatrix4(matrix4);
  4027. this.direction.transformDirection(matrix4);
  4028. return this;
  4029. };
  4030. _proto.equals = function equals(ray) {
  4031. return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
  4032. };
  4033. return Ray;
  4034. }();
  4035. var Matrix4 = /*#__PURE__*/function () {
  4036. function Matrix4() {
  4037. Object.defineProperty(this, 'isMatrix4', {
  4038. value: true
  4039. });
  4040. this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  4041. if (arguments.length > 0) {
  4042. console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
  4043. }
  4044. }
  4045. var _proto = Matrix4.prototype;
  4046. _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
  4047. var te = this.elements;
  4048. te[0] = n11;
  4049. te[4] = n12;
  4050. te[8] = n13;
  4051. te[12] = n14;
  4052. te[1] = n21;
  4053. te[5] = n22;
  4054. te[9] = n23;
  4055. te[13] = n24;
  4056. te[2] = n31;
  4057. te[6] = n32;
  4058. te[10] = n33;
  4059. te[14] = n34;
  4060. te[3] = n41;
  4061. te[7] = n42;
  4062. te[11] = n43;
  4063. te[15] = n44;
  4064. return this;
  4065. };
  4066. _proto.identity = function identity() {
  4067. this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4068. return this;
  4069. };
  4070. _proto.clone = function clone() {
  4071. return new Matrix4().fromArray(this.elements);
  4072. };
  4073. _proto.copy = function copy(m) {
  4074. var te = this.elements;
  4075. var me = m.elements;
  4076. te[0] = me[0];
  4077. te[1] = me[1];
  4078. te[2] = me[2];
  4079. te[3] = me[3];
  4080. te[4] = me[4];
  4081. te[5] = me[5];
  4082. te[6] = me[6];
  4083. te[7] = me[7];
  4084. te[8] = me[8];
  4085. te[9] = me[9];
  4086. te[10] = me[10];
  4087. te[11] = me[11];
  4088. te[12] = me[12];
  4089. te[13] = me[13];
  4090. te[14] = me[14];
  4091. te[15] = me[15];
  4092. return this;
  4093. };
  4094. _proto.copyPosition = function copyPosition(m) {
  4095. var te = this.elements,
  4096. me = m.elements;
  4097. te[12] = me[12];
  4098. te[13] = me[13];
  4099. te[14] = me[14];
  4100. return this;
  4101. };
  4102. _proto.setFromMatrix3 = function setFromMatrix3(m) {
  4103. var me = m.elements;
  4104. 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);
  4105. return this;
  4106. };
  4107. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  4108. xAxis.setFromMatrixColumn(this, 0);
  4109. yAxis.setFromMatrixColumn(this, 1);
  4110. zAxis.setFromMatrixColumn(this, 2);
  4111. return this;
  4112. };
  4113. _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
  4114. 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);
  4115. return this;
  4116. };
  4117. _proto.extractRotation = function extractRotation(m) {
  4118. // this method does not support reflection matrices
  4119. var te = this.elements;
  4120. var me = m.elements;
  4121. var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
  4122. var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
  4123. var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
  4124. te[0] = me[0] * scaleX;
  4125. te[1] = me[1] * scaleX;
  4126. te[2] = me[2] * scaleX;
  4127. te[3] = 0;
  4128. te[4] = me[4] * scaleY;
  4129. te[5] = me[5] * scaleY;
  4130. te[6] = me[6] * scaleY;
  4131. te[7] = 0;
  4132. te[8] = me[8] * scaleZ;
  4133. te[9] = me[9] * scaleZ;
  4134. te[10] = me[10] * scaleZ;
  4135. te[11] = 0;
  4136. te[12] = 0;
  4137. te[13] = 0;
  4138. te[14] = 0;
  4139. te[15] = 1;
  4140. return this;
  4141. };
  4142. _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
  4143. if (!(euler && euler.isEuler)) {
  4144. console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
  4145. }
  4146. var te = this.elements;
  4147. var x = euler.x,
  4148. y = euler.y,
  4149. z = euler.z;
  4150. var a = Math.cos(x),
  4151. b = Math.sin(x);
  4152. var c = Math.cos(y),
  4153. d = Math.sin(y);
  4154. var e = Math.cos(z),
  4155. f = Math.sin(z);
  4156. if (euler.order === 'XYZ') {
  4157. var ae = a * e,
  4158. af = a * f,
  4159. be = b * e,
  4160. bf = b * f;
  4161. te[0] = c * e;
  4162. te[4] = -c * f;
  4163. te[8] = d;
  4164. te[1] = af + be * d;
  4165. te[5] = ae - bf * d;
  4166. te[9] = -b * c;
  4167. te[2] = bf - ae * d;
  4168. te[6] = be + af * d;
  4169. te[10] = a * c;
  4170. } else if (euler.order === 'YXZ') {
  4171. var ce = c * e,
  4172. cf = c * f,
  4173. de = d * e,
  4174. df = d * f;
  4175. te[0] = ce + df * b;
  4176. te[4] = de * b - cf;
  4177. te[8] = a * d;
  4178. te[1] = a * f;
  4179. te[5] = a * e;
  4180. te[9] = -b;
  4181. te[2] = cf * b - de;
  4182. te[6] = df + ce * b;
  4183. te[10] = a * c;
  4184. } else if (euler.order === 'ZXY') {
  4185. var _ce = c * e,
  4186. _cf = c * f,
  4187. _de = d * e,
  4188. _df = d * f;
  4189. te[0] = _ce - _df * b;
  4190. te[4] = -a * f;
  4191. te[8] = _de + _cf * b;
  4192. te[1] = _cf + _de * b;
  4193. te[5] = a * e;
  4194. te[9] = _df - _ce * b;
  4195. te[2] = -a * d;
  4196. te[6] = b;
  4197. te[10] = a * c;
  4198. } else if (euler.order === 'ZYX') {
  4199. var _ae = a * e,
  4200. _af = a * f,
  4201. _be = b * e,
  4202. _bf = b * f;
  4203. te[0] = c * e;
  4204. te[4] = _be * d - _af;
  4205. te[8] = _ae * d + _bf;
  4206. te[1] = c * f;
  4207. te[5] = _bf * d + _ae;
  4208. te[9] = _af * d - _be;
  4209. te[2] = -d;
  4210. te[6] = b * c;
  4211. te[10] = a * c;
  4212. } else if (euler.order === 'YZX') {
  4213. var ac = a * c,
  4214. ad = a * d,
  4215. bc = b * c,
  4216. bd = b * d;
  4217. te[0] = c * e;
  4218. te[4] = bd - ac * f;
  4219. te[8] = bc * f + ad;
  4220. te[1] = f;
  4221. te[5] = a * e;
  4222. te[9] = -b * e;
  4223. te[2] = -d * e;
  4224. te[6] = ad * f + bc;
  4225. te[10] = ac - bd * f;
  4226. } else if (euler.order === 'XZY') {
  4227. var _ac = a * c,
  4228. _ad = a * d,
  4229. _bc = b * c,
  4230. _bd = b * d;
  4231. te[0] = c * e;
  4232. te[4] = -f;
  4233. te[8] = d * e;
  4234. te[1] = _ac * f + _bd;
  4235. te[5] = a * e;
  4236. te[9] = _ad * f - _bc;
  4237. te[2] = _bc * f - _ad;
  4238. te[6] = b * e;
  4239. te[10] = _bd * f + _ac;
  4240. } // bottom row
  4241. te[3] = 0;
  4242. te[7] = 0;
  4243. te[11] = 0; // last column
  4244. te[12] = 0;
  4245. te[13] = 0;
  4246. te[14] = 0;
  4247. te[15] = 1;
  4248. return this;
  4249. };
  4250. _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
  4251. return this.compose(_zero, q, _one);
  4252. };
  4253. _proto.lookAt = function lookAt(eye, target, up) {
  4254. var te = this.elements;
  4255. _z.subVectors(eye, target);
  4256. if (_z.lengthSq() === 0) {
  4257. // eye and target are in the same position
  4258. _z.z = 1;
  4259. }
  4260. _z.normalize();
  4261. _x.crossVectors(up, _z);
  4262. if (_x.lengthSq() === 0) {
  4263. // up and z are parallel
  4264. if (Math.abs(up.z) === 1) {
  4265. _z.x += 0.0001;
  4266. } else {
  4267. _z.z += 0.0001;
  4268. }
  4269. _z.normalize();
  4270. _x.crossVectors(up, _z);
  4271. }
  4272. _x.normalize();
  4273. _y.crossVectors(_z, _x);
  4274. te[0] = _x.x;
  4275. te[4] = _y.x;
  4276. te[8] = _z.x;
  4277. te[1] = _x.y;
  4278. te[5] = _y.y;
  4279. te[9] = _z.y;
  4280. te[2] = _x.z;
  4281. te[6] = _y.z;
  4282. te[10] = _z.z;
  4283. return this;
  4284. };
  4285. _proto.multiply = function multiply(m, n) {
  4286. if (n !== undefined) {
  4287. console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
  4288. return this.multiplyMatrices(m, n);
  4289. }
  4290. return this.multiplyMatrices(this, m);
  4291. };
  4292. _proto.premultiply = function premultiply(m) {
  4293. return this.multiplyMatrices(m, this);
  4294. };
  4295. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  4296. var ae = a.elements;
  4297. var be = b.elements;
  4298. var te = this.elements;
  4299. var a11 = ae[0],
  4300. a12 = ae[4],
  4301. a13 = ae[8],
  4302. a14 = ae[12];
  4303. var a21 = ae[1],
  4304. a22 = ae[5],
  4305. a23 = ae[9],
  4306. a24 = ae[13];
  4307. var a31 = ae[2],
  4308. a32 = ae[6],
  4309. a33 = ae[10],
  4310. a34 = ae[14];
  4311. var a41 = ae[3],
  4312. a42 = ae[7],
  4313. a43 = ae[11],
  4314. a44 = ae[15];
  4315. var b11 = be[0],
  4316. b12 = be[4],
  4317. b13 = be[8],
  4318. b14 = be[12];
  4319. var b21 = be[1],
  4320. b22 = be[5],
  4321. b23 = be[9],
  4322. b24 = be[13];
  4323. var b31 = be[2],
  4324. b32 = be[6],
  4325. b33 = be[10],
  4326. b34 = be[14];
  4327. var b41 = be[3],
  4328. b42 = be[7],
  4329. b43 = be[11],
  4330. b44 = be[15];
  4331. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  4332. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  4333. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  4334. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  4335. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  4336. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  4337. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  4338. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  4339. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  4340. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  4341. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  4342. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  4343. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  4344. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  4345. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  4346. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  4347. return this;
  4348. };
  4349. _proto.multiplyScalar = function multiplyScalar(s) {
  4350. var te = this.elements;
  4351. te[0] *= s;
  4352. te[4] *= s;
  4353. te[8] *= s;
  4354. te[12] *= s;
  4355. te[1] *= s;
  4356. te[5] *= s;
  4357. te[9] *= s;
  4358. te[13] *= s;
  4359. te[2] *= s;
  4360. te[6] *= s;
  4361. te[10] *= s;
  4362. te[14] *= s;
  4363. te[3] *= s;
  4364. te[7] *= s;
  4365. te[11] *= s;
  4366. te[15] *= s;
  4367. return this;
  4368. };
  4369. _proto.determinant = function determinant() {
  4370. var te = this.elements;
  4371. var n11 = te[0],
  4372. n12 = te[4],
  4373. n13 = te[8],
  4374. n14 = te[12];
  4375. var n21 = te[1],
  4376. n22 = te[5],
  4377. n23 = te[9],
  4378. n24 = te[13];
  4379. var n31 = te[2],
  4380. n32 = te[6],
  4381. n33 = te[10],
  4382. n34 = te[14];
  4383. var n41 = te[3],
  4384. n42 = te[7],
  4385. n43 = te[11],
  4386. n44 = te[15]; //TODO: make this more efficient
  4387. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  4388. 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);
  4389. };
  4390. _proto.transpose = function transpose() {
  4391. var te = this.elements;
  4392. var tmp;
  4393. tmp = te[1];
  4394. te[1] = te[4];
  4395. te[4] = tmp;
  4396. tmp = te[2];
  4397. te[2] = te[8];
  4398. te[8] = tmp;
  4399. tmp = te[6];
  4400. te[6] = te[9];
  4401. te[9] = tmp;
  4402. tmp = te[3];
  4403. te[3] = te[12];
  4404. te[12] = tmp;
  4405. tmp = te[7];
  4406. te[7] = te[13];
  4407. te[13] = tmp;
  4408. tmp = te[11];
  4409. te[11] = te[14];
  4410. te[14] = tmp;
  4411. return this;
  4412. };
  4413. _proto.setPosition = function setPosition(x, y, z) {
  4414. var te = this.elements;
  4415. if (x.isVector3) {
  4416. te[12] = x.x;
  4417. te[13] = x.y;
  4418. te[14] = x.z;
  4419. } else {
  4420. te[12] = x;
  4421. te[13] = y;
  4422. te[14] = z;
  4423. }
  4424. return this;
  4425. };
  4426. _proto.invert = function invert() {
  4427. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  4428. var te = this.elements,
  4429. n11 = te[0],
  4430. n21 = te[1],
  4431. n31 = te[2],
  4432. n41 = te[3],
  4433. n12 = te[4],
  4434. n22 = te[5],
  4435. n32 = te[6],
  4436. n42 = te[7],
  4437. n13 = te[8],
  4438. n23 = te[9],
  4439. n33 = te[10],
  4440. n43 = te[11],
  4441. n14 = te[12],
  4442. n24 = te[13],
  4443. n34 = te[14],
  4444. n44 = te[15],
  4445. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  4446. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  4447. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  4448. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  4449. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  4450. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  4451. var detInv = 1 / det;
  4452. te[0] = t11 * detInv;
  4453. te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
  4454. te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
  4455. te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
  4456. te[4] = t12 * detInv;
  4457. te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
  4458. te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
  4459. te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
  4460. te[8] = t13 * detInv;
  4461. te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
  4462. te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
  4463. te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
  4464. te[12] = t14 * detInv;
  4465. te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
  4466. te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
  4467. te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
  4468. return this;
  4469. };
  4470. _proto.scale = function scale(v) {
  4471. var te = this.elements;
  4472. var x = v.x,
  4473. y = v.y,
  4474. z = v.z;
  4475. te[0] *= x;
  4476. te[4] *= y;
  4477. te[8] *= z;
  4478. te[1] *= x;
  4479. te[5] *= y;
  4480. te[9] *= z;
  4481. te[2] *= x;
  4482. te[6] *= y;
  4483. te[10] *= z;
  4484. te[3] *= x;
  4485. te[7] *= y;
  4486. te[11] *= z;
  4487. return this;
  4488. };
  4489. _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
  4490. var te = this.elements;
  4491. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  4492. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  4493. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  4494. return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
  4495. };
  4496. _proto.makeTranslation = function makeTranslation(x, y, z) {
  4497. this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
  4498. return this;
  4499. };
  4500. _proto.makeRotationX = function makeRotationX(theta) {
  4501. var c = Math.cos(theta),
  4502. s = Math.sin(theta);
  4503. this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
  4504. return this;
  4505. };
  4506. _proto.makeRotationY = function makeRotationY(theta) {
  4507. var c = Math.cos(theta),
  4508. s = Math.sin(theta);
  4509. this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
  4510. return this;
  4511. };
  4512. _proto.makeRotationZ = function makeRotationZ(theta) {
  4513. var c = Math.cos(theta),
  4514. s = Math.sin(theta);
  4515. this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4516. return this;
  4517. };
  4518. _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
  4519. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  4520. var c = Math.cos(angle);
  4521. var s = Math.sin(angle);
  4522. var t = 1 - c;
  4523. var x = axis.x,
  4524. y = axis.y,
  4525. z = axis.z;
  4526. var tx = t * x,
  4527. ty = t * y;
  4528. 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);
  4529. return this;
  4530. };
  4531. _proto.makeScale = function makeScale(x, y, z) {
  4532. this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
  4533. return this;
  4534. };
  4535. _proto.makeShear = function makeShear(x, y, z) {
  4536. this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
  4537. return this;
  4538. };
  4539. _proto.compose = function compose(position, quaternion, scale) {
  4540. var te = this.elements;
  4541. var x = quaternion._x,
  4542. y = quaternion._y,
  4543. z = quaternion._z,
  4544. w = quaternion._w;
  4545. var x2 = x + x,
  4546. y2 = y + y,
  4547. z2 = z + z;
  4548. var xx = x * x2,
  4549. xy = x * y2,
  4550. xz = x * z2;
  4551. var yy = y * y2,
  4552. yz = y * z2,
  4553. zz = z * z2;
  4554. var wx = w * x2,
  4555. wy = w * y2,
  4556. wz = w * z2;
  4557. var sx = scale.x,
  4558. sy = scale.y,
  4559. sz = scale.z;
  4560. te[0] = (1 - (yy + zz)) * sx;
  4561. te[1] = (xy + wz) * sx;
  4562. te[2] = (xz - wy) * sx;
  4563. te[3] = 0;
  4564. te[4] = (xy - wz) * sy;
  4565. te[5] = (1 - (xx + zz)) * sy;
  4566. te[6] = (yz + wx) * sy;
  4567. te[7] = 0;
  4568. te[8] = (xz + wy) * sz;
  4569. te[9] = (yz - wx) * sz;
  4570. te[10] = (1 - (xx + yy)) * sz;
  4571. te[11] = 0;
  4572. te[12] = position.x;
  4573. te[13] = position.y;
  4574. te[14] = position.z;
  4575. te[15] = 1;
  4576. return this;
  4577. };
  4578. _proto.decompose = function decompose(position, quaternion, scale) {
  4579. var te = this.elements;
  4580. var sx = _v1$1.set(te[0], te[1], te[2]).length();
  4581. var sy = _v1$1.set(te[4], te[5], te[6]).length();
  4582. var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
  4583. var det = this.determinant();
  4584. if (det < 0) sx = -sx;
  4585. position.x = te[12];
  4586. position.y = te[13];
  4587. position.z = te[14]; // scale the rotation part
  4588. _m1.copy(this);
  4589. var invSX = 1 / sx;
  4590. var invSY = 1 / sy;
  4591. var invSZ = 1 / sz;
  4592. _m1.elements[0] *= invSX;
  4593. _m1.elements[1] *= invSX;
  4594. _m1.elements[2] *= invSX;
  4595. _m1.elements[4] *= invSY;
  4596. _m1.elements[5] *= invSY;
  4597. _m1.elements[6] *= invSY;
  4598. _m1.elements[8] *= invSZ;
  4599. _m1.elements[9] *= invSZ;
  4600. _m1.elements[10] *= invSZ;
  4601. quaternion.setFromRotationMatrix(_m1);
  4602. scale.x = sx;
  4603. scale.y = sy;
  4604. scale.z = sz;
  4605. return this;
  4606. };
  4607. _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
  4608. if (far === undefined) {
  4609. console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
  4610. }
  4611. var te = this.elements;
  4612. var x = 2 * near / (right - left);
  4613. var y = 2 * near / (top - bottom);
  4614. var a = (right + left) / (right - left);
  4615. var b = (top + bottom) / (top - bottom);
  4616. var c = -(far + near) / (far - near);
  4617. var d = -2 * far * near / (far - near);
  4618. te[0] = x;
  4619. te[4] = 0;
  4620. te[8] = a;
  4621. te[12] = 0;
  4622. te[1] = 0;
  4623. te[5] = y;
  4624. te[9] = b;
  4625. te[13] = 0;
  4626. te[2] = 0;
  4627. te[6] = 0;
  4628. te[10] = c;
  4629. te[14] = d;
  4630. te[3] = 0;
  4631. te[7] = 0;
  4632. te[11] = -1;
  4633. te[15] = 0;
  4634. return this;
  4635. };
  4636. _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
  4637. var te = this.elements;
  4638. var w = 1.0 / (right - left);
  4639. var h = 1.0 / (top - bottom);
  4640. var p = 1.0 / (far - near);
  4641. var x = (right + left) * w;
  4642. var y = (top + bottom) * h;
  4643. var z = (far + near) * p;
  4644. te[0] = 2 * w;
  4645. te[4] = 0;
  4646. te[8] = 0;
  4647. te[12] = -x;
  4648. te[1] = 0;
  4649. te[5] = 2 * h;
  4650. te[9] = 0;
  4651. te[13] = -y;
  4652. te[2] = 0;
  4653. te[6] = 0;
  4654. te[10] = -2 * p;
  4655. te[14] = -z;
  4656. te[3] = 0;
  4657. te[7] = 0;
  4658. te[11] = 0;
  4659. te[15] = 1;
  4660. return this;
  4661. };
  4662. _proto.equals = function equals(matrix) {
  4663. var te = this.elements;
  4664. var me = matrix.elements;
  4665. for (var i = 0; i < 16; i++) {
  4666. if (te[i] !== me[i]) return false;
  4667. }
  4668. return true;
  4669. };
  4670. _proto.fromArray = function fromArray(array, offset) {
  4671. if (offset === void 0) {
  4672. offset = 0;
  4673. }
  4674. for (var i = 0; i < 16; i++) {
  4675. this.elements[i] = array[i + offset];
  4676. }
  4677. return this;
  4678. };
  4679. _proto.toArray = function toArray(array, offset) {
  4680. if (array === void 0) {
  4681. array = [];
  4682. }
  4683. if (offset === void 0) {
  4684. offset = 0;
  4685. }
  4686. var te = this.elements;
  4687. array[offset] = te[0];
  4688. array[offset + 1] = te[1];
  4689. array[offset + 2] = te[2];
  4690. array[offset + 3] = te[3];
  4691. array[offset + 4] = te[4];
  4692. array[offset + 5] = te[5];
  4693. array[offset + 6] = te[6];
  4694. array[offset + 7] = te[7];
  4695. array[offset + 8] = te[8];
  4696. array[offset + 9] = te[9];
  4697. array[offset + 10] = te[10];
  4698. array[offset + 11] = te[11];
  4699. array[offset + 12] = te[12];
  4700. array[offset + 13] = te[13];
  4701. array[offset + 14] = te[14];
  4702. array[offset + 15] = te[15];
  4703. return array;
  4704. };
  4705. return Matrix4;
  4706. }();
  4707. var _v1$1 = /*@__PURE__*/new Vector3();
  4708. var _m1 = /*@__PURE__*/new Matrix4();
  4709. var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
  4710. var _one = /*@__PURE__*/new Vector3(1, 1, 1);
  4711. var _x = /*@__PURE__*/new Vector3();
  4712. var _y = /*@__PURE__*/new Vector3();
  4713. var _z = /*@__PURE__*/new Vector3();
  4714. var Euler = /*#__PURE__*/function () {
  4715. function Euler(x, y, z, order) {
  4716. if (x === void 0) {
  4717. x = 0;
  4718. }
  4719. if (y === void 0) {
  4720. y = 0;
  4721. }
  4722. if (z === void 0) {
  4723. z = 0;
  4724. }
  4725. if (order === void 0) {
  4726. order = Euler.DefaultOrder;
  4727. }
  4728. Object.defineProperty(this, 'isEuler', {
  4729. value: true
  4730. });
  4731. this._x = x;
  4732. this._y = y;
  4733. this._z = z;
  4734. this._order = order;
  4735. }
  4736. var _proto = Euler.prototype;
  4737. _proto.set = function set(x, y, z, order) {
  4738. this._x = x;
  4739. this._y = y;
  4740. this._z = z;
  4741. this._order = order || this._order;
  4742. this._onChangeCallback();
  4743. return this;
  4744. };
  4745. _proto.clone = function clone() {
  4746. return new this.constructor(this._x, this._y, this._z, this._order);
  4747. };
  4748. _proto.copy = function copy(euler) {
  4749. this._x = euler._x;
  4750. this._y = euler._y;
  4751. this._z = euler._z;
  4752. this._order = euler._order;
  4753. this._onChangeCallback();
  4754. return this;
  4755. };
  4756. _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
  4757. var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4758. var te = m.elements;
  4759. var m11 = te[0],
  4760. m12 = te[4],
  4761. m13 = te[8];
  4762. var m21 = te[1],
  4763. m22 = te[5],
  4764. m23 = te[9];
  4765. var m31 = te[2],
  4766. m32 = te[6],
  4767. m33 = te[10];
  4768. order = order || this._order;
  4769. switch (order) {
  4770. case 'XYZ':
  4771. this._y = Math.asin(clamp(m13, -1, 1));
  4772. if (Math.abs(m13) < 0.9999999) {
  4773. this._x = Math.atan2(-m23, m33);
  4774. this._z = Math.atan2(-m12, m11);
  4775. } else {
  4776. this._x = Math.atan2(m32, m22);
  4777. this._z = 0;
  4778. }
  4779. break;
  4780. case 'YXZ':
  4781. this._x = Math.asin(-clamp(m23, -1, 1));
  4782. if (Math.abs(m23) < 0.9999999) {
  4783. this._y = Math.atan2(m13, m33);
  4784. this._z = Math.atan2(m21, m22);
  4785. } else {
  4786. this._y = Math.atan2(-m31, m11);
  4787. this._z = 0;
  4788. }
  4789. break;
  4790. case 'ZXY':
  4791. this._x = Math.asin(clamp(m32, -1, 1));
  4792. if (Math.abs(m32) < 0.9999999) {
  4793. this._y = Math.atan2(-m31, m33);
  4794. this._z = Math.atan2(-m12, m22);
  4795. } else {
  4796. this._y = 0;
  4797. this._z = Math.atan2(m21, m11);
  4798. }
  4799. break;
  4800. case 'ZYX':
  4801. this._y = Math.asin(-clamp(m31, -1, 1));
  4802. if (Math.abs(m31) < 0.9999999) {
  4803. this._x = Math.atan2(m32, m33);
  4804. this._z = Math.atan2(m21, m11);
  4805. } else {
  4806. this._x = 0;
  4807. this._z = Math.atan2(-m12, m22);
  4808. }
  4809. break;
  4810. case 'YZX':
  4811. this._z = Math.asin(clamp(m21, -1, 1));
  4812. if (Math.abs(m21) < 0.9999999) {
  4813. this._x = Math.atan2(-m23, m22);
  4814. this._y = Math.atan2(-m31, m11);
  4815. } else {
  4816. this._x = 0;
  4817. this._y = Math.atan2(m13, m33);
  4818. }
  4819. break;
  4820. case 'XZY':
  4821. this._z = Math.asin(-clamp(m12, -1, 1));
  4822. if (Math.abs(m12) < 0.9999999) {
  4823. this._x = Math.atan2(m32, m22);
  4824. this._y = Math.atan2(m13, m11);
  4825. } else {
  4826. this._x = Math.atan2(-m23, m33);
  4827. this._y = 0;
  4828. }
  4829. break;
  4830. default:
  4831. console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
  4832. }
  4833. this._order = order;
  4834. if (update !== false) this._onChangeCallback();
  4835. return this;
  4836. };
  4837. _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
  4838. _matrix.makeRotationFromQuaternion(q);
  4839. return this.setFromRotationMatrix(_matrix, order, update);
  4840. };
  4841. _proto.setFromVector3 = function setFromVector3(v, order) {
  4842. return this.set(v.x, v.y, v.z, order || this._order);
  4843. };
  4844. _proto.reorder = function reorder(newOrder) {
  4845. // WARNING: this discards revolution information -bhouston
  4846. _quaternion$1.setFromEuler(this);
  4847. return this.setFromQuaternion(_quaternion$1, newOrder);
  4848. };
  4849. _proto.equals = function equals(euler) {
  4850. return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
  4851. };
  4852. _proto.fromArray = function fromArray(array) {
  4853. this._x = array[0];
  4854. this._y = array[1];
  4855. this._z = array[2];
  4856. if (array[3] !== undefined) this._order = array[3];
  4857. this._onChangeCallback();
  4858. return this;
  4859. };
  4860. _proto.toArray = function toArray(array, offset) {
  4861. if (array === void 0) {
  4862. array = [];
  4863. }
  4864. if (offset === void 0) {
  4865. offset = 0;
  4866. }
  4867. array[offset] = this._x;
  4868. array[offset + 1] = this._y;
  4869. array[offset + 2] = this._z;
  4870. array[offset + 3] = this._order;
  4871. return array;
  4872. };
  4873. _proto.toVector3 = function toVector3(optionalResult) {
  4874. if (optionalResult) {
  4875. return optionalResult.set(this._x, this._y, this._z);
  4876. } else {
  4877. return new Vector3(this._x, this._y, this._z);
  4878. }
  4879. };
  4880. _proto._onChange = function _onChange(callback) {
  4881. this._onChangeCallback = callback;
  4882. return this;
  4883. };
  4884. _proto._onChangeCallback = function _onChangeCallback() {};
  4885. _createClass(Euler, [{
  4886. key: "x",
  4887. get: function get() {
  4888. return this._x;
  4889. },
  4890. set: function set(value) {
  4891. this._x = value;
  4892. this._onChangeCallback();
  4893. }
  4894. }, {
  4895. key: "y",
  4896. get: function get() {
  4897. return this._y;
  4898. },
  4899. set: function set(value) {
  4900. this._y = value;
  4901. this._onChangeCallback();
  4902. }
  4903. }, {
  4904. key: "z",
  4905. get: function get() {
  4906. return this._z;
  4907. },
  4908. set: function set(value) {
  4909. this._z = value;
  4910. this._onChangeCallback();
  4911. }
  4912. }, {
  4913. key: "order",
  4914. get: function get() {
  4915. return this._order;
  4916. },
  4917. set: function set(value) {
  4918. this._order = value;
  4919. this._onChangeCallback();
  4920. }
  4921. }]);
  4922. return Euler;
  4923. }();
  4924. Euler.DefaultOrder = 'XYZ';
  4925. Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
  4926. var _matrix = /*@__PURE__*/new Matrix4();
  4927. var _quaternion$1 = /*@__PURE__*/new Quaternion();
  4928. var Layers = /*#__PURE__*/function () {
  4929. function Layers() {
  4930. this.mask = 1 | 0;
  4931. }
  4932. var _proto = Layers.prototype;
  4933. _proto.set = function set(channel) {
  4934. this.mask = 1 << channel | 0;
  4935. };
  4936. _proto.enable = function enable(channel) {
  4937. this.mask |= 1 << channel | 0;
  4938. };
  4939. _proto.enableAll = function enableAll() {
  4940. this.mask = 0xffffffff | 0;
  4941. };
  4942. _proto.toggle = function toggle(channel) {
  4943. this.mask ^= 1 << channel | 0;
  4944. };
  4945. _proto.disable = function disable(channel) {
  4946. this.mask &= ~(1 << channel | 0);
  4947. };
  4948. _proto.disableAll = function disableAll() {
  4949. this.mask = 0;
  4950. };
  4951. _proto.test = function test(layers) {
  4952. return (this.mask & layers.mask) !== 0;
  4953. };
  4954. return Layers;
  4955. }();
  4956. var _object3DId = 0;
  4957. var _v1$2 = new Vector3();
  4958. var _q1 = new Quaternion();
  4959. var _m1$1 = new Matrix4();
  4960. var _target = new Vector3();
  4961. var _position = new Vector3();
  4962. var _scale = new Vector3();
  4963. var _quaternion$2 = new Quaternion();
  4964. var _xAxis = new Vector3(1, 0, 0);
  4965. var _yAxis = new Vector3(0, 1, 0);
  4966. var _zAxis = new Vector3(0, 0, 1);
  4967. var _addedEvent = {
  4968. type: 'added'
  4969. };
  4970. var _removedEvent = {
  4971. type: 'removed'
  4972. };
  4973. function Object3D() {
  4974. Object.defineProperty(this, 'id', {
  4975. value: _object3DId++
  4976. });
  4977. this.uuid = MathUtils.generateUUID();
  4978. this.name = '';
  4979. this.type = 'Object3D';
  4980. this.parent = null;
  4981. this.children = [];
  4982. this.up = Object3D.DefaultUp.clone();
  4983. var position = new Vector3();
  4984. var rotation = new Euler();
  4985. var quaternion = new Quaternion();
  4986. var scale = new Vector3(1, 1, 1);
  4987. function onRotationChange() {
  4988. quaternion.setFromEuler(rotation, false);
  4989. }
  4990. function onQuaternionChange() {
  4991. rotation.setFromQuaternion(quaternion, undefined, false);
  4992. }
  4993. rotation._onChange(onRotationChange);
  4994. quaternion._onChange(onQuaternionChange);
  4995. Object.defineProperties(this, {
  4996. position: {
  4997. configurable: true,
  4998. enumerable: true,
  4999. value: position
  5000. },
  5001. rotation: {
  5002. configurable: true,
  5003. enumerable: true,
  5004. value: rotation
  5005. },
  5006. quaternion: {
  5007. configurable: true,
  5008. enumerable: true,
  5009. value: quaternion
  5010. },
  5011. scale: {
  5012. configurable: true,
  5013. enumerable: true,
  5014. value: scale
  5015. },
  5016. modelViewMatrix: {
  5017. value: new Matrix4()
  5018. },
  5019. normalMatrix: {
  5020. value: new Matrix3()
  5021. }
  5022. });
  5023. this.matrix = new Matrix4();
  5024. this.matrixWorld = new Matrix4();
  5025. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  5026. this.matrixWorldNeedsUpdate = false;
  5027. this.layers = new Layers();
  5028. this.visible = true;
  5029. this.castShadow = false;
  5030. this.receiveShadow = false;
  5031. this.frustumCulled = true;
  5032. this.renderOrder = 0;
  5033. this.animations = [];
  5034. this.userData = {};
  5035. }
  5036. Object3D.DefaultUp = new Vector3(0, 1, 0);
  5037. Object3D.DefaultMatrixAutoUpdate = true;
  5038. Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5039. constructor: Object3D,
  5040. isObject3D: true,
  5041. onBeforeRender: function onBeforeRender() {},
  5042. onAfterRender: function onAfterRender() {},
  5043. applyMatrix4: function applyMatrix4(matrix) {
  5044. if (this.matrixAutoUpdate) this.updateMatrix();
  5045. this.matrix.premultiply(matrix);
  5046. this.matrix.decompose(this.position, this.quaternion, this.scale);
  5047. },
  5048. applyQuaternion: function applyQuaternion(q) {
  5049. this.quaternion.premultiply(q);
  5050. return this;
  5051. },
  5052. setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
  5053. // assumes axis is normalized
  5054. this.quaternion.setFromAxisAngle(axis, angle);
  5055. },
  5056. setRotationFromEuler: function setRotationFromEuler(euler) {
  5057. this.quaternion.setFromEuler(euler, true);
  5058. },
  5059. setRotationFromMatrix: function setRotationFromMatrix(m) {
  5060. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5061. this.quaternion.setFromRotationMatrix(m);
  5062. },
  5063. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  5064. // assumes q is normalized
  5065. this.quaternion.copy(q);
  5066. },
  5067. rotateOnAxis: function rotateOnAxis(axis, angle) {
  5068. // rotate object on axis in object space
  5069. // axis is assumed to be normalized
  5070. _q1.setFromAxisAngle(axis, angle);
  5071. this.quaternion.multiply(_q1);
  5072. return this;
  5073. },
  5074. rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
  5075. // rotate object on axis in world space
  5076. // axis is assumed to be normalized
  5077. // method assumes no rotated parent
  5078. _q1.setFromAxisAngle(axis, angle);
  5079. this.quaternion.premultiply(_q1);
  5080. return this;
  5081. },
  5082. rotateX: function rotateX(angle) {
  5083. return this.rotateOnAxis(_xAxis, angle);
  5084. },
  5085. rotateY: function rotateY(angle) {
  5086. return this.rotateOnAxis(_yAxis, angle);
  5087. },
  5088. rotateZ: function rotateZ(angle) {
  5089. return this.rotateOnAxis(_zAxis, angle);
  5090. },
  5091. translateOnAxis: function translateOnAxis(axis, distance) {
  5092. // translate object by distance along axis in object space
  5093. // axis is assumed to be normalized
  5094. _v1$2.copy(axis).applyQuaternion(this.quaternion);
  5095. this.position.add(_v1$2.multiplyScalar(distance));
  5096. return this;
  5097. },
  5098. translateX: function translateX(distance) {
  5099. return this.translateOnAxis(_xAxis, distance);
  5100. },
  5101. translateY: function translateY(distance) {
  5102. return this.translateOnAxis(_yAxis, distance);
  5103. },
  5104. translateZ: function translateZ(distance) {
  5105. return this.translateOnAxis(_zAxis, distance);
  5106. },
  5107. localToWorld: function localToWorld(vector) {
  5108. return vector.applyMatrix4(this.matrixWorld);
  5109. },
  5110. worldToLocal: function worldToLocal(vector) {
  5111. return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert());
  5112. },
  5113. lookAt: function lookAt(x, y, z) {
  5114. // This method does not support objects having non-uniformly-scaled parent(s)
  5115. if (x.isVector3) {
  5116. _target.copy(x);
  5117. } else {
  5118. _target.set(x, y, z);
  5119. }
  5120. var parent = this.parent;
  5121. this.updateWorldMatrix(true, false);
  5122. _position.setFromMatrixPosition(this.matrixWorld);
  5123. if (this.isCamera || this.isLight) {
  5124. _m1$1.lookAt(_position, _target, this.up);
  5125. } else {
  5126. _m1$1.lookAt(_target, _position, this.up);
  5127. }
  5128. this.quaternion.setFromRotationMatrix(_m1$1);
  5129. if (parent) {
  5130. _m1$1.extractRotation(parent.matrixWorld);
  5131. _q1.setFromRotationMatrix(_m1$1);
  5132. this.quaternion.premultiply(_q1.invert());
  5133. }
  5134. },
  5135. add: function add(object) {
  5136. if (arguments.length > 1) {
  5137. for (var i = 0; i < arguments.length; i++) {
  5138. this.add(arguments[i]);
  5139. }
  5140. return this;
  5141. }
  5142. if (object === this) {
  5143. console.error('THREE.Object3D.add: object can\'t be added as a child of itself.', object);
  5144. return this;
  5145. }
  5146. if (object && object.isObject3D) {
  5147. if (object.parent !== null) {
  5148. object.parent.remove(object);
  5149. }
  5150. object.parent = this;
  5151. this.children.push(object);
  5152. object.dispatchEvent(_addedEvent);
  5153. } else {
  5154. console.error('THREE.Object3D.add: object not an instance of THREE.Object3D.', object);
  5155. }
  5156. return this;
  5157. },
  5158. remove: function remove(object) {
  5159. if (arguments.length > 1) {
  5160. for (var i = 0; i < arguments.length; i++) {
  5161. this.remove(arguments[i]);
  5162. }
  5163. return this;
  5164. }
  5165. var index = this.children.indexOf(object);
  5166. if (index !== -1) {
  5167. object.parent = null;
  5168. this.children.splice(index, 1);
  5169. object.dispatchEvent(_removedEvent);
  5170. }
  5171. return this;
  5172. },
  5173. clear: function clear() {
  5174. for (var i = 0; i < this.children.length; i++) {
  5175. var object = this.children[i];
  5176. object.parent = null;
  5177. object.dispatchEvent(_removedEvent);
  5178. }
  5179. this.children.length = 0;
  5180. return this;
  5181. },
  5182. attach: function attach(object) {
  5183. // adds object as a child of this, while maintaining the object's world transform
  5184. this.updateWorldMatrix(true, false);
  5185. _m1$1.copy(this.matrixWorld).invert();
  5186. if (object.parent !== null) {
  5187. object.parent.updateWorldMatrix(true, false);
  5188. _m1$1.multiply(object.parent.matrixWorld);
  5189. }
  5190. object.applyMatrix4(_m1$1);
  5191. object.updateWorldMatrix(false, false);
  5192. this.add(object);
  5193. return this;
  5194. },
  5195. getObjectById: function getObjectById(id) {
  5196. return this.getObjectByProperty('id', id);
  5197. },
  5198. getObjectByName: function getObjectByName(name) {
  5199. return this.getObjectByProperty('name', name);
  5200. },
  5201. getObjectByProperty: function getObjectByProperty(name, value) {
  5202. if (this[name] === value) return this;
  5203. for (var i = 0, l = this.children.length; i < l; i++) {
  5204. var child = this.children[i];
  5205. var object = child.getObjectByProperty(name, value);
  5206. if (object !== undefined) {
  5207. return object;
  5208. }
  5209. }
  5210. return undefined;
  5211. },
  5212. getWorldPosition: function getWorldPosition(target) {
  5213. if (target === undefined) {
  5214. console.warn('THREE.Object3D: .getWorldPosition() target is now required');
  5215. target = new Vector3();
  5216. }
  5217. this.updateWorldMatrix(true, false);
  5218. return target.setFromMatrixPosition(this.matrixWorld);
  5219. },
  5220. getWorldQuaternion: function getWorldQuaternion(target) {
  5221. if (target === undefined) {
  5222. console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
  5223. target = new Quaternion();
  5224. }
  5225. this.updateWorldMatrix(true, false);
  5226. this.matrixWorld.decompose(_position, target, _scale);
  5227. return target;
  5228. },
  5229. getWorldScale: function getWorldScale(target) {
  5230. if (target === undefined) {
  5231. console.warn('THREE.Object3D: .getWorldScale() target is now required');
  5232. target = new Vector3();
  5233. }
  5234. this.updateWorldMatrix(true, false);
  5235. this.matrixWorld.decompose(_position, _quaternion$2, target);
  5236. return target;
  5237. },
  5238. getWorldDirection: function getWorldDirection(target) {
  5239. if (target === undefined) {
  5240. console.warn('THREE.Object3D: .getWorldDirection() target is now required');
  5241. target = new Vector3();
  5242. }
  5243. this.updateWorldMatrix(true, false);
  5244. var e = this.matrixWorld.elements;
  5245. return target.set(e[8], e[9], e[10]).normalize();
  5246. },
  5247. raycast: function raycast() {},
  5248. traverse: function traverse(callback) {
  5249. callback(this);
  5250. var children = this.children;
  5251. for (var i = 0, l = children.length; i < l; i++) {
  5252. children[i].traverse(callback);
  5253. }
  5254. },
  5255. traverseVisible: function traverseVisible(callback) {
  5256. if (this.visible === false) return;
  5257. callback(this);
  5258. var children = this.children;
  5259. for (var i = 0, l = children.length; i < l; i++) {
  5260. children[i].traverseVisible(callback);
  5261. }
  5262. },
  5263. traverseAncestors: function traverseAncestors(callback) {
  5264. var parent = this.parent;
  5265. if (parent !== null) {
  5266. callback(parent);
  5267. parent.traverseAncestors(callback);
  5268. }
  5269. },
  5270. updateMatrix: function updateMatrix() {
  5271. this.matrix.compose(this.position, this.quaternion, this.scale);
  5272. this.matrixWorldNeedsUpdate = true;
  5273. },
  5274. updateMatrixWorld: function updateMatrixWorld(force) {
  5275. if (this.matrixAutoUpdate) this.updateMatrix();
  5276. if (this.matrixWorldNeedsUpdate || force) {
  5277. if (this.parent === null) {
  5278. this.matrixWorld.copy(this.matrix);
  5279. } else {
  5280. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  5281. }
  5282. this.matrixWorldNeedsUpdate = false;
  5283. force = true;
  5284. } // update children
  5285. var children = this.children;
  5286. for (var i = 0, l = children.length; i < l; i++) {
  5287. children[i].updateMatrixWorld(force);
  5288. }
  5289. },
  5290. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  5291. var parent = this.parent;
  5292. if (updateParents === true && parent !== null) {
  5293. parent.updateWorldMatrix(true, false);
  5294. }
  5295. if (this.matrixAutoUpdate) this.updateMatrix();
  5296. if (this.parent === null) {
  5297. this.matrixWorld.copy(this.matrix);
  5298. } else {
  5299. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  5300. } // update children
  5301. if (updateChildren === true) {
  5302. var children = this.children;
  5303. for (var i = 0, l = children.length; i < l; i++) {
  5304. children[i].updateWorldMatrix(false, true);
  5305. }
  5306. }
  5307. },
  5308. toJSON: function toJSON(meta) {
  5309. // meta is a string when called from JSON.stringify
  5310. var isRootObject = meta === undefined || typeof meta === 'string';
  5311. var output = {}; // meta is a hash used to collect geometries, materials.
  5312. // not providing it implies that this is the root object
  5313. // being serialized.
  5314. if (isRootObject) {
  5315. // initialize meta obj
  5316. meta = {
  5317. geometries: {},
  5318. materials: {},
  5319. textures: {},
  5320. images: {},
  5321. shapes: {},
  5322. skeletons: {},
  5323. animations: {}
  5324. };
  5325. output.metadata = {
  5326. version: 4.5,
  5327. type: 'Object',
  5328. generator: 'Object3D.toJSON'
  5329. };
  5330. } // standard Object3D serialization
  5331. var object = {};
  5332. object.uuid = this.uuid;
  5333. object.type = this.type;
  5334. if (this.name !== '') object.name = this.name;
  5335. if (this.castShadow === true) object.castShadow = true;
  5336. if (this.receiveShadow === true) object.receiveShadow = true;
  5337. if (this.visible === false) object.visible = false;
  5338. if (this.frustumCulled === false) object.frustumCulled = false;
  5339. if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
  5340. if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
  5341. object.layers = this.layers.mask;
  5342. object.matrix = this.matrix.toArray();
  5343. if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
  5344. if (this.isInstancedMesh) {
  5345. object.type = 'InstancedMesh';
  5346. object.count = this.count;
  5347. object.instanceMatrix = this.instanceMatrix.toJSON();
  5348. } //
  5349. function serialize(library, element) {
  5350. if (library[element.uuid] === undefined) {
  5351. library[element.uuid] = element.toJSON(meta);
  5352. }
  5353. return element.uuid;
  5354. }
  5355. if (this.isMesh || this.isLine || this.isPoints) {
  5356. object.geometry = serialize(meta.geometries, this.geometry);
  5357. var parameters = this.geometry.parameters;
  5358. if (parameters !== undefined && parameters.shapes !== undefined) {
  5359. var shapes = parameters.shapes;
  5360. if (Array.isArray(shapes)) {
  5361. for (var i = 0, l = shapes.length; i < l; i++) {
  5362. var shape = shapes[i];
  5363. serialize(meta.shapes, shape);
  5364. }
  5365. } else {
  5366. serialize(meta.shapes, shapes);
  5367. }
  5368. }
  5369. }
  5370. if (this.isSkinnedMesh) {
  5371. object.bindMode = this.bindMode;
  5372. object.bindMatrix = this.bindMatrix.toArray();
  5373. if (this.skeleton !== undefined) {
  5374. serialize(meta.skeletons, this.skeleton);
  5375. object.skeleton = this.skeleton.uuid;
  5376. }
  5377. }
  5378. if (this.material !== undefined) {
  5379. if (Array.isArray(this.material)) {
  5380. var uuids = [];
  5381. for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
  5382. uuids.push(serialize(meta.materials, this.material[_i]));
  5383. }
  5384. object.material = uuids;
  5385. } else {
  5386. object.material = serialize(meta.materials, this.material);
  5387. }
  5388. } //
  5389. if (this.children.length > 0) {
  5390. object.children = [];
  5391. for (var _i2 = 0; _i2 < this.children.length; _i2++) {
  5392. object.children.push(this.children[_i2].toJSON(meta).object);
  5393. }
  5394. } //
  5395. if (this.animations.length > 0) {
  5396. object.animations = [];
  5397. for (var _i3 = 0; _i3 < this.animations.length; _i3++) {
  5398. var animation = this.animations[_i3];
  5399. object.animations.push(serialize(meta.animations, animation));
  5400. }
  5401. }
  5402. if (isRootObject) {
  5403. var geometries = extractFromCache(meta.geometries);
  5404. var materials = extractFromCache(meta.materials);
  5405. var textures = extractFromCache(meta.textures);
  5406. var images = extractFromCache(meta.images);
  5407. var _shapes = extractFromCache(meta.shapes);
  5408. var skeletons = extractFromCache(meta.skeletons);
  5409. var animations = extractFromCache(meta.animations);
  5410. if (geometries.length > 0) output.geometries = geometries;
  5411. if (materials.length > 0) output.materials = materials;
  5412. if (textures.length > 0) output.textures = textures;
  5413. if (images.length > 0) output.images = images;
  5414. if (_shapes.length > 0) output.shapes = _shapes;
  5415. if (skeletons.length > 0) output.skeletons = skeletons;
  5416. if (animations.length > 0) output.animations = animations;
  5417. }
  5418. output.object = object;
  5419. return output; // extract data from the cache hash
  5420. // remove metadata on each item
  5421. // and return as array
  5422. function extractFromCache(cache) {
  5423. var values = [];
  5424. for (var key in cache) {
  5425. var data = cache[key];
  5426. delete data.metadata;
  5427. values.push(data);
  5428. }
  5429. return values;
  5430. }
  5431. },
  5432. clone: function clone(recursive) {
  5433. return new this.constructor().copy(this, recursive);
  5434. },
  5435. copy: function copy(source, recursive) {
  5436. if (recursive === void 0) {
  5437. recursive = true;
  5438. }
  5439. this.name = source.name;
  5440. this.up.copy(source.up);
  5441. this.position.copy(source.position);
  5442. this.rotation.order = source.rotation.order;
  5443. this.quaternion.copy(source.quaternion);
  5444. this.scale.copy(source.scale);
  5445. this.matrix.copy(source.matrix);
  5446. this.matrixWorld.copy(source.matrixWorld);
  5447. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5448. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5449. this.layers.mask = source.layers.mask;
  5450. this.visible = source.visible;
  5451. this.castShadow = source.castShadow;
  5452. this.receiveShadow = source.receiveShadow;
  5453. this.frustumCulled = source.frustumCulled;
  5454. this.renderOrder = source.renderOrder;
  5455. this.userData = JSON.parse(JSON.stringify(source.userData));
  5456. if (recursive === true) {
  5457. for (var i = 0; i < source.children.length; i++) {
  5458. var child = source.children[i];
  5459. this.add(child.clone());
  5460. }
  5461. }
  5462. return this;
  5463. }
  5464. });
  5465. var _vector1 = /*@__PURE__*/new Vector3();
  5466. var _vector2 = /*@__PURE__*/new Vector3();
  5467. var _normalMatrix = /*@__PURE__*/new Matrix3();
  5468. var Plane = /*#__PURE__*/function () {
  5469. function Plane(normal, constant) {
  5470. Object.defineProperty(this, 'isPlane', {
  5471. value: true
  5472. }); // normal is assumed to be normalized
  5473. this.normal = normal !== undefined ? normal : new Vector3(1, 0, 0);
  5474. this.constant = constant !== undefined ? constant : 0;
  5475. }
  5476. var _proto = Plane.prototype;
  5477. _proto.set = function set(normal, constant) {
  5478. this.normal.copy(normal);
  5479. this.constant = constant;
  5480. return this;
  5481. };
  5482. _proto.setComponents = function setComponents(x, y, z, w) {
  5483. this.normal.set(x, y, z);
  5484. this.constant = w;
  5485. return this;
  5486. };
  5487. _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
  5488. this.normal.copy(normal);
  5489. this.constant = -point.dot(this.normal);
  5490. return this;
  5491. };
  5492. _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
  5493. 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)?
  5494. this.setFromNormalAndCoplanarPoint(normal, a);
  5495. return this;
  5496. };
  5497. _proto.clone = function clone() {
  5498. return new this.constructor().copy(this);
  5499. };
  5500. _proto.copy = function copy(plane) {
  5501. this.normal.copy(plane.normal);
  5502. this.constant = plane.constant;
  5503. return this;
  5504. };
  5505. _proto.normalize = function normalize() {
  5506. // Note: will lead to a divide by zero if the plane is invalid.
  5507. var inverseNormalLength = 1.0 / this.normal.length();
  5508. this.normal.multiplyScalar(inverseNormalLength);
  5509. this.constant *= inverseNormalLength;
  5510. return this;
  5511. };
  5512. _proto.negate = function negate() {
  5513. this.constant *= -1;
  5514. this.normal.negate();
  5515. return this;
  5516. };
  5517. _proto.distanceToPoint = function distanceToPoint(point) {
  5518. return this.normal.dot(point) + this.constant;
  5519. };
  5520. _proto.distanceToSphere = function distanceToSphere(sphere) {
  5521. return this.distanceToPoint(sphere.center) - sphere.radius;
  5522. };
  5523. _proto.projectPoint = function projectPoint(point, target) {
  5524. if (target === undefined) {
  5525. console.warn('THREE.Plane: .projectPoint() target is now required');
  5526. target = new Vector3();
  5527. }
  5528. return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
  5529. };
  5530. _proto.intersectLine = function intersectLine(line, target) {
  5531. if (target === undefined) {
  5532. console.warn('THREE.Plane: .intersectLine() target is now required');
  5533. target = new Vector3();
  5534. }
  5535. var direction = line.delta(_vector1);
  5536. var denominator = this.normal.dot(direction);
  5537. if (denominator === 0) {
  5538. // line is coplanar, return origin
  5539. if (this.distanceToPoint(line.start) === 0) {
  5540. return target.copy(line.start);
  5541. } // Unsure if this is the correct method to handle this case.
  5542. return undefined;
  5543. }
  5544. var t = -(line.start.dot(this.normal) + this.constant) / denominator;
  5545. if (t < 0 || t > 1) {
  5546. return undefined;
  5547. }
  5548. return target.copy(direction).multiplyScalar(t).add(line.start);
  5549. };
  5550. _proto.intersectsLine = function intersectsLine(line) {
  5551. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  5552. var startSign = this.distanceToPoint(line.start);
  5553. var endSign = this.distanceToPoint(line.end);
  5554. return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
  5555. };
  5556. _proto.intersectsBox = function intersectsBox(box) {
  5557. return box.intersectsPlane(this);
  5558. };
  5559. _proto.intersectsSphere = function intersectsSphere(sphere) {
  5560. return sphere.intersectsPlane(this);
  5561. };
  5562. _proto.coplanarPoint = function coplanarPoint(target) {
  5563. if (target === undefined) {
  5564. console.warn('THREE.Plane: .coplanarPoint() target is now required');
  5565. target = new Vector3();
  5566. }
  5567. return target.copy(this.normal).multiplyScalar(-this.constant);
  5568. };
  5569. _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
  5570. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
  5571. var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
  5572. var normal = this.normal.applyMatrix3(normalMatrix).normalize();
  5573. this.constant = -referencePoint.dot(normal);
  5574. return this;
  5575. };
  5576. _proto.translate = function translate(offset) {
  5577. this.constant -= offset.dot(this.normal);
  5578. return this;
  5579. };
  5580. _proto.equals = function equals(plane) {
  5581. return plane.normal.equals(this.normal) && plane.constant === this.constant;
  5582. };
  5583. return Plane;
  5584. }();
  5585. var _v0$1 = /*@__PURE__*/new Vector3();
  5586. var _v1$3 = /*@__PURE__*/new Vector3();
  5587. var _v2$1 = /*@__PURE__*/new Vector3();
  5588. var _v3 = /*@__PURE__*/new Vector3();
  5589. var _vab = /*@__PURE__*/new Vector3();
  5590. var _vac = /*@__PURE__*/new Vector3();
  5591. var _vbc = /*@__PURE__*/new Vector3();
  5592. var _vap = /*@__PURE__*/new Vector3();
  5593. var _vbp = /*@__PURE__*/new Vector3();
  5594. var _vcp = /*@__PURE__*/new Vector3();
  5595. var Triangle = /*#__PURE__*/function () {
  5596. function Triangle(a, b, c) {
  5597. this.a = a !== undefined ? a : new Vector3();
  5598. this.b = b !== undefined ? b : new Vector3();
  5599. this.c = c !== undefined ? c : new Vector3();
  5600. }
  5601. Triangle.getNormal = function getNormal(a, b, c, target) {
  5602. if (target === undefined) {
  5603. console.warn('THREE.Triangle: .getNormal() target is now required');
  5604. target = new Vector3();
  5605. }
  5606. target.subVectors(c, b);
  5607. _v0$1.subVectors(a, b);
  5608. target.cross(_v0$1);
  5609. var targetLengthSq = target.lengthSq();
  5610. if (targetLengthSq > 0) {
  5611. return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
  5612. }
  5613. return target.set(0, 0, 0);
  5614. } // static/instance method to calculate barycentric coordinates
  5615. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  5616. ;
  5617. Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
  5618. _v0$1.subVectors(c, a);
  5619. _v1$3.subVectors(b, a);
  5620. _v2$1.subVectors(point, a);
  5621. var dot00 = _v0$1.dot(_v0$1);
  5622. var dot01 = _v0$1.dot(_v1$3);
  5623. var dot02 = _v0$1.dot(_v2$1);
  5624. var dot11 = _v1$3.dot(_v1$3);
  5625. var dot12 = _v1$3.dot(_v2$1);
  5626. var denom = dot00 * dot11 - dot01 * dot01;
  5627. if (target === undefined) {
  5628. console.warn('THREE.Triangle: .getBarycoord() target is now required');
  5629. target = new Vector3();
  5630. } // collinear or singular triangle
  5631. if (denom === 0) {
  5632. // arbitrary location outside of triangle?
  5633. // not sure if this is the best idea, maybe should be returning undefined
  5634. return target.set(-2, -1, -1);
  5635. }
  5636. var invDenom = 1 / denom;
  5637. var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  5638. var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
  5639. return target.set(1 - u - v, v, u);
  5640. };
  5641. Triangle.containsPoint = function containsPoint(point, a, b, c) {
  5642. this.getBarycoord(point, a, b, c, _v3);
  5643. return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
  5644. };
  5645. Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
  5646. this.getBarycoord(point, p1, p2, p3, _v3);
  5647. target.set(0, 0);
  5648. target.addScaledVector(uv1, _v3.x);
  5649. target.addScaledVector(uv2, _v3.y);
  5650. target.addScaledVector(uv3, _v3.z);
  5651. return target;
  5652. };
  5653. Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
  5654. _v0$1.subVectors(c, b);
  5655. _v1$3.subVectors(a, b); // strictly front facing
  5656. return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
  5657. };
  5658. var _proto = Triangle.prototype;
  5659. _proto.set = function set(a, b, c) {
  5660. this.a.copy(a);
  5661. this.b.copy(b);
  5662. this.c.copy(c);
  5663. return this;
  5664. };
  5665. _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
  5666. this.a.copy(points[i0]);
  5667. this.b.copy(points[i1]);
  5668. this.c.copy(points[i2]);
  5669. return this;
  5670. };
  5671. _proto.clone = function clone() {
  5672. return new this.constructor().copy(this);
  5673. };
  5674. _proto.copy = function copy(triangle) {
  5675. this.a.copy(triangle.a);
  5676. this.b.copy(triangle.b);
  5677. this.c.copy(triangle.c);
  5678. return this;
  5679. };
  5680. _proto.getArea = function getArea() {
  5681. _v0$1.subVectors(this.c, this.b);
  5682. _v1$3.subVectors(this.a, this.b);
  5683. return _v0$1.cross(_v1$3).length() * 0.5;
  5684. };
  5685. _proto.getMidpoint = function getMidpoint(target) {
  5686. if (target === undefined) {
  5687. console.warn('THREE.Triangle: .getMidpoint() target is now required');
  5688. target = new Vector3();
  5689. }
  5690. return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  5691. };
  5692. _proto.getNormal = function getNormal(target) {
  5693. return Triangle.getNormal(this.a, this.b, this.c, target);
  5694. };
  5695. _proto.getPlane = function getPlane(target) {
  5696. if (target === undefined) {
  5697. console.warn('THREE.Triangle: .getPlane() target is now required');
  5698. target = new Plane();
  5699. }
  5700. return target.setFromCoplanarPoints(this.a, this.b, this.c);
  5701. };
  5702. _proto.getBarycoord = function getBarycoord(point, target) {
  5703. return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
  5704. };
  5705. _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
  5706. return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
  5707. };
  5708. _proto.containsPoint = function containsPoint(point) {
  5709. return Triangle.containsPoint(point, this.a, this.b, this.c);
  5710. };
  5711. _proto.isFrontFacing = function isFrontFacing(direction) {
  5712. return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
  5713. };
  5714. _proto.intersectsBox = function intersectsBox(box) {
  5715. return box.intersectsTriangle(this);
  5716. };
  5717. _proto.closestPointToPoint = function closestPointToPoint(p, target) {
  5718. if (target === undefined) {
  5719. console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
  5720. target = new Vector3();
  5721. }
  5722. var a = this.a,
  5723. b = this.b,
  5724. c = this.c;
  5725. var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  5726. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  5727. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  5728. // basically, we're distinguishing which of the voronoi regions of the triangle
  5729. // the point lies in with the minimum amount of redundant computation.
  5730. _vab.subVectors(b, a);
  5731. _vac.subVectors(c, a);
  5732. _vap.subVectors(p, a);
  5733. var d1 = _vab.dot(_vap);
  5734. var d2 = _vac.dot(_vap);
  5735. if (d1 <= 0 && d2 <= 0) {
  5736. // vertex region of A; barycentric coords (1, 0, 0)
  5737. return target.copy(a);
  5738. }
  5739. _vbp.subVectors(p, b);
  5740. var d3 = _vab.dot(_vbp);
  5741. var d4 = _vac.dot(_vbp);
  5742. if (d3 >= 0 && d4 <= d3) {
  5743. // vertex region of B; barycentric coords (0, 1, 0)
  5744. return target.copy(b);
  5745. }
  5746. var vc = d1 * d4 - d3 * d2;
  5747. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  5748. v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
  5749. return target.copy(a).addScaledVector(_vab, v);
  5750. }
  5751. _vcp.subVectors(p, c);
  5752. var d5 = _vab.dot(_vcp);
  5753. var d6 = _vac.dot(_vcp);
  5754. if (d6 >= 0 && d5 <= d6) {
  5755. // vertex region of C; barycentric coords (0, 0, 1)
  5756. return target.copy(c);
  5757. }
  5758. var vb = d5 * d2 - d1 * d6;
  5759. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  5760. w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
  5761. return target.copy(a).addScaledVector(_vac, w);
  5762. }
  5763. var va = d3 * d6 - d5 * d4;
  5764. if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
  5765. _vbc.subVectors(c, b);
  5766. w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
  5767. return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
  5768. } // face region
  5769. var denom = 1 / (va + vb + vc); // u = va * denom
  5770. v = vb * denom;
  5771. w = vc * denom;
  5772. return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
  5773. };
  5774. _proto.equals = function equals(triangle) {
  5775. return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
  5776. };
  5777. return Triangle;
  5778. }();
  5779. var _colorKeywords = {
  5780. 'aliceblue': 0xF0F8FF,
  5781. 'antiquewhite': 0xFAEBD7,
  5782. 'aqua': 0x00FFFF,
  5783. 'aquamarine': 0x7FFFD4,
  5784. 'azure': 0xF0FFFF,
  5785. 'beige': 0xF5F5DC,
  5786. 'bisque': 0xFFE4C4,
  5787. 'black': 0x000000,
  5788. 'blanchedalmond': 0xFFEBCD,
  5789. 'blue': 0x0000FF,
  5790. 'blueviolet': 0x8A2BE2,
  5791. 'brown': 0xA52A2A,
  5792. 'burlywood': 0xDEB887,
  5793. 'cadetblue': 0x5F9EA0,
  5794. 'chartreuse': 0x7FFF00,
  5795. 'chocolate': 0xD2691E,
  5796. 'coral': 0xFF7F50,
  5797. 'cornflowerblue': 0x6495ED,
  5798. 'cornsilk': 0xFFF8DC,
  5799. 'crimson': 0xDC143C,
  5800. 'cyan': 0x00FFFF,
  5801. 'darkblue': 0x00008B,
  5802. 'darkcyan': 0x008B8B,
  5803. 'darkgoldenrod': 0xB8860B,
  5804. 'darkgray': 0xA9A9A9,
  5805. 'darkgreen': 0x006400,
  5806. 'darkgrey': 0xA9A9A9,
  5807. 'darkkhaki': 0xBDB76B,
  5808. 'darkmagenta': 0x8B008B,
  5809. 'darkolivegreen': 0x556B2F,
  5810. 'darkorange': 0xFF8C00,
  5811. 'darkorchid': 0x9932CC,
  5812. 'darkred': 0x8B0000,
  5813. 'darksalmon': 0xE9967A,
  5814. 'darkseagreen': 0x8FBC8F,
  5815. 'darkslateblue': 0x483D8B,
  5816. 'darkslategray': 0x2F4F4F,
  5817. 'darkslategrey': 0x2F4F4F,
  5818. 'darkturquoise': 0x00CED1,
  5819. 'darkviolet': 0x9400D3,
  5820. 'deeppink': 0xFF1493,
  5821. 'deepskyblue': 0x00BFFF,
  5822. 'dimgray': 0x696969,
  5823. 'dimgrey': 0x696969,
  5824. 'dodgerblue': 0x1E90FF,
  5825. 'firebrick': 0xB22222,
  5826. 'floralwhite': 0xFFFAF0,
  5827. 'forestgreen': 0x228B22,
  5828. 'fuchsia': 0xFF00FF,
  5829. 'gainsboro': 0xDCDCDC,
  5830. 'ghostwhite': 0xF8F8FF,
  5831. 'gold': 0xFFD700,
  5832. 'goldenrod': 0xDAA520,
  5833. 'gray': 0x808080,
  5834. 'green': 0x008000,
  5835. 'greenyellow': 0xADFF2F,
  5836. 'grey': 0x808080,
  5837. 'honeydew': 0xF0FFF0,
  5838. 'hotpink': 0xFF69B4,
  5839. 'indianred': 0xCD5C5C,
  5840. 'indigo': 0x4B0082,
  5841. 'ivory': 0xFFFFF0,
  5842. 'khaki': 0xF0E68C,
  5843. 'lavender': 0xE6E6FA,
  5844. 'lavenderblush': 0xFFF0F5,
  5845. 'lawngreen': 0x7CFC00,
  5846. 'lemonchiffon': 0xFFFACD,
  5847. 'lightblue': 0xADD8E6,
  5848. 'lightcoral': 0xF08080,
  5849. 'lightcyan': 0xE0FFFF,
  5850. 'lightgoldenrodyellow': 0xFAFAD2,
  5851. 'lightgray': 0xD3D3D3,
  5852. 'lightgreen': 0x90EE90,
  5853. 'lightgrey': 0xD3D3D3,
  5854. 'lightpink': 0xFFB6C1,
  5855. 'lightsalmon': 0xFFA07A,
  5856. 'lightseagreen': 0x20B2AA,
  5857. 'lightskyblue': 0x87CEFA,
  5858. 'lightslategray': 0x778899,
  5859. 'lightslategrey': 0x778899,
  5860. 'lightsteelblue': 0xB0C4DE,
  5861. 'lightyellow': 0xFFFFE0,
  5862. 'lime': 0x00FF00,
  5863. 'limegreen': 0x32CD32,
  5864. 'linen': 0xFAF0E6,
  5865. 'magenta': 0xFF00FF,
  5866. 'maroon': 0x800000,
  5867. 'mediumaquamarine': 0x66CDAA,
  5868. 'mediumblue': 0x0000CD,
  5869. 'mediumorchid': 0xBA55D3,
  5870. 'mediumpurple': 0x9370DB,
  5871. 'mediumseagreen': 0x3CB371,
  5872. 'mediumslateblue': 0x7B68EE,
  5873. 'mediumspringgreen': 0x00FA9A,
  5874. 'mediumturquoise': 0x48D1CC,
  5875. 'mediumvioletred': 0xC71585,
  5876. 'midnightblue': 0x191970,
  5877. 'mintcream': 0xF5FFFA,
  5878. 'mistyrose': 0xFFE4E1,
  5879. 'moccasin': 0xFFE4B5,
  5880. 'navajowhite': 0xFFDEAD,
  5881. 'navy': 0x000080,
  5882. 'oldlace': 0xFDF5E6,
  5883. 'olive': 0x808000,
  5884. 'olivedrab': 0x6B8E23,
  5885. 'orange': 0xFFA500,
  5886. 'orangered': 0xFF4500,
  5887. 'orchid': 0xDA70D6,
  5888. 'palegoldenrod': 0xEEE8AA,
  5889. 'palegreen': 0x98FB98,
  5890. 'paleturquoise': 0xAFEEEE,
  5891. 'palevioletred': 0xDB7093,
  5892. 'papayawhip': 0xFFEFD5,
  5893. 'peachpuff': 0xFFDAB9,
  5894. 'peru': 0xCD853F,
  5895. 'pink': 0xFFC0CB,
  5896. 'plum': 0xDDA0DD,
  5897. 'powderblue': 0xB0E0E6,
  5898. 'purple': 0x800080,
  5899. 'rebeccapurple': 0x663399,
  5900. 'red': 0xFF0000,
  5901. 'rosybrown': 0xBC8F8F,
  5902. 'royalblue': 0x4169E1,
  5903. 'saddlebrown': 0x8B4513,
  5904. 'salmon': 0xFA8072,
  5905. 'sandybrown': 0xF4A460,
  5906. 'seagreen': 0x2E8B57,
  5907. 'seashell': 0xFFF5EE,
  5908. 'sienna': 0xA0522D,
  5909. 'silver': 0xC0C0C0,
  5910. 'skyblue': 0x87CEEB,
  5911. 'slateblue': 0x6A5ACD,
  5912. 'slategray': 0x708090,
  5913. 'slategrey': 0x708090,
  5914. 'snow': 0xFFFAFA,
  5915. 'springgreen': 0x00FF7F,
  5916. 'steelblue': 0x4682B4,
  5917. 'tan': 0xD2B48C,
  5918. 'teal': 0x008080,
  5919. 'thistle': 0xD8BFD8,
  5920. 'tomato': 0xFF6347,
  5921. 'turquoise': 0x40E0D0,
  5922. 'violet': 0xEE82EE,
  5923. 'wheat': 0xF5DEB3,
  5924. 'white': 0xFFFFFF,
  5925. 'whitesmoke': 0xF5F5F5,
  5926. 'yellow': 0xFFFF00,
  5927. 'yellowgreen': 0x9ACD32
  5928. };
  5929. var _hslA = {
  5930. h: 0,
  5931. s: 0,
  5932. l: 0
  5933. };
  5934. var _hslB = {
  5935. h: 0,
  5936. s: 0,
  5937. l: 0
  5938. };
  5939. function hue2rgb(p, q, t) {
  5940. if (t < 0) t += 1;
  5941. if (t > 1) t -= 1;
  5942. if (t < 1 / 6) return p + (q - p) * 6 * t;
  5943. if (t < 1 / 2) return q;
  5944. if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  5945. return p;
  5946. }
  5947. function SRGBToLinear(c) {
  5948. return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
  5949. }
  5950. function LinearToSRGB(c) {
  5951. return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
  5952. }
  5953. var Color = /*#__PURE__*/function () {
  5954. function Color(r, g, b) {
  5955. Object.defineProperty(this, 'isColor', {
  5956. value: true
  5957. });
  5958. if (g === undefined && b === undefined) {
  5959. // r is THREE.Color, hex or string
  5960. return this.set(r);
  5961. }
  5962. return this.setRGB(r, g, b);
  5963. }
  5964. var _proto = Color.prototype;
  5965. _proto.set = function set(value) {
  5966. if (value && value.isColor) {
  5967. this.copy(value);
  5968. } else if (typeof value === 'number') {
  5969. this.setHex(value);
  5970. } else if (typeof value === 'string') {
  5971. this.setStyle(value);
  5972. }
  5973. return this;
  5974. };
  5975. _proto.setScalar = function setScalar(scalar) {
  5976. this.r = scalar;
  5977. this.g = scalar;
  5978. this.b = scalar;
  5979. return this;
  5980. };
  5981. _proto.setHex = function setHex(hex) {
  5982. hex = Math.floor(hex);
  5983. this.r = (hex >> 16 & 255) / 255;
  5984. this.g = (hex >> 8 & 255) / 255;
  5985. this.b = (hex & 255) / 255;
  5986. return this;
  5987. };
  5988. _proto.setRGB = function setRGB(r, g, b) {
  5989. this.r = r;
  5990. this.g = g;
  5991. this.b = b;
  5992. return this;
  5993. };
  5994. _proto.setHSL = function setHSL(h, s, l) {
  5995. // h,s,l ranges are in 0.0 - 1.0
  5996. h = MathUtils.euclideanModulo(h, 1);
  5997. s = MathUtils.clamp(s, 0, 1);
  5998. l = MathUtils.clamp(l, 0, 1);
  5999. if (s === 0) {
  6000. this.r = this.g = this.b = l;
  6001. } else {
  6002. var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  6003. var q = 2 * l - p;
  6004. this.r = hue2rgb(q, p, h + 1 / 3);
  6005. this.g = hue2rgb(q, p, h);
  6006. this.b = hue2rgb(q, p, h - 1 / 3);
  6007. }
  6008. return this;
  6009. };
  6010. _proto.setStyle = function setStyle(style) {
  6011. function handleAlpha(string) {
  6012. if (string === undefined) return;
  6013. if (parseFloat(string) < 1) {
  6014. console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
  6015. }
  6016. }
  6017. var m;
  6018. if (m = /^((?:rgb|hsl)a?)\(([^\)]*)\)/.exec(style)) {
  6019. // rgb / hsl
  6020. var color;
  6021. var name = m[1];
  6022. var components = m[2];
  6023. switch (name) {
  6024. case 'rgb':
  6025. case 'rgba':
  6026. if (color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6027. // rgb(255,0,0) rgba(255,0,0,0.5)
  6028. this.r = Math.min(255, parseInt(color[1], 10)) / 255;
  6029. this.g = Math.min(255, parseInt(color[2], 10)) / 255;
  6030. this.b = Math.min(255, parseInt(color[3], 10)) / 255;
  6031. handleAlpha(color[4]);
  6032. return this;
  6033. }
  6034. if (color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6035. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  6036. this.r = Math.min(100, parseInt(color[1], 10)) / 100;
  6037. this.g = Math.min(100, parseInt(color[2], 10)) / 100;
  6038. this.b = Math.min(100, parseInt(color[3], 10)) / 100;
  6039. handleAlpha(color[4]);
  6040. return this;
  6041. }
  6042. break;
  6043. case 'hsl':
  6044. case 'hsla':
  6045. if (color = /^\s*(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6046. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  6047. var h = parseFloat(color[1]) / 360;
  6048. var s = parseInt(color[2], 10) / 100;
  6049. var l = parseInt(color[3], 10) / 100;
  6050. handleAlpha(color[4]);
  6051. return this.setHSL(h, s, l);
  6052. }
  6053. break;
  6054. }
  6055. } else if (m = /^\#([A-Fa-f\d]+)$/.exec(style)) {
  6056. // hex color
  6057. var hex = m[1];
  6058. var size = hex.length;
  6059. if (size === 3) {
  6060. // #ff0
  6061. this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
  6062. this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
  6063. this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
  6064. return this;
  6065. } else if (size === 6) {
  6066. // #ff0000
  6067. this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
  6068. this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
  6069. this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
  6070. return this;
  6071. }
  6072. }
  6073. if (style && style.length > 0) {
  6074. return this.setColorName(style);
  6075. }
  6076. return this;
  6077. };
  6078. _proto.setColorName = function setColorName(style) {
  6079. // color keywords
  6080. var hex = _colorKeywords[style];
  6081. if (hex !== undefined) {
  6082. // red
  6083. this.setHex(hex);
  6084. } else {
  6085. // unknown color
  6086. console.warn('THREE.Color: Unknown color ' + style);
  6087. }
  6088. return this;
  6089. };
  6090. _proto.clone = function clone() {
  6091. return new this.constructor(this.r, this.g, this.b);
  6092. };
  6093. _proto.copy = function copy(color) {
  6094. this.r = color.r;
  6095. this.g = color.g;
  6096. this.b = color.b;
  6097. return this;
  6098. };
  6099. _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
  6100. if (gammaFactor === void 0) {
  6101. gammaFactor = 2.0;
  6102. }
  6103. this.r = Math.pow(color.r, gammaFactor);
  6104. this.g = Math.pow(color.g, gammaFactor);
  6105. this.b = Math.pow(color.b, gammaFactor);
  6106. return this;
  6107. };
  6108. _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
  6109. if (gammaFactor === void 0) {
  6110. gammaFactor = 2.0;
  6111. }
  6112. var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
  6113. this.r = Math.pow(color.r, safeInverse);
  6114. this.g = Math.pow(color.g, safeInverse);
  6115. this.b = Math.pow(color.b, safeInverse);
  6116. return this;
  6117. };
  6118. _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
  6119. this.copyGammaToLinear(this, gammaFactor);
  6120. return this;
  6121. };
  6122. _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
  6123. this.copyLinearToGamma(this, gammaFactor);
  6124. return this;
  6125. };
  6126. _proto.copySRGBToLinear = function copySRGBToLinear(color) {
  6127. this.r = SRGBToLinear(color.r);
  6128. this.g = SRGBToLinear(color.g);
  6129. this.b = SRGBToLinear(color.b);
  6130. return this;
  6131. };
  6132. _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
  6133. this.r = LinearToSRGB(color.r);
  6134. this.g = LinearToSRGB(color.g);
  6135. this.b = LinearToSRGB(color.b);
  6136. return this;
  6137. };
  6138. _proto.convertSRGBToLinear = function convertSRGBToLinear() {
  6139. this.copySRGBToLinear(this);
  6140. return this;
  6141. };
  6142. _proto.convertLinearToSRGB = function convertLinearToSRGB() {
  6143. this.copyLinearToSRGB(this);
  6144. return this;
  6145. };
  6146. _proto.getHex = function getHex() {
  6147. return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
  6148. };
  6149. _proto.getHexString = function getHexString() {
  6150. return ('000000' + this.getHex().toString(16)).slice(-6);
  6151. };
  6152. _proto.getHSL = function getHSL(target) {
  6153. // h,s,l ranges are in 0.0 - 1.0
  6154. if (target === undefined) {
  6155. console.warn('THREE.Color: .getHSL() target is now required');
  6156. target = {
  6157. h: 0,
  6158. s: 0,
  6159. l: 0
  6160. };
  6161. }
  6162. var r = this.r,
  6163. g = this.g,
  6164. b = this.b;
  6165. var max = Math.max(r, g, b);
  6166. var min = Math.min(r, g, b);
  6167. var hue, saturation;
  6168. var lightness = (min + max) / 2.0;
  6169. if (min === max) {
  6170. hue = 0;
  6171. saturation = 0;
  6172. } else {
  6173. var delta = max - min;
  6174. saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
  6175. switch (max) {
  6176. case r:
  6177. hue = (g - b) / delta + (g < b ? 6 : 0);
  6178. break;
  6179. case g:
  6180. hue = (b - r) / delta + 2;
  6181. break;
  6182. case b:
  6183. hue = (r - g) / delta + 4;
  6184. break;
  6185. }
  6186. hue /= 6;
  6187. }
  6188. target.h = hue;
  6189. target.s = saturation;
  6190. target.l = lightness;
  6191. return target;
  6192. };
  6193. _proto.getStyle = function getStyle() {
  6194. return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
  6195. };
  6196. _proto.offsetHSL = function offsetHSL(h, s, l) {
  6197. this.getHSL(_hslA);
  6198. _hslA.h += h;
  6199. _hslA.s += s;
  6200. _hslA.l += l;
  6201. this.setHSL(_hslA.h, _hslA.s, _hslA.l);
  6202. return this;
  6203. };
  6204. _proto.add = function add(color) {
  6205. this.r += color.r;
  6206. this.g += color.g;
  6207. this.b += color.b;
  6208. return this;
  6209. };
  6210. _proto.addColors = function addColors(color1, color2) {
  6211. this.r = color1.r + color2.r;
  6212. this.g = color1.g + color2.g;
  6213. this.b = color1.b + color2.b;
  6214. return this;
  6215. };
  6216. _proto.addScalar = function addScalar(s) {
  6217. this.r += s;
  6218. this.g += s;
  6219. this.b += s;
  6220. return this;
  6221. };
  6222. _proto.sub = function sub(color) {
  6223. this.r = Math.max(0, this.r - color.r);
  6224. this.g = Math.max(0, this.g - color.g);
  6225. this.b = Math.max(0, this.b - color.b);
  6226. return this;
  6227. };
  6228. _proto.multiply = function multiply(color) {
  6229. this.r *= color.r;
  6230. this.g *= color.g;
  6231. this.b *= color.b;
  6232. return this;
  6233. };
  6234. _proto.multiplyScalar = function multiplyScalar(s) {
  6235. this.r *= s;
  6236. this.g *= s;
  6237. this.b *= s;
  6238. return this;
  6239. };
  6240. _proto.lerp = function lerp(color, alpha) {
  6241. this.r += (color.r - this.r) * alpha;
  6242. this.g += (color.g - this.g) * alpha;
  6243. this.b += (color.b - this.b) * alpha;
  6244. return this;
  6245. };
  6246. _proto.lerpColors = function lerpColors(color1, color2, alpha) {
  6247. this.r = color1.r + (color2.r - color1.r) * alpha;
  6248. this.g = color1.g + (color2.g - color1.g) * alpha;
  6249. this.b = color1.b + (color2.b - color1.b) * alpha;
  6250. return this;
  6251. };
  6252. _proto.lerpHSL = function lerpHSL(color, alpha) {
  6253. this.getHSL(_hslA);
  6254. color.getHSL(_hslB);
  6255. var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
  6256. var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
  6257. var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
  6258. this.setHSL(h, s, l);
  6259. return this;
  6260. };
  6261. _proto.equals = function equals(c) {
  6262. return c.r === this.r && c.g === this.g && c.b === this.b;
  6263. };
  6264. _proto.fromArray = function fromArray(array, offset) {
  6265. if (offset === void 0) {
  6266. offset = 0;
  6267. }
  6268. this.r = array[offset];
  6269. this.g = array[offset + 1];
  6270. this.b = array[offset + 2];
  6271. return this;
  6272. };
  6273. _proto.toArray = function toArray(array, offset) {
  6274. if (array === void 0) {
  6275. array = [];
  6276. }
  6277. if (offset === void 0) {
  6278. offset = 0;
  6279. }
  6280. array[offset] = this.r;
  6281. array[offset + 1] = this.g;
  6282. array[offset + 2] = this.b;
  6283. return array;
  6284. };
  6285. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  6286. this.r = attribute.getX(index);
  6287. this.g = attribute.getY(index);
  6288. this.b = attribute.getZ(index);
  6289. if (attribute.normalized === true) {
  6290. // assuming Uint8Array
  6291. this.r /= 255;
  6292. this.g /= 255;
  6293. this.b /= 255;
  6294. }
  6295. return this;
  6296. };
  6297. _proto.toJSON = function toJSON() {
  6298. return this.getHex();
  6299. };
  6300. return Color;
  6301. }();
  6302. Color.NAMES = _colorKeywords;
  6303. Color.prototype.r = 1;
  6304. Color.prototype.g = 1;
  6305. Color.prototype.b = 1;
  6306. var Face3 = /*#__PURE__*/function () {
  6307. function Face3(a, b, c, normal, color, materialIndex) {
  6308. if (materialIndex === void 0) {
  6309. materialIndex = 0;
  6310. }
  6311. this.a = a;
  6312. this.b = b;
  6313. this.c = c;
  6314. this.normal = normal && normal.isVector3 ? normal : new Vector3();
  6315. this.vertexNormals = Array.isArray(normal) ? normal : [];
  6316. this.color = color && color.isColor ? color : new Color();
  6317. this.vertexColors = Array.isArray(color) ? color : [];
  6318. this.materialIndex = materialIndex;
  6319. }
  6320. var _proto = Face3.prototype;
  6321. _proto.clone = function clone() {
  6322. return new this.constructor().copy(this);
  6323. };
  6324. _proto.copy = function copy(source) {
  6325. this.a = source.a;
  6326. this.b = source.b;
  6327. this.c = source.c;
  6328. this.normal.copy(source.normal);
  6329. this.color.copy(source.color);
  6330. this.materialIndex = source.materialIndex;
  6331. for (var i = 0, il = source.vertexNormals.length; i < il; i++) {
  6332. this.vertexNormals[i] = source.vertexNormals[i].clone();
  6333. }
  6334. for (var _i = 0, _il = source.vertexColors.length; _i < _il; _i++) {
  6335. this.vertexColors[_i] = source.vertexColors[_i].clone();
  6336. }
  6337. return this;
  6338. };
  6339. return Face3;
  6340. }();
  6341. var materialId = 0;
  6342. function Material() {
  6343. Object.defineProperty(this, 'id', {
  6344. value: materialId++
  6345. });
  6346. this.uuid = MathUtils.generateUUID();
  6347. this.name = '';
  6348. this.type = 'Material';
  6349. this.fog = true;
  6350. this.blending = NormalBlending;
  6351. this.side = FrontSide;
  6352. this.flatShading = false;
  6353. this.vertexColors = false;
  6354. this.opacity = 1;
  6355. this.transparent = false;
  6356. this.blendSrc = SrcAlphaFactor;
  6357. this.blendDst = OneMinusSrcAlphaFactor;
  6358. this.blendEquation = AddEquation;
  6359. this.blendSrcAlpha = null;
  6360. this.blendDstAlpha = null;
  6361. this.blendEquationAlpha = null;
  6362. this.depthFunc = LessEqualDepth;
  6363. this.depthTest = true;
  6364. this.depthWrite = true;
  6365. this.stencilWriteMask = 0xff;
  6366. this.stencilFunc = AlwaysStencilFunc;
  6367. this.stencilRef = 0;
  6368. this.stencilFuncMask = 0xff;
  6369. this.stencilFail = KeepStencilOp;
  6370. this.stencilZFail = KeepStencilOp;
  6371. this.stencilZPass = KeepStencilOp;
  6372. this.stencilWrite = false;
  6373. this.clippingPlanes = null;
  6374. this.clipIntersection = false;
  6375. this.clipShadows = false;
  6376. this.shadowSide = null;
  6377. this.colorWrite = true;
  6378. this.precision = null; // override the renderer's default precision for this material
  6379. this.polygonOffset = false;
  6380. this.polygonOffsetFactor = 0;
  6381. this.polygonOffsetUnits = 0;
  6382. this.dithering = false;
  6383. this.alphaTest = 0;
  6384. this.premultipliedAlpha = false;
  6385. this.visible = true;
  6386. this.toneMapped = true;
  6387. this.userData = {};
  6388. this.version = 0;
  6389. }
  6390. Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  6391. constructor: Material,
  6392. isMaterial: true,
  6393. onBeforeCompile: function onBeforeCompile()
  6394. /* shaderobject, renderer */
  6395. {},
  6396. customProgramCacheKey: function customProgramCacheKey() {
  6397. return this.onBeforeCompile.toString();
  6398. },
  6399. setValues: function setValues(values) {
  6400. if (values === undefined) return;
  6401. for (var key in values) {
  6402. var newValue = values[key];
  6403. if (newValue === undefined) {
  6404. console.warn('THREE.Material: \'' + key + '\' parameter is undefined.');
  6405. continue;
  6406. } // for backward compatability if shading is set in the constructor
  6407. if (key === 'shading') {
  6408. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  6409. this.flatShading = newValue === FlatShading ? true : false;
  6410. continue;
  6411. }
  6412. var currentValue = this[key];
  6413. if (currentValue === undefined) {
  6414. console.warn('THREE.' + this.type + ': \'' + key + '\' is not a property of this material.');
  6415. continue;
  6416. }
  6417. if (currentValue && currentValue.isColor) {
  6418. currentValue.set(newValue);
  6419. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  6420. currentValue.copy(newValue);
  6421. } else {
  6422. this[key] = newValue;
  6423. }
  6424. }
  6425. },
  6426. toJSON: function toJSON(meta) {
  6427. var isRoot = meta === undefined || typeof meta === 'string';
  6428. if (isRoot) {
  6429. meta = {
  6430. textures: {},
  6431. images: {}
  6432. };
  6433. }
  6434. var data = {
  6435. metadata: {
  6436. version: 4.5,
  6437. type: 'Material',
  6438. generator: 'Material.toJSON'
  6439. }
  6440. }; // standard Material serialization
  6441. data.uuid = this.uuid;
  6442. data.type = this.type;
  6443. if (this.name !== '') data.name = this.name;
  6444. if (this.color && this.color.isColor) data.color = this.color.getHex();
  6445. if (this.roughness !== undefined) data.roughness = this.roughness;
  6446. if (this.metalness !== undefined) data.metalness = this.metalness;
  6447. if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
  6448. if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
  6449. if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
  6450. if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
  6451. if (this.shininess !== undefined) data.shininess = this.shininess;
  6452. if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
  6453. if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
  6454. if (this.clearcoatMap && this.clearcoatMap.isTexture) {
  6455. data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
  6456. }
  6457. if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
  6458. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
  6459. }
  6460. if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
  6461. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
  6462. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  6463. }
  6464. if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
  6465. if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
  6466. if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
  6467. if (this.lightMap && this.lightMap.isTexture) data.lightMap = this.lightMap.toJSON(meta).uuid;
  6468. if (this.aoMap && this.aoMap.isTexture) {
  6469. data.aoMap = this.aoMap.toJSON(meta).uuid;
  6470. data.aoMapIntensity = this.aoMapIntensity;
  6471. }
  6472. if (this.bumpMap && this.bumpMap.isTexture) {
  6473. data.bumpMap = this.bumpMap.toJSON(meta).uuid;
  6474. data.bumpScale = this.bumpScale;
  6475. }
  6476. if (this.normalMap && this.normalMap.isTexture) {
  6477. data.normalMap = this.normalMap.toJSON(meta).uuid;
  6478. data.normalMapType = this.normalMapType;
  6479. data.normalScale = this.normalScale.toArray();
  6480. }
  6481. if (this.displacementMap && this.displacementMap.isTexture) {
  6482. data.displacementMap = this.displacementMap.toJSON(meta).uuid;
  6483. data.displacementScale = this.displacementScale;
  6484. data.displacementBias = this.displacementBias;
  6485. }
  6486. if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
  6487. if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
  6488. if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
  6489. if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
  6490. if (this.envMap && this.envMap.isTexture) {
  6491. data.envMap = this.envMap.toJSON(meta).uuid;
  6492. data.reflectivity = this.reflectivity; // Scale behind envMap
  6493. data.refractionRatio = this.refractionRatio;
  6494. if (this.combine !== undefined) data.combine = this.combine;
  6495. if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
  6496. }
  6497. if (this.gradientMap && this.gradientMap.isTexture) {
  6498. data.gradientMap = this.gradientMap.toJSON(meta).uuid;
  6499. }
  6500. if (this.size !== undefined) data.size = this.size;
  6501. if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
  6502. if (this.blending !== NormalBlending) data.blending = this.blending;
  6503. if (this.flatShading === true) data.flatShading = this.flatShading;
  6504. if (this.side !== FrontSide) data.side = this.side;
  6505. if (this.vertexColors) data.vertexColors = true;
  6506. if (this.opacity < 1) data.opacity = this.opacity;
  6507. if (this.transparent === true) data.transparent = this.transparent;
  6508. data.depthFunc = this.depthFunc;
  6509. data.depthTest = this.depthTest;
  6510. data.depthWrite = this.depthWrite;
  6511. data.stencilWrite = this.stencilWrite;
  6512. data.stencilWriteMask = this.stencilWriteMask;
  6513. data.stencilFunc = this.stencilFunc;
  6514. data.stencilRef = this.stencilRef;
  6515. data.stencilFuncMask = this.stencilFuncMask;
  6516. data.stencilFail = this.stencilFail;
  6517. data.stencilZFail = this.stencilZFail;
  6518. data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
  6519. if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
  6520. if (this.polygonOffset === true) data.polygonOffset = true;
  6521. if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
  6522. if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
  6523. if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
  6524. if (this.dashSize !== undefined) data.dashSize = this.dashSize;
  6525. if (this.gapSize !== undefined) data.gapSize = this.gapSize;
  6526. if (this.scale !== undefined) data.scale = this.scale;
  6527. if (this.dithering === true) data.dithering = true;
  6528. if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
  6529. if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
  6530. if (this.wireframe === true) data.wireframe = this.wireframe;
  6531. if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
  6532. if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
  6533. if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
  6534. if (this.morphTargets === true) data.morphTargets = true;
  6535. if (this.morphNormals === true) data.morphNormals = true;
  6536. if (this.skinning === true) data.skinning = true;
  6537. if (this.visible === false) data.visible = false;
  6538. if (this.toneMapped === false) data.toneMapped = false;
  6539. if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
  6540. function extractFromCache(cache) {
  6541. var values = [];
  6542. for (var key in cache) {
  6543. var _data = cache[key];
  6544. delete _data.metadata;
  6545. values.push(_data);
  6546. }
  6547. return values;
  6548. }
  6549. if (isRoot) {
  6550. var textures = extractFromCache(meta.textures);
  6551. var images = extractFromCache(meta.images);
  6552. if (textures.length > 0) data.textures = textures;
  6553. if (images.length > 0) data.images = images;
  6554. }
  6555. return data;
  6556. },
  6557. clone: function clone() {
  6558. return new this.constructor().copy(this);
  6559. },
  6560. copy: function copy(source) {
  6561. this.name = source.name;
  6562. this.fog = source.fog;
  6563. this.blending = source.blending;
  6564. this.side = source.side;
  6565. this.flatShading = source.flatShading;
  6566. this.vertexColors = source.vertexColors;
  6567. this.opacity = source.opacity;
  6568. this.transparent = source.transparent;
  6569. this.blendSrc = source.blendSrc;
  6570. this.blendDst = source.blendDst;
  6571. this.blendEquation = source.blendEquation;
  6572. this.blendSrcAlpha = source.blendSrcAlpha;
  6573. this.blendDstAlpha = source.blendDstAlpha;
  6574. this.blendEquationAlpha = source.blendEquationAlpha;
  6575. this.depthFunc = source.depthFunc;
  6576. this.depthTest = source.depthTest;
  6577. this.depthWrite = source.depthWrite;
  6578. this.stencilWriteMask = source.stencilWriteMask;
  6579. this.stencilFunc = source.stencilFunc;
  6580. this.stencilRef = source.stencilRef;
  6581. this.stencilFuncMask = source.stencilFuncMask;
  6582. this.stencilFail = source.stencilFail;
  6583. this.stencilZFail = source.stencilZFail;
  6584. this.stencilZPass = source.stencilZPass;
  6585. this.stencilWrite = source.stencilWrite;
  6586. var srcPlanes = source.clippingPlanes;
  6587. var dstPlanes = null;
  6588. if (srcPlanes !== null) {
  6589. var n = srcPlanes.length;
  6590. dstPlanes = new Array(n);
  6591. for (var i = 0; i !== n; ++i) {
  6592. dstPlanes[i] = srcPlanes[i].clone();
  6593. }
  6594. }
  6595. this.clippingPlanes = dstPlanes;
  6596. this.clipIntersection = source.clipIntersection;
  6597. this.clipShadows = source.clipShadows;
  6598. this.shadowSide = source.shadowSide;
  6599. this.colorWrite = source.colorWrite;
  6600. this.precision = source.precision;
  6601. this.polygonOffset = source.polygonOffset;
  6602. this.polygonOffsetFactor = source.polygonOffsetFactor;
  6603. this.polygonOffsetUnits = source.polygonOffsetUnits;
  6604. this.dithering = source.dithering;
  6605. this.alphaTest = source.alphaTest;
  6606. this.premultipliedAlpha = source.premultipliedAlpha;
  6607. this.visible = source.visible;
  6608. this.toneMapped = source.toneMapped;
  6609. this.userData = JSON.parse(JSON.stringify(source.userData));
  6610. return this;
  6611. },
  6612. dispose: function dispose() {
  6613. this.dispatchEvent({
  6614. type: 'dispose'
  6615. });
  6616. }
  6617. });
  6618. Object.defineProperty(Material.prototype, 'needsUpdate', {
  6619. set: function set(value) {
  6620. if (value === true) this.version++;
  6621. }
  6622. });
  6623. /**
  6624. * parameters = {
  6625. * color: <hex>,
  6626. * opacity: <float>,
  6627. * map: new THREE.Texture( <Image> ),
  6628. *
  6629. * lightMap: new THREE.Texture( <Image> ),
  6630. * lightMapIntensity: <float>
  6631. *
  6632. * aoMap: new THREE.Texture( <Image> ),
  6633. * aoMapIntensity: <float>
  6634. *
  6635. * specularMap: new THREE.Texture( <Image> ),
  6636. *
  6637. * alphaMap: new THREE.Texture( <Image> ),
  6638. *
  6639. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  6640. * combine: THREE.Multiply,
  6641. * reflectivity: <float>,
  6642. * refractionRatio: <float>,
  6643. *
  6644. * depthTest: <bool>,
  6645. * depthWrite: <bool>,
  6646. *
  6647. * wireframe: <boolean>,
  6648. * wireframeLinewidth: <float>,
  6649. *
  6650. * skinning: <bool>,
  6651. * morphTargets: <bool>
  6652. * }
  6653. */
  6654. function MeshBasicMaterial(parameters) {
  6655. Material.call(this);
  6656. this.type = 'MeshBasicMaterial';
  6657. this.color = new Color(0xffffff); // emissive
  6658. this.map = null;
  6659. this.lightMap = null;
  6660. this.lightMapIntensity = 1.0;
  6661. this.aoMap = null;
  6662. this.aoMapIntensity = 1.0;
  6663. this.specularMap = null;
  6664. this.alphaMap = null;
  6665. this.envMap = null;
  6666. this.combine = MultiplyOperation;
  6667. this.reflectivity = 1;
  6668. this.refractionRatio = 0.98;
  6669. this.wireframe = false;
  6670. this.wireframeLinewidth = 1;
  6671. this.wireframeLinecap = 'round';
  6672. this.wireframeLinejoin = 'round';
  6673. this.skinning = false;
  6674. this.morphTargets = false;
  6675. this.setValues(parameters);
  6676. }
  6677. MeshBasicMaterial.prototype = Object.create(Material.prototype);
  6678. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  6679. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  6680. MeshBasicMaterial.prototype.copy = function (source) {
  6681. Material.prototype.copy.call(this, source);
  6682. this.color.copy(source.color);
  6683. this.map = source.map;
  6684. this.lightMap = source.lightMap;
  6685. this.lightMapIntensity = source.lightMapIntensity;
  6686. this.aoMap = source.aoMap;
  6687. this.aoMapIntensity = source.aoMapIntensity;
  6688. this.specularMap = source.specularMap;
  6689. this.alphaMap = source.alphaMap;
  6690. this.envMap = source.envMap;
  6691. this.combine = source.combine;
  6692. this.reflectivity = source.reflectivity;
  6693. this.refractionRatio = source.refractionRatio;
  6694. this.wireframe = source.wireframe;
  6695. this.wireframeLinewidth = source.wireframeLinewidth;
  6696. this.wireframeLinecap = source.wireframeLinecap;
  6697. this.wireframeLinejoin = source.wireframeLinejoin;
  6698. this.skinning = source.skinning;
  6699. this.morphTargets = source.morphTargets;
  6700. return this;
  6701. };
  6702. var _vector$3 = new Vector3();
  6703. var _vector2$1 = new Vector2();
  6704. function BufferAttribute(array, itemSize, normalized) {
  6705. if (Array.isArray(array)) {
  6706. throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
  6707. }
  6708. this.name = '';
  6709. this.array = array;
  6710. this.itemSize = itemSize;
  6711. this.count = array !== undefined ? array.length / itemSize : 0;
  6712. this.normalized = normalized === true;
  6713. this.usage = StaticDrawUsage;
  6714. this.updateRange = {
  6715. offset: 0,
  6716. count: -1
  6717. };
  6718. this.version = 0;
  6719. }
  6720. Object.defineProperty(BufferAttribute.prototype, 'needsUpdate', {
  6721. set: function set(value) {
  6722. if (value === true) this.version++;
  6723. }
  6724. });
  6725. Object.assign(BufferAttribute.prototype, {
  6726. isBufferAttribute: true,
  6727. onUploadCallback: function onUploadCallback() {},
  6728. setUsage: function setUsage(value) {
  6729. this.usage = value;
  6730. return this;
  6731. },
  6732. copy: function copy(source) {
  6733. this.name = source.name;
  6734. this.array = new source.array.constructor(source.array);
  6735. this.itemSize = source.itemSize;
  6736. this.count = source.count;
  6737. this.normalized = source.normalized;
  6738. this.usage = source.usage;
  6739. return this;
  6740. },
  6741. copyAt: function copyAt(index1, attribute, index2) {
  6742. index1 *= this.itemSize;
  6743. index2 *= attribute.itemSize;
  6744. for (var i = 0, l = this.itemSize; i < l; i++) {
  6745. this.array[index1 + i] = attribute.array[index2 + i];
  6746. }
  6747. return this;
  6748. },
  6749. copyArray: function copyArray(array) {
  6750. this.array.set(array);
  6751. return this;
  6752. },
  6753. copyColorsArray: function copyColorsArray(colors) {
  6754. var array = this.array;
  6755. var offset = 0;
  6756. for (var i = 0, l = colors.length; i < l; i++) {
  6757. var color = colors[i];
  6758. if (color === undefined) {
  6759. console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
  6760. color = new Color();
  6761. }
  6762. array[offset++] = color.r;
  6763. array[offset++] = color.g;
  6764. array[offset++] = color.b;
  6765. }
  6766. return this;
  6767. },
  6768. copyVector2sArray: function copyVector2sArray(vectors) {
  6769. var array = this.array;
  6770. var offset = 0;
  6771. for (var i = 0, l = vectors.length; i < l; i++) {
  6772. var vector = vectors[i];
  6773. if (vector === undefined) {
  6774. console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
  6775. vector = new Vector2();
  6776. }
  6777. array[offset++] = vector.x;
  6778. array[offset++] = vector.y;
  6779. }
  6780. return this;
  6781. },
  6782. copyVector3sArray: function copyVector3sArray(vectors) {
  6783. var array = this.array;
  6784. var offset = 0;
  6785. for (var i = 0, l = vectors.length; i < l; i++) {
  6786. var vector = vectors[i];
  6787. if (vector === undefined) {
  6788. console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
  6789. vector = new Vector3();
  6790. }
  6791. array[offset++] = vector.x;
  6792. array[offset++] = vector.y;
  6793. array[offset++] = vector.z;
  6794. }
  6795. return this;
  6796. },
  6797. copyVector4sArray: function copyVector4sArray(vectors) {
  6798. var array = this.array;
  6799. var offset = 0;
  6800. for (var i = 0, l = vectors.length; i < l; i++) {
  6801. var vector = vectors[i];
  6802. if (vector === undefined) {
  6803. console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
  6804. vector = new Vector4();
  6805. }
  6806. array[offset++] = vector.x;
  6807. array[offset++] = vector.y;
  6808. array[offset++] = vector.z;
  6809. array[offset++] = vector.w;
  6810. }
  6811. return this;
  6812. },
  6813. applyMatrix3: function applyMatrix3(m) {
  6814. if (this.itemSize === 2) {
  6815. for (var i = 0, l = this.count; i < l; i++) {
  6816. _vector2$1.fromBufferAttribute(this, i);
  6817. _vector2$1.applyMatrix3(m);
  6818. this.setXY(i, _vector2$1.x, _vector2$1.y);
  6819. }
  6820. } else if (this.itemSize === 3) {
  6821. for (var _i = 0, _l = this.count; _i < _l; _i++) {
  6822. _vector$3.fromBufferAttribute(this, _i);
  6823. _vector$3.applyMatrix3(m);
  6824. this.setXYZ(_i, _vector$3.x, _vector$3.y, _vector$3.z);
  6825. }
  6826. }
  6827. return this;
  6828. },
  6829. applyMatrix4: function applyMatrix4(m) {
  6830. for (var i = 0, l = this.count; i < l; i++) {
  6831. _vector$3.x = this.getX(i);
  6832. _vector$3.y = this.getY(i);
  6833. _vector$3.z = this.getZ(i);
  6834. _vector$3.applyMatrix4(m);
  6835. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6836. }
  6837. return this;
  6838. },
  6839. applyNormalMatrix: function applyNormalMatrix(m) {
  6840. for (var i = 0, l = this.count; i < l; i++) {
  6841. _vector$3.x = this.getX(i);
  6842. _vector$3.y = this.getY(i);
  6843. _vector$3.z = this.getZ(i);
  6844. _vector$3.applyNormalMatrix(m);
  6845. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6846. }
  6847. return this;
  6848. },
  6849. transformDirection: function transformDirection(m) {
  6850. for (var i = 0, l = this.count; i < l; i++) {
  6851. _vector$3.x = this.getX(i);
  6852. _vector$3.y = this.getY(i);
  6853. _vector$3.z = this.getZ(i);
  6854. _vector$3.transformDirection(m);
  6855. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6856. }
  6857. return this;
  6858. },
  6859. set: function set(value, offset) {
  6860. if (offset === void 0) {
  6861. offset = 0;
  6862. }
  6863. this.array.set(value, offset);
  6864. return this;
  6865. },
  6866. getX: function getX(index) {
  6867. return this.array[index * this.itemSize];
  6868. },
  6869. setX: function setX(index, x) {
  6870. this.array[index * this.itemSize] = x;
  6871. return this;
  6872. },
  6873. getY: function getY(index) {
  6874. return this.array[index * this.itemSize + 1];
  6875. },
  6876. setY: function setY(index, y) {
  6877. this.array[index * this.itemSize + 1] = y;
  6878. return this;
  6879. },
  6880. getZ: function getZ(index) {
  6881. return this.array[index * this.itemSize + 2];
  6882. },
  6883. setZ: function setZ(index, z) {
  6884. this.array[index * this.itemSize + 2] = z;
  6885. return this;
  6886. },
  6887. getW: function getW(index) {
  6888. return this.array[index * this.itemSize + 3];
  6889. },
  6890. setW: function setW(index, w) {
  6891. this.array[index * this.itemSize + 3] = w;
  6892. return this;
  6893. },
  6894. setXY: function setXY(index, x, y) {
  6895. index *= this.itemSize;
  6896. this.array[index + 0] = x;
  6897. this.array[index + 1] = y;
  6898. return this;
  6899. },
  6900. setXYZ: function setXYZ(index, x, y, z) {
  6901. index *= this.itemSize;
  6902. this.array[index + 0] = x;
  6903. this.array[index + 1] = y;
  6904. this.array[index + 2] = z;
  6905. return this;
  6906. },
  6907. setXYZW: function setXYZW(index, x, y, z, w) {
  6908. index *= this.itemSize;
  6909. this.array[index + 0] = x;
  6910. this.array[index + 1] = y;
  6911. this.array[index + 2] = z;
  6912. this.array[index + 3] = w;
  6913. return this;
  6914. },
  6915. onUpload: function onUpload(callback) {
  6916. this.onUploadCallback = callback;
  6917. return this;
  6918. },
  6919. clone: function clone() {
  6920. return new this.constructor(this.array, this.itemSize).copy(this);
  6921. },
  6922. toJSON: function toJSON() {
  6923. return {
  6924. itemSize: this.itemSize,
  6925. type: this.array.constructor.name,
  6926. array: Array.prototype.slice.call(this.array),
  6927. normalized: this.normalized
  6928. };
  6929. }
  6930. }); //
  6931. function Int8BufferAttribute(array, itemSize, normalized) {
  6932. BufferAttribute.call(this, new Int8Array(array), itemSize, normalized);
  6933. }
  6934. Int8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6935. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6936. function Uint8BufferAttribute(array, itemSize, normalized) {
  6937. BufferAttribute.call(this, new Uint8Array(array), itemSize, normalized);
  6938. }
  6939. Uint8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6940. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6941. function Uint8ClampedBufferAttribute(array, itemSize, normalized) {
  6942. BufferAttribute.call(this, new Uint8ClampedArray(array), itemSize, normalized);
  6943. }
  6944. Uint8ClampedBufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6945. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6946. function Int16BufferAttribute(array, itemSize, normalized) {
  6947. BufferAttribute.call(this, new Int16Array(array), itemSize, normalized);
  6948. }
  6949. Int16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6950. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6951. function Uint16BufferAttribute(array, itemSize, normalized) {
  6952. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6953. }
  6954. Uint16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6955. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6956. function Int32BufferAttribute(array, itemSize, normalized) {
  6957. BufferAttribute.call(this, new Int32Array(array), itemSize, normalized);
  6958. }
  6959. Int32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6960. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6961. function Uint32BufferAttribute(array, itemSize, normalized) {
  6962. BufferAttribute.call(this, new Uint32Array(array), itemSize, normalized);
  6963. }
  6964. Uint32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6965. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6966. function Float16BufferAttribute(array, itemSize, normalized) {
  6967. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6968. }
  6969. Float16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6970. Float16BufferAttribute.prototype.constructor = Float16BufferAttribute;
  6971. Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
  6972. function Float32BufferAttribute(array, itemSize, normalized) {
  6973. BufferAttribute.call(this, new Float32Array(array), itemSize, normalized);
  6974. }
  6975. Float32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6976. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6977. function Float64BufferAttribute(array, itemSize, normalized) {
  6978. BufferAttribute.call(this, new Float64Array(array), itemSize, normalized);
  6979. }
  6980. Float64BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6981. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; //
  6982. function arrayMax(array) {
  6983. if (array.length === 0) return -Infinity;
  6984. var max = array[0];
  6985. for (var i = 1, l = array.length; i < l; ++i) {
  6986. if (array[i] > max) max = array[i];
  6987. }
  6988. return max;
  6989. }
  6990. var TYPED_ARRAYS = {
  6991. Int8Array: Int8Array,
  6992. Uint8Array: Uint8Array,
  6993. // Workaround for IE11 pre KB2929437. See #11440
  6994. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  6995. Int16Array: Int16Array,
  6996. Uint16Array: Uint16Array,
  6997. Int32Array: Int32Array,
  6998. Uint32Array: Uint32Array,
  6999. Float32Array: Float32Array,
  7000. Float64Array: Float64Array
  7001. };
  7002. function getTypedArray(type, buffer) {
  7003. return new TYPED_ARRAYS[type](buffer);
  7004. }
  7005. var _id = 0;
  7006. var _m1$2 = new Matrix4();
  7007. var _obj = new Object3D();
  7008. var _offset = new Vector3();
  7009. var _box$2 = new Box3();
  7010. var _boxMorphTargets = new Box3();
  7011. var _vector$4 = new Vector3();
  7012. function BufferGeometry() {
  7013. Object.defineProperty(this, 'id', {
  7014. value: _id++
  7015. });
  7016. this.uuid = MathUtils.generateUUID();
  7017. this.name = '';
  7018. this.type = 'BufferGeometry';
  7019. this.index = null;
  7020. this.attributes = {};
  7021. this.morphAttributes = {};
  7022. this.morphTargetsRelative = false;
  7023. this.groups = [];
  7024. this.boundingBox = null;
  7025. this.boundingSphere = null;
  7026. this.drawRange = {
  7027. start: 0,
  7028. count: Infinity
  7029. };
  7030. this.userData = {};
  7031. }
  7032. BufferGeometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  7033. constructor: BufferGeometry,
  7034. isBufferGeometry: true,
  7035. getIndex: function getIndex() {
  7036. return this.index;
  7037. },
  7038. setIndex: function setIndex(index) {
  7039. if (Array.isArray(index)) {
  7040. this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
  7041. } else {
  7042. this.index = index;
  7043. }
  7044. return this;
  7045. },
  7046. getAttribute: function getAttribute(name) {
  7047. return this.attributes[name];
  7048. },
  7049. setAttribute: function setAttribute(name, attribute) {
  7050. this.attributes[name] = attribute;
  7051. return this;
  7052. },
  7053. deleteAttribute: function deleteAttribute(name) {
  7054. delete this.attributes[name];
  7055. return this;
  7056. },
  7057. hasAttribute: function hasAttribute(name) {
  7058. return this.attributes[name] !== undefined;
  7059. },
  7060. addGroup: function addGroup(start, count, materialIndex) {
  7061. if (materialIndex === void 0) {
  7062. materialIndex = 0;
  7063. }
  7064. this.groups.push({
  7065. start: start,
  7066. count: count,
  7067. materialIndex: materialIndex
  7068. });
  7069. },
  7070. clearGroups: function clearGroups() {
  7071. this.groups = [];
  7072. },
  7073. setDrawRange: function setDrawRange(start, count) {
  7074. this.drawRange.start = start;
  7075. this.drawRange.count = count;
  7076. },
  7077. applyMatrix4: function applyMatrix4(matrix) {
  7078. var position = this.attributes.position;
  7079. if (position !== undefined) {
  7080. position.applyMatrix4(matrix);
  7081. position.needsUpdate = true;
  7082. }
  7083. var normal = this.attributes.normal;
  7084. if (normal !== undefined) {
  7085. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  7086. normal.applyNormalMatrix(normalMatrix);
  7087. normal.needsUpdate = true;
  7088. }
  7089. var tangent = this.attributes.tangent;
  7090. if (tangent !== undefined) {
  7091. tangent.transformDirection(matrix);
  7092. tangent.needsUpdate = true;
  7093. }
  7094. if (this.boundingBox !== null) {
  7095. this.computeBoundingBox();
  7096. }
  7097. if (this.boundingSphere !== null) {
  7098. this.computeBoundingSphere();
  7099. }
  7100. return this;
  7101. },
  7102. rotateX: function rotateX(angle) {
  7103. // rotate geometry around world x-axis
  7104. _m1$2.makeRotationX(angle);
  7105. this.applyMatrix4(_m1$2);
  7106. return this;
  7107. },
  7108. rotateY: function rotateY(angle) {
  7109. // rotate geometry around world y-axis
  7110. _m1$2.makeRotationY(angle);
  7111. this.applyMatrix4(_m1$2);
  7112. return this;
  7113. },
  7114. rotateZ: function rotateZ(angle) {
  7115. // rotate geometry around world z-axis
  7116. _m1$2.makeRotationZ(angle);
  7117. this.applyMatrix4(_m1$2);
  7118. return this;
  7119. },
  7120. translate: function translate(x, y, z) {
  7121. // translate geometry
  7122. _m1$2.makeTranslation(x, y, z);
  7123. this.applyMatrix4(_m1$2);
  7124. return this;
  7125. },
  7126. scale: function scale(x, y, z) {
  7127. // scale geometry
  7128. _m1$2.makeScale(x, y, z);
  7129. this.applyMatrix4(_m1$2);
  7130. return this;
  7131. },
  7132. lookAt: function lookAt(vector) {
  7133. _obj.lookAt(vector);
  7134. _obj.updateMatrix();
  7135. this.applyMatrix4(_obj.matrix);
  7136. return this;
  7137. },
  7138. center: function center() {
  7139. this.computeBoundingBox();
  7140. this.boundingBox.getCenter(_offset).negate();
  7141. this.translate(_offset.x, _offset.y, _offset.z);
  7142. return this;
  7143. },
  7144. setFromPoints: function setFromPoints(points) {
  7145. var position = [];
  7146. for (var i = 0, l = points.length; i < l; i++) {
  7147. var point = points[i];
  7148. position.push(point.x, point.y, point.z || 0);
  7149. }
  7150. this.setAttribute('position', new Float32BufferAttribute(position, 3));
  7151. return this;
  7152. },
  7153. computeBoundingBox: function computeBoundingBox() {
  7154. if (this.boundingBox === null) {
  7155. this.boundingBox = new Box3();
  7156. }
  7157. var position = this.attributes.position;
  7158. var morphAttributesPosition = this.morphAttributes.position;
  7159. if (position && position.isGLBufferAttribute) {
  7160. console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this);
  7161. this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
  7162. return;
  7163. }
  7164. if (position !== undefined) {
  7165. this.boundingBox.setFromBufferAttribute(position); // process morph attributes if present
  7166. if (morphAttributesPosition) {
  7167. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  7168. var morphAttribute = morphAttributesPosition[i];
  7169. _box$2.setFromBufferAttribute(morphAttribute);
  7170. if (this.morphTargetsRelative) {
  7171. _vector$4.addVectors(this.boundingBox.min, _box$2.min);
  7172. this.boundingBox.expandByPoint(_vector$4);
  7173. _vector$4.addVectors(this.boundingBox.max, _box$2.max);
  7174. this.boundingBox.expandByPoint(_vector$4);
  7175. } else {
  7176. this.boundingBox.expandByPoint(_box$2.min);
  7177. this.boundingBox.expandByPoint(_box$2.max);
  7178. }
  7179. }
  7180. }
  7181. } else {
  7182. this.boundingBox.makeEmpty();
  7183. }
  7184. if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
  7185. console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
  7186. }
  7187. },
  7188. computeBoundingSphere: function computeBoundingSphere() {
  7189. if (this.boundingSphere === null) {
  7190. this.boundingSphere = new Sphere();
  7191. }
  7192. var position = this.attributes.position;
  7193. var morphAttributesPosition = this.morphAttributes.position;
  7194. if (position && position.isGLBufferAttribute) {
  7195. console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this);
  7196. this.boundingSphere.set(new Vector3(), Infinity);
  7197. return;
  7198. }
  7199. if (position) {
  7200. // first, find the center of the bounding sphere
  7201. var center = this.boundingSphere.center;
  7202. _box$2.setFromBufferAttribute(position); // process morph attributes if present
  7203. if (morphAttributesPosition) {
  7204. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  7205. var morphAttribute = morphAttributesPosition[i];
  7206. _boxMorphTargets.setFromBufferAttribute(morphAttribute);
  7207. if (this.morphTargetsRelative) {
  7208. _vector$4.addVectors(_box$2.min, _boxMorphTargets.min);
  7209. _box$2.expandByPoint(_vector$4);
  7210. _vector$4.addVectors(_box$2.max, _boxMorphTargets.max);
  7211. _box$2.expandByPoint(_vector$4);
  7212. } else {
  7213. _box$2.expandByPoint(_boxMorphTargets.min);
  7214. _box$2.expandByPoint(_boxMorphTargets.max);
  7215. }
  7216. }
  7217. }
  7218. _box$2.getCenter(center); // second, try to find a boundingSphere with a radius smaller than the
  7219. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  7220. var maxRadiusSq = 0;
  7221. for (var _i = 0, _il = position.count; _i < _il; _i++) {
  7222. _vector$4.fromBufferAttribute(position, _i);
  7223. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  7224. } // process morph attributes if present
  7225. if (morphAttributesPosition) {
  7226. for (var _i2 = 0, _il2 = morphAttributesPosition.length; _i2 < _il2; _i2++) {
  7227. var _morphAttribute = morphAttributesPosition[_i2];
  7228. var morphTargetsRelative = this.morphTargetsRelative;
  7229. for (var j = 0, jl = _morphAttribute.count; j < jl; j++) {
  7230. _vector$4.fromBufferAttribute(_morphAttribute, j);
  7231. if (morphTargetsRelative) {
  7232. _offset.fromBufferAttribute(position, j);
  7233. _vector$4.add(_offset);
  7234. }
  7235. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  7236. }
  7237. }
  7238. }
  7239. this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
  7240. if (isNaN(this.boundingSphere.radius)) {
  7241. console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
  7242. }
  7243. }
  7244. },
  7245. computeFaceNormals: function computeFaceNormals() {// backwards compatibility
  7246. },
  7247. computeTangents: function computeTangents() {
  7248. var index = this.index;
  7249. var attributes = this.attributes; // based on http://www.terathon.com/code/tangent.html
  7250. // (per vertex tangents)
  7251. if (index === null || attributes.position === undefined || attributes.normal === undefined || attributes.uv === undefined) {
  7252. console.error('THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)');
  7253. return;
  7254. }
  7255. var indices = index.array;
  7256. var positions = attributes.position.array;
  7257. var normals = attributes.normal.array;
  7258. var uvs = attributes.uv.array;
  7259. var nVertices = positions.length / 3;
  7260. if (attributes.tangent === undefined) {
  7261. this.setAttribute('tangent', new BufferAttribute(new Float32Array(4 * nVertices), 4));
  7262. }
  7263. var tangents = attributes.tangent.array;
  7264. var tan1 = [],
  7265. tan2 = [];
  7266. for (var i = 0; i < nVertices; i++) {
  7267. tan1[i] = new Vector3();
  7268. tan2[i] = new Vector3();
  7269. }
  7270. var vA = new Vector3(),
  7271. vB = new Vector3(),
  7272. vC = new Vector3(),
  7273. uvA = new Vector2(),
  7274. uvB = new Vector2(),
  7275. uvC = new Vector2(),
  7276. sdir = new Vector3(),
  7277. tdir = new Vector3();
  7278. function handleTriangle(a, b, c) {
  7279. vA.fromArray(positions, a * 3);
  7280. vB.fromArray(positions, b * 3);
  7281. vC.fromArray(positions, c * 3);
  7282. uvA.fromArray(uvs, a * 2);
  7283. uvB.fromArray(uvs, b * 2);
  7284. uvC.fromArray(uvs, c * 2);
  7285. vB.sub(vA);
  7286. vC.sub(vA);
  7287. uvB.sub(uvA);
  7288. uvC.sub(uvA);
  7289. var r = 1.0 / (uvB.x * uvC.y - uvC.x * uvB.y); // silently ignore degenerate uv triangles having coincident or colinear vertices
  7290. if (!isFinite(r)) return;
  7291. sdir.copy(vB).multiplyScalar(uvC.y).addScaledVector(vC, -uvB.y).multiplyScalar(r);
  7292. tdir.copy(vC).multiplyScalar(uvB.x).addScaledVector(vB, -uvC.x).multiplyScalar(r);
  7293. tan1[a].add(sdir);
  7294. tan1[b].add(sdir);
  7295. tan1[c].add(sdir);
  7296. tan2[a].add(tdir);
  7297. tan2[b].add(tdir);
  7298. tan2[c].add(tdir);
  7299. }
  7300. var groups = this.groups;
  7301. if (groups.length === 0) {
  7302. groups = [{
  7303. start: 0,
  7304. count: indices.length
  7305. }];
  7306. }
  7307. for (var _i3 = 0, il = groups.length; _i3 < il; ++_i3) {
  7308. var group = groups[_i3];
  7309. var start = group.start;
  7310. var count = group.count;
  7311. for (var j = start, jl = start + count; j < jl; j += 3) {
  7312. handleTriangle(indices[j + 0], indices[j + 1], indices[j + 2]);
  7313. }
  7314. }
  7315. var tmp = new Vector3(),
  7316. tmp2 = new Vector3();
  7317. var n = new Vector3(),
  7318. n2 = new Vector3();
  7319. function handleVertex(v) {
  7320. n.fromArray(normals, v * 3);
  7321. n2.copy(n);
  7322. var t = tan1[v]; // Gram-Schmidt orthogonalize
  7323. tmp.copy(t);
  7324. tmp.sub(n.multiplyScalar(n.dot(t))).normalize(); // Calculate handedness
  7325. tmp2.crossVectors(n2, t);
  7326. var test = tmp2.dot(tan2[v]);
  7327. var w = test < 0.0 ? -1.0 : 1.0;
  7328. tangents[v * 4] = tmp.x;
  7329. tangents[v * 4 + 1] = tmp.y;
  7330. tangents[v * 4 + 2] = tmp.z;
  7331. tangents[v * 4 + 3] = w;
  7332. }
  7333. for (var _i4 = 0, _il3 = groups.length; _i4 < _il3; ++_i4) {
  7334. var _group = groups[_i4];
  7335. var _start = _group.start;
  7336. var _count = _group.count;
  7337. for (var _j = _start, _jl = _start + _count; _j < _jl; _j += 3) {
  7338. handleVertex(indices[_j + 0]);
  7339. handleVertex(indices[_j + 1]);
  7340. handleVertex(indices[_j + 2]);
  7341. }
  7342. }
  7343. },
  7344. computeVertexNormals: function computeVertexNormals() {
  7345. var index = this.index;
  7346. var positionAttribute = this.getAttribute('position');
  7347. if (positionAttribute !== undefined) {
  7348. var normalAttribute = this.getAttribute('normal');
  7349. if (normalAttribute === undefined) {
  7350. normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
  7351. this.setAttribute('normal', normalAttribute);
  7352. } else {
  7353. // reset existing normals to zero
  7354. for (var i = 0, il = normalAttribute.count; i < il; i++) {
  7355. normalAttribute.setXYZ(i, 0, 0, 0);
  7356. }
  7357. }
  7358. var pA = new Vector3(),
  7359. pB = new Vector3(),
  7360. pC = new Vector3();
  7361. var nA = new Vector3(),
  7362. nB = new Vector3(),
  7363. nC = new Vector3();
  7364. var cb = new Vector3(),
  7365. ab = new Vector3(); // indexed elements
  7366. if (index) {
  7367. for (var _i5 = 0, _il4 = index.count; _i5 < _il4; _i5 += 3) {
  7368. var vA = index.getX(_i5 + 0);
  7369. var vB = index.getX(_i5 + 1);
  7370. var vC = index.getX(_i5 + 2);
  7371. pA.fromBufferAttribute(positionAttribute, vA);
  7372. pB.fromBufferAttribute(positionAttribute, vB);
  7373. pC.fromBufferAttribute(positionAttribute, vC);
  7374. cb.subVectors(pC, pB);
  7375. ab.subVectors(pA, pB);
  7376. cb.cross(ab);
  7377. nA.fromBufferAttribute(normalAttribute, vA);
  7378. nB.fromBufferAttribute(normalAttribute, vB);
  7379. nC.fromBufferAttribute(normalAttribute, vC);
  7380. nA.add(cb);
  7381. nB.add(cb);
  7382. nC.add(cb);
  7383. normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
  7384. normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
  7385. normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
  7386. }
  7387. } else {
  7388. // non-indexed elements (unconnected triangle soup)
  7389. for (var _i6 = 0, _il5 = positionAttribute.count; _i6 < _il5; _i6 += 3) {
  7390. pA.fromBufferAttribute(positionAttribute, _i6 + 0);
  7391. pB.fromBufferAttribute(positionAttribute, _i6 + 1);
  7392. pC.fromBufferAttribute(positionAttribute, _i6 + 2);
  7393. cb.subVectors(pC, pB);
  7394. ab.subVectors(pA, pB);
  7395. cb.cross(ab);
  7396. normalAttribute.setXYZ(_i6 + 0, cb.x, cb.y, cb.z);
  7397. normalAttribute.setXYZ(_i6 + 1, cb.x, cb.y, cb.z);
  7398. normalAttribute.setXYZ(_i6 + 2, cb.x, cb.y, cb.z);
  7399. }
  7400. }
  7401. this.normalizeNormals();
  7402. normalAttribute.needsUpdate = true;
  7403. }
  7404. },
  7405. merge: function merge(geometry, offset) {
  7406. if (!(geometry && geometry.isBufferGeometry)) {
  7407. console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
  7408. return;
  7409. }
  7410. if (offset === undefined) {
  7411. offset = 0;
  7412. console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');
  7413. }
  7414. var attributes = this.attributes;
  7415. for (var key in attributes) {
  7416. if (geometry.attributes[key] === undefined) continue;
  7417. var attribute1 = attributes[key];
  7418. var attributeArray1 = attribute1.array;
  7419. var attribute2 = geometry.attributes[key];
  7420. var attributeArray2 = attribute2.array;
  7421. var attributeOffset = attribute2.itemSize * offset;
  7422. var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
  7423. for (var i = 0, j = attributeOffset; i < length; i++, j++) {
  7424. attributeArray1[j] = attributeArray2[i];
  7425. }
  7426. }
  7427. return this;
  7428. },
  7429. normalizeNormals: function normalizeNormals() {
  7430. var normals = this.attributes.normal;
  7431. for (var i = 0, il = normals.count; i < il; i++) {
  7432. _vector$4.fromBufferAttribute(normals, i);
  7433. _vector$4.normalize();
  7434. normals.setXYZ(i, _vector$4.x, _vector$4.y, _vector$4.z);
  7435. }
  7436. },
  7437. toNonIndexed: function toNonIndexed() {
  7438. function convertBufferAttribute(attribute, indices) {
  7439. var array = attribute.array;
  7440. var itemSize = attribute.itemSize;
  7441. var normalized = attribute.normalized;
  7442. var array2 = new array.constructor(indices.length * itemSize);
  7443. var index = 0,
  7444. index2 = 0;
  7445. for (var i = 0, l = indices.length; i < l; i++) {
  7446. index = indices[i] * itemSize;
  7447. for (var j = 0; j < itemSize; j++) {
  7448. array2[index2++] = array[index++];
  7449. }
  7450. }
  7451. return new BufferAttribute(array2, itemSize, normalized);
  7452. } //
  7453. if (this.index === null) {
  7454. console.warn('THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.');
  7455. return this;
  7456. }
  7457. var geometry2 = new BufferGeometry();
  7458. var indices = this.index.array;
  7459. var attributes = this.attributes; // attributes
  7460. for (var name in attributes) {
  7461. var attribute = attributes[name];
  7462. var newAttribute = convertBufferAttribute(attribute, indices);
  7463. geometry2.setAttribute(name, newAttribute);
  7464. } // morph attributes
  7465. var morphAttributes = this.morphAttributes;
  7466. for (var _name in morphAttributes) {
  7467. var morphArray = [];
  7468. var morphAttribute = morphAttributes[_name]; // morphAttribute: array of Float32BufferAttributes
  7469. for (var i = 0, il = morphAttribute.length; i < il; i++) {
  7470. var _attribute = morphAttribute[i];
  7471. var _newAttribute = convertBufferAttribute(_attribute, indices);
  7472. morphArray.push(_newAttribute);
  7473. }
  7474. geometry2.morphAttributes[_name] = morphArray;
  7475. }
  7476. geometry2.morphTargetsRelative = this.morphTargetsRelative; // groups
  7477. var groups = this.groups;
  7478. for (var _i7 = 0, l = groups.length; _i7 < l; _i7++) {
  7479. var group = groups[_i7];
  7480. geometry2.addGroup(group.start, group.count, group.materialIndex);
  7481. }
  7482. return geometry2;
  7483. },
  7484. toJSON: function toJSON() {
  7485. var data = {
  7486. metadata: {
  7487. version: 4.5,
  7488. type: 'BufferGeometry',
  7489. generator: 'BufferGeometry.toJSON'
  7490. }
  7491. }; // standard BufferGeometry serialization
  7492. data.uuid = this.uuid;
  7493. data.type = this.type;
  7494. if (this.name !== '') data.name = this.name;
  7495. if (Object.keys(this.userData).length > 0) data.userData = this.userData;
  7496. if (this.parameters !== undefined) {
  7497. var parameters = this.parameters;
  7498. for (var key in parameters) {
  7499. if (parameters[key] !== undefined) data[key] = parameters[key];
  7500. }
  7501. return data;
  7502. }
  7503. data.data = {
  7504. attributes: {}
  7505. };
  7506. var index = this.index;
  7507. if (index !== null) {
  7508. data.data.index = {
  7509. type: index.array.constructor.name,
  7510. array: Array.prototype.slice.call(index.array)
  7511. };
  7512. }
  7513. var attributes = this.attributes;
  7514. for (var _key in attributes) {
  7515. var attribute = attributes[_key];
  7516. var attributeData = attribute.toJSON(data.data);
  7517. if (attribute.name !== '') attributeData.name = attribute.name;
  7518. data.data.attributes[_key] = attributeData;
  7519. }
  7520. var morphAttributes = {};
  7521. var hasMorphAttributes = false;
  7522. for (var _key2 in this.morphAttributes) {
  7523. var attributeArray = this.morphAttributes[_key2];
  7524. var array = [];
  7525. for (var i = 0, il = attributeArray.length; i < il; i++) {
  7526. var _attribute2 = attributeArray[i];
  7527. var _attributeData = _attribute2.toJSON(data.data);
  7528. if (_attribute2.name !== '') _attributeData.name = _attribute2.name;
  7529. array.push(_attributeData);
  7530. }
  7531. if (array.length > 0) {
  7532. morphAttributes[_key2] = array;
  7533. hasMorphAttributes = true;
  7534. }
  7535. }
  7536. if (hasMorphAttributes) {
  7537. data.data.morphAttributes = morphAttributes;
  7538. data.data.morphTargetsRelative = this.morphTargetsRelative;
  7539. }
  7540. var groups = this.groups;
  7541. if (groups.length > 0) {
  7542. data.data.groups = JSON.parse(JSON.stringify(groups));
  7543. }
  7544. var boundingSphere = this.boundingSphere;
  7545. if (boundingSphere !== null) {
  7546. data.data.boundingSphere = {
  7547. center: boundingSphere.center.toArray(),
  7548. radius: boundingSphere.radius
  7549. };
  7550. }
  7551. return data;
  7552. },
  7553. clone: function clone() {
  7554. /*
  7555. // Handle primitives
  7556. const parameters = this.parameters;
  7557. if ( parameters !== undefined ) {
  7558. const values = [];
  7559. for ( const key in parameters ) {
  7560. values.push( parameters[ key ] );
  7561. }
  7562. const geometry = Object.create( this.constructor.prototype );
  7563. this.constructor.apply( geometry, values );
  7564. return geometry;
  7565. }
  7566. return new this.constructor().copy( this );
  7567. */
  7568. return new BufferGeometry().copy(this);
  7569. },
  7570. copy: function copy(source) {
  7571. // reset
  7572. this.index = null;
  7573. this.attributes = {};
  7574. this.morphAttributes = {};
  7575. this.groups = [];
  7576. this.boundingBox = null;
  7577. this.boundingSphere = null; // used for storing cloned, shared data
  7578. var data = {}; // name
  7579. this.name = source.name; // index
  7580. var index = source.index;
  7581. if (index !== null) {
  7582. this.setIndex(index.clone(data));
  7583. } // attributes
  7584. var attributes = source.attributes;
  7585. for (var name in attributes) {
  7586. var attribute = attributes[name];
  7587. this.setAttribute(name, attribute.clone(data));
  7588. } // morph attributes
  7589. var morphAttributes = source.morphAttributes;
  7590. for (var _name2 in morphAttributes) {
  7591. var array = [];
  7592. var morphAttribute = morphAttributes[_name2]; // morphAttribute: array of Float32BufferAttributes
  7593. for (var i = 0, l = morphAttribute.length; i < l; i++) {
  7594. array.push(morphAttribute[i].clone(data));
  7595. }
  7596. this.morphAttributes[_name2] = array;
  7597. }
  7598. this.morphTargetsRelative = source.morphTargetsRelative; // groups
  7599. var groups = source.groups;
  7600. for (var _i8 = 0, _l = groups.length; _i8 < _l; _i8++) {
  7601. var group = groups[_i8];
  7602. this.addGroup(group.start, group.count, group.materialIndex);
  7603. } // bounding box
  7604. var boundingBox = source.boundingBox;
  7605. if (boundingBox !== null) {
  7606. this.boundingBox = boundingBox.clone();
  7607. } // bounding sphere
  7608. var boundingSphere = source.boundingSphere;
  7609. if (boundingSphere !== null) {
  7610. this.boundingSphere = boundingSphere.clone();
  7611. } // draw range
  7612. this.drawRange.start = source.drawRange.start;
  7613. this.drawRange.count = source.drawRange.count; // user data
  7614. this.userData = source.userData;
  7615. return this;
  7616. },
  7617. dispose: function dispose() {
  7618. this.dispatchEvent({
  7619. type: 'dispose'
  7620. });
  7621. }
  7622. });
  7623. var _inverseMatrix = new Matrix4();
  7624. var _ray = new Ray();
  7625. var _sphere = new Sphere();
  7626. var _vA = new Vector3();
  7627. var _vB = new Vector3();
  7628. var _vC = new Vector3();
  7629. var _tempA = new Vector3();
  7630. var _tempB = new Vector3();
  7631. var _tempC = new Vector3();
  7632. var _morphA = new Vector3();
  7633. var _morphB = new Vector3();
  7634. var _morphC = new Vector3();
  7635. var _uvA = new Vector2();
  7636. var _uvB = new Vector2();
  7637. var _uvC = new Vector2();
  7638. var _intersectionPoint = new Vector3();
  7639. var _intersectionPointWorld = new Vector3();
  7640. function Mesh(geometry, material) {
  7641. if (geometry === void 0) {
  7642. geometry = new BufferGeometry();
  7643. }
  7644. if (material === void 0) {
  7645. material = new MeshBasicMaterial();
  7646. }
  7647. Object3D.call(this);
  7648. this.type = 'Mesh';
  7649. this.geometry = geometry;
  7650. this.material = material;
  7651. this.updateMorphTargets();
  7652. }
  7653. Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
  7654. constructor: Mesh,
  7655. isMesh: true,
  7656. copy: function copy(source) {
  7657. Object3D.prototype.copy.call(this, source);
  7658. if (source.morphTargetInfluences !== undefined) {
  7659. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  7660. }
  7661. if (source.morphTargetDictionary !== undefined) {
  7662. this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
  7663. }
  7664. this.material = source.material;
  7665. this.geometry = source.geometry;
  7666. return this;
  7667. },
  7668. updateMorphTargets: function updateMorphTargets() {
  7669. var geometry = this.geometry;
  7670. if (geometry.isBufferGeometry) {
  7671. var morphAttributes = geometry.morphAttributes;
  7672. var keys = Object.keys(morphAttributes);
  7673. if (keys.length > 0) {
  7674. var morphAttribute = morphAttributes[keys[0]];
  7675. if (morphAttribute !== undefined) {
  7676. this.morphTargetInfluences = [];
  7677. this.morphTargetDictionary = {};
  7678. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  7679. var name = morphAttribute[m].name || String(m);
  7680. this.morphTargetInfluences.push(0);
  7681. this.morphTargetDictionary[name] = m;
  7682. }
  7683. }
  7684. }
  7685. } else {
  7686. var morphTargets = geometry.morphTargets;
  7687. if (morphTargets !== undefined && morphTargets.length > 0) {
  7688. console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7689. }
  7690. }
  7691. },
  7692. raycast: function raycast(raycaster, intersects) {
  7693. var geometry = this.geometry;
  7694. var material = this.material;
  7695. var matrixWorld = this.matrixWorld;
  7696. if (material === undefined) return; // Checking boundingSphere distance to ray
  7697. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7698. _sphere.copy(geometry.boundingSphere);
  7699. _sphere.applyMatrix4(matrixWorld);
  7700. if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
  7701. _inverseMatrix.copy(matrixWorld).invert();
  7702. _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
  7703. if (geometry.boundingBox !== null) {
  7704. if (_ray.intersectsBox(geometry.boundingBox) === false) return;
  7705. }
  7706. var intersection;
  7707. if (geometry.isBufferGeometry) {
  7708. var index = geometry.index;
  7709. var position = geometry.attributes.position;
  7710. var morphPosition = geometry.morphAttributes.position;
  7711. var morphTargetsRelative = geometry.morphTargetsRelative;
  7712. var uv = geometry.attributes.uv;
  7713. var uv2 = geometry.attributes.uv2;
  7714. var groups = geometry.groups;
  7715. var drawRange = geometry.drawRange;
  7716. if (index !== null) {
  7717. // indexed buffer geometry
  7718. if (Array.isArray(material)) {
  7719. for (var i = 0, il = groups.length; i < il; i++) {
  7720. var group = groups[i];
  7721. var groupMaterial = material[group.materialIndex];
  7722. var start = Math.max(group.start, drawRange.start);
  7723. var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
  7724. for (var j = start, jl = end; j < jl; j += 3) {
  7725. var a = index.getX(j);
  7726. var b = index.getX(j + 1);
  7727. var c = index.getX(j + 2);
  7728. intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
  7729. if (intersection) {
  7730. intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
  7731. intersection.face.materialIndex = group.materialIndex;
  7732. intersects.push(intersection);
  7733. }
  7734. }
  7735. }
  7736. } else {
  7737. var _start = Math.max(0, drawRange.start);
  7738. var _end = Math.min(index.count, drawRange.start + drawRange.count);
  7739. for (var _i = _start, _il = _end; _i < _il; _i += 3) {
  7740. var _a = index.getX(_i);
  7741. var _b = index.getX(_i + 1);
  7742. var _c = index.getX(_i + 2);
  7743. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
  7744. if (intersection) {
  7745. intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
  7746. intersects.push(intersection);
  7747. }
  7748. }
  7749. }
  7750. } else if (position !== undefined) {
  7751. // non-indexed buffer geometry
  7752. if (Array.isArray(material)) {
  7753. for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
  7754. var _group = groups[_i2];
  7755. var _groupMaterial = material[_group.materialIndex];
  7756. var _start2 = Math.max(_group.start, drawRange.start);
  7757. var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
  7758. for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
  7759. var _a2 = _j;
  7760. var _b2 = _j + 1;
  7761. var _c2 = _j + 2;
  7762. intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
  7763. if (intersection) {
  7764. intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
  7765. intersection.face.materialIndex = _group.materialIndex;
  7766. intersects.push(intersection);
  7767. }
  7768. }
  7769. }
  7770. } else {
  7771. var _start3 = Math.max(0, drawRange.start);
  7772. var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
  7773. for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
  7774. var _a3 = _i3;
  7775. var _b3 = _i3 + 1;
  7776. var _c3 = _i3 + 2;
  7777. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
  7778. if (intersection) {
  7779. intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
  7780. intersects.push(intersection);
  7781. }
  7782. }
  7783. }
  7784. }
  7785. } else if (geometry.isGeometry) {
  7786. console.error('THREE.Mesh.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7787. }
  7788. }
  7789. });
  7790. function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
  7791. var intersect;
  7792. if (material.side === BackSide) {
  7793. intersect = ray.intersectTriangle(pC, pB, pA, true, point);
  7794. } else {
  7795. intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
  7796. }
  7797. if (intersect === null) return null;
  7798. _intersectionPointWorld.copy(point);
  7799. _intersectionPointWorld.applyMatrix4(object.matrixWorld);
  7800. var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
  7801. if (distance < raycaster.near || distance > raycaster.far) return null;
  7802. return {
  7803. distance: distance,
  7804. point: _intersectionPointWorld.clone(),
  7805. object: object
  7806. };
  7807. }
  7808. function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
  7809. _vA.fromBufferAttribute(position, a);
  7810. _vB.fromBufferAttribute(position, b);
  7811. _vC.fromBufferAttribute(position, c);
  7812. var morphInfluences = object.morphTargetInfluences;
  7813. if (material.morphTargets && morphPosition && morphInfluences) {
  7814. _morphA.set(0, 0, 0);
  7815. _morphB.set(0, 0, 0);
  7816. _morphC.set(0, 0, 0);
  7817. for (var i = 0, il = morphPosition.length; i < il; i++) {
  7818. var influence = morphInfluences[i];
  7819. var morphAttribute = morphPosition[i];
  7820. if (influence === 0) continue;
  7821. _tempA.fromBufferAttribute(morphAttribute, a);
  7822. _tempB.fromBufferAttribute(morphAttribute, b);
  7823. _tempC.fromBufferAttribute(morphAttribute, c);
  7824. if (morphTargetsRelative) {
  7825. _morphA.addScaledVector(_tempA, influence);
  7826. _morphB.addScaledVector(_tempB, influence);
  7827. _morphC.addScaledVector(_tempC, influence);
  7828. } else {
  7829. _morphA.addScaledVector(_tempA.sub(_vA), influence);
  7830. _morphB.addScaledVector(_tempB.sub(_vB), influence);
  7831. _morphC.addScaledVector(_tempC.sub(_vC), influence);
  7832. }
  7833. }
  7834. _vA.add(_morphA);
  7835. _vB.add(_morphB);
  7836. _vC.add(_morphC);
  7837. }
  7838. if (object.isSkinnedMesh) {
  7839. object.boneTransform(a, _vA);
  7840. object.boneTransform(b, _vB);
  7841. object.boneTransform(c, _vC);
  7842. }
  7843. var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
  7844. if (intersection) {
  7845. if (uv) {
  7846. _uvA.fromBufferAttribute(uv, a);
  7847. _uvB.fromBufferAttribute(uv, b);
  7848. _uvC.fromBufferAttribute(uv, c);
  7849. intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7850. }
  7851. if (uv2) {
  7852. _uvA.fromBufferAttribute(uv2, a);
  7853. _uvB.fromBufferAttribute(uv2, b);
  7854. _uvC.fromBufferAttribute(uv2, c);
  7855. intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7856. }
  7857. var face = new Face3(a, b, c);
  7858. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7859. intersection.face = face;
  7860. }
  7861. return intersection;
  7862. }
  7863. var BoxGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7864. _inheritsLoose(BoxGeometry, _BufferGeometry);
  7865. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7866. var _this;
  7867. if (width === void 0) {
  7868. width = 1;
  7869. }
  7870. if (height === void 0) {
  7871. height = 1;
  7872. }
  7873. if (depth === void 0) {
  7874. depth = 1;
  7875. }
  7876. if (widthSegments === void 0) {
  7877. widthSegments = 1;
  7878. }
  7879. if (heightSegments === void 0) {
  7880. heightSegments = 1;
  7881. }
  7882. if (depthSegments === void 0) {
  7883. depthSegments = 1;
  7884. }
  7885. _this = _BufferGeometry.call(this) || this;
  7886. _this.type = 'BoxGeometry';
  7887. _this.parameters = {
  7888. width: width,
  7889. height: height,
  7890. depth: depth,
  7891. widthSegments: widthSegments,
  7892. heightSegments: heightSegments,
  7893. depthSegments: depthSegments
  7894. };
  7895. var scope = _assertThisInitialized(_this); // segments
  7896. widthSegments = Math.floor(widthSegments);
  7897. heightSegments = Math.floor(heightSegments);
  7898. depthSegments = Math.floor(depthSegments); // buffers
  7899. var indices = [];
  7900. var vertices = [];
  7901. var normals = [];
  7902. var uvs = []; // helper variables
  7903. var numberOfVertices = 0;
  7904. var groupStart = 0; // build each side of the box geometry
  7905. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7906. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7907. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7908. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7909. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7910. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7911. // build geometry
  7912. _this.setIndex(indices);
  7913. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7914. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7915. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7916. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7917. var segmentWidth = width / gridX;
  7918. var segmentHeight = height / gridY;
  7919. var widthHalf = width / 2;
  7920. var heightHalf = height / 2;
  7921. var depthHalf = depth / 2;
  7922. var gridX1 = gridX + 1;
  7923. var gridY1 = gridY + 1;
  7924. var vertexCounter = 0;
  7925. var groupCount = 0;
  7926. var vector = new Vector3(); // generate vertices, normals and uvs
  7927. for (var iy = 0; iy < gridY1; iy++) {
  7928. var y = iy * segmentHeight - heightHalf;
  7929. for (var ix = 0; ix < gridX1; ix++) {
  7930. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7931. vector[u] = x * udir;
  7932. vector[v] = y * vdir;
  7933. vector[w] = depthHalf; // now apply vector to vertex buffer
  7934. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7935. vector[u] = 0;
  7936. vector[v] = 0;
  7937. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7938. normals.push(vector.x, vector.y, vector.z); // uvs
  7939. uvs.push(ix / gridX);
  7940. uvs.push(1 - iy / gridY); // counters
  7941. vertexCounter += 1;
  7942. }
  7943. } // indices
  7944. // 1. you need three indices to draw a single face
  7945. // 2. a single segment consists of two faces
  7946. // 3. so we need to generate six (2*3) indices per segment
  7947. for (var _iy = 0; _iy < gridY; _iy++) {
  7948. for (var _ix = 0; _ix < gridX; _ix++) {
  7949. var a = numberOfVertices + _ix + gridX1 * _iy;
  7950. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7951. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7952. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7953. indices.push(a, b, d);
  7954. indices.push(b, c, d); // increase counter
  7955. groupCount += 6;
  7956. }
  7957. } // add a group to the geometry. this will ensure multi material support
  7958. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7959. groupStart += groupCount; // update total number of vertices
  7960. numberOfVertices += vertexCounter;
  7961. }
  7962. return _this;
  7963. }
  7964. return BoxGeometry;
  7965. }(BufferGeometry);
  7966. /**
  7967. * Uniform Utilities
  7968. */
  7969. function cloneUniforms(src) {
  7970. var dst = {};
  7971. for (var u in src) {
  7972. dst[u] = {};
  7973. for (var p in src[u]) {
  7974. var property = src[u][p];
  7975. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture)) {
  7976. dst[u][p] = property.clone();
  7977. } else if (Array.isArray(property)) {
  7978. dst[u][p] = property.slice();
  7979. } else {
  7980. dst[u][p] = property;
  7981. }
  7982. }
  7983. }
  7984. return dst;
  7985. }
  7986. function mergeUniforms(uniforms) {
  7987. var merged = {};
  7988. for (var u = 0; u < uniforms.length; u++) {
  7989. var tmp = cloneUniforms(uniforms[u]);
  7990. for (var p in tmp) {
  7991. merged[p] = tmp[p];
  7992. }
  7993. }
  7994. return merged;
  7995. } // Legacy
  7996. var UniformsUtils = {
  7997. clone: cloneUniforms,
  7998. merge: mergeUniforms
  7999. };
  8000. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  8001. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  8002. /**
  8003. * parameters = {
  8004. * defines: { "label" : "value" },
  8005. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  8006. *
  8007. * fragmentShader: <string>,
  8008. * vertexShader: <string>,
  8009. *
  8010. * wireframe: <boolean>,
  8011. * wireframeLinewidth: <float>,
  8012. *
  8013. * lights: <bool>,
  8014. *
  8015. * skinning: <bool>,
  8016. * morphTargets: <bool>,
  8017. * morphNormals: <bool>
  8018. * }
  8019. */
  8020. function ShaderMaterial(parameters) {
  8021. Material.call(this);
  8022. this.type = 'ShaderMaterial';
  8023. this.defines = {};
  8024. this.uniforms = {};
  8025. this.vertexShader = default_vertex;
  8026. this.fragmentShader = default_fragment;
  8027. this.linewidth = 1;
  8028. this.wireframe = false;
  8029. this.wireframeLinewidth = 1;
  8030. this.fog = false; // set to use scene fog
  8031. this.lights = false; // set to use scene lights
  8032. this.clipping = false; // set to use user-defined clipping planes
  8033. this.skinning = false; // set to use skinning attribute streams
  8034. this.morphTargets = false; // set to use morph targets
  8035. this.morphNormals = false; // set to use morph normals
  8036. this.extensions = {
  8037. derivatives: false,
  8038. // set to use derivatives
  8039. fragDepth: false,
  8040. // set to use fragment depth values
  8041. drawBuffers: false,
  8042. // set to use draw buffers
  8043. shaderTextureLOD: false // set to use shader texture LOD
  8044. }; // When rendered geometry doesn't include these attributes but the material does,
  8045. // use these default values in WebGL. This avoids errors when buffer data is missing.
  8046. this.defaultAttributeValues = {
  8047. 'color': [1, 1, 1],
  8048. 'uv': [0, 0],
  8049. 'uv2': [0, 0]
  8050. };
  8051. this.index0AttributeName = undefined;
  8052. this.uniformsNeedUpdate = false;
  8053. this.glslVersion = null;
  8054. if (parameters !== undefined) {
  8055. if (parameters.attributes !== undefined) {
  8056. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  8057. }
  8058. this.setValues(parameters);
  8059. }
  8060. }
  8061. ShaderMaterial.prototype = Object.create(Material.prototype);
  8062. ShaderMaterial.prototype.constructor = ShaderMaterial;
  8063. ShaderMaterial.prototype.isShaderMaterial = true;
  8064. ShaderMaterial.prototype.copy = function (source) {
  8065. Material.prototype.copy.call(this, source);
  8066. this.fragmentShader = source.fragmentShader;
  8067. this.vertexShader = source.vertexShader;
  8068. this.uniforms = cloneUniforms(source.uniforms);
  8069. this.defines = Object.assign({}, source.defines);
  8070. this.wireframe = source.wireframe;
  8071. this.wireframeLinewidth = source.wireframeLinewidth;
  8072. this.lights = source.lights;
  8073. this.clipping = source.clipping;
  8074. this.skinning = source.skinning;
  8075. this.morphTargets = source.morphTargets;
  8076. this.morphNormals = source.morphNormals;
  8077. this.extensions = Object.assign({}, source.extensions);
  8078. this.glslVersion = source.glslVersion;
  8079. return this;
  8080. };
  8081. ShaderMaterial.prototype.toJSON = function (meta) {
  8082. var data = Material.prototype.toJSON.call(this, meta);
  8083. data.glslVersion = this.glslVersion;
  8084. data.uniforms = {};
  8085. for (var name in this.uniforms) {
  8086. var uniform = this.uniforms[name];
  8087. var value = uniform.value;
  8088. if (value && value.isTexture) {
  8089. data.uniforms[name] = {
  8090. type: 't',
  8091. value: value.toJSON(meta).uuid
  8092. };
  8093. } else if (value && value.isColor) {
  8094. data.uniforms[name] = {
  8095. type: 'c',
  8096. value: value.getHex()
  8097. };
  8098. } else if (value && value.isVector2) {
  8099. data.uniforms[name] = {
  8100. type: 'v2',
  8101. value: value.toArray()
  8102. };
  8103. } else if (value && value.isVector3) {
  8104. data.uniforms[name] = {
  8105. type: 'v3',
  8106. value: value.toArray()
  8107. };
  8108. } else if (value && value.isVector4) {
  8109. data.uniforms[name] = {
  8110. type: 'v4',
  8111. value: value.toArray()
  8112. };
  8113. } else if (value && value.isMatrix3) {
  8114. data.uniforms[name] = {
  8115. type: 'm3',
  8116. value: value.toArray()
  8117. };
  8118. } else if (value && value.isMatrix4) {
  8119. data.uniforms[name] = {
  8120. type: 'm4',
  8121. value: value.toArray()
  8122. };
  8123. } else {
  8124. data.uniforms[name] = {
  8125. value: value
  8126. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  8127. }
  8128. }
  8129. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  8130. data.vertexShader = this.vertexShader;
  8131. data.fragmentShader = this.fragmentShader;
  8132. var extensions = {};
  8133. for (var key in this.extensions) {
  8134. if (this.extensions[key] === true) extensions[key] = true;
  8135. }
  8136. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  8137. return data;
  8138. };
  8139. function Camera() {
  8140. Object3D.call(this);
  8141. this.type = 'Camera';
  8142. this.matrixWorldInverse = new Matrix4();
  8143. this.projectionMatrix = new Matrix4();
  8144. this.projectionMatrixInverse = new Matrix4();
  8145. }
  8146. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  8147. constructor: Camera,
  8148. isCamera: true,
  8149. copy: function copy(source, recursive) {
  8150. Object3D.prototype.copy.call(this, source, recursive);
  8151. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  8152. this.projectionMatrix.copy(source.projectionMatrix);
  8153. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  8154. return this;
  8155. },
  8156. getWorldDirection: function getWorldDirection(target) {
  8157. if (target === undefined) {
  8158. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  8159. target = new Vector3();
  8160. }
  8161. this.updateWorldMatrix(true, false);
  8162. var e = this.matrixWorld.elements;
  8163. return target.set(-e[8], -e[9], -e[10]).normalize();
  8164. },
  8165. updateMatrixWorld: function updateMatrixWorld(force) {
  8166. Object3D.prototype.updateMatrixWorld.call(this, force);
  8167. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  8168. },
  8169. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  8170. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  8171. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  8172. },
  8173. clone: function clone() {
  8174. return new this.constructor().copy(this);
  8175. }
  8176. });
  8177. function PerspectiveCamera(fov, aspect, near, far) {
  8178. if (fov === void 0) {
  8179. fov = 50;
  8180. }
  8181. if (aspect === void 0) {
  8182. aspect = 1;
  8183. }
  8184. if (near === void 0) {
  8185. near = 0.1;
  8186. }
  8187. if (far === void 0) {
  8188. far = 2000;
  8189. }
  8190. Camera.call(this);
  8191. this.type = 'PerspectiveCamera';
  8192. this.fov = fov;
  8193. this.zoom = 1;
  8194. this.near = near;
  8195. this.far = far;
  8196. this.focus = 10;
  8197. this.aspect = aspect;
  8198. this.view = null;
  8199. this.filmGauge = 35; // width of the film (default in millimeters)
  8200. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  8201. this.updateProjectionMatrix();
  8202. }
  8203. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  8204. constructor: PerspectiveCamera,
  8205. isPerspectiveCamera: true,
  8206. copy: function copy(source, recursive) {
  8207. Camera.prototype.copy.call(this, source, recursive);
  8208. this.fov = source.fov;
  8209. this.zoom = source.zoom;
  8210. this.near = source.near;
  8211. this.far = source.far;
  8212. this.focus = source.focus;
  8213. this.aspect = source.aspect;
  8214. this.view = source.view === null ? null : Object.assign({}, source.view);
  8215. this.filmGauge = source.filmGauge;
  8216. this.filmOffset = source.filmOffset;
  8217. return this;
  8218. },
  8219. /**
  8220. * Sets the FOV by focal length in respect to the current .filmGauge.
  8221. *
  8222. * The default film gauge is 35, so that the focal length can be specified for
  8223. * a 35mm (full frame) camera.
  8224. *
  8225. * Values for focal length and film gauge must have the same unit.
  8226. */
  8227. setFocalLength: function setFocalLength(focalLength) {
  8228. /** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
  8229. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  8230. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  8231. this.updateProjectionMatrix();
  8232. },
  8233. /**
  8234. * Calculates the focal length from the current .fov and .filmGauge.
  8235. */
  8236. getFocalLength: function getFocalLength() {
  8237. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  8238. return 0.5 * this.getFilmHeight() / vExtentSlope;
  8239. },
  8240. getEffectiveFOV: function getEffectiveFOV() {
  8241. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  8242. },
  8243. getFilmWidth: function getFilmWidth() {
  8244. // film not completely covered in portrait format (aspect < 1)
  8245. return this.filmGauge * Math.min(this.aspect, 1);
  8246. },
  8247. getFilmHeight: function getFilmHeight() {
  8248. // film not completely covered in landscape format (aspect > 1)
  8249. return this.filmGauge / Math.max(this.aspect, 1);
  8250. },
  8251. /**
  8252. * Sets an offset in a larger frustum. This is useful for multi-window or
  8253. * multi-monitor/multi-machine setups.
  8254. *
  8255. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  8256. * the monitors are in grid like this
  8257. *
  8258. * +---+---+---+
  8259. * | A | B | C |
  8260. * +---+---+---+
  8261. * | D | E | F |
  8262. * +---+---+---+
  8263. *
  8264. * then for each monitor you would call it like this
  8265. *
  8266. * const w = 1920;
  8267. * const h = 1080;
  8268. * const fullWidth = w * 3;
  8269. * const fullHeight = h * 2;
  8270. *
  8271. * --A--
  8272. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8273. * --B--
  8274. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8275. * --C--
  8276. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8277. * --D--
  8278. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8279. * --E--
  8280. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8281. * --F--
  8282. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8283. *
  8284. * Note there is no reason monitors have to be the same size or in a grid.
  8285. */
  8286. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  8287. this.aspect = fullWidth / fullHeight;
  8288. if (this.view === null) {
  8289. this.view = {
  8290. enabled: true,
  8291. fullWidth: 1,
  8292. fullHeight: 1,
  8293. offsetX: 0,
  8294. offsetY: 0,
  8295. width: 1,
  8296. height: 1
  8297. };
  8298. }
  8299. this.view.enabled = true;
  8300. this.view.fullWidth = fullWidth;
  8301. this.view.fullHeight = fullHeight;
  8302. this.view.offsetX = x;
  8303. this.view.offsetY = y;
  8304. this.view.width = width;
  8305. this.view.height = height;
  8306. this.updateProjectionMatrix();
  8307. },
  8308. clearViewOffset: function clearViewOffset() {
  8309. if (this.view !== null) {
  8310. this.view.enabled = false;
  8311. }
  8312. this.updateProjectionMatrix();
  8313. },
  8314. updateProjectionMatrix: function updateProjectionMatrix() {
  8315. var near = this.near;
  8316. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  8317. var height = 2 * top;
  8318. var width = this.aspect * height;
  8319. var left = -0.5 * width;
  8320. var view = this.view;
  8321. if (this.view !== null && this.view.enabled) {
  8322. var fullWidth = view.fullWidth,
  8323. fullHeight = view.fullHeight;
  8324. left += view.offsetX * width / fullWidth;
  8325. top -= view.offsetY * height / fullHeight;
  8326. width *= view.width / fullWidth;
  8327. height *= view.height / fullHeight;
  8328. }
  8329. var skew = this.filmOffset;
  8330. if (skew !== 0) left += near * skew / this.getFilmWidth();
  8331. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  8332. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  8333. },
  8334. toJSON: function toJSON(meta) {
  8335. var data = Object3D.prototype.toJSON.call(this, meta);
  8336. data.object.fov = this.fov;
  8337. data.object.zoom = this.zoom;
  8338. data.object.near = this.near;
  8339. data.object.far = this.far;
  8340. data.object.focus = this.focus;
  8341. data.object.aspect = this.aspect;
  8342. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  8343. data.object.filmGauge = this.filmGauge;
  8344. data.object.filmOffset = this.filmOffset;
  8345. return data;
  8346. }
  8347. });
  8348. var fov = 90,
  8349. aspect = 1;
  8350. function CubeCamera(near, far, renderTarget) {
  8351. Object3D.call(this);
  8352. this.type = 'CubeCamera';
  8353. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  8354. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  8355. return;
  8356. }
  8357. this.renderTarget = renderTarget;
  8358. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  8359. cameraPX.layers = this.layers;
  8360. cameraPX.up.set(0, -1, 0);
  8361. cameraPX.lookAt(new Vector3(1, 0, 0));
  8362. this.add(cameraPX);
  8363. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  8364. cameraNX.layers = this.layers;
  8365. cameraNX.up.set(0, -1, 0);
  8366. cameraNX.lookAt(new Vector3(-1, 0, 0));
  8367. this.add(cameraNX);
  8368. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  8369. cameraPY.layers = this.layers;
  8370. cameraPY.up.set(0, 0, 1);
  8371. cameraPY.lookAt(new Vector3(0, 1, 0));
  8372. this.add(cameraPY);
  8373. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  8374. cameraNY.layers = this.layers;
  8375. cameraNY.up.set(0, 0, -1);
  8376. cameraNY.lookAt(new Vector3(0, -1, 0));
  8377. this.add(cameraNY);
  8378. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  8379. cameraPZ.layers = this.layers;
  8380. cameraPZ.up.set(0, -1, 0);
  8381. cameraPZ.lookAt(new Vector3(0, 0, 1));
  8382. this.add(cameraPZ);
  8383. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  8384. cameraNZ.layers = this.layers;
  8385. cameraNZ.up.set(0, -1, 0);
  8386. cameraNZ.lookAt(new Vector3(0, 0, -1));
  8387. this.add(cameraNZ);
  8388. this.update = function (renderer, scene) {
  8389. if (this.parent === null) this.updateMatrixWorld();
  8390. var currentXrEnabled = renderer.xr.enabled;
  8391. var currentRenderTarget = renderer.getRenderTarget();
  8392. renderer.xr.enabled = false;
  8393. var generateMipmaps = renderTarget.texture.generateMipmaps;
  8394. renderTarget.texture.generateMipmaps = false;
  8395. renderer.setRenderTarget(renderTarget, 0);
  8396. renderer.render(scene, cameraPX);
  8397. renderer.setRenderTarget(renderTarget, 1);
  8398. renderer.render(scene, cameraNX);
  8399. renderer.setRenderTarget(renderTarget, 2);
  8400. renderer.render(scene, cameraPY);
  8401. renderer.setRenderTarget(renderTarget, 3);
  8402. renderer.render(scene, cameraNY);
  8403. renderer.setRenderTarget(renderTarget, 4);
  8404. renderer.render(scene, cameraPZ);
  8405. renderTarget.texture.generateMipmaps = generateMipmaps;
  8406. renderer.setRenderTarget(renderTarget, 5);
  8407. renderer.render(scene, cameraNZ);
  8408. renderer.setRenderTarget(currentRenderTarget);
  8409. renderer.xr.enabled = currentXrEnabled;
  8410. };
  8411. }
  8412. CubeCamera.prototype = Object.create(Object3D.prototype);
  8413. CubeCamera.prototype.constructor = CubeCamera;
  8414. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  8415. images = images !== undefined ? images : [];
  8416. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  8417. format = format !== undefined ? format : RGBFormat;
  8418. Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8419. this.flipY = false; // Why CubeTexture._needsFlipEnvMap is necessary:
  8420. //
  8421. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  8422. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  8423. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  8424. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  8425. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  8426. // when using WebGLCubeRenderTarget.texture as a cube texture.
  8427. this._needsFlipEnvMap = true;
  8428. }
  8429. CubeTexture.prototype = Object.create(Texture.prototype);
  8430. CubeTexture.prototype.constructor = CubeTexture;
  8431. CubeTexture.prototype.isCubeTexture = true;
  8432. Object.defineProperty(CubeTexture.prototype, 'images', {
  8433. get: function get() {
  8434. return this.image;
  8435. },
  8436. set: function set(value) {
  8437. this.image = value;
  8438. }
  8439. });
  8440. var WebGLCubeRenderTarget = /*#__PURE__*/function (_WebGLRenderTarget) {
  8441. _inheritsLoose(WebGLCubeRenderTarget, _WebGLRenderTarget);
  8442. function WebGLCubeRenderTarget(size, options, dummy) {
  8443. var _this;
  8444. if (Number.isInteger(options)) {
  8445. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  8446. options = dummy;
  8447. }
  8448. _this = _WebGLRenderTarget.call(this, size, size, options) || this;
  8449. Object.defineProperty(_assertThisInitialized(_this), 'isWebGLCubeRenderTarget', {
  8450. value: true
  8451. });
  8452. options = options || {};
  8453. _this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  8454. _this.texture._needsFlipEnvMap = false;
  8455. return _this;
  8456. }
  8457. var _proto = WebGLCubeRenderTarget.prototype;
  8458. _proto.fromEquirectangularTexture = function fromEquirectangularTexture(renderer, texture) {
  8459. this.texture.type = texture.type;
  8460. this.texture.format = RGBAFormat; // see #18859
  8461. this.texture.encoding = texture.encoding;
  8462. this.texture.generateMipmaps = texture.generateMipmaps;
  8463. this.texture.minFilter = texture.minFilter;
  8464. this.texture.magFilter = texture.magFilter;
  8465. var shader = {
  8466. uniforms: {
  8467. tEquirect: {
  8468. value: null
  8469. }
  8470. },
  8471. vertexShader:
  8472. /* glsl */
  8473. "\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",
  8474. fragmentShader:
  8475. /* glsl */
  8476. "\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"
  8477. };
  8478. var geometry = new BoxGeometry(5, 5, 5);
  8479. var material = new ShaderMaterial({
  8480. name: 'CubemapFromEquirect',
  8481. uniforms: cloneUniforms(shader.uniforms),
  8482. vertexShader: shader.vertexShader,
  8483. fragmentShader: shader.fragmentShader,
  8484. side: BackSide,
  8485. blending: NoBlending
  8486. });
  8487. material.uniforms.tEquirect.value = texture;
  8488. var mesh = new Mesh(geometry, material);
  8489. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  8490. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  8491. var camera = new CubeCamera(1, 10, this);
  8492. camera.update(renderer, mesh);
  8493. texture.minFilter = currentMinFilter;
  8494. mesh.geometry.dispose();
  8495. mesh.material.dispose();
  8496. return this;
  8497. };
  8498. _proto.clear = function clear(renderer, color, depth, stencil) {
  8499. var currentRenderTarget = renderer.getRenderTarget();
  8500. for (var i = 0; i < 6; i++) {
  8501. renderer.setRenderTarget(this, i);
  8502. renderer.clear(color, depth, stencil);
  8503. }
  8504. renderer.setRenderTarget(currentRenderTarget);
  8505. };
  8506. return WebGLCubeRenderTarget;
  8507. }(WebGLRenderTarget);
  8508. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  8509. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8510. this.image = {
  8511. data: data || null,
  8512. width: width || 1,
  8513. height: height || 1
  8514. };
  8515. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8516. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8517. this.generateMipmaps = false;
  8518. this.flipY = false;
  8519. this.unpackAlignment = 1;
  8520. this.needsUpdate = true;
  8521. }
  8522. DataTexture.prototype = Object.create(Texture.prototype);
  8523. DataTexture.prototype.constructor = DataTexture;
  8524. DataTexture.prototype.isDataTexture = true;
  8525. var _sphere$1 = /*@__PURE__*/new Sphere();
  8526. var _vector$5 = /*@__PURE__*/new Vector3();
  8527. var Frustum = /*#__PURE__*/function () {
  8528. function Frustum(p0, p1, p2, p3, p4, p5) {
  8529. this.planes = [p0 !== undefined ? p0 : new Plane(), p1 !== undefined ? p1 : new Plane(), p2 !== undefined ? p2 : new Plane(), p3 !== undefined ? p3 : new Plane(), p4 !== undefined ? p4 : new Plane(), p5 !== undefined ? p5 : new Plane()];
  8530. }
  8531. var _proto = Frustum.prototype;
  8532. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  8533. var planes = this.planes;
  8534. planes[0].copy(p0);
  8535. planes[1].copy(p1);
  8536. planes[2].copy(p2);
  8537. planes[3].copy(p3);
  8538. planes[4].copy(p4);
  8539. planes[5].copy(p5);
  8540. return this;
  8541. };
  8542. _proto.clone = function clone() {
  8543. return new this.constructor().copy(this);
  8544. };
  8545. _proto.copy = function copy(frustum) {
  8546. var planes = this.planes;
  8547. for (var i = 0; i < 6; i++) {
  8548. planes[i].copy(frustum.planes[i]);
  8549. }
  8550. return this;
  8551. };
  8552. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  8553. var planes = this.planes;
  8554. var me = m.elements;
  8555. var me0 = me[0],
  8556. me1 = me[1],
  8557. me2 = me[2],
  8558. me3 = me[3];
  8559. var me4 = me[4],
  8560. me5 = me[5],
  8561. me6 = me[6],
  8562. me7 = me[7];
  8563. var me8 = me[8],
  8564. me9 = me[9],
  8565. me10 = me[10],
  8566. me11 = me[11];
  8567. var me12 = me[12],
  8568. me13 = me[13],
  8569. me14 = me[14],
  8570. me15 = me[15];
  8571. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  8572. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  8573. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  8574. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  8575. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  8576. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  8577. return this;
  8578. };
  8579. _proto.intersectsObject = function intersectsObject(object) {
  8580. var geometry = object.geometry;
  8581. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  8582. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  8583. return this.intersectsSphere(_sphere$1);
  8584. };
  8585. _proto.intersectsSprite = function intersectsSprite(sprite) {
  8586. _sphere$1.center.set(0, 0, 0);
  8587. _sphere$1.radius = 0.7071067811865476;
  8588. _sphere$1.applyMatrix4(sprite.matrixWorld);
  8589. return this.intersectsSphere(_sphere$1);
  8590. };
  8591. _proto.intersectsSphere = function intersectsSphere(sphere) {
  8592. var planes = this.planes;
  8593. var center = sphere.center;
  8594. var negRadius = -sphere.radius;
  8595. for (var i = 0; i < 6; i++) {
  8596. var distance = planes[i].distanceToPoint(center);
  8597. if (distance < negRadius) {
  8598. return false;
  8599. }
  8600. }
  8601. return true;
  8602. };
  8603. _proto.intersectsBox = function intersectsBox(box) {
  8604. var planes = this.planes;
  8605. for (var i = 0; i < 6; i++) {
  8606. var plane = planes[i]; // corner at max distance
  8607. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8608. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8609. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8610. if (plane.distanceToPoint(_vector$5) < 0) {
  8611. return false;
  8612. }
  8613. }
  8614. return true;
  8615. };
  8616. _proto.containsPoint = function containsPoint(point) {
  8617. var planes = this.planes;
  8618. for (var i = 0; i < 6; i++) {
  8619. if (planes[i].distanceToPoint(point) < 0) {
  8620. return false;
  8621. }
  8622. }
  8623. return true;
  8624. };
  8625. return Frustum;
  8626. }();
  8627. function WebGLAnimation() {
  8628. var context = null;
  8629. var isAnimating = false;
  8630. var animationLoop = null;
  8631. var requestId = null;
  8632. function onAnimationFrame(time, frame) {
  8633. animationLoop(time, frame);
  8634. requestId = context.requestAnimationFrame(onAnimationFrame);
  8635. }
  8636. return {
  8637. start: function start() {
  8638. if (isAnimating === true) return;
  8639. if (animationLoop === null) return;
  8640. requestId = context.requestAnimationFrame(onAnimationFrame);
  8641. isAnimating = true;
  8642. },
  8643. stop: function stop() {
  8644. context.cancelAnimationFrame(requestId);
  8645. isAnimating = false;
  8646. },
  8647. setAnimationLoop: function setAnimationLoop(callback) {
  8648. animationLoop = callback;
  8649. },
  8650. setContext: function setContext(value) {
  8651. context = value;
  8652. }
  8653. };
  8654. }
  8655. function WebGLAttributes(gl, capabilities) {
  8656. var isWebGL2 = capabilities.isWebGL2;
  8657. var buffers = new WeakMap();
  8658. function createBuffer(attribute, bufferType) {
  8659. var array = attribute.array;
  8660. var usage = attribute.usage;
  8661. var buffer = gl.createBuffer();
  8662. gl.bindBuffer(bufferType, buffer);
  8663. gl.bufferData(bufferType, array, usage);
  8664. attribute.onUploadCallback();
  8665. var type = 5126;
  8666. if (array instanceof Float32Array) {
  8667. type = 5126;
  8668. } else if (array instanceof Float64Array) {
  8669. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  8670. } else if (array instanceof Uint16Array) {
  8671. if (attribute.isFloat16BufferAttribute) {
  8672. if (isWebGL2) {
  8673. type = 5131;
  8674. } else {
  8675. console.warn('THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.');
  8676. }
  8677. } else {
  8678. type = 5123;
  8679. }
  8680. } else if (array instanceof Int16Array) {
  8681. type = 5122;
  8682. } else if (array instanceof Uint32Array) {
  8683. type = 5125;
  8684. } else if (array instanceof Int32Array) {
  8685. type = 5124;
  8686. } else if (array instanceof Int8Array) {
  8687. type = 5120;
  8688. } else if (array instanceof Uint8Array) {
  8689. type = 5121;
  8690. }
  8691. return {
  8692. buffer: buffer,
  8693. type: type,
  8694. bytesPerElement: array.BYTES_PER_ELEMENT,
  8695. version: attribute.version
  8696. };
  8697. }
  8698. function updateBuffer(buffer, attribute, bufferType) {
  8699. var array = attribute.array;
  8700. var updateRange = attribute.updateRange;
  8701. gl.bindBuffer(bufferType, buffer);
  8702. if (updateRange.count === -1) {
  8703. // Not using update ranges
  8704. gl.bufferSubData(bufferType, 0, array);
  8705. } else {
  8706. if (isWebGL2) {
  8707. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8708. } else {
  8709. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8710. }
  8711. updateRange.count = -1; // reset range
  8712. }
  8713. } //
  8714. function get(attribute) {
  8715. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8716. return buffers.get(attribute);
  8717. }
  8718. function remove(attribute) {
  8719. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8720. var data = buffers.get(attribute);
  8721. if (data) {
  8722. gl.deleteBuffer(data.buffer);
  8723. buffers.delete(attribute);
  8724. }
  8725. }
  8726. function update(attribute, bufferType) {
  8727. if (attribute.isGLBufferAttribute) {
  8728. var cached = buffers.get(attribute);
  8729. if (!cached || cached.version < attribute.version) {
  8730. buffers.set(attribute, {
  8731. buffer: attribute.buffer,
  8732. type: attribute.type,
  8733. bytesPerElement: attribute.elementSize,
  8734. version: attribute.version
  8735. });
  8736. }
  8737. return;
  8738. }
  8739. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8740. var data = buffers.get(attribute);
  8741. if (data === undefined) {
  8742. buffers.set(attribute, createBuffer(attribute, bufferType));
  8743. } else if (data.version < attribute.version) {
  8744. updateBuffer(data.buffer, attribute, bufferType);
  8745. data.version = attribute.version;
  8746. }
  8747. }
  8748. return {
  8749. get: get,
  8750. remove: remove,
  8751. update: update
  8752. };
  8753. }
  8754. var PlaneGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8755. _inheritsLoose(PlaneGeometry, _BufferGeometry);
  8756. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  8757. var _this;
  8758. if (width === void 0) {
  8759. width = 1;
  8760. }
  8761. if (height === void 0) {
  8762. height = 1;
  8763. }
  8764. if (widthSegments === void 0) {
  8765. widthSegments = 1;
  8766. }
  8767. if (heightSegments === void 0) {
  8768. heightSegments = 1;
  8769. }
  8770. _this = _BufferGeometry.call(this) || this;
  8771. _this.type = 'PlaneGeometry';
  8772. _this.parameters = {
  8773. width: width,
  8774. height: height,
  8775. widthSegments: widthSegments,
  8776. heightSegments: heightSegments
  8777. };
  8778. var width_half = width / 2;
  8779. var height_half = height / 2;
  8780. var gridX = Math.floor(widthSegments);
  8781. var gridY = Math.floor(heightSegments);
  8782. var gridX1 = gridX + 1;
  8783. var gridY1 = gridY + 1;
  8784. var segment_width = width / gridX;
  8785. var segment_height = height / gridY; //
  8786. var indices = [];
  8787. var vertices = [];
  8788. var normals = [];
  8789. var uvs = [];
  8790. for (var iy = 0; iy < gridY1; iy++) {
  8791. var y = iy * segment_height - height_half;
  8792. for (var ix = 0; ix < gridX1; ix++) {
  8793. var x = ix * segment_width - width_half;
  8794. vertices.push(x, -y, 0);
  8795. normals.push(0, 0, 1);
  8796. uvs.push(ix / gridX);
  8797. uvs.push(1 - iy / gridY);
  8798. }
  8799. }
  8800. for (var _iy = 0; _iy < gridY; _iy++) {
  8801. for (var _ix = 0; _ix < gridX; _ix++) {
  8802. var a = _ix + gridX1 * _iy;
  8803. var b = _ix + gridX1 * (_iy + 1);
  8804. var c = _ix + 1 + gridX1 * (_iy + 1);
  8805. var d = _ix + 1 + gridX1 * _iy;
  8806. indices.push(a, b, d);
  8807. indices.push(b, c, d);
  8808. }
  8809. }
  8810. _this.setIndex(indices);
  8811. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8812. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8813. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8814. return _this;
  8815. }
  8816. return PlaneGeometry;
  8817. }(BufferGeometry);
  8818. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8819. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8820. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8821. 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";
  8822. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8823. var begin_vertex = "vec3 transformed = vec3( position );";
  8824. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8825. 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";
  8826. var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 );\n\t\tfDet *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif";
  8827. 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";
  8828. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8829. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8830. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8831. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8832. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8833. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8834. 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";
  8835. 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}";
  8836. 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";
  8837. 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";
  8838. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8839. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8840. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8841. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8842. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8843. 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}";
  8844. 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";
  8845. 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";
  8846. 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";
  8847. 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";
  8848. 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";
  8849. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8850. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8851. 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";
  8852. 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";
  8853. 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}";
  8854. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8855. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8856. 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";
  8857. 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";
  8858. 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";
  8859. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8860. 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)";
  8861. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8862. 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)";
  8863. 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";
  8864. 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}";
  8865. 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";
  8866. 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";
  8867. 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";
  8868. 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";
  8869. 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";
  8870. 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";
  8871. 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";
  8872. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8873. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8874. 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";
  8875. 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";
  8876. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8877. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8878. 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";
  8879. 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";
  8880. 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";
  8881. var normal_fragment_begin = "#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t#endif\n\t#ifdef USE_TANGENT\n\t\tvec3 tangent = normalize( vTangent );\n\t\tvec3 bitangent = normalize( vBitangent );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\ttangent = tangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t\tbitangent = bitangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t#endif\n\t\t#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t#endif\n\t#endif\n#endif\nvec3 geometryNormal = normal;";
  8882. var normal_fragment_maps = "#ifdef OBJECTSPACE_NORMALMAP\n\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( TANGENTSPACE_NORMALMAP )\n\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\t#ifdef USE_TANGENT\n\t\tnormal = normalize( vTBN * mapN );\n\t#else\n\t\tnormal = perturbNormal2Arb( -vViewPosition, normal, mapN );\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif";
  8883. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( TANGENTSPACE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP ) )\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 mapN ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\n\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\tvec3 N = normalize( surf_norm );\n\t\tmat3 tsn = mat3( S, T, N );\n\t\tmapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif";
  8884. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8885. var clearcoat_normal_fragment_maps = "#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\t#ifdef USE_TANGENT\n\t\tclearcoatNormal = normalize( vTBN * clearcoatMapN );\n\t#else\n\t\tclearcoatNormal = perturbNormal2Arb( - vViewPosition, clearcoatNormal, clearcoatMapN );\n\t#endif\n#endif";
  8886. 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";
  8887. 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}";
  8888. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8889. 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;";
  8890. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8891. 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";
  8892. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8893. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8894. 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";
  8895. 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";
  8896. 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";
  8897. 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}";
  8898. 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";
  8899. 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";
  8900. 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";
  8901. 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";
  8902. 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";
  8903. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8904. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8905. 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; }";
  8906. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8907. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8908. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8909. 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";
  8910. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8911. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8912. 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";
  8913. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8914. 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";
  8915. 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}";
  8916. 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}";
  8917. 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}";
  8918. 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}";
  8919. 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}";
  8920. 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}";
  8921. 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}";
  8922. 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}";
  8923. 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}";
  8924. 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}";
  8925. 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}";
  8926. 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}";
  8927. 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}";
  8928. 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}";
  8929. 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}";
  8930. 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}";
  8931. 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}";
  8932. 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}";
  8933. 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}";
  8934. 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}";
  8935. 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}";
  8936. 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}";
  8937. 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}";
  8938. 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}";
  8939. 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}";
  8940. 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}";
  8941. 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}";
  8942. 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}";
  8943. 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}";
  8944. 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}";
  8945. 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}";
  8946. 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}";
  8947. var ShaderChunk = {
  8948. alphamap_fragment: alphamap_fragment,
  8949. alphamap_pars_fragment: alphamap_pars_fragment,
  8950. alphatest_fragment: alphatest_fragment,
  8951. aomap_fragment: aomap_fragment,
  8952. aomap_pars_fragment: aomap_pars_fragment,
  8953. begin_vertex: begin_vertex,
  8954. beginnormal_vertex: beginnormal_vertex,
  8955. bsdfs: bsdfs,
  8956. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8957. clipping_planes_fragment: clipping_planes_fragment,
  8958. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8959. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8960. clipping_planes_vertex: clipping_planes_vertex,
  8961. color_fragment: color_fragment,
  8962. color_pars_fragment: color_pars_fragment,
  8963. color_pars_vertex: color_pars_vertex,
  8964. color_vertex: color_vertex,
  8965. common: common,
  8966. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8967. defaultnormal_vertex: defaultnormal_vertex,
  8968. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8969. displacementmap_vertex: displacementmap_vertex,
  8970. emissivemap_fragment: emissivemap_fragment,
  8971. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8972. encodings_fragment: encodings_fragment,
  8973. encodings_pars_fragment: encodings_pars_fragment,
  8974. envmap_fragment: envmap_fragment,
  8975. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8976. envmap_pars_fragment: envmap_pars_fragment,
  8977. envmap_pars_vertex: envmap_pars_vertex,
  8978. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8979. envmap_vertex: envmap_vertex,
  8980. fog_vertex: fog_vertex,
  8981. fog_pars_vertex: fog_pars_vertex,
  8982. fog_fragment: fog_fragment,
  8983. fog_pars_fragment: fog_pars_fragment,
  8984. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8985. lightmap_fragment: lightmap_fragment,
  8986. lightmap_pars_fragment: lightmap_pars_fragment,
  8987. lights_lambert_vertex: lights_lambert_vertex,
  8988. lights_pars_begin: lights_pars_begin,
  8989. lights_toon_fragment: lights_toon_fragment,
  8990. lights_toon_pars_fragment: lights_toon_pars_fragment,
  8991. lights_phong_fragment: lights_phong_fragment,
  8992. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8993. lights_physical_fragment: lights_physical_fragment,
  8994. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8995. lights_fragment_begin: lights_fragment_begin,
  8996. lights_fragment_maps: lights_fragment_maps,
  8997. lights_fragment_end: lights_fragment_end,
  8998. logdepthbuf_fragment: logdepthbuf_fragment,
  8999. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  9000. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  9001. logdepthbuf_vertex: logdepthbuf_vertex,
  9002. map_fragment: map_fragment,
  9003. map_pars_fragment: map_pars_fragment,
  9004. map_particle_fragment: map_particle_fragment,
  9005. map_particle_pars_fragment: map_particle_pars_fragment,
  9006. metalnessmap_fragment: metalnessmap_fragment,
  9007. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  9008. morphnormal_vertex: morphnormal_vertex,
  9009. morphtarget_pars_vertex: morphtarget_pars_vertex,
  9010. morphtarget_vertex: morphtarget_vertex,
  9011. normal_fragment_begin: normal_fragment_begin,
  9012. normal_fragment_maps: normal_fragment_maps,
  9013. normalmap_pars_fragment: normalmap_pars_fragment,
  9014. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  9015. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  9016. clearcoat_pars_fragment: clearcoat_pars_fragment,
  9017. packing: packing,
  9018. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  9019. project_vertex: project_vertex,
  9020. dithering_fragment: dithering_fragment,
  9021. dithering_pars_fragment: dithering_pars_fragment,
  9022. roughnessmap_fragment: roughnessmap_fragment,
  9023. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  9024. shadowmap_pars_fragment: shadowmap_pars_fragment,
  9025. shadowmap_pars_vertex: shadowmap_pars_vertex,
  9026. shadowmap_vertex: shadowmap_vertex,
  9027. shadowmask_pars_fragment: shadowmask_pars_fragment,
  9028. skinbase_vertex: skinbase_vertex,
  9029. skinning_pars_vertex: skinning_pars_vertex,
  9030. skinning_vertex: skinning_vertex,
  9031. skinnormal_vertex: skinnormal_vertex,
  9032. specularmap_fragment: specularmap_fragment,
  9033. specularmap_pars_fragment: specularmap_pars_fragment,
  9034. tonemapping_fragment: tonemapping_fragment,
  9035. tonemapping_pars_fragment: tonemapping_pars_fragment,
  9036. transmissionmap_fragment: transmissionmap_fragment,
  9037. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  9038. uv_pars_fragment: uv_pars_fragment,
  9039. uv_pars_vertex: uv_pars_vertex,
  9040. uv_vertex: uv_vertex,
  9041. uv2_pars_fragment: uv2_pars_fragment,
  9042. uv2_pars_vertex: uv2_pars_vertex,
  9043. uv2_vertex: uv2_vertex,
  9044. worldpos_vertex: worldpos_vertex,
  9045. background_frag: background_frag,
  9046. background_vert: background_vert,
  9047. cube_frag: cube_frag,
  9048. cube_vert: cube_vert,
  9049. depth_frag: depth_frag,
  9050. depth_vert: depth_vert,
  9051. distanceRGBA_frag: distanceRGBA_frag,
  9052. distanceRGBA_vert: distanceRGBA_vert,
  9053. equirect_frag: equirect_frag,
  9054. equirect_vert: equirect_vert,
  9055. linedashed_frag: linedashed_frag,
  9056. linedashed_vert: linedashed_vert,
  9057. meshbasic_frag: meshbasic_frag,
  9058. meshbasic_vert: meshbasic_vert,
  9059. meshlambert_frag: meshlambert_frag,
  9060. meshlambert_vert: meshlambert_vert,
  9061. meshmatcap_frag: meshmatcap_frag,
  9062. meshmatcap_vert: meshmatcap_vert,
  9063. meshtoon_frag: meshtoon_frag,
  9064. meshtoon_vert: meshtoon_vert,
  9065. meshphong_frag: meshphong_frag,
  9066. meshphong_vert: meshphong_vert,
  9067. meshphysical_frag: meshphysical_frag,
  9068. meshphysical_vert: meshphysical_vert,
  9069. normal_frag: normal_frag,
  9070. normal_vert: normal_vert,
  9071. points_frag: points_frag,
  9072. points_vert: points_vert,
  9073. shadow_frag: shadow_frag,
  9074. shadow_vert: shadow_vert,
  9075. sprite_frag: sprite_frag,
  9076. sprite_vert: sprite_vert
  9077. };
  9078. /**
  9079. * Uniforms library for shared webgl shaders
  9080. */
  9081. var UniformsLib = {
  9082. common: {
  9083. diffuse: {
  9084. value: new Color(0xeeeeee)
  9085. },
  9086. opacity: {
  9087. value: 1.0
  9088. },
  9089. map: {
  9090. value: null
  9091. },
  9092. uvTransform: {
  9093. value: new Matrix3()
  9094. },
  9095. uv2Transform: {
  9096. value: new Matrix3()
  9097. },
  9098. alphaMap: {
  9099. value: null
  9100. }
  9101. },
  9102. specularmap: {
  9103. specularMap: {
  9104. value: null
  9105. }
  9106. },
  9107. envmap: {
  9108. envMap: {
  9109. value: null
  9110. },
  9111. flipEnvMap: {
  9112. value: -1
  9113. },
  9114. reflectivity: {
  9115. value: 1.0
  9116. },
  9117. refractionRatio: {
  9118. value: 0.98
  9119. },
  9120. maxMipLevel: {
  9121. value: 0
  9122. }
  9123. },
  9124. aomap: {
  9125. aoMap: {
  9126. value: null
  9127. },
  9128. aoMapIntensity: {
  9129. value: 1
  9130. }
  9131. },
  9132. lightmap: {
  9133. lightMap: {
  9134. value: null
  9135. },
  9136. lightMapIntensity: {
  9137. value: 1
  9138. }
  9139. },
  9140. emissivemap: {
  9141. emissiveMap: {
  9142. value: null
  9143. }
  9144. },
  9145. bumpmap: {
  9146. bumpMap: {
  9147. value: null
  9148. },
  9149. bumpScale: {
  9150. value: 1
  9151. }
  9152. },
  9153. normalmap: {
  9154. normalMap: {
  9155. value: null
  9156. },
  9157. normalScale: {
  9158. value: new Vector2(1, 1)
  9159. }
  9160. },
  9161. displacementmap: {
  9162. displacementMap: {
  9163. value: null
  9164. },
  9165. displacementScale: {
  9166. value: 1
  9167. },
  9168. displacementBias: {
  9169. value: 0
  9170. }
  9171. },
  9172. roughnessmap: {
  9173. roughnessMap: {
  9174. value: null
  9175. }
  9176. },
  9177. metalnessmap: {
  9178. metalnessMap: {
  9179. value: null
  9180. }
  9181. },
  9182. gradientmap: {
  9183. gradientMap: {
  9184. value: null
  9185. }
  9186. },
  9187. fog: {
  9188. fogDensity: {
  9189. value: 0.00025
  9190. },
  9191. fogNear: {
  9192. value: 1
  9193. },
  9194. fogFar: {
  9195. value: 2000
  9196. },
  9197. fogColor: {
  9198. value: new Color(0xffffff)
  9199. }
  9200. },
  9201. lights: {
  9202. ambientLightColor: {
  9203. value: []
  9204. },
  9205. lightProbe: {
  9206. value: []
  9207. },
  9208. directionalLights: {
  9209. value: [],
  9210. properties: {
  9211. direction: {},
  9212. color: {}
  9213. }
  9214. },
  9215. directionalLightShadows: {
  9216. value: [],
  9217. properties: {
  9218. shadowBias: {},
  9219. shadowNormalBias: {},
  9220. shadowRadius: {},
  9221. shadowMapSize: {}
  9222. }
  9223. },
  9224. directionalShadowMap: {
  9225. value: []
  9226. },
  9227. directionalShadowMatrix: {
  9228. value: []
  9229. },
  9230. spotLights: {
  9231. value: [],
  9232. properties: {
  9233. color: {},
  9234. position: {},
  9235. direction: {},
  9236. distance: {},
  9237. coneCos: {},
  9238. penumbraCos: {},
  9239. decay: {}
  9240. }
  9241. },
  9242. spotLightShadows: {
  9243. value: [],
  9244. properties: {
  9245. shadowBias: {},
  9246. shadowNormalBias: {},
  9247. shadowRadius: {},
  9248. shadowMapSize: {}
  9249. }
  9250. },
  9251. spotShadowMap: {
  9252. value: []
  9253. },
  9254. spotShadowMatrix: {
  9255. value: []
  9256. },
  9257. pointLights: {
  9258. value: [],
  9259. properties: {
  9260. color: {},
  9261. position: {},
  9262. decay: {},
  9263. distance: {}
  9264. }
  9265. },
  9266. pointLightShadows: {
  9267. value: [],
  9268. properties: {
  9269. shadowBias: {},
  9270. shadowNormalBias: {},
  9271. shadowRadius: {},
  9272. shadowMapSize: {},
  9273. shadowCameraNear: {},
  9274. shadowCameraFar: {}
  9275. }
  9276. },
  9277. pointShadowMap: {
  9278. value: []
  9279. },
  9280. pointShadowMatrix: {
  9281. value: []
  9282. },
  9283. hemisphereLights: {
  9284. value: [],
  9285. properties: {
  9286. direction: {},
  9287. skyColor: {},
  9288. groundColor: {}
  9289. }
  9290. },
  9291. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  9292. rectAreaLights: {
  9293. value: [],
  9294. properties: {
  9295. color: {},
  9296. position: {},
  9297. width: {},
  9298. height: {}
  9299. }
  9300. },
  9301. ltc_1: {
  9302. value: null
  9303. },
  9304. ltc_2: {
  9305. value: null
  9306. }
  9307. },
  9308. points: {
  9309. diffuse: {
  9310. value: new Color(0xeeeeee)
  9311. },
  9312. opacity: {
  9313. value: 1.0
  9314. },
  9315. size: {
  9316. value: 1.0
  9317. },
  9318. scale: {
  9319. value: 1.0
  9320. },
  9321. map: {
  9322. value: null
  9323. },
  9324. alphaMap: {
  9325. value: null
  9326. },
  9327. uvTransform: {
  9328. value: new Matrix3()
  9329. }
  9330. },
  9331. sprite: {
  9332. diffuse: {
  9333. value: new Color(0xeeeeee)
  9334. },
  9335. opacity: {
  9336. value: 1.0
  9337. },
  9338. center: {
  9339. value: new Vector2(0.5, 0.5)
  9340. },
  9341. rotation: {
  9342. value: 0.0
  9343. },
  9344. map: {
  9345. value: null
  9346. },
  9347. alphaMap: {
  9348. value: null
  9349. },
  9350. uvTransform: {
  9351. value: new Matrix3()
  9352. }
  9353. }
  9354. };
  9355. var ShaderLib = {
  9356. basic: {
  9357. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  9358. vertexShader: ShaderChunk.meshbasic_vert,
  9359. fragmentShader: ShaderChunk.meshbasic_frag
  9360. },
  9361. lambert: {
  9362. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  9363. emissive: {
  9364. value: new Color(0x000000)
  9365. }
  9366. }]),
  9367. vertexShader: ShaderChunk.meshlambert_vert,
  9368. fragmentShader: ShaderChunk.meshlambert_frag
  9369. },
  9370. phong: {
  9371. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  9372. emissive: {
  9373. value: new Color(0x000000)
  9374. },
  9375. specular: {
  9376. value: new Color(0x111111)
  9377. },
  9378. shininess: {
  9379. value: 30
  9380. }
  9381. }]),
  9382. vertexShader: ShaderChunk.meshphong_vert,
  9383. fragmentShader: ShaderChunk.meshphong_frag
  9384. },
  9385. standard: {
  9386. 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, {
  9387. emissive: {
  9388. value: new Color(0x000000)
  9389. },
  9390. roughness: {
  9391. value: 1.0
  9392. },
  9393. metalness: {
  9394. value: 0.0
  9395. },
  9396. envMapIntensity: {
  9397. value: 1
  9398. } // temporary
  9399. }]),
  9400. vertexShader: ShaderChunk.meshphysical_vert,
  9401. fragmentShader: ShaderChunk.meshphysical_frag
  9402. },
  9403. toon: {
  9404. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  9405. emissive: {
  9406. value: new Color(0x000000)
  9407. }
  9408. }]),
  9409. vertexShader: ShaderChunk.meshtoon_vert,
  9410. fragmentShader: ShaderChunk.meshtoon_frag
  9411. },
  9412. matcap: {
  9413. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  9414. matcap: {
  9415. value: null
  9416. }
  9417. }]),
  9418. vertexShader: ShaderChunk.meshmatcap_vert,
  9419. fragmentShader: ShaderChunk.meshmatcap_frag
  9420. },
  9421. points: {
  9422. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  9423. vertexShader: ShaderChunk.points_vert,
  9424. fragmentShader: ShaderChunk.points_frag
  9425. },
  9426. dashed: {
  9427. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  9428. scale: {
  9429. value: 1
  9430. },
  9431. dashSize: {
  9432. value: 1
  9433. },
  9434. totalSize: {
  9435. value: 2
  9436. }
  9437. }]),
  9438. vertexShader: ShaderChunk.linedashed_vert,
  9439. fragmentShader: ShaderChunk.linedashed_frag
  9440. },
  9441. depth: {
  9442. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  9443. vertexShader: ShaderChunk.depth_vert,
  9444. fragmentShader: ShaderChunk.depth_frag
  9445. },
  9446. normal: {
  9447. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  9448. opacity: {
  9449. value: 1.0
  9450. }
  9451. }]),
  9452. vertexShader: ShaderChunk.normal_vert,
  9453. fragmentShader: ShaderChunk.normal_frag
  9454. },
  9455. sprite: {
  9456. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  9457. vertexShader: ShaderChunk.sprite_vert,
  9458. fragmentShader: ShaderChunk.sprite_frag
  9459. },
  9460. background: {
  9461. uniforms: {
  9462. uvTransform: {
  9463. value: new Matrix3()
  9464. },
  9465. t2D: {
  9466. value: null
  9467. }
  9468. },
  9469. vertexShader: ShaderChunk.background_vert,
  9470. fragmentShader: ShaderChunk.background_frag
  9471. },
  9472. /* -------------------------------------------------------------------------
  9473. // Cube map shader
  9474. ------------------------------------------------------------------------- */
  9475. cube: {
  9476. uniforms: mergeUniforms([UniformsLib.envmap, {
  9477. opacity: {
  9478. value: 1.0
  9479. }
  9480. }]),
  9481. vertexShader: ShaderChunk.cube_vert,
  9482. fragmentShader: ShaderChunk.cube_frag
  9483. },
  9484. equirect: {
  9485. uniforms: {
  9486. tEquirect: {
  9487. value: null
  9488. }
  9489. },
  9490. vertexShader: ShaderChunk.equirect_vert,
  9491. fragmentShader: ShaderChunk.equirect_frag
  9492. },
  9493. distanceRGBA: {
  9494. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  9495. referencePosition: {
  9496. value: new Vector3()
  9497. },
  9498. nearDistance: {
  9499. value: 1
  9500. },
  9501. farDistance: {
  9502. value: 1000
  9503. }
  9504. }]),
  9505. vertexShader: ShaderChunk.distanceRGBA_vert,
  9506. fragmentShader: ShaderChunk.distanceRGBA_frag
  9507. },
  9508. shadow: {
  9509. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  9510. color: {
  9511. value: new Color(0x00000)
  9512. },
  9513. opacity: {
  9514. value: 1.0
  9515. }
  9516. }]),
  9517. vertexShader: ShaderChunk.shadow_vert,
  9518. fragmentShader: ShaderChunk.shadow_frag
  9519. }
  9520. };
  9521. ShaderLib.physical = {
  9522. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  9523. clearcoat: {
  9524. value: 0
  9525. },
  9526. clearcoatMap: {
  9527. value: null
  9528. },
  9529. clearcoatRoughness: {
  9530. value: 0
  9531. },
  9532. clearcoatRoughnessMap: {
  9533. value: null
  9534. },
  9535. clearcoatNormalScale: {
  9536. value: new Vector2(1, 1)
  9537. },
  9538. clearcoatNormalMap: {
  9539. value: null
  9540. },
  9541. sheen: {
  9542. value: new Color(0x000000)
  9543. },
  9544. transmission: {
  9545. value: 0
  9546. },
  9547. transmissionMap: {
  9548. value: null
  9549. }
  9550. }]),
  9551. vertexShader: ShaderChunk.meshphysical_vert,
  9552. fragmentShader: ShaderChunk.meshphysical_frag
  9553. };
  9554. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  9555. var clearColor = new Color(0x000000);
  9556. var clearAlpha = 0;
  9557. var planeMesh;
  9558. var boxMesh;
  9559. var currentBackground = null;
  9560. var currentBackgroundVersion = 0;
  9561. var currentTonemapping = null;
  9562. function render(renderList, scene, camera, forceClear) {
  9563. var background = scene.isScene === true ? scene.background : null;
  9564. if (background && background.isTexture) {
  9565. background = cubemaps.get(background);
  9566. } // Ignore background in AR
  9567. // TODO: Reconsider this.
  9568. var xr = renderer.xr;
  9569. var session = xr.getSession && xr.getSession();
  9570. if (session && session.environmentBlendMode === 'additive') {
  9571. background = null;
  9572. }
  9573. if (background === null) {
  9574. setClear(clearColor, clearAlpha);
  9575. } else if (background && background.isColor) {
  9576. setClear(background, 1);
  9577. forceClear = true;
  9578. }
  9579. if (renderer.autoClear || forceClear) {
  9580. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  9581. }
  9582. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  9583. if (boxMesh === undefined) {
  9584. boxMesh = new Mesh(new BoxGeometry(1, 1, 1), new ShaderMaterial({
  9585. name: 'BackgroundCubeMaterial',
  9586. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  9587. vertexShader: ShaderLib.cube.vertexShader,
  9588. fragmentShader: ShaderLib.cube.fragmentShader,
  9589. side: BackSide,
  9590. depthTest: false,
  9591. depthWrite: false,
  9592. fog: false
  9593. }));
  9594. boxMesh.geometry.deleteAttribute('normal');
  9595. boxMesh.geometry.deleteAttribute('uv');
  9596. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  9597. this.matrixWorld.copyPosition(camera.matrixWorld);
  9598. }; // enable code injection for non-built-in material
  9599. Object.defineProperty(boxMesh.material, 'envMap', {
  9600. get: function get() {
  9601. return this.uniforms.envMap.value;
  9602. }
  9603. });
  9604. objects.update(boxMesh);
  9605. }
  9606. if (background.isWebGLCubeRenderTarget) {
  9607. // TODO Deprecate
  9608. background = background.texture;
  9609. }
  9610. boxMesh.material.uniforms.envMap.value = background;
  9611. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  9612. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9613. boxMesh.material.needsUpdate = true;
  9614. currentBackground = background;
  9615. currentBackgroundVersion = background.version;
  9616. currentTonemapping = renderer.toneMapping;
  9617. } // push to the pre-sorted opaque render list
  9618. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  9619. } else if (background && background.isTexture) {
  9620. if (planeMesh === undefined) {
  9621. planeMesh = new Mesh(new PlaneGeometry(2, 2), new ShaderMaterial({
  9622. name: 'BackgroundMaterial',
  9623. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  9624. vertexShader: ShaderLib.background.vertexShader,
  9625. fragmentShader: ShaderLib.background.fragmentShader,
  9626. side: FrontSide,
  9627. depthTest: false,
  9628. depthWrite: false,
  9629. fog: false
  9630. }));
  9631. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  9632. Object.defineProperty(planeMesh.material, 'map', {
  9633. get: function get() {
  9634. return this.uniforms.t2D.value;
  9635. }
  9636. });
  9637. objects.update(planeMesh);
  9638. }
  9639. planeMesh.material.uniforms.t2D.value = background;
  9640. if (background.matrixAutoUpdate === true) {
  9641. background.updateMatrix();
  9642. }
  9643. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  9644. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9645. planeMesh.material.needsUpdate = true;
  9646. currentBackground = background;
  9647. currentBackgroundVersion = background.version;
  9648. currentTonemapping = renderer.toneMapping;
  9649. } // push to the pre-sorted opaque render list
  9650. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  9651. }
  9652. }
  9653. function setClear(color, alpha) {
  9654. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  9655. }
  9656. return {
  9657. getClearColor: function getClearColor() {
  9658. return clearColor;
  9659. },
  9660. setClearColor: function setClearColor(color, alpha) {
  9661. if (alpha === void 0) {
  9662. alpha = 1;
  9663. }
  9664. clearColor.set(color);
  9665. clearAlpha = alpha;
  9666. setClear(clearColor, clearAlpha);
  9667. },
  9668. getClearAlpha: function getClearAlpha() {
  9669. return clearAlpha;
  9670. },
  9671. setClearAlpha: function setClearAlpha(alpha) {
  9672. clearAlpha = alpha;
  9673. setClear(clearColor, clearAlpha);
  9674. },
  9675. render: render
  9676. };
  9677. }
  9678. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  9679. var maxVertexAttributes = gl.getParameter(34921);
  9680. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  9681. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9682. var bindingStates = {};
  9683. var defaultState = createBindingState(null);
  9684. var currentState = defaultState;
  9685. function setup(object, material, program, geometry, index) {
  9686. var updateBuffers = false;
  9687. if (vaoAvailable) {
  9688. var state = getBindingState(geometry, program, material);
  9689. if (currentState !== state) {
  9690. currentState = state;
  9691. bindVertexArrayObject(currentState.object);
  9692. }
  9693. updateBuffers = needsUpdate(geometry, index);
  9694. if (updateBuffers) saveCache(geometry, index);
  9695. } else {
  9696. var wireframe = material.wireframe === true;
  9697. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9698. currentState.geometry = geometry.id;
  9699. currentState.program = program.id;
  9700. currentState.wireframe = wireframe;
  9701. updateBuffers = true;
  9702. }
  9703. }
  9704. if (object.isInstancedMesh === true) {
  9705. updateBuffers = true;
  9706. }
  9707. if (index !== null) {
  9708. attributes.update(index, 34963);
  9709. }
  9710. if (updateBuffers) {
  9711. setupVertexAttributes(object, material, program, geometry);
  9712. if (index !== null) {
  9713. gl.bindBuffer(34963, attributes.get(index).buffer);
  9714. }
  9715. }
  9716. }
  9717. function createVertexArrayObject() {
  9718. if (capabilities.isWebGL2) return gl.createVertexArray();
  9719. return extension.createVertexArrayOES();
  9720. }
  9721. function bindVertexArrayObject(vao) {
  9722. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9723. return extension.bindVertexArrayOES(vao);
  9724. }
  9725. function deleteVertexArrayObject(vao) {
  9726. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9727. return extension.deleteVertexArrayOES(vao);
  9728. }
  9729. function getBindingState(geometry, program, material) {
  9730. var wireframe = material.wireframe === true;
  9731. var programMap = bindingStates[geometry.id];
  9732. if (programMap === undefined) {
  9733. programMap = {};
  9734. bindingStates[geometry.id] = programMap;
  9735. }
  9736. var stateMap = programMap[program.id];
  9737. if (stateMap === undefined) {
  9738. stateMap = {};
  9739. programMap[program.id] = stateMap;
  9740. }
  9741. var state = stateMap[wireframe];
  9742. if (state === undefined) {
  9743. state = createBindingState(createVertexArrayObject());
  9744. stateMap[wireframe] = state;
  9745. }
  9746. return state;
  9747. }
  9748. function createBindingState(vao) {
  9749. var newAttributes = [];
  9750. var enabledAttributes = [];
  9751. var attributeDivisors = [];
  9752. for (var i = 0; i < maxVertexAttributes; i++) {
  9753. newAttributes[i] = 0;
  9754. enabledAttributes[i] = 0;
  9755. attributeDivisors[i] = 0;
  9756. }
  9757. return {
  9758. // for backward compatibility on non-VAO support browser
  9759. geometry: null,
  9760. program: null,
  9761. wireframe: false,
  9762. newAttributes: newAttributes,
  9763. enabledAttributes: enabledAttributes,
  9764. attributeDivisors: attributeDivisors,
  9765. object: vao,
  9766. attributes: {},
  9767. index: null
  9768. };
  9769. }
  9770. function needsUpdate(geometry, index) {
  9771. var cachedAttributes = currentState.attributes;
  9772. var geometryAttributes = geometry.attributes;
  9773. var attributesNum = 0;
  9774. for (var key in geometryAttributes) {
  9775. var cachedAttribute = cachedAttributes[key];
  9776. var geometryAttribute = geometryAttributes[key];
  9777. if (cachedAttribute === undefined) return true;
  9778. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9779. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9780. attributesNum++;
  9781. }
  9782. if (currentState.attributesNum !== attributesNum) return true;
  9783. if (currentState.index !== index) return true;
  9784. return false;
  9785. }
  9786. function saveCache(geometry, index) {
  9787. var cache = {};
  9788. var attributes = geometry.attributes;
  9789. var attributesNum = 0;
  9790. for (var key in attributes) {
  9791. var attribute = attributes[key];
  9792. var data = {};
  9793. data.attribute = attribute;
  9794. if (attribute.data) {
  9795. data.data = attribute.data;
  9796. }
  9797. cache[key] = data;
  9798. attributesNum++;
  9799. }
  9800. currentState.attributes = cache;
  9801. currentState.attributesNum = attributesNum;
  9802. currentState.index = index;
  9803. }
  9804. function initAttributes() {
  9805. var newAttributes = currentState.newAttributes;
  9806. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9807. newAttributes[i] = 0;
  9808. }
  9809. }
  9810. function enableAttribute(attribute) {
  9811. enableAttributeAndDivisor(attribute, 0);
  9812. }
  9813. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9814. var newAttributes = currentState.newAttributes;
  9815. var enabledAttributes = currentState.enabledAttributes;
  9816. var attributeDivisors = currentState.attributeDivisors;
  9817. newAttributes[attribute] = 1;
  9818. if (enabledAttributes[attribute] === 0) {
  9819. gl.enableVertexAttribArray(attribute);
  9820. enabledAttributes[attribute] = 1;
  9821. }
  9822. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9823. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9824. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9825. attributeDivisors[attribute] = meshPerAttribute;
  9826. }
  9827. }
  9828. function disableUnusedAttributes() {
  9829. var newAttributes = currentState.newAttributes;
  9830. var enabledAttributes = currentState.enabledAttributes;
  9831. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9832. if (enabledAttributes[i] !== newAttributes[i]) {
  9833. gl.disableVertexAttribArray(i);
  9834. enabledAttributes[i] = 0;
  9835. }
  9836. }
  9837. }
  9838. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9839. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9840. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9841. } else {
  9842. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9843. }
  9844. }
  9845. function setupVertexAttributes(object, material, program, geometry) {
  9846. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9847. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9848. }
  9849. initAttributes();
  9850. var geometryAttributes = geometry.attributes;
  9851. var programAttributes = program.getAttributes();
  9852. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9853. for (var name in programAttributes) {
  9854. var programAttribute = programAttributes[name];
  9855. if (programAttribute >= 0) {
  9856. var geometryAttribute = geometryAttributes[name];
  9857. if (geometryAttribute !== undefined) {
  9858. var normalized = geometryAttribute.normalized;
  9859. var size = geometryAttribute.itemSize;
  9860. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9861. if (attribute === undefined) continue;
  9862. var buffer = attribute.buffer;
  9863. var type = attribute.type;
  9864. var bytesPerElement = attribute.bytesPerElement;
  9865. if (geometryAttribute.isInterleavedBufferAttribute) {
  9866. var data = geometryAttribute.data;
  9867. var stride = data.stride;
  9868. var offset = geometryAttribute.offset;
  9869. if (data && data.isInstancedInterleavedBuffer) {
  9870. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9871. if (geometry._maxInstanceCount === undefined) {
  9872. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9873. }
  9874. } else {
  9875. enableAttribute(programAttribute);
  9876. }
  9877. gl.bindBuffer(34962, buffer);
  9878. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9879. } else {
  9880. if (geometryAttribute.isInstancedBufferAttribute) {
  9881. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9882. if (geometry._maxInstanceCount === undefined) {
  9883. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9884. }
  9885. } else {
  9886. enableAttribute(programAttribute);
  9887. }
  9888. gl.bindBuffer(34962, buffer);
  9889. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9890. }
  9891. } else if (name === 'instanceMatrix') {
  9892. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9893. if (_attribute === undefined) continue;
  9894. var _buffer = _attribute.buffer;
  9895. var _type = _attribute.type;
  9896. enableAttributeAndDivisor(programAttribute + 0, 1);
  9897. enableAttributeAndDivisor(programAttribute + 1, 1);
  9898. enableAttributeAndDivisor(programAttribute + 2, 1);
  9899. enableAttributeAndDivisor(programAttribute + 3, 1);
  9900. gl.bindBuffer(34962, _buffer);
  9901. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9902. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9903. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9904. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9905. } else if (name === 'instanceColor') {
  9906. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9907. if (_attribute2 === undefined) continue;
  9908. var _buffer2 = _attribute2.buffer;
  9909. var _type2 = _attribute2.type;
  9910. enableAttributeAndDivisor(programAttribute, 1);
  9911. gl.bindBuffer(34962, _buffer2);
  9912. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9913. } else if (materialDefaultAttributeValues !== undefined) {
  9914. var value = materialDefaultAttributeValues[name];
  9915. if (value !== undefined) {
  9916. switch (value.length) {
  9917. case 2:
  9918. gl.vertexAttrib2fv(programAttribute, value);
  9919. break;
  9920. case 3:
  9921. gl.vertexAttrib3fv(programAttribute, value);
  9922. break;
  9923. case 4:
  9924. gl.vertexAttrib4fv(programAttribute, value);
  9925. break;
  9926. default:
  9927. gl.vertexAttrib1fv(programAttribute, value);
  9928. }
  9929. }
  9930. }
  9931. }
  9932. }
  9933. disableUnusedAttributes();
  9934. }
  9935. function dispose() {
  9936. reset();
  9937. for (var geometryId in bindingStates) {
  9938. var programMap = bindingStates[geometryId];
  9939. for (var programId in programMap) {
  9940. var stateMap = programMap[programId];
  9941. for (var wireframe in stateMap) {
  9942. deleteVertexArrayObject(stateMap[wireframe].object);
  9943. delete stateMap[wireframe];
  9944. }
  9945. delete programMap[programId];
  9946. }
  9947. delete bindingStates[geometryId];
  9948. }
  9949. }
  9950. function releaseStatesOfGeometry(geometry) {
  9951. if (bindingStates[geometry.id] === undefined) return;
  9952. var programMap = bindingStates[geometry.id];
  9953. for (var programId in programMap) {
  9954. var stateMap = programMap[programId];
  9955. for (var wireframe in stateMap) {
  9956. deleteVertexArrayObject(stateMap[wireframe].object);
  9957. delete stateMap[wireframe];
  9958. }
  9959. delete programMap[programId];
  9960. }
  9961. delete bindingStates[geometry.id];
  9962. }
  9963. function releaseStatesOfProgram(program) {
  9964. for (var geometryId in bindingStates) {
  9965. var programMap = bindingStates[geometryId];
  9966. if (programMap[program.id] === undefined) continue;
  9967. var stateMap = programMap[program.id];
  9968. for (var wireframe in stateMap) {
  9969. deleteVertexArrayObject(stateMap[wireframe].object);
  9970. delete stateMap[wireframe];
  9971. }
  9972. delete programMap[program.id];
  9973. }
  9974. }
  9975. function reset() {
  9976. resetDefaultState();
  9977. if (currentState === defaultState) return;
  9978. currentState = defaultState;
  9979. bindVertexArrayObject(currentState.object);
  9980. } // for backward-compatilibity
  9981. function resetDefaultState() {
  9982. defaultState.geometry = null;
  9983. defaultState.program = null;
  9984. defaultState.wireframe = false;
  9985. }
  9986. return {
  9987. setup: setup,
  9988. reset: reset,
  9989. resetDefaultState: resetDefaultState,
  9990. dispose: dispose,
  9991. releaseStatesOfGeometry: releaseStatesOfGeometry,
  9992. releaseStatesOfProgram: releaseStatesOfProgram,
  9993. initAttributes: initAttributes,
  9994. enableAttribute: enableAttribute,
  9995. disableUnusedAttributes: disableUnusedAttributes
  9996. };
  9997. }
  9998. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  9999. var isWebGL2 = capabilities.isWebGL2;
  10000. var mode;
  10001. function setMode(value) {
  10002. mode = value;
  10003. }
  10004. function render(start, count) {
  10005. gl.drawArrays(mode, start, count);
  10006. info.update(count, mode, 1);
  10007. }
  10008. function renderInstances(start, count, primcount) {
  10009. if (primcount === 0) return;
  10010. var extension, methodName;
  10011. if (isWebGL2) {
  10012. extension = gl;
  10013. methodName = 'drawArraysInstanced';
  10014. } else {
  10015. extension = extensions.get('ANGLE_instanced_arrays');
  10016. methodName = 'drawArraysInstancedANGLE';
  10017. if (extension === null) {
  10018. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  10019. return;
  10020. }
  10021. }
  10022. extension[methodName](mode, start, count, primcount);
  10023. info.update(count, mode, primcount);
  10024. } //
  10025. this.setMode = setMode;
  10026. this.render = render;
  10027. this.renderInstances = renderInstances;
  10028. }
  10029. function WebGLCapabilities(gl, extensions, parameters) {
  10030. var maxAnisotropy;
  10031. function getMaxAnisotropy() {
  10032. if (maxAnisotropy !== undefined) return maxAnisotropy;
  10033. var extension = extensions.get('EXT_texture_filter_anisotropic');
  10034. if (extension !== null) {
  10035. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  10036. } else {
  10037. maxAnisotropy = 0;
  10038. }
  10039. return maxAnisotropy;
  10040. }
  10041. function getMaxPrecision(precision) {
  10042. if (precision === 'highp') {
  10043. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  10044. return 'highp';
  10045. }
  10046. precision = 'mediump';
  10047. }
  10048. if (precision === 'mediump') {
  10049. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  10050. return 'mediump';
  10051. }
  10052. }
  10053. return 'lowp';
  10054. }
  10055. /* eslint-disable no-undef */
  10056. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  10057. /* eslint-enable no-undef */
  10058. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  10059. var maxPrecision = getMaxPrecision(precision);
  10060. if (maxPrecision !== precision) {
  10061. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  10062. precision = maxPrecision;
  10063. }
  10064. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  10065. var maxTextures = gl.getParameter(34930);
  10066. var maxVertexTextures = gl.getParameter(35660);
  10067. var maxTextureSize = gl.getParameter(3379);
  10068. var maxCubemapSize = gl.getParameter(34076);
  10069. var maxAttributes = gl.getParameter(34921);
  10070. var maxVertexUniforms = gl.getParameter(36347);
  10071. var maxVaryings = gl.getParameter(36348);
  10072. var maxFragmentUniforms = gl.getParameter(36349);
  10073. var vertexTextures = maxVertexTextures > 0;
  10074. var floatFragmentTextures = isWebGL2 || !!extensions.get('OES_texture_float');
  10075. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  10076. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  10077. return {
  10078. isWebGL2: isWebGL2,
  10079. getMaxAnisotropy: getMaxAnisotropy,
  10080. getMaxPrecision: getMaxPrecision,
  10081. precision: precision,
  10082. logarithmicDepthBuffer: logarithmicDepthBuffer,
  10083. maxTextures: maxTextures,
  10084. maxVertexTextures: maxVertexTextures,
  10085. maxTextureSize: maxTextureSize,
  10086. maxCubemapSize: maxCubemapSize,
  10087. maxAttributes: maxAttributes,
  10088. maxVertexUniforms: maxVertexUniforms,
  10089. maxVaryings: maxVaryings,
  10090. maxFragmentUniforms: maxFragmentUniforms,
  10091. vertexTextures: vertexTextures,
  10092. floatFragmentTextures: floatFragmentTextures,
  10093. floatVertexTextures: floatVertexTextures,
  10094. maxSamples: maxSamples
  10095. };
  10096. }
  10097. function WebGLClipping(properties) {
  10098. var scope = this;
  10099. var globalState = null,
  10100. numGlobalPlanes = 0,
  10101. localClippingEnabled = false,
  10102. renderingShadows = false;
  10103. var plane = new Plane(),
  10104. viewNormalMatrix = new Matrix3(),
  10105. uniform = {
  10106. value: null,
  10107. needsUpdate: false
  10108. };
  10109. this.uniform = uniform;
  10110. this.numPlanes = 0;
  10111. this.numIntersection = 0;
  10112. this.init = function (planes, enableLocalClipping, camera) {
  10113. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  10114. // run another frame in order to reset the state:
  10115. numGlobalPlanes !== 0 || localClippingEnabled;
  10116. localClippingEnabled = enableLocalClipping;
  10117. globalState = projectPlanes(planes, camera, 0);
  10118. numGlobalPlanes = planes.length;
  10119. return enabled;
  10120. };
  10121. this.beginShadows = function () {
  10122. renderingShadows = true;
  10123. projectPlanes(null);
  10124. };
  10125. this.endShadows = function () {
  10126. renderingShadows = false;
  10127. resetGlobalState();
  10128. };
  10129. this.setState = function (material, camera, useCache) {
  10130. var planes = material.clippingPlanes,
  10131. clipIntersection = material.clipIntersection,
  10132. clipShadows = material.clipShadows;
  10133. var materialProperties = properties.get(material);
  10134. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  10135. // there's no local clipping
  10136. if (renderingShadows) {
  10137. // there's no global clipping
  10138. projectPlanes(null);
  10139. } else {
  10140. resetGlobalState();
  10141. }
  10142. } else {
  10143. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  10144. lGlobal = nGlobal * 4;
  10145. var dstArray = materialProperties.clippingState || null;
  10146. uniform.value = dstArray; // ensure unique state
  10147. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  10148. for (var i = 0; i !== lGlobal; ++i) {
  10149. dstArray[i] = globalState[i];
  10150. }
  10151. materialProperties.clippingState = dstArray;
  10152. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  10153. this.numPlanes += nGlobal;
  10154. }
  10155. };
  10156. function resetGlobalState() {
  10157. if (uniform.value !== globalState) {
  10158. uniform.value = globalState;
  10159. uniform.needsUpdate = numGlobalPlanes > 0;
  10160. }
  10161. scope.numPlanes = numGlobalPlanes;
  10162. scope.numIntersection = 0;
  10163. }
  10164. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  10165. var nPlanes = planes !== null ? planes.length : 0;
  10166. var dstArray = null;
  10167. if (nPlanes !== 0) {
  10168. dstArray = uniform.value;
  10169. if (skipTransform !== true || dstArray === null) {
  10170. var flatSize = dstOffset + nPlanes * 4,
  10171. viewMatrix = camera.matrixWorldInverse;
  10172. viewNormalMatrix.getNormalMatrix(viewMatrix);
  10173. if (dstArray === null || dstArray.length < flatSize) {
  10174. dstArray = new Float32Array(flatSize);
  10175. }
  10176. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  10177. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  10178. plane.normal.toArray(dstArray, i4);
  10179. dstArray[i4 + 3] = plane.constant;
  10180. }
  10181. }
  10182. uniform.value = dstArray;
  10183. uniform.needsUpdate = true;
  10184. }
  10185. scope.numPlanes = nPlanes;
  10186. scope.numIntersection = 0;
  10187. return dstArray;
  10188. }
  10189. }
  10190. function WebGLCubeMaps(renderer) {
  10191. var cubemaps = new WeakMap();
  10192. function mapTextureMapping(texture, mapping) {
  10193. if (mapping === EquirectangularReflectionMapping) {
  10194. texture.mapping = CubeReflectionMapping;
  10195. } else if (mapping === EquirectangularRefractionMapping) {
  10196. texture.mapping = CubeRefractionMapping;
  10197. }
  10198. return texture;
  10199. }
  10200. function get(texture) {
  10201. if (texture && texture.isTexture) {
  10202. var mapping = texture.mapping;
  10203. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  10204. if (cubemaps.has(texture)) {
  10205. var cubemap = cubemaps.get(texture).texture;
  10206. return mapTextureMapping(cubemap, texture.mapping);
  10207. } else {
  10208. var image = texture.image;
  10209. if (image && image.height > 0) {
  10210. var currentRenderList = renderer.getRenderList();
  10211. var currentRenderTarget = renderer.getRenderTarget();
  10212. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  10213. renderTarget.fromEquirectangularTexture(renderer, texture);
  10214. cubemaps.set(texture, renderTarget);
  10215. renderer.setRenderTarget(currentRenderTarget);
  10216. renderer.setRenderList(currentRenderList);
  10217. texture.addEventListener('dispose', onTextureDispose);
  10218. return mapTextureMapping(renderTarget.texture, texture.mapping);
  10219. } else {
  10220. // image not yet ready. try the conversion next frame
  10221. return null;
  10222. }
  10223. }
  10224. }
  10225. }
  10226. return texture;
  10227. }
  10228. function onTextureDispose(event) {
  10229. var texture = event.target;
  10230. texture.removeEventListener('dispose', onTextureDispose);
  10231. var cubemap = cubemaps.get(texture);
  10232. if (cubemap !== undefined) {
  10233. cubemaps.delete(texture);
  10234. cubemap.dispose();
  10235. }
  10236. }
  10237. function dispose() {
  10238. cubemaps = new WeakMap();
  10239. }
  10240. return {
  10241. get: get,
  10242. dispose: dispose
  10243. };
  10244. }
  10245. function WebGLExtensions(gl) {
  10246. var extensions = {};
  10247. function getExtension(name) {
  10248. if (extensions[name] !== undefined) {
  10249. return extensions[name];
  10250. }
  10251. var extension;
  10252. switch (name) {
  10253. case 'WEBGL_depth_texture':
  10254. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  10255. break;
  10256. case 'EXT_texture_filter_anisotropic':
  10257. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  10258. break;
  10259. case 'WEBGL_compressed_texture_s3tc':
  10260. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  10261. break;
  10262. case 'WEBGL_compressed_texture_pvrtc':
  10263. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  10264. break;
  10265. default:
  10266. extension = gl.getExtension(name);
  10267. }
  10268. extensions[name] = extension;
  10269. return extension;
  10270. }
  10271. return {
  10272. has: function has(name) {
  10273. return getExtension(name) !== null;
  10274. },
  10275. init: function init(capabilities) {
  10276. if (capabilities.isWebGL2) {
  10277. getExtension('EXT_color_buffer_float');
  10278. } else {
  10279. getExtension('WEBGL_depth_texture');
  10280. getExtension('OES_texture_float');
  10281. getExtension('OES_texture_half_float');
  10282. getExtension('OES_texture_half_float_linear');
  10283. getExtension('OES_standard_derivatives');
  10284. getExtension('OES_element_index_uint');
  10285. getExtension('OES_vertex_array_object');
  10286. getExtension('ANGLE_instanced_arrays');
  10287. }
  10288. getExtension('OES_texture_float_linear');
  10289. getExtension('EXT_color_buffer_half_float');
  10290. },
  10291. get: function get(name) {
  10292. var extension = getExtension(name);
  10293. if (extension === null) {
  10294. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  10295. }
  10296. return extension;
  10297. }
  10298. };
  10299. }
  10300. function WebGLGeometries(gl, attributes, info, bindingStates) {
  10301. var geometries = {};
  10302. var wireframeAttributes = new WeakMap();
  10303. function onGeometryDispose(event) {
  10304. var geometry = event.target;
  10305. if (geometry.index !== null) {
  10306. attributes.remove(geometry.index);
  10307. }
  10308. for (var name in geometry.attributes) {
  10309. attributes.remove(geometry.attributes[name]);
  10310. }
  10311. geometry.removeEventListener('dispose', onGeometryDispose);
  10312. delete geometries[geometry.id];
  10313. var attribute = wireframeAttributes.get(geometry);
  10314. if (attribute) {
  10315. attributes.remove(attribute);
  10316. wireframeAttributes.delete(geometry);
  10317. }
  10318. bindingStates.releaseStatesOfGeometry(geometry);
  10319. if (geometry.isInstancedBufferGeometry === true) {
  10320. delete geometry._maxInstanceCount;
  10321. } //
  10322. info.memory.geometries--;
  10323. }
  10324. function get(object, geometry) {
  10325. if (geometries[geometry.id] === true) return geometry;
  10326. geometry.addEventListener('dispose', onGeometryDispose);
  10327. geometries[geometry.id] = true;
  10328. info.memory.geometries++;
  10329. return geometry;
  10330. }
  10331. function update(geometry) {
  10332. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  10333. for (var name in geometryAttributes) {
  10334. attributes.update(geometryAttributes[name], 34962);
  10335. } // morph targets
  10336. var morphAttributes = geometry.morphAttributes;
  10337. for (var _name in morphAttributes) {
  10338. var array = morphAttributes[_name];
  10339. for (var i = 0, l = array.length; i < l; i++) {
  10340. attributes.update(array[i], 34962);
  10341. }
  10342. }
  10343. }
  10344. function updateWireframeAttribute(geometry) {
  10345. var indices = [];
  10346. var geometryIndex = geometry.index;
  10347. var geometryPosition = geometry.attributes.position;
  10348. var version = 0;
  10349. if (geometryIndex !== null) {
  10350. var array = geometryIndex.array;
  10351. version = geometryIndex.version;
  10352. for (var i = 0, l = array.length; i < l; i += 3) {
  10353. var a = array[i + 0];
  10354. var b = array[i + 1];
  10355. var c = array[i + 2];
  10356. indices.push(a, b, b, c, c, a);
  10357. }
  10358. } else {
  10359. var _array = geometryPosition.array;
  10360. version = geometryPosition.version;
  10361. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  10362. var _a = _i + 0;
  10363. var _b = _i + 1;
  10364. var _c = _i + 2;
  10365. indices.push(_a, _b, _b, _c, _c, _a);
  10366. }
  10367. }
  10368. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  10369. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  10370. //
  10371. var previousAttribute = wireframeAttributes.get(geometry);
  10372. if (previousAttribute) attributes.remove(previousAttribute); //
  10373. wireframeAttributes.set(geometry, attribute);
  10374. }
  10375. function getWireframeAttribute(geometry) {
  10376. var currentAttribute = wireframeAttributes.get(geometry);
  10377. if (currentAttribute) {
  10378. var geometryIndex = geometry.index;
  10379. if (geometryIndex !== null) {
  10380. // if the attribute is obsolete, create a new one
  10381. if (currentAttribute.version < geometryIndex.version) {
  10382. updateWireframeAttribute(geometry);
  10383. }
  10384. }
  10385. } else {
  10386. updateWireframeAttribute(geometry);
  10387. }
  10388. return wireframeAttributes.get(geometry);
  10389. }
  10390. return {
  10391. get: get,
  10392. update: update,
  10393. getWireframeAttribute: getWireframeAttribute
  10394. };
  10395. }
  10396. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  10397. var isWebGL2 = capabilities.isWebGL2;
  10398. var mode;
  10399. function setMode(value) {
  10400. mode = value;
  10401. }
  10402. var type, bytesPerElement;
  10403. function setIndex(value) {
  10404. type = value.type;
  10405. bytesPerElement = value.bytesPerElement;
  10406. }
  10407. function render(start, count) {
  10408. gl.drawElements(mode, count, type, start * bytesPerElement);
  10409. info.update(count, mode, 1);
  10410. }
  10411. function renderInstances(start, count, primcount) {
  10412. if (primcount === 0) return;
  10413. var extension, methodName;
  10414. if (isWebGL2) {
  10415. extension = gl;
  10416. methodName = 'drawElementsInstanced';
  10417. } else {
  10418. extension = extensions.get('ANGLE_instanced_arrays');
  10419. methodName = 'drawElementsInstancedANGLE';
  10420. if (extension === null) {
  10421. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  10422. return;
  10423. }
  10424. }
  10425. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  10426. info.update(count, mode, primcount);
  10427. } //
  10428. this.setMode = setMode;
  10429. this.setIndex = setIndex;
  10430. this.render = render;
  10431. this.renderInstances = renderInstances;
  10432. }
  10433. function WebGLInfo(gl) {
  10434. var memory = {
  10435. geometries: 0,
  10436. textures: 0
  10437. };
  10438. var render = {
  10439. frame: 0,
  10440. calls: 0,
  10441. triangles: 0,
  10442. points: 0,
  10443. lines: 0
  10444. };
  10445. function update(count, mode, instanceCount) {
  10446. render.calls++;
  10447. switch (mode) {
  10448. case 4:
  10449. render.triangles += instanceCount * (count / 3);
  10450. break;
  10451. case 1:
  10452. render.lines += instanceCount * (count / 2);
  10453. break;
  10454. case 3:
  10455. render.lines += instanceCount * (count - 1);
  10456. break;
  10457. case 2:
  10458. render.lines += instanceCount * count;
  10459. break;
  10460. case 0:
  10461. render.points += instanceCount * count;
  10462. break;
  10463. default:
  10464. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  10465. break;
  10466. }
  10467. }
  10468. function reset() {
  10469. render.frame++;
  10470. render.calls = 0;
  10471. render.triangles = 0;
  10472. render.points = 0;
  10473. render.lines = 0;
  10474. }
  10475. return {
  10476. memory: memory,
  10477. render: render,
  10478. programs: null,
  10479. autoReset: true,
  10480. reset: reset,
  10481. update: update
  10482. };
  10483. }
  10484. function numericalSort(a, b) {
  10485. return a[0] - b[0];
  10486. }
  10487. function absNumericalSort(a, b) {
  10488. return Math.abs(b[1]) - Math.abs(a[1]);
  10489. }
  10490. function WebGLMorphtargets(gl) {
  10491. var influencesList = {};
  10492. var morphInfluences = new Float32Array(8);
  10493. var workInfluences = [];
  10494. for (var i = 0; i < 8; i++) {
  10495. workInfluences[i] = [i, 0];
  10496. }
  10497. function update(object, geometry, material, program) {
  10498. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  10499. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  10500. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  10501. var influences = influencesList[geometry.id];
  10502. if (influences === undefined) {
  10503. // initialise list
  10504. influences = [];
  10505. for (var _i = 0; _i < length; _i++) {
  10506. influences[_i] = [_i, 0];
  10507. }
  10508. influencesList[geometry.id] = influences;
  10509. } // Collect influences
  10510. for (var _i2 = 0; _i2 < length; _i2++) {
  10511. var influence = influences[_i2];
  10512. influence[0] = _i2;
  10513. influence[1] = objectInfluences[_i2];
  10514. }
  10515. influences.sort(absNumericalSort);
  10516. for (var _i3 = 0; _i3 < 8; _i3++) {
  10517. if (_i3 < length && influences[_i3][1]) {
  10518. workInfluences[_i3][0] = influences[_i3][0];
  10519. workInfluences[_i3][1] = influences[_i3][1];
  10520. } else {
  10521. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  10522. workInfluences[_i3][1] = 0;
  10523. }
  10524. }
  10525. workInfluences.sort(numericalSort);
  10526. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  10527. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  10528. var morphInfluencesSum = 0;
  10529. for (var _i4 = 0; _i4 < 8; _i4++) {
  10530. var _influence = workInfluences[_i4];
  10531. var index = _influence[0];
  10532. var value = _influence[1];
  10533. if (index !== Number.MAX_SAFE_INTEGER && value) {
  10534. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  10535. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  10536. }
  10537. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  10538. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  10539. }
  10540. morphInfluences[_i4] = value;
  10541. morphInfluencesSum += value;
  10542. } else {
  10543. if (morphTargets && geometry.hasAttribute('morphTarget' + _i4) === true) {
  10544. geometry.deleteAttribute('morphTarget' + _i4);
  10545. }
  10546. if (morphNormals && geometry.hasAttribute('morphNormal' + _i4) === true) {
  10547. geometry.deleteAttribute('morphNormal' + _i4);
  10548. }
  10549. morphInfluences[_i4] = 0;
  10550. }
  10551. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  10552. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  10553. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  10554. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  10555. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  10556. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  10557. }
  10558. return {
  10559. update: update
  10560. };
  10561. }
  10562. function WebGLObjects(gl, geometries, attributes, info) {
  10563. var updateMap = new WeakMap();
  10564. function update(object) {
  10565. var frame = info.render.frame;
  10566. var geometry = object.geometry;
  10567. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  10568. if (updateMap.get(buffergeometry) !== frame) {
  10569. geometries.update(buffergeometry);
  10570. updateMap.set(buffergeometry, frame);
  10571. }
  10572. if (object.isInstancedMesh) {
  10573. if (object.hasEventListener('dispose', onInstancedMeshDispose) === false) {
  10574. object.addEventListener('dispose', onInstancedMeshDispose);
  10575. }
  10576. attributes.update(object.instanceMatrix, 34962);
  10577. if (object.instanceColor !== null) {
  10578. attributes.update(object.instanceColor, 34962);
  10579. }
  10580. }
  10581. return buffergeometry;
  10582. }
  10583. function dispose() {
  10584. updateMap = new WeakMap();
  10585. }
  10586. function onInstancedMeshDispose(event) {
  10587. var instancedMesh = event.target;
  10588. instancedMesh.removeEventListener('dispose', onInstancedMeshDispose);
  10589. attributes.remove(instancedMesh.instanceMatrix);
  10590. if (instancedMesh.instanceColor !== null) attributes.remove(instancedMesh.instanceColor);
  10591. }
  10592. return {
  10593. update: update,
  10594. dispose: dispose
  10595. };
  10596. }
  10597. function DataTexture2DArray(data, width, height, depth) {
  10598. if (data === void 0) {
  10599. data = null;
  10600. }
  10601. if (width === void 0) {
  10602. width = 1;
  10603. }
  10604. if (height === void 0) {
  10605. height = 1;
  10606. }
  10607. if (depth === void 0) {
  10608. depth = 1;
  10609. }
  10610. Texture.call(this, null);
  10611. this.image = {
  10612. data: data,
  10613. width: width,
  10614. height: height,
  10615. depth: depth
  10616. };
  10617. this.magFilter = NearestFilter;
  10618. this.minFilter = NearestFilter;
  10619. this.wrapR = ClampToEdgeWrapping;
  10620. this.generateMipmaps = false;
  10621. this.flipY = false;
  10622. this.needsUpdate = true;
  10623. }
  10624. DataTexture2DArray.prototype = Object.create(Texture.prototype);
  10625. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  10626. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  10627. function DataTexture3D(data, width, height, depth) {
  10628. if (data === void 0) {
  10629. data = null;
  10630. }
  10631. if (width === void 0) {
  10632. width = 1;
  10633. }
  10634. if (height === void 0) {
  10635. height = 1;
  10636. }
  10637. if (depth === void 0) {
  10638. depth = 1;
  10639. }
  10640. // We're going to add .setXXX() methods for setting properties later.
  10641. // Users can still set in DataTexture3D directly.
  10642. //
  10643. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  10644. // texture.anisotropy = 16;
  10645. //
  10646. // See #14839
  10647. Texture.call(this, null);
  10648. this.image = {
  10649. data: data,
  10650. width: width,
  10651. height: height,
  10652. depth: depth
  10653. };
  10654. this.magFilter = NearestFilter;
  10655. this.minFilter = NearestFilter;
  10656. this.wrapR = ClampToEdgeWrapping;
  10657. this.generateMipmaps = false;
  10658. this.flipY = false;
  10659. this.needsUpdate = true;
  10660. }
  10661. DataTexture3D.prototype = Object.create(Texture.prototype);
  10662. DataTexture3D.prototype.constructor = DataTexture3D;
  10663. DataTexture3D.prototype.isDataTexture3D = true;
  10664. /**
  10665. * Uniforms of a program.
  10666. * Those form a tree structure with a special top-level container for the root,
  10667. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10668. *
  10669. *
  10670. * Properties of inner nodes including the top-level container:
  10671. *
  10672. * .seq - array of nested uniforms
  10673. * .map - nested uniforms by name
  10674. *
  10675. *
  10676. * Methods of all nodes except the top-level container:
  10677. *
  10678. * .setValue( gl, value, [textures] )
  10679. *
  10680. * uploads a uniform value(s)
  10681. * the 'textures' parameter is needed for sampler uniforms
  10682. *
  10683. *
  10684. * Static methods of the top-level container (textures factorizations):
  10685. *
  10686. * .upload( gl, seq, values, textures )
  10687. *
  10688. * sets uniforms in 'seq' to 'values[id].value'
  10689. *
  10690. * .seqWithValue( seq, values ) : filteredSeq
  10691. *
  10692. * filters 'seq' entries with corresponding entry in values
  10693. *
  10694. *
  10695. * Methods of the top-level container (textures factorizations):
  10696. *
  10697. * .setValue( gl, name, value, textures )
  10698. *
  10699. * sets uniform with name 'name' to 'value'
  10700. *
  10701. * .setOptional( gl, obj, prop )
  10702. *
  10703. * like .set for an optional property of the object
  10704. *
  10705. */
  10706. var emptyTexture = new Texture();
  10707. var emptyTexture2dArray = new DataTexture2DArray();
  10708. var emptyTexture3d = new DataTexture3D();
  10709. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  10710. // Array Caches (provide typed arrays for temporary by size)
  10711. var arrayCacheF32 = [];
  10712. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  10713. var mat4array = new Float32Array(16);
  10714. var mat3array = new Float32Array(9);
  10715. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  10716. function flatten(array, nBlocks, blockSize) {
  10717. var firstElem = array[0];
  10718. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  10719. // see http://jacksondunstan.com/articles/983
  10720. var n = nBlocks * blockSize;
  10721. var r = arrayCacheF32[n];
  10722. if (r === undefined) {
  10723. r = new Float32Array(n);
  10724. arrayCacheF32[n] = r;
  10725. }
  10726. if (nBlocks !== 0) {
  10727. firstElem.toArray(r, 0);
  10728. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  10729. offset += blockSize;
  10730. array[i].toArray(r, offset);
  10731. }
  10732. }
  10733. return r;
  10734. }
  10735. function arraysEqual(a, b) {
  10736. if (a.length !== b.length) return false;
  10737. for (var i = 0, l = a.length; i < l; i++) {
  10738. if (a[i] !== b[i]) return false;
  10739. }
  10740. return true;
  10741. }
  10742. function copyArray(a, b) {
  10743. for (var i = 0, l = b.length; i < l; i++) {
  10744. a[i] = b[i];
  10745. }
  10746. } // Texture unit allocation
  10747. function allocTexUnits(textures, n) {
  10748. var r = arrayCacheI32[n];
  10749. if (r === undefined) {
  10750. r = new Int32Array(n);
  10751. arrayCacheI32[n] = r;
  10752. }
  10753. for (var i = 0; i !== n; ++i) {
  10754. r[i] = textures.allocateTextureUnit();
  10755. }
  10756. return r;
  10757. } // --- Setters ---
  10758. // Note: Defining these methods externally, because they come in a bunch
  10759. // and this way their names minify.
  10760. // Single scalar
  10761. function setValueV1f(gl, v) {
  10762. var cache = this.cache;
  10763. if (cache[0] === v) return;
  10764. gl.uniform1f(this.addr, v);
  10765. cache[0] = v;
  10766. } // Single float vector (from flat array or THREE.VectorN)
  10767. function setValueV2f(gl, v) {
  10768. var cache = this.cache;
  10769. if (v.x !== undefined) {
  10770. if (cache[0] !== v.x || cache[1] !== v.y) {
  10771. gl.uniform2f(this.addr, v.x, v.y);
  10772. cache[0] = v.x;
  10773. cache[1] = v.y;
  10774. }
  10775. } else {
  10776. if (arraysEqual(cache, v)) return;
  10777. gl.uniform2fv(this.addr, v);
  10778. copyArray(cache, v);
  10779. }
  10780. }
  10781. function setValueV3f(gl, v) {
  10782. var cache = this.cache;
  10783. if (v.x !== undefined) {
  10784. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10785. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10786. cache[0] = v.x;
  10787. cache[1] = v.y;
  10788. cache[2] = v.z;
  10789. }
  10790. } else if (v.r !== undefined) {
  10791. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10792. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10793. cache[0] = v.r;
  10794. cache[1] = v.g;
  10795. cache[2] = v.b;
  10796. }
  10797. } else {
  10798. if (arraysEqual(cache, v)) return;
  10799. gl.uniform3fv(this.addr, v);
  10800. copyArray(cache, v);
  10801. }
  10802. }
  10803. function setValueV4f(gl, v) {
  10804. var cache = this.cache;
  10805. if (v.x !== undefined) {
  10806. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10807. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10808. cache[0] = v.x;
  10809. cache[1] = v.y;
  10810. cache[2] = v.z;
  10811. cache[3] = v.w;
  10812. }
  10813. } else {
  10814. if (arraysEqual(cache, v)) return;
  10815. gl.uniform4fv(this.addr, v);
  10816. copyArray(cache, v);
  10817. }
  10818. } // Single matrix (from flat array or MatrixN)
  10819. function setValueM2(gl, v) {
  10820. var cache = this.cache;
  10821. var elements = v.elements;
  10822. if (elements === undefined) {
  10823. if (arraysEqual(cache, v)) return;
  10824. gl.uniformMatrix2fv(this.addr, false, v);
  10825. copyArray(cache, v);
  10826. } else {
  10827. if (arraysEqual(cache, elements)) return;
  10828. mat2array.set(elements);
  10829. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10830. copyArray(cache, elements);
  10831. }
  10832. }
  10833. function setValueM3(gl, v) {
  10834. var cache = this.cache;
  10835. var elements = v.elements;
  10836. if (elements === undefined) {
  10837. if (arraysEqual(cache, v)) return;
  10838. gl.uniformMatrix3fv(this.addr, false, v);
  10839. copyArray(cache, v);
  10840. } else {
  10841. if (arraysEqual(cache, elements)) return;
  10842. mat3array.set(elements);
  10843. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10844. copyArray(cache, elements);
  10845. }
  10846. }
  10847. function setValueM4(gl, v) {
  10848. var cache = this.cache;
  10849. var elements = v.elements;
  10850. if (elements === undefined) {
  10851. if (arraysEqual(cache, v)) return;
  10852. gl.uniformMatrix4fv(this.addr, false, v);
  10853. copyArray(cache, v);
  10854. } else {
  10855. if (arraysEqual(cache, elements)) return;
  10856. mat4array.set(elements);
  10857. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10858. copyArray(cache, elements);
  10859. }
  10860. } // Single texture (2D / Cube)
  10861. function setValueT1(gl, v, textures) {
  10862. var cache = this.cache;
  10863. var unit = textures.allocateTextureUnit();
  10864. if (cache[0] !== unit) {
  10865. gl.uniform1i(this.addr, unit);
  10866. cache[0] = unit;
  10867. }
  10868. textures.safeSetTexture2D(v || emptyTexture, unit);
  10869. }
  10870. function setValueT2DArray1(gl, v, textures) {
  10871. var cache = this.cache;
  10872. var unit = textures.allocateTextureUnit();
  10873. if (cache[0] !== unit) {
  10874. gl.uniform1i(this.addr, unit);
  10875. cache[0] = unit;
  10876. }
  10877. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10878. }
  10879. function setValueT3D1(gl, v, textures) {
  10880. var cache = this.cache;
  10881. var unit = textures.allocateTextureUnit();
  10882. if (cache[0] !== unit) {
  10883. gl.uniform1i(this.addr, unit);
  10884. cache[0] = unit;
  10885. }
  10886. textures.setTexture3D(v || emptyTexture3d, unit);
  10887. }
  10888. function setValueT6(gl, v, textures) {
  10889. var cache = this.cache;
  10890. var unit = textures.allocateTextureUnit();
  10891. if (cache[0] !== unit) {
  10892. gl.uniform1i(this.addr, unit);
  10893. cache[0] = unit;
  10894. }
  10895. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10896. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10897. function setValueV1i(gl, v) {
  10898. var cache = this.cache;
  10899. if (cache[0] === v) return;
  10900. gl.uniform1i(this.addr, v);
  10901. cache[0] = v;
  10902. }
  10903. function setValueV2i(gl, v) {
  10904. var cache = this.cache;
  10905. if (arraysEqual(cache, v)) return;
  10906. gl.uniform2iv(this.addr, v);
  10907. copyArray(cache, v);
  10908. }
  10909. function setValueV3i(gl, v) {
  10910. var cache = this.cache;
  10911. if (arraysEqual(cache, v)) return;
  10912. gl.uniform3iv(this.addr, v);
  10913. copyArray(cache, v);
  10914. }
  10915. function setValueV4i(gl, v) {
  10916. var cache = this.cache;
  10917. if (arraysEqual(cache, v)) return;
  10918. gl.uniform4iv(this.addr, v);
  10919. copyArray(cache, v);
  10920. } // uint
  10921. function setValueV1ui(gl, v) {
  10922. var cache = this.cache;
  10923. if (cache[0] === v) return;
  10924. gl.uniform1ui(this.addr, v);
  10925. cache[0] = v;
  10926. } // Helper to pick the right setter for the singular case
  10927. function getSingularSetter(type) {
  10928. switch (type) {
  10929. case 0x1406:
  10930. return setValueV1f;
  10931. // FLOAT
  10932. case 0x8b50:
  10933. return setValueV2f;
  10934. // _VEC2
  10935. case 0x8b51:
  10936. return setValueV3f;
  10937. // _VEC3
  10938. case 0x8b52:
  10939. return setValueV4f;
  10940. // _VEC4
  10941. case 0x8b5a:
  10942. return setValueM2;
  10943. // _MAT2
  10944. case 0x8b5b:
  10945. return setValueM3;
  10946. // _MAT3
  10947. case 0x8b5c:
  10948. return setValueM4;
  10949. // _MAT4
  10950. case 0x1404:
  10951. case 0x8b56:
  10952. return setValueV1i;
  10953. // INT, BOOL
  10954. case 0x8b53:
  10955. case 0x8b57:
  10956. return setValueV2i;
  10957. // _VEC2
  10958. case 0x8b54:
  10959. case 0x8b58:
  10960. return setValueV3i;
  10961. // _VEC3
  10962. case 0x8b55:
  10963. case 0x8b59:
  10964. return setValueV4i;
  10965. // _VEC4
  10966. case 0x1405:
  10967. return setValueV1ui;
  10968. // UINT
  10969. case 0x8b5e: // SAMPLER_2D
  10970. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10971. case 0x8dca: // INT_SAMPLER_2D
  10972. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10973. case 0x8b62:
  10974. // SAMPLER_2D_SHADOW
  10975. return setValueT1;
  10976. case 0x8b5f: // SAMPLER_3D
  10977. case 0x8dcb: // INT_SAMPLER_3D
  10978. case 0x8dd3:
  10979. // UNSIGNED_INT_SAMPLER_3D
  10980. return setValueT3D1;
  10981. case 0x8b60: // SAMPLER_CUBE
  10982. case 0x8dcc: // INT_SAMPLER_CUBE
  10983. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10984. case 0x8dc5:
  10985. // SAMPLER_CUBE_SHADOW
  10986. return setValueT6;
  10987. case 0x8dc1: // SAMPLER_2D_ARRAY
  10988. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10989. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10990. case 0x8dc4:
  10991. // SAMPLER_2D_ARRAY_SHADOW
  10992. return setValueT2DArray1;
  10993. }
  10994. } // Array of scalars
  10995. function setValueV1fArray(gl, v) {
  10996. gl.uniform1fv(this.addr, v);
  10997. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10998. function setValueV1iArray(gl, v) {
  10999. gl.uniform1iv(this.addr, v);
  11000. }
  11001. function setValueV2iArray(gl, v) {
  11002. gl.uniform2iv(this.addr, v);
  11003. }
  11004. function setValueV3iArray(gl, v) {
  11005. gl.uniform3iv(this.addr, v);
  11006. }
  11007. function setValueV4iArray(gl, v) {
  11008. gl.uniform4iv(this.addr, v);
  11009. } // Array of vectors (flat or from THREE classes)
  11010. function setValueV2fArray(gl, v) {
  11011. var data = flatten(v, this.size, 2);
  11012. gl.uniform2fv(this.addr, data);
  11013. }
  11014. function setValueV3fArray(gl, v) {
  11015. var data = flatten(v, this.size, 3);
  11016. gl.uniform3fv(this.addr, data);
  11017. }
  11018. function setValueV4fArray(gl, v) {
  11019. var data = flatten(v, this.size, 4);
  11020. gl.uniform4fv(this.addr, data);
  11021. } // Array of matrices (flat or from THREE clases)
  11022. function setValueM2Array(gl, v) {
  11023. var data = flatten(v, this.size, 4);
  11024. gl.uniformMatrix2fv(this.addr, false, data);
  11025. }
  11026. function setValueM3Array(gl, v) {
  11027. var data = flatten(v, this.size, 9);
  11028. gl.uniformMatrix3fv(this.addr, false, data);
  11029. }
  11030. function setValueM4Array(gl, v) {
  11031. var data = flatten(v, this.size, 16);
  11032. gl.uniformMatrix4fv(this.addr, false, data);
  11033. } // Array of textures (2D / Cube)
  11034. function setValueT1Array(gl, v, textures) {
  11035. var n = v.length;
  11036. var units = allocTexUnits(textures, n);
  11037. gl.uniform1iv(this.addr, units);
  11038. for (var i = 0; i !== n; ++i) {
  11039. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  11040. }
  11041. }
  11042. function setValueT6Array(gl, v, textures) {
  11043. var n = v.length;
  11044. var units = allocTexUnits(textures, n);
  11045. gl.uniform1iv(this.addr, units);
  11046. for (var i = 0; i !== n; ++i) {
  11047. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  11048. }
  11049. } // Helper to pick the right setter for a pure (bottom-level) array
  11050. function getPureArraySetter(type) {
  11051. switch (type) {
  11052. case 0x1406:
  11053. return setValueV1fArray;
  11054. // FLOAT
  11055. case 0x8b50:
  11056. return setValueV2fArray;
  11057. // _VEC2
  11058. case 0x8b51:
  11059. return setValueV3fArray;
  11060. // _VEC3
  11061. case 0x8b52:
  11062. return setValueV4fArray;
  11063. // _VEC4
  11064. case 0x8b5a:
  11065. return setValueM2Array;
  11066. // _MAT2
  11067. case 0x8b5b:
  11068. return setValueM3Array;
  11069. // _MAT3
  11070. case 0x8b5c:
  11071. return setValueM4Array;
  11072. // _MAT4
  11073. case 0x1404:
  11074. case 0x8b56:
  11075. return setValueV1iArray;
  11076. // INT, BOOL
  11077. case 0x8b53:
  11078. case 0x8b57:
  11079. return setValueV2iArray;
  11080. // _VEC2
  11081. case 0x8b54:
  11082. case 0x8b58:
  11083. return setValueV3iArray;
  11084. // _VEC3
  11085. case 0x8b55:
  11086. case 0x8b59:
  11087. return setValueV4iArray;
  11088. // _VEC4
  11089. case 0x8b5e: // SAMPLER_2D
  11090. case 0x8d66: // SAMPLER_EXTERNAL_OES
  11091. case 0x8dca: // INT_SAMPLER_2D
  11092. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  11093. case 0x8b62:
  11094. // SAMPLER_2D_SHADOW
  11095. return setValueT1Array;
  11096. case 0x8b60: // SAMPLER_CUBE
  11097. case 0x8dcc: // INT_SAMPLER_CUBE
  11098. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  11099. case 0x8dc5:
  11100. // SAMPLER_CUBE_SHADOW
  11101. return setValueT6Array;
  11102. }
  11103. } // --- Uniform Classes ---
  11104. function SingleUniform(id, activeInfo, addr) {
  11105. this.id = id;
  11106. this.addr = addr;
  11107. this.cache = [];
  11108. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  11109. }
  11110. function PureArrayUniform(id, activeInfo, addr) {
  11111. this.id = id;
  11112. this.addr = addr;
  11113. this.cache = [];
  11114. this.size = activeInfo.size;
  11115. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  11116. }
  11117. PureArrayUniform.prototype.updateCache = function (data) {
  11118. var cache = this.cache;
  11119. if (data instanceof Float32Array && cache.length !== data.length) {
  11120. this.cache = new Float32Array(data.length);
  11121. }
  11122. copyArray(cache, data);
  11123. };
  11124. function StructuredUniform(id) {
  11125. this.id = id;
  11126. this.seq = [];
  11127. this.map = {};
  11128. }
  11129. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  11130. var seq = this.seq;
  11131. for (var i = 0, n = seq.length; i !== n; ++i) {
  11132. var u = seq[i];
  11133. u.setValue(gl, value[u.id], textures);
  11134. }
  11135. }; // --- Top-level ---
  11136. // Parser - builds up the property tree from the path strings
  11137. var RePathPart = /(\w+)(\])?(\[|\.)?/g; // extracts
  11138. // - the identifier (member name or array index)
  11139. // - followed by an optional right bracket (found when array index)
  11140. // - followed by an optional left bracket or dot (type of subscript)
  11141. //
  11142. // Note: These portions can be read in a non-overlapping fashion and
  11143. // allow straightforward parsing of the hierarchy that WebGL encodes
  11144. // in the uniform names.
  11145. function addUniform(container, uniformObject) {
  11146. container.seq.push(uniformObject);
  11147. container.map[uniformObject.id] = uniformObject;
  11148. }
  11149. function parseUniform(activeInfo, addr, container) {
  11150. var path = activeInfo.name,
  11151. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  11152. RePathPart.lastIndex = 0;
  11153. while (true) {
  11154. var match = RePathPart.exec(path),
  11155. matchEnd = RePathPart.lastIndex;
  11156. var id = match[1];
  11157. var idIsIndex = match[2] === ']',
  11158. subscript = match[3];
  11159. if (idIsIndex) id = id | 0; // convert to integer
  11160. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  11161. // bare name or "pure" bottom-level array "[0]" suffix
  11162. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  11163. break;
  11164. } else {
  11165. // step into inner node / create it in case it doesn't exist
  11166. var map = container.map;
  11167. var next = map[id];
  11168. if (next === undefined) {
  11169. next = new StructuredUniform(id);
  11170. addUniform(container, next);
  11171. }
  11172. container = next;
  11173. }
  11174. }
  11175. } // Root Container
  11176. function WebGLUniforms(gl, program) {
  11177. this.seq = [];
  11178. this.map = {};
  11179. var n = gl.getProgramParameter(program, 35718);
  11180. for (var i = 0; i < n; ++i) {
  11181. var info = gl.getActiveUniform(program, i),
  11182. addr = gl.getUniformLocation(program, info.name);
  11183. parseUniform(info, addr, this);
  11184. }
  11185. }
  11186. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  11187. var u = this.map[name];
  11188. if (u !== undefined) u.setValue(gl, value, textures);
  11189. };
  11190. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  11191. var v = object[name];
  11192. if (v !== undefined) this.setValue(gl, name, v);
  11193. }; // Static interface
  11194. WebGLUniforms.upload = function (gl, seq, values, textures) {
  11195. for (var i = 0, n = seq.length; i !== n; ++i) {
  11196. var u = seq[i],
  11197. v = values[u.id];
  11198. if (v.needsUpdate !== false) {
  11199. // note: always updating when .needsUpdate is undefined
  11200. u.setValue(gl, v.value, textures);
  11201. }
  11202. }
  11203. };
  11204. WebGLUniforms.seqWithValue = function (seq, values) {
  11205. var r = [];
  11206. for (var i = 0, n = seq.length; i !== n; ++i) {
  11207. var u = seq[i];
  11208. if (u.id in values) r.push(u);
  11209. }
  11210. return r;
  11211. };
  11212. function WebGLShader(gl, type, string) {
  11213. var shader = gl.createShader(type);
  11214. gl.shaderSource(shader, string);
  11215. gl.compileShader(shader);
  11216. return shader;
  11217. }
  11218. var programIdCount = 0;
  11219. function addLineNumbers(string) {
  11220. var lines = string.split('\n');
  11221. for (var i = 0; i < lines.length; i++) {
  11222. lines[i] = i + 1 + ': ' + lines[i];
  11223. }
  11224. return lines.join('\n');
  11225. }
  11226. function getEncodingComponents(encoding) {
  11227. switch (encoding) {
  11228. case LinearEncoding:
  11229. return ['Linear', '( value )'];
  11230. case sRGBEncoding:
  11231. return ['sRGB', '( value )'];
  11232. case RGBEEncoding:
  11233. return ['RGBE', '( value )'];
  11234. case RGBM7Encoding:
  11235. return ['RGBM', '( value, 7.0 )'];
  11236. case RGBM16Encoding:
  11237. return ['RGBM', '( value, 16.0 )'];
  11238. case RGBDEncoding:
  11239. return ['RGBD', '( value, 256.0 )'];
  11240. case GammaEncoding:
  11241. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  11242. case LogLuvEncoding:
  11243. return ['LogLuv', '( value )'];
  11244. default:
  11245. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  11246. return ['Linear', '( value )'];
  11247. }
  11248. }
  11249. function getShaderErrors(gl, shader, type) {
  11250. var status = gl.getShaderParameter(shader, 35713);
  11251. var log = gl.getShaderInfoLog(shader).trim();
  11252. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  11253. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  11254. var source = gl.getShaderSource(shader);
  11255. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  11256. }
  11257. function getTexelDecodingFunction(functionName, encoding) {
  11258. var components = getEncodingComponents(encoding);
  11259. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  11260. }
  11261. function getTexelEncodingFunction(functionName, encoding) {
  11262. var components = getEncodingComponents(encoding);
  11263. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  11264. }
  11265. function getToneMappingFunction(functionName, toneMapping) {
  11266. var toneMappingName;
  11267. switch (toneMapping) {
  11268. case LinearToneMapping:
  11269. toneMappingName = 'Linear';
  11270. break;
  11271. case ReinhardToneMapping:
  11272. toneMappingName = 'Reinhard';
  11273. break;
  11274. case CineonToneMapping:
  11275. toneMappingName = 'OptimizedCineon';
  11276. break;
  11277. case ACESFilmicToneMapping:
  11278. toneMappingName = 'ACESFilmic';
  11279. break;
  11280. case CustomToneMapping:
  11281. toneMappingName = 'Custom';
  11282. break;
  11283. default:
  11284. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  11285. toneMappingName = 'Linear';
  11286. }
  11287. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  11288. }
  11289. function generateExtensions(parameters) {
  11290. 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' : ''];
  11291. return chunks.filter(filterEmptyLine).join('\n');
  11292. }
  11293. function generateDefines(defines) {
  11294. var chunks = [];
  11295. for (var name in defines) {
  11296. var value = defines[name];
  11297. if (value === false) continue;
  11298. chunks.push('#define ' + name + ' ' + value);
  11299. }
  11300. return chunks.join('\n');
  11301. }
  11302. function fetchAttributeLocations(gl, program) {
  11303. var attributes = {};
  11304. var n = gl.getProgramParameter(program, 35721);
  11305. for (var i = 0; i < n; i++) {
  11306. var info = gl.getActiveAttrib(program, i);
  11307. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  11308. attributes[name] = gl.getAttribLocation(program, name);
  11309. }
  11310. return attributes;
  11311. }
  11312. function filterEmptyLine(string) {
  11313. return string !== '';
  11314. }
  11315. function replaceLightNums(string, parameters) {
  11316. 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);
  11317. }
  11318. function replaceClippingPlaneNums(string, parameters) {
  11319. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  11320. } // Resolve Includes
  11321. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  11322. function resolveIncludes(string) {
  11323. return string.replace(includePattern, includeReplacer);
  11324. }
  11325. function includeReplacer(match, include) {
  11326. var string = ShaderChunk[include];
  11327. if (string === undefined) {
  11328. throw new Error('Can not resolve #include <' + include + '>');
  11329. }
  11330. return resolveIncludes(string);
  11331. } // Unroll Loops
  11332. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  11333. 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;
  11334. function unrollLoops(string) {
  11335. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  11336. }
  11337. function deprecatedLoopReplacer(match, start, end, snippet) {
  11338. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  11339. return loopReplacer(match, start, end, snippet);
  11340. }
  11341. function loopReplacer(match, start, end, snippet) {
  11342. var string = '';
  11343. for (var i = parseInt(start); i < parseInt(end); i++) {
  11344. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  11345. }
  11346. return string;
  11347. } //
  11348. function generatePrecision(parameters) {
  11349. var precisionstring = 'precision ' + parameters.precision + ' float;\nprecision ' + parameters.precision + ' int;';
  11350. if (parameters.precision === 'highp') {
  11351. precisionstring += '\n#define HIGH_PRECISION';
  11352. } else if (parameters.precision === 'mediump') {
  11353. precisionstring += '\n#define MEDIUM_PRECISION';
  11354. } else if (parameters.precision === 'lowp') {
  11355. precisionstring += '\n#define LOW_PRECISION';
  11356. }
  11357. return precisionstring;
  11358. }
  11359. function generateShadowMapTypeDefine(parameters) {
  11360. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  11361. if (parameters.shadowMapType === PCFShadowMap) {
  11362. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  11363. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  11364. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  11365. } else if (parameters.shadowMapType === VSMShadowMap) {
  11366. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  11367. }
  11368. return shadowMapTypeDefine;
  11369. }
  11370. function generateEnvMapTypeDefine(parameters) {
  11371. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11372. if (parameters.envMap) {
  11373. switch (parameters.envMapMode) {
  11374. case CubeReflectionMapping:
  11375. case CubeRefractionMapping:
  11376. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11377. break;
  11378. case CubeUVReflectionMapping:
  11379. case CubeUVRefractionMapping:
  11380. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  11381. break;
  11382. }
  11383. }
  11384. return envMapTypeDefine;
  11385. }
  11386. function generateEnvMapModeDefine(parameters) {
  11387. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  11388. if (parameters.envMap) {
  11389. switch (parameters.envMapMode) {
  11390. case CubeRefractionMapping:
  11391. case CubeUVRefractionMapping:
  11392. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  11393. break;
  11394. }
  11395. }
  11396. return envMapModeDefine;
  11397. }
  11398. function generateEnvMapBlendingDefine(parameters) {
  11399. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  11400. if (parameters.envMap) {
  11401. switch (parameters.combine) {
  11402. case MultiplyOperation:
  11403. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  11404. break;
  11405. case MixOperation:
  11406. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  11407. break;
  11408. case AddOperation:
  11409. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  11410. break;
  11411. }
  11412. }
  11413. return envMapBlendingDefine;
  11414. }
  11415. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  11416. var gl = renderer.getContext();
  11417. var defines = parameters.defines;
  11418. var vertexShader = parameters.vertexShader;
  11419. var fragmentShader = parameters.fragmentShader;
  11420. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  11421. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  11422. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  11423. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  11424. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  11425. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  11426. var customDefines = generateDefines(defines);
  11427. var program = gl.createProgram();
  11428. var prefixVertex, prefixFragment;
  11429. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : '';
  11430. if (parameters.isRawShaderMaterial) {
  11431. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  11432. if (prefixVertex.length > 0) {
  11433. prefixVertex += '\n';
  11434. }
  11435. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  11436. if (prefixFragment.length > 0) {
  11437. prefixFragment += '\n';
  11438. }
  11439. } else {
  11440. 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');
  11441. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  11442. '#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
  11443. 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
  11444. 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');
  11445. }
  11446. vertexShader = resolveIncludes(vertexShader);
  11447. vertexShader = replaceLightNums(vertexShader, parameters);
  11448. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  11449. fragmentShader = resolveIncludes(fragmentShader);
  11450. fragmentShader = replaceLightNums(fragmentShader, parameters);
  11451. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  11452. vertexShader = unrollLoops(vertexShader);
  11453. fragmentShader = unrollLoops(fragmentShader);
  11454. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  11455. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  11456. versionString = '#version 300 es\n';
  11457. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  11458. 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;
  11459. }
  11460. var vertexGlsl = versionString + prefixVertex + vertexShader;
  11461. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  11462. // console.log( '*FRAGMENT*', fragmentGlsl );
  11463. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  11464. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  11465. gl.attachShader(program, glVertexShader);
  11466. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  11467. if (parameters.index0AttributeName !== undefined) {
  11468. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  11469. } else if (parameters.morphTargets === true) {
  11470. // programs with morphTargets displace position out of attribute 0
  11471. gl.bindAttribLocation(program, 0, 'position');
  11472. }
  11473. gl.linkProgram(program); // check for link errors
  11474. if (renderer.debug.checkShaderErrors) {
  11475. var programLog = gl.getProgramInfoLog(program).trim();
  11476. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  11477. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  11478. var runnable = true;
  11479. var haveDiagnostics = true;
  11480. if (gl.getProgramParameter(program, 35714) === false) {
  11481. runnable = false;
  11482. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  11483. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  11484. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  11485. } else if (programLog !== '') {
  11486. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  11487. } else if (vertexLog === '' || fragmentLog === '') {
  11488. haveDiagnostics = false;
  11489. }
  11490. if (haveDiagnostics) {
  11491. this.diagnostics = {
  11492. runnable: runnable,
  11493. programLog: programLog,
  11494. vertexShader: {
  11495. log: vertexLog,
  11496. prefix: prefixVertex
  11497. },
  11498. fragmentShader: {
  11499. log: fragmentLog,
  11500. prefix: prefixFragment
  11501. }
  11502. };
  11503. }
  11504. } // Clean up
  11505. // Crashes in iOS9 and iOS10. #18402
  11506. // gl.detachShader( program, glVertexShader );
  11507. // gl.detachShader( program, glFragmentShader );
  11508. gl.deleteShader(glVertexShader);
  11509. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  11510. var cachedUniforms;
  11511. this.getUniforms = function () {
  11512. if (cachedUniforms === undefined) {
  11513. cachedUniforms = new WebGLUniforms(gl, program);
  11514. }
  11515. return cachedUniforms;
  11516. }; // set up caching for attribute locations
  11517. var cachedAttributes;
  11518. this.getAttributes = function () {
  11519. if (cachedAttributes === undefined) {
  11520. cachedAttributes = fetchAttributeLocations(gl, program);
  11521. }
  11522. return cachedAttributes;
  11523. }; // free resource
  11524. this.destroy = function () {
  11525. bindingStates.releaseStatesOfProgram(this);
  11526. gl.deleteProgram(program);
  11527. this.program = undefined;
  11528. }; //
  11529. this.name = parameters.shaderName;
  11530. this.id = programIdCount++;
  11531. this.cacheKey = cacheKey;
  11532. this.usedTimes = 1;
  11533. this.program = program;
  11534. this.vertexShader = glVertexShader;
  11535. this.fragmentShader = glFragmentShader;
  11536. return this;
  11537. }
  11538. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  11539. var programs = [];
  11540. var isWebGL2 = capabilities.isWebGL2;
  11541. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  11542. var floatVertexTextures = capabilities.floatVertexTextures;
  11543. var maxVertexUniforms = capabilities.maxVertexUniforms;
  11544. var vertexTextures = capabilities.vertexTextures;
  11545. var precision = capabilities.precision;
  11546. var shaderIDs = {
  11547. MeshDepthMaterial: 'depth',
  11548. MeshDistanceMaterial: 'distanceRGBA',
  11549. MeshNormalMaterial: 'normal',
  11550. MeshBasicMaterial: 'basic',
  11551. MeshLambertMaterial: 'lambert',
  11552. MeshPhongMaterial: 'phong',
  11553. MeshToonMaterial: 'toon',
  11554. MeshStandardMaterial: 'physical',
  11555. MeshPhysicalMaterial: 'physical',
  11556. MeshMatcapMaterial: 'matcap',
  11557. LineBasicMaterial: 'basic',
  11558. LineDashedMaterial: 'dashed',
  11559. PointsMaterial: 'points',
  11560. ShadowMaterial: 'shadow',
  11561. SpriteMaterial: 'sprite'
  11562. };
  11563. 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'];
  11564. function getMaxBones(object) {
  11565. var skeleton = object.skeleton;
  11566. var bones = skeleton.bones;
  11567. if (floatVertexTextures) {
  11568. return 1024;
  11569. } else {
  11570. // default for when object is not specified
  11571. // ( for example when prebuilding shader to be used with multiple objects )
  11572. //
  11573. // - leave some extra space for other uniforms
  11574. // - limit here is ANGLE's 254 max uniform vectors
  11575. // (up to 54 should be safe)
  11576. var nVertexUniforms = maxVertexUniforms;
  11577. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  11578. var maxBones = Math.min(nVertexMatrices, bones.length);
  11579. if (maxBones < bones.length) {
  11580. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  11581. return 0;
  11582. }
  11583. return maxBones;
  11584. }
  11585. }
  11586. function getTextureEncodingFromMap(map) {
  11587. var encoding;
  11588. if (map && map.isTexture) {
  11589. encoding = map.encoding;
  11590. } else if (map && map.isWebGLRenderTarget) {
  11591. console.warn('THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.');
  11592. encoding = map.texture.encoding;
  11593. } else {
  11594. encoding = LinearEncoding;
  11595. }
  11596. return encoding;
  11597. }
  11598. function getParameters(material, lights, shadows, scene, object) {
  11599. var fog = scene.fog;
  11600. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  11601. var envMap = cubemaps.get(material.envMap || environment);
  11602. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  11603. // (not to blow over maxLights budget)
  11604. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  11605. if (material.precision !== null) {
  11606. precision = capabilities.getMaxPrecision(material.precision);
  11607. if (precision !== material.precision) {
  11608. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  11609. }
  11610. }
  11611. var vertexShader, fragmentShader;
  11612. if (shaderID) {
  11613. var shader = ShaderLib[shaderID];
  11614. vertexShader = shader.vertexShader;
  11615. fragmentShader = shader.fragmentShader;
  11616. } else {
  11617. vertexShader = material.vertexShader;
  11618. fragmentShader = material.fragmentShader;
  11619. }
  11620. var currentRenderTarget = renderer.getRenderTarget();
  11621. var parameters = {
  11622. isWebGL2: isWebGL2,
  11623. shaderID: shaderID,
  11624. shaderName: material.type,
  11625. vertexShader: vertexShader,
  11626. fragmentShader: fragmentShader,
  11627. defines: material.defines,
  11628. isRawShaderMaterial: material.isRawShaderMaterial === true,
  11629. glslVersion: material.glslVersion,
  11630. precision: precision,
  11631. instancing: object.isInstancedMesh === true,
  11632. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  11633. supportsVertexTextures: vertexTextures,
  11634. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  11635. map: !!material.map,
  11636. mapEncoding: getTextureEncodingFromMap(material.map),
  11637. matcap: !!material.matcap,
  11638. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  11639. envMap: !!envMap,
  11640. envMapMode: envMap && envMap.mapping,
  11641. envMapEncoding: getTextureEncodingFromMap(envMap),
  11642. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  11643. lightMap: !!material.lightMap,
  11644. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  11645. aoMap: !!material.aoMap,
  11646. emissiveMap: !!material.emissiveMap,
  11647. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  11648. bumpMap: !!material.bumpMap,
  11649. normalMap: !!material.normalMap,
  11650. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11651. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11652. clearcoatMap: !!material.clearcoatMap,
  11653. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  11654. clearcoatNormalMap: !!material.clearcoatNormalMap,
  11655. displacementMap: !!material.displacementMap,
  11656. roughnessMap: !!material.roughnessMap,
  11657. metalnessMap: !!material.metalnessMap,
  11658. specularMap: !!material.specularMap,
  11659. alphaMap: !!material.alphaMap,
  11660. gradientMap: !!material.gradientMap,
  11661. sheen: !!material.sheen,
  11662. transmissionMap: !!material.transmissionMap,
  11663. combine: material.combine,
  11664. vertexTangents: material.normalMap && material.vertexTangents,
  11665. vertexColors: material.vertexColors,
  11666. 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,
  11667. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  11668. fog: !!fog,
  11669. useFog: material.fog,
  11670. fogExp2: fog && fog.isFogExp2,
  11671. flatShading: material.flatShading,
  11672. sizeAttenuation: material.sizeAttenuation,
  11673. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11674. skinning: material.skinning && maxBones > 0,
  11675. maxBones: maxBones,
  11676. useVertexTexture: floatVertexTextures,
  11677. morphTargets: material.morphTargets,
  11678. morphNormals: material.morphNormals,
  11679. maxMorphTargets: renderer.maxMorphTargets,
  11680. maxMorphNormals: renderer.maxMorphNormals,
  11681. numDirLights: lights.directional.length,
  11682. numPointLights: lights.point.length,
  11683. numSpotLights: lights.spot.length,
  11684. numRectAreaLights: lights.rectArea.length,
  11685. numHemiLights: lights.hemi.length,
  11686. numDirLightShadows: lights.directionalShadowMap.length,
  11687. numPointLightShadows: lights.pointShadowMap.length,
  11688. numSpotLightShadows: lights.spotShadowMap.length,
  11689. numClippingPlanes: clipping.numPlanes,
  11690. numClipIntersection: clipping.numIntersection,
  11691. dithering: material.dithering,
  11692. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11693. shadowMapType: renderer.shadowMap.type,
  11694. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11695. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11696. premultipliedAlpha: material.premultipliedAlpha,
  11697. alphaTest: material.alphaTest,
  11698. doubleSided: material.side === DoubleSide,
  11699. flipSided: material.side === BackSide,
  11700. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  11701. index0AttributeName: material.index0AttributeName,
  11702. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11703. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11704. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11705. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11706. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  11707. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  11708. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  11709. customProgramCacheKey: material.customProgramCacheKey()
  11710. };
  11711. return parameters;
  11712. }
  11713. function getProgramCacheKey(parameters) {
  11714. var array = [];
  11715. if (parameters.shaderID) {
  11716. array.push(parameters.shaderID);
  11717. } else {
  11718. array.push(parameters.fragmentShader);
  11719. array.push(parameters.vertexShader);
  11720. }
  11721. if (parameters.defines !== undefined) {
  11722. for (var name in parameters.defines) {
  11723. array.push(name);
  11724. array.push(parameters.defines[name]);
  11725. }
  11726. }
  11727. if (parameters.isRawShaderMaterial === false) {
  11728. for (var i = 0; i < parameterNames.length; i++) {
  11729. array.push(parameters[parameterNames[i]]);
  11730. }
  11731. array.push(renderer.outputEncoding);
  11732. array.push(renderer.gammaFactor);
  11733. }
  11734. array.push(parameters.customProgramCacheKey);
  11735. return array.join();
  11736. }
  11737. function getUniforms(material) {
  11738. var shaderID = shaderIDs[material.type];
  11739. var uniforms;
  11740. if (shaderID) {
  11741. var shader = ShaderLib[shaderID];
  11742. uniforms = UniformsUtils.clone(shader.uniforms);
  11743. } else {
  11744. uniforms = material.uniforms;
  11745. }
  11746. return uniforms;
  11747. }
  11748. function acquireProgram(parameters, cacheKey) {
  11749. var program; // Check if code has been already compiled
  11750. for (var p = 0, pl = programs.length; p < pl; p++) {
  11751. var preexistingProgram = programs[p];
  11752. if (preexistingProgram.cacheKey === cacheKey) {
  11753. program = preexistingProgram;
  11754. ++program.usedTimes;
  11755. break;
  11756. }
  11757. }
  11758. if (program === undefined) {
  11759. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11760. programs.push(program);
  11761. }
  11762. return program;
  11763. }
  11764. function releaseProgram(program) {
  11765. if (--program.usedTimes === 0) {
  11766. // Remove from unordered set
  11767. var i = programs.indexOf(program);
  11768. programs[i] = programs[programs.length - 1];
  11769. programs.pop(); // Free WebGL resources
  11770. program.destroy();
  11771. }
  11772. }
  11773. return {
  11774. getParameters: getParameters,
  11775. getProgramCacheKey: getProgramCacheKey,
  11776. getUniforms: getUniforms,
  11777. acquireProgram: acquireProgram,
  11778. releaseProgram: releaseProgram,
  11779. // Exposed for resource monitoring & error feedback via renderer.info:
  11780. programs: programs
  11781. };
  11782. }
  11783. function WebGLProperties() {
  11784. var properties = new WeakMap();
  11785. function get(object) {
  11786. var map = properties.get(object);
  11787. if (map === undefined) {
  11788. map = {};
  11789. properties.set(object, map);
  11790. }
  11791. return map;
  11792. }
  11793. function remove(object) {
  11794. properties.delete(object);
  11795. }
  11796. function update(object, key, value) {
  11797. properties.get(object)[key] = value;
  11798. }
  11799. function dispose() {
  11800. properties = new WeakMap();
  11801. }
  11802. return {
  11803. get: get,
  11804. remove: remove,
  11805. update: update,
  11806. dispose: dispose
  11807. };
  11808. }
  11809. function painterSortStable(a, b) {
  11810. if (a.groupOrder !== b.groupOrder) {
  11811. return a.groupOrder - b.groupOrder;
  11812. } else if (a.renderOrder !== b.renderOrder) {
  11813. return a.renderOrder - b.renderOrder;
  11814. } else if (a.program !== b.program) {
  11815. return a.program.id - b.program.id;
  11816. } else if (a.material.id !== b.material.id) {
  11817. return a.material.id - b.material.id;
  11818. } else if (a.z !== b.z) {
  11819. return a.z - b.z;
  11820. } else {
  11821. return a.id - b.id;
  11822. }
  11823. }
  11824. function reversePainterSortStable(a, b) {
  11825. if (a.groupOrder !== b.groupOrder) {
  11826. return a.groupOrder - b.groupOrder;
  11827. } else if (a.renderOrder !== b.renderOrder) {
  11828. return a.renderOrder - b.renderOrder;
  11829. } else if (a.z !== b.z) {
  11830. return b.z - a.z;
  11831. } else {
  11832. return a.id - b.id;
  11833. }
  11834. }
  11835. function WebGLRenderList(properties) {
  11836. var renderItems = [];
  11837. var renderItemsIndex = 0;
  11838. var opaque = [];
  11839. var transparent = [];
  11840. var defaultProgram = {
  11841. id: -1
  11842. };
  11843. function init() {
  11844. renderItemsIndex = 0;
  11845. opaque.length = 0;
  11846. transparent.length = 0;
  11847. }
  11848. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11849. var renderItem = renderItems[renderItemsIndex];
  11850. var materialProperties = properties.get(material);
  11851. if (renderItem === undefined) {
  11852. renderItem = {
  11853. id: object.id,
  11854. object: object,
  11855. geometry: geometry,
  11856. material: material,
  11857. program: materialProperties.program || defaultProgram,
  11858. groupOrder: groupOrder,
  11859. renderOrder: object.renderOrder,
  11860. z: z,
  11861. group: group
  11862. };
  11863. renderItems[renderItemsIndex] = renderItem;
  11864. } else {
  11865. renderItem.id = object.id;
  11866. renderItem.object = object;
  11867. renderItem.geometry = geometry;
  11868. renderItem.material = material;
  11869. renderItem.program = materialProperties.program || defaultProgram;
  11870. renderItem.groupOrder = groupOrder;
  11871. renderItem.renderOrder = object.renderOrder;
  11872. renderItem.z = z;
  11873. renderItem.group = group;
  11874. }
  11875. renderItemsIndex++;
  11876. return renderItem;
  11877. }
  11878. function push(object, geometry, material, groupOrder, z, group) {
  11879. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11880. (material.transparent === true ? transparent : opaque).push(renderItem);
  11881. }
  11882. function unshift(object, geometry, material, groupOrder, z, group) {
  11883. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11884. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11885. }
  11886. function sort(customOpaqueSort, customTransparentSort) {
  11887. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11888. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11889. }
  11890. function finish() {
  11891. // Clear references from inactive renderItems in the list
  11892. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11893. var renderItem = renderItems[i];
  11894. if (renderItem.id === null) break;
  11895. renderItem.id = null;
  11896. renderItem.object = null;
  11897. renderItem.geometry = null;
  11898. renderItem.material = null;
  11899. renderItem.program = null;
  11900. renderItem.group = null;
  11901. }
  11902. }
  11903. return {
  11904. opaque: opaque,
  11905. transparent: transparent,
  11906. init: init,
  11907. push: push,
  11908. unshift: unshift,
  11909. finish: finish,
  11910. sort: sort
  11911. };
  11912. }
  11913. function WebGLRenderLists(properties) {
  11914. var lists = new WeakMap();
  11915. function get(scene, camera) {
  11916. var cameras = lists.get(scene);
  11917. var list;
  11918. if (cameras === undefined) {
  11919. list = new WebGLRenderList(properties);
  11920. lists.set(scene, new WeakMap());
  11921. lists.get(scene).set(camera, list);
  11922. } else {
  11923. list = cameras.get(camera);
  11924. if (list === undefined) {
  11925. list = new WebGLRenderList(properties);
  11926. cameras.set(camera, list);
  11927. }
  11928. }
  11929. return list;
  11930. }
  11931. function dispose() {
  11932. lists = new WeakMap();
  11933. }
  11934. return {
  11935. get: get,
  11936. dispose: dispose
  11937. };
  11938. }
  11939. function UniformsCache() {
  11940. var lights = {};
  11941. return {
  11942. get: function get(light) {
  11943. if (lights[light.id] !== undefined) {
  11944. return lights[light.id];
  11945. }
  11946. var uniforms;
  11947. switch (light.type) {
  11948. case 'DirectionalLight':
  11949. uniforms = {
  11950. direction: new Vector3(),
  11951. color: new Color()
  11952. };
  11953. break;
  11954. case 'SpotLight':
  11955. uniforms = {
  11956. position: new Vector3(),
  11957. direction: new Vector3(),
  11958. color: new Color(),
  11959. distance: 0,
  11960. coneCos: 0,
  11961. penumbraCos: 0,
  11962. decay: 0
  11963. };
  11964. break;
  11965. case 'PointLight':
  11966. uniforms = {
  11967. position: new Vector3(),
  11968. color: new Color(),
  11969. distance: 0,
  11970. decay: 0
  11971. };
  11972. break;
  11973. case 'HemisphereLight':
  11974. uniforms = {
  11975. direction: new Vector3(),
  11976. skyColor: new Color(),
  11977. groundColor: new Color()
  11978. };
  11979. break;
  11980. case 'RectAreaLight':
  11981. uniforms = {
  11982. color: new Color(),
  11983. position: new Vector3(),
  11984. halfWidth: new Vector3(),
  11985. halfHeight: new Vector3()
  11986. };
  11987. break;
  11988. }
  11989. lights[light.id] = uniforms;
  11990. return uniforms;
  11991. }
  11992. };
  11993. }
  11994. function ShadowUniformsCache() {
  11995. var lights = {};
  11996. return {
  11997. get: function get(light) {
  11998. if (lights[light.id] !== undefined) {
  11999. return lights[light.id];
  12000. }
  12001. var uniforms;
  12002. switch (light.type) {
  12003. case 'DirectionalLight':
  12004. uniforms = {
  12005. shadowBias: 0,
  12006. shadowNormalBias: 0,
  12007. shadowRadius: 1,
  12008. shadowMapSize: new Vector2()
  12009. };
  12010. break;
  12011. case 'SpotLight':
  12012. uniforms = {
  12013. shadowBias: 0,
  12014. shadowNormalBias: 0,
  12015. shadowRadius: 1,
  12016. shadowMapSize: new Vector2()
  12017. };
  12018. break;
  12019. case 'PointLight':
  12020. uniforms = {
  12021. shadowBias: 0,
  12022. shadowNormalBias: 0,
  12023. shadowRadius: 1,
  12024. shadowMapSize: new Vector2(),
  12025. shadowCameraNear: 1,
  12026. shadowCameraFar: 1000
  12027. };
  12028. break;
  12029. // TODO (abelnation): set RectAreaLight shadow uniforms
  12030. }
  12031. lights[light.id] = uniforms;
  12032. return uniforms;
  12033. }
  12034. };
  12035. }
  12036. var nextVersion = 0;
  12037. function shadowCastingLightsFirst(lightA, lightB) {
  12038. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  12039. }
  12040. function WebGLLights(extensions, capabilities) {
  12041. var cache = new UniformsCache();
  12042. var shadowCache = ShadowUniformsCache();
  12043. var state = {
  12044. version: 0,
  12045. hash: {
  12046. directionalLength: -1,
  12047. pointLength: -1,
  12048. spotLength: -1,
  12049. rectAreaLength: -1,
  12050. hemiLength: -1,
  12051. numDirectionalShadows: -1,
  12052. numPointShadows: -1,
  12053. numSpotShadows: -1
  12054. },
  12055. ambient: [0, 0, 0],
  12056. probe: [],
  12057. directional: [],
  12058. directionalShadow: [],
  12059. directionalShadowMap: [],
  12060. directionalShadowMatrix: [],
  12061. spot: [],
  12062. spotShadow: [],
  12063. spotShadowMap: [],
  12064. spotShadowMatrix: [],
  12065. rectArea: [],
  12066. rectAreaLTC1: null,
  12067. rectAreaLTC2: null,
  12068. point: [],
  12069. pointShadow: [],
  12070. pointShadowMap: [],
  12071. pointShadowMatrix: [],
  12072. hemi: []
  12073. };
  12074. for (var i = 0; i < 9; i++) {
  12075. state.probe.push(new Vector3());
  12076. }
  12077. var vector3 = new Vector3();
  12078. var matrix4 = new Matrix4();
  12079. var matrix42 = new Matrix4();
  12080. function setup(lights) {
  12081. var r = 0,
  12082. g = 0,
  12083. b = 0;
  12084. for (var _i = 0; _i < 9; _i++) {
  12085. state.probe[_i].set(0, 0, 0);
  12086. }
  12087. var directionalLength = 0;
  12088. var pointLength = 0;
  12089. var spotLength = 0;
  12090. var rectAreaLength = 0;
  12091. var hemiLength = 0;
  12092. var numDirectionalShadows = 0;
  12093. var numPointShadows = 0;
  12094. var numSpotShadows = 0;
  12095. lights.sort(shadowCastingLightsFirst);
  12096. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  12097. var light = lights[_i2];
  12098. var color = light.color;
  12099. var intensity = light.intensity;
  12100. var distance = light.distance;
  12101. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  12102. if (light.isAmbientLight) {
  12103. r += color.r * intensity;
  12104. g += color.g * intensity;
  12105. b += color.b * intensity;
  12106. } else if (light.isLightProbe) {
  12107. for (var j = 0; j < 9; j++) {
  12108. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  12109. }
  12110. } else if (light.isDirectionalLight) {
  12111. var uniforms = cache.get(light);
  12112. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  12113. if (light.castShadow) {
  12114. var shadow = light.shadow;
  12115. var shadowUniforms = shadowCache.get(light);
  12116. shadowUniforms.shadowBias = shadow.bias;
  12117. shadowUniforms.shadowNormalBias = shadow.normalBias;
  12118. shadowUniforms.shadowRadius = shadow.radius;
  12119. shadowUniforms.shadowMapSize = shadow.mapSize;
  12120. state.directionalShadow[directionalLength] = shadowUniforms;
  12121. state.directionalShadowMap[directionalLength] = shadowMap;
  12122. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  12123. numDirectionalShadows++;
  12124. }
  12125. state.directional[directionalLength] = uniforms;
  12126. directionalLength++;
  12127. } else if (light.isSpotLight) {
  12128. var _uniforms = cache.get(light);
  12129. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  12130. _uniforms.color.copy(color).multiplyScalar(intensity);
  12131. _uniforms.distance = distance;
  12132. _uniforms.coneCos = Math.cos(light.angle);
  12133. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  12134. _uniforms.decay = light.decay;
  12135. if (light.castShadow) {
  12136. var _shadow = light.shadow;
  12137. var _shadowUniforms = shadowCache.get(light);
  12138. _shadowUniforms.shadowBias = _shadow.bias;
  12139. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  12140. _shadowUniforms.shadowRadius = _shadow.radius;
  12141. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  12142. state.spotShadow[spotLength] = _shadowUniforms;
  12143. state.spotShadowMap[spotLength] = shadowMap;
  12144. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  12145. numSpotShadows++;
  12146. }
  12147. state.spot[spotLength] = _uniforms;
  12148. spotLength++;
  12149. } else if (light.isRectAreaLight) {
  12150. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  12151. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  12152. // (b) intensity is the brightness of the light
  12153. _uniforms2.color.copy(color).multiplyScalar(intensity);
  12154. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  12155. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  12156. state.rectArea[rectAreaLength] = _uniforms2;
  12157. rectAreaLength++;
  12158. } else if (light.isPointLight) {
  12159. var _uniforms3 = cache.get(light);
  12160. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  12161. _uniforms3.distance = light.distance;
  12162. _uniforms3.decay = light.decay;
  12163. if (light.castShadow) {
  12164. var _shadow2 = light.shadow;
  12165. var _shadowUniforms2 = shadowCache.get(light);
  12166. _shadowUniforms2.shadowBias = _shadow2.bias;
  12167. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  12168. _shadowUniforms2.shadowRadius = _shadow2.radius;
  12169. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  12170. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  12171. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  12172. state.pointShadow[pointLength] = _shadowUniforms2;
  12173. state.pointShadowMap[pointLength] = shadowMap;
  12174. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  12175. numPointShadows++;
  12176. }
  12177. state.point[pointLength] = _uniforms3;
  12178. pointLength++;
  12179. } else if (light.isHemisphereLight) {
  12180. var _uniforms4 = cache.get(light);
  12181. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  12182. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  12183. state.hemi[hemiLength] = _uniforms4;
  12184. hemiLength++;
  12185. }
  12186. }
  12187. if (rectAreaLength > 0) {
  12188. if (capabilities.isWebGL2) {
  12189. // WebGL 2
  12190. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12191. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12192. } else {
  12193. // WebGL 1
  12194. if (extensions.has('OES_texture_float_linear') === true) {
  12195. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12196. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12197. } else if (extensions.has('OES_texture_half_float_linear') === true) {
  12198. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  12199. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  12200. } else {
  12201. console.error('THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.');
  12202. }
  12203. }
  12204. }
  12205. state.ambient[0] = r;
  12206. state.ambient[1] = g;
  12207. state.ambient[2] = b;
  12208. var hash = state.hash;
  12209. 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) {
  12210. state.directional.length = directionalLength;
  12211. state.spot.length = spotLength;
  12212. state.rectArea.length = rectAreaLength;
  12213. state.point.length = pointLength;
  12214. state.hemi.length = hemiLength;
  12215. state.directionalShadow.length = numDirectionalShadows;
  12216. state.directionalShadowMap.length = numDirectionalShadows;
  12217. state.pointShadow.length = numPointShadows;
  12218. state.pointShadowMap.length = numPointShadows;
  12219. state.spotShadow.length = numSpotShadows;
  12220. state.spotShadowMap.length = numSpotShadows;
  12221. state.directionalShadowMatrix.length = numDirectionalShadows;
  12222. state.pointShadowMatrix.length = numPointShadows;
  12223. state.spotShadowMatrix.length = numSpotShadows;
  12224. hash.directionalLength = directionalLength;
  12225. hash.pointLength = pointLength;
  12226. hash.spotLength = spotLength;
  12227. hash.rectAreaLength = rectAreaLength;
  12228. hash.hemiLength = hemiLength;
  12229. hash.numDirectionalShadows = numDirectionalShadows;
  12230. hash.numPointShadows = numPointShadows;
  12231. hash.numSpotShadows = numSpotShadows;
  12232. state.version = nextVersion++;
  12233. }
  12234. }
  12235. function setupView(lights, camera) {
  12236. var directionalLength = 0;
  12237. var pointLength = 0;
  12238. var spotLength = 0;
  12239. var rectAreaLength = 0;
  12240. var hemiLength = 0;
  12241. var viewMatrix = camera.matrixWorldInverse;
  12242. for (var _i3 = 0, l = lights.length; _i3 < l; _i3++) {
  12243. var light = lights[_i3];
  12244. if (light.isDirectionalLight) {
  12245. var uniforms = state.directional[directionalLength];
  12246. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  12247. vector3.setFromMatrixPosition(light.target.matrixWorld);
  12248. uniforms.direction.sub(vector3);
  12249. uniforms.direction.transformDirection(viewMatrix);
  12250. directionalLength++;
  12251. } else if (light.isSpotLight) {
  12252. var _uniforms5 = state.spot[spotLength];
  12253. _uniforms5.position.setFromMatrixPosition(light.matrixWorld);
  12254. _uniforms5.position.applyMatrix4(viewMatrix);
  12255. _uniforms5.direction.setFromMatrixPosition(light.matrixWorld);
  12256. vector3.setFromMatrixPosition(light.target.matrixWorld);
  12257. _uniforms5.direction.sub(vector3);
  12258. _uniforms5.direction.transformDirection(viewMatrix);
  12259. spotLength++;
  12260. } else if (light.isRectAreaLight) {
  12261. var _uniforms6 = state.rectArea[rectAreaLength];
  12262. _uniforms6.position.setFromMatrixPosition(light.matrixWorld);
  12263. _uniforms6.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  12264. matrix42.identity();
  12265. matrix4.copy(light.matrixWorld);
  12266. matrix4.premultiply(viewMatrix);
  12267. matrix42.extractRotation(matrix4);
  12268. _uniforms6.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  12269. _uniforms6.halfHeight.set(0.0, light.height * 0.5, 0.0);
  12270. _uniforms6.halfWidth.applyMatrix4(matrix42);
  12271. _uniforms6.halfHeight.applyMatrix4(matrix42);
  12272. rectAreaLength++;
  12273. } else if (light.isPointLight) {
  12274. var _uniforms7 = state.point[pointLength];
  12275. _uniforms7.position.setFromMatrixPosition(light.matrixWorld);
  12276. _uniforms7.position.applyMatrix4(viewMatrix);
  12277. pointLength++;
  12278. } else if (light.isHemisphereLight) {
  12279. var _uniforms8 = state.hemi[hemiLength];
  12280. _uniforms8.direction.setFromMatrixPosition(light.matrixWorld);
  12281. _uniforms8.direction.transformDirection(viewMatrix);
  12282. _uniforms8.direction.normalize();
  12283. hemiLength++;
  12284. }
  12285. }
  12286. }
  12287. return {
  12288. setup: setup,
  12289. setupView: setupView,
  12290. state: state
  12291. };
  12292. }
  12293. function WebGLRenderState(extensions, capabilities) {
  12294. var lights = new WebGLLights(extensions, capabilities);
  12295. var lightsArray = [];
  12296. var shadowsArray = [];
  12297. function init() {
  12298. lightsArray.length = 0;
  12299. shadowsArray.length = 0;
  12300. }
  12301. function pushLight(light) {
  12302. lightsArray.push(light);
  12303. }
  12304. function pushShadow(shadowLight) {
  12305. shadowsArray.push(shadowLight);
  12306. }
  12307. function setupLights() {
  12308. lights.setup(lightsArray);
  12309. }
  12310. function setupLightsView(camera) {
  12311. lights.setupView(lightsArray, camera);
  12312. }
  12313. var state = {
  12314. lightsArray: lightsArray,
  12315. shadowsArray: shadowsArray,
  12316. lights: lights
  12317. };
  12318. return {
  12319. init: init,
  12320. state: state,
  12321. setupLights: setupLights,
  12322. setupLightsView: setupLightsView,
  12323. pushLight: pushLight,
  12324. pushShadow: pushShadow
  12325. };
  12326. }
  12327. function WebGLRenderStates(extensions, capabilities) {
  12328. var renderStates = new WeakMap();
  12329. function get(scene, renderCallDepth) {
  12330. if (renderCallDepth === void 0) {
  12331. renderCallDepth = 0;
  12332. }
  12333. var renderState;
  12334. if (renderStates.has(scene) === false) {
  12335. renderState = new WebGLRenderState(extensions, capabilities);
  12336. renderStates.set(scene, []);
  12337. renderStates.get(scene).push(renderState);
  12338. } else {
  12339. if (renderCallDepth >= renderStates.get(scene).length) {
  12340. renderState = new WebGLRenderState(extensions, capabilities);
  12341. renderStates.get(scene).push(renderState);
  12342. } else {
  12343. renderState = renderStates.get(scene)[renderCallDepth];
  12344. }
  12345. }
  12346. return renderState;
  12347. }
  12348. function dispose() {
  12349. renderStates = new WeakMap();
  12350. }
  12351. return {
  12352. get: get,
  12353. dispose: dispose
  12354. };
  12355. }
  12356. /**
  12357. * parameters = {
  12358. *
  12359. * opacity: <float>,
  12360. *
  12361. * map: new THREE.Texture( <Image> ),
  12362. *
  12363. * alphaMap: new THREE.Texture( <Image> ),
  12364. *
  12365. * displacementMap: new THREE.Texture( <Image> ),
  12366. * displacementScale: <float>,
  12367. * displacementBias: <float>,
  12368. *
  12369. * wireframe: <boolean>,
  12370. * wireframeLinewidth: <float>
  12371. * }
  12372. */
  12373. function MeshDepthMaterial(parameters) {
  12374. Material.call(this);
  12375. this.type = 'MeshDepthMaterial';
  12376. this.depthPacking = BasicDepthPacking;
  12377. this.skinning = false;
  12378. this.morphTargets = false;
  12379. this.map = null;
  12380. this.alphaMap = null;
  12381. this.displacementMap = null;
  12382. this.displacementScale = 1;
  12383. this.displacementBias = 0;
  12384. this.wireframe = false;
  12385. this.wireframeLinewidth = 1;
  12386. this.fog = false;
  12387. this.setValues(parameters);
  12388. }
  12389. MeshDepthMaterial.prototype = Object.create(Material.prototype);
  12390. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  12391. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  12392. MeshDepthMaterial.prototype.copy = function (source) {
  12393. Material.prototype.copy.call(this, source);
  12394. this.depthPacking = source.depthPacking;
  12395. this.skinning = source.skinning;
  12396. this.morphTargets = source.morphTargets;
  12397. this.map = source.map;
  12398. this.alphaMap = source.alphaMap;
  12399. this.displacementMap = source.displacementMap;
  12400. this.displacementScale = source.displacementScale;
  12401. this.displacementBias = source.displacementBias;
  12402. this.wireframe = source.wireframe;
  12403. this.wireframeLinewidth = source.wireframeLinewidth;
  12404. return this;
  12405. };
  12406. /**
  12407. * parameters = {
  12408. *
  12409. * referencePosition: <float>,
  12410. * nearDistance: <float>,
  12411. * farDistance: <float>,
  12412. *
  12413. * skinning: <bool>,
  12414. * morphTargets: <bool>,
  12415. *
  12416. * map: new THREE.Texture( <Image> ),
  12417. *
  12418. * alphaMap: new THREE.Texture( <Image> ),
  12419. *
  12420. * displacementMap: new THREE.Texture( <Image> ),
  12421. * displacementScale: <float>,
  12422. * displacementBias: <float>
  12423. *
  12424. * }
  12425. */
  12426. function MeshDistanceMaterial(parameters) {
  12427. Material.call(this);
  12428. this.type = 'MeshDistanceMaterial';
  12429. this.referencePosition = new Vector3();
  12430. this.nearDistance = 1;
  12431. this.farDistance = 1000;
  12432. this.skinning = false;
  12433. this.morphTargets = false;
  12434. this.map = null;
  12435. this.alphaMap = null;
  12436. this.displacementMap = null;
  12437. this.displacementScale = 1;
  12438. this.displacementBias = 0;
  12439. this.fog = false;
  12440. this.setValues(parameters);
  12441. }
  12442. MeshDistanceMaterial.prototype = Object.create(Material.prototype);
  12443. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  12444. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  12445. MeshDistanceMaterial.prototype.copy = function (source) {
  12446. Material.prototype.copy.call(this, source);
  12447. this.referencePosition.copy(source.referencePosition);
  12448. this.nearDistance = source.nearDistance;
  12449. this.farDistance = source.farDistance;
  12450. this.skinning = source.skinning;
  12451. this.morphTargets = source.morphTargets;
  12452. this.map = source.map;
  12453. this.alphaMap = source.alphaMap;
  12454. this.displacementMap = source.displacementMap;
  12455. this.displacementScale = source.displacementScale;
  12456. this.displacementBias = source.displacementBias;
  12457. return this;
  12458. };
  12459. 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}";
  12460. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  12461. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  12462. var _frustum = new Frustum();
  12463. var _shadowMapSize = new Vector2(),
  12464. _viewportSize = new Vector2(),
  12465. _viewport = new Vector4(),
  12466. _depthMaterials = [],
  12467. _distanceMaterials = [],
  12468. _materialCache = {};
  12469. var shadowSide = {
  12470. 0: BackSide,
  12471. 1: FrontSide,
  12472. 2: DoubleSide
  12473. };
  12474. var shadowMaterialVertical = new ShaderMaterial({
  12475. defines: {
  12476. SAMPLE_RATE: 2.0 / 8.0,
  12477. HALF_SAMPLE_RATE: 1.0 / 8.0
  12478. },
  12479. uniforms: {
  12480. shadow_pass: {
  12481. value: null
  12482. },
  12483. resolution: {
  12484. value: new Vector2()
  12485. },
  12486. radius: {
  12487. value: 4.0
  12488. }
  12489. },
  12490. vertexShader: vsm_vert,
  12491. fragmentShader: vsm_frag
  12492. });
  12493. var shadowMaterialHorizontal = shadowMaterialVertical.clone();
  12494. shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1;
  12495. var fullScreenTri = new BufferGeometry();
  12496. fullScreenTri.setAttribute('position', new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  12497. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  12498. var scope = this;
  12499. this.enabled = false;
  12500. this.autoUpdate = true;
  12501. this.needsUpdate = false;
  12502. this.type = PCFShadowMap;
  12503. this.render = function (lights, scene, camera) {
  12504. if (scope.enabled === false) return;
  12505. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  12506. if (lights.length === 0) return;
  12507. var currentRenderTarget = _renderer.getRenderTarget();
  12508. var activeCubeFace = _renderer.getActiveCubeFace();
  12509. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  12510. var _state = _renderer.state; // Set GL state for depth map.
  12511. _state.setBlending(NoBlending);
  12512. _state.buffers.color.setClear(1, 1, 1, 1);
  12513. _state.buffers.depth.setTest(true);
  12514. _state.setScissorTest(false); // render depth map
  12515. for (var i = 0, il = lights.length; i < il; i++) {
  12516. var light = lights[i];
  12517. var shadow = light.shadow;
  12518. if (shadow === undefined) {
  12519. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  12520. continue;
  12521. }
  12522. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  12523. _shadowMapSize.copy(shadow.mapSize);
  12524. var shadowFrameExtents = shadow.getFrameExtents();
  12525. _shadowMapSize.multiply(shadowFrameExtents);
  12526. _viewportSize.copy(shadow.mapSize);
  12527. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  12528. if (_shadowMapSize.x > maxTextureSize) {
  12529. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  12530. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  12531. shadow.mapSize.x = _viewportSize.x;
  12532. }
  12533. if (_shadowMapSize.y > maxTextureSize) {
  12534. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  12535. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  12536. shadow.mapSize.y = _viewportSize.y;
  12537. }
  12538. }
  12539. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12540. var pars = {
  12541. minFilter: LinearFilter,
  12542. magFilter: LinearFilter,
  12543. format: RGBAFormat
  12544. };
  12545. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12546. shadow.map.texture.name = light.name + '.shadowMap';
  12547. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12548. shadow.camera.updateProjectionMatrix();
  12549. }
  12550. if (shadow.map === null) {
  12551. var _pars = {
  12552. minFilter: NearestFilter,
  12553. magFilter: NearestFilter,
  12554. format: RGBAFormat
  12555. };
  12556. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  12557. shadow.map.texture.name = light.name + '.shadowMap';
  12558. shadow.camera.updateProjectionMatrix();
  12559. }
  12560. _renderer.setRenderTarget(shadow.map);
  12561. _renderer.clear();
  12562. var viewportCount = shadow.getViewportCount();
  12563. for (var vp = 0; vp < viewportCount; vp++) {
  12564. var viewport = shadow.getViewport(vp);
  12565. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  12566. _state.viewport(_viewport);
  12567. shadow.updateMatrices(light, vp);
  12568. _frustum = shadow.getFrustum();
  12569. renderObject(scene, camera, shadow.camera, light, this.type);
  12570. } // do blur pass for VSM
  12571. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12572. VSMPass(shadow, camera);
  12573. }
  12574. shadow.needsUpdate = false;
  12575. }
  12576. scope.needsUpdate = false;
  12577. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  12578. };
  12579. function VSMPass(shadow, camera) {
  12580. var geometry = _objects.update(fullScreenMesh); // vertical pass
  12581. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  12582. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  12583. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  12584. _renderer.setRenderTarget(shadow.mapPass);
  12585. _renderer.clear();
  12586. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizontal pass
  12587. shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  12588. shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize;
  12589. shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;
  12590. _renderer.setRenderTarget(shadow.map);
  12591. _renderer.clear();
  12592. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null);
  12593. }
  12594. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12595. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12596. var material = _depthMaterials[index];
  12597. if (material === undefined) {
  12598. material = new MeshDepthMaterial({
  12599. depthPacking: RGBADepthPacking,
  12600. morphTargets: useMorphing,
  12601. skinning: useSkinning
  12602. });
  12603. _depthMaterials[index] = material;
  12604. }
  12605. return material;
  12606. }
  12607. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12608. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12609. var material = _distanceMaterials[index];
  12610. if (material === undefined) {
  12611. material = new MeshDistanceMaterial({
  12612. morphTargets: useMorphing,
  12613. skinning: useSkinning
  12614. });
  12615. _distanceMaterials[index] = material;
  12616. }
  12617. return material;
  12618. }
  12619. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  12620. var result = null;
  12621. var getMaterialVariant = getDepthMaterialVariant;
  12622. var customMaterial = object.customDepthMaterial;
  12623. if (light.isPointLight === true) {
  12624. getMaterialVariant = getDistanceMaterialVariant;
  12625. customMaterial = object.customDistanceMaterial;
  12626. }
  12627. if (customMaterial === undefined) {
  12628. var useMorphing = false;
  12629. if (material.morphTargets === true) {
  12630. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  12631. }
  12632. var useSkinning = false;
  12633. if (object.isSkinnedMesh === true) {
  12634. if (material.skinning === true) {
  12635. useSkinning = true;
  12636. } else {
  12637. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  12638. }
  12639. }
  12640. var useInstancing = object.isInstancedMesh === true;
  12641. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  12642. } else {
  12643. result = customMaterial;
  12644. }
  12645. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  12646. // in this case we need a unique material instance reflecting the
  12647. // appropriate state
  12648. var keyA = result.uuid,
  12649. keyB = material.uuid;
  12650. var materialsForVariant = _materialCache[keyA];
  12651. if (materialsForVariant === undefined) {
  12652. materialsForVariant = {};
  12653. _materialCache[keyA] = materialsForVariant;
  12654. }
  12655. var cachedMaterial = materialsForVariant[keyB];
  12656. if (cachedMaterial === undefined) {
  12657. cachedMaterial = result.clone();
  12658. materialsForVariant[keyB] = cachedMaterial;
  12659. }
  12660. result = cachedMaterial;
  12661. }
  12662. result.visible = material.visible;
  12663. result.wireframe = material.wireframe;
  12664. if (type === VSMShadowMap) {
  12665. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  12666. } else {
  12667. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  12668. }
  12669. result.clipShadows = material.clipShadows;
  12670. result.clippingPlanes = material.clippingPlanes;
  12671. result.clipIntersection = material.clipIntersection;
  12672. result.wireframeLinewidth = material.wireframeLinewidth;
  12673. result.linewidth = material.linewidth;
  12674. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  12675. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  12676. result.nearDistance = shadowCameraNear;
  12677. result.farDistance = shadowCameraFar;
  12678. }
  12679. return result;
  12680. }
  12681. function renderObject(object, camera, shadowCamera, light, type) {
  12682. if (object.visible === false) return;
  12683. var visible = object.layers.test(camera.layers);
  12684. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  12685. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  12686. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  12687. var geometry = _objects.update(object);
  12688. var material = object.material;
  12689. if (Array.isArray(material)) {
  12690. var groups = geometry.groups;
  12691. for (var k = 0, kl = groups.length; k < kl; k++) {
  12692. var group = groups[k];
  12693. var groupMaterial = material[group.materialIndex];
  12694. if (groupMaterial && groupMaterial.visible) {
  12695. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  12696. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  12697. }
  12698. }
  12699. } else if (material.visible) {
  12700. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  12701. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  12702. }
  12703. }
  12704. }
  12705. var children = object.children;
  12706. for (var i = 0, l = children.length; i < l; i++) {
  12707. renderObject(children[i], camera, shadowCamera, light, type);
  12708. }
  12709. }
  12710. }
  12711. function WebGLState(gl, extensions, capabilities) {
  12712. var _equationToGL, _factorToGL;
  12713. var isWebGL2 = capabilities.isWebGL2;
  12714. function ColorBuffer() {
  12715. var locked = false;
  12716. var color = new Vector4();
  12717. var currentColorMask = null;
  12718. var currentColorClear = new Vector4(0, 0, 0, 0);
  12719. return {
  12720. setMask: function setMask(colorMask) {
  12721. if (currentColorMask !== colorMask && !locked) {
  12722. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  12723. currentColorMask = colorMask;
  12724. }
  12725. },
  12726. setLocked: function setLocked(lock) {
  12727. locked = lock;
  12728. },
  12729. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  12730. if (premultipliedAlpha === true) {
  12731. r *= a;
  12732. g *= a;
  12733. b *= a;
  12734. }
  12735. color.set(r, g, b, a);
  12736. if (currentColorClear.equals(color) === false) {
  12737. gl.clearColor(r, g, b, a);
  12738. currentColorClear.copy(color);
  12739. }
  12740. },
  12741. reset: function reset() {
  12742. locked = false;
  12743. currentColorMask = null;
  12744. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  12745. }
  12746. };
  12747. }
  12748. function DepthBuffer() {
  12749. var locked = false;
  12750. var currentDepthMask = null;
  12751. var currentDepthFunc = null;
  12752. var currentDepthClear = null;
  12753. return {
  12754. setTest: function setTest(depthTest) {
  12755. if (depthTest) {
  12756. enable(2929);
  12757. } else {
  12758. disable(2929);
  12759. }
  12760. },
  12761. setMask: function setMask(depthMask) {
  12762. if (currentDepthMask !== depthMask && !locked) {
  12763. gl.depthMask(depthMask);
  12764. currentDepthMask = depthMask;
  12765. }
  12766. },
  12767. setFunc: function setFunc(depthFunc) {
  12768. if (currentDepthFunc !== depthFunc) {
  12769. if (depthFunc) {
  12770. switch (depthFunc) {
  12771. case NeverDepth:
  12772. gl.depthFunc(512);
  12773. break;
  12774. case AlwaysDepth:
  12775. gl.depthFunc(519);
  12776. break;
  12777. case LessDepth:
  12778. gl.depthFunc(513);
  12779. break;
  12780. case LessEqualDepth:
  12781. gl.depthFunc(515);
  12782. break;
  12783. case EqualDepth:
  12784. gl.depthFunc(514);
  12785. break;
  12786. case GreaterEqualDepth:
  12787. gl.depthFunc(518);
  12788. break;
  12789. case GreaterDepth:
  12790. gl.depthFunc(516);
  12791. break;
  12792. case NotEqualDepth:
  12793. gl.depthFunc(517);
  12794. break;
  12795. default:
  12796. gl.depthFunc(515);
  12797. }
  12798. } else {
  12799. gl.depthFunc(515);
  12800. }
  12801. currentDepthFunc = depthFunc;
  12802. }
  12803. },
  12804. setLocked: function setLocked(lock) {
  12805. locked = lock;
  12806. },
  12807. setClear: function setClear(depth) {
  12808. if (currentDepthClear !== depth) {
  12809. gl.clearDepth(depth);
  12810. currentDepthClear = depth;
  12811. }
  12812. },
  12813. reset: function reset() {
  12814. locked = false;
  12815. currentDepthMask = null;
  12816. currentDepthFunc = null;
  12817. currentDepthClear = null;
  12818. }
  12819. };
  12820. }
  12821. function StencilBuffer() {
  12822. var locked = false;
  12823. var currentStencilMask = null;
  12824. var currentStencilFunc = null;
  12825. var currentStencilRef = null;
  12826. var currentStencilFuncMask = null;
  12827. var currentStencilFail = null;
  12828. var currentStencilZFail = null;
  12829. var currentStencilZPass = null;
  12830. var currentStencilClear = null;
  12831. return {
  12832. setTest: function setTest(stencilTest) {
  12833. if (!locked) {
  12834. if (stencilTest) {
  12835. enable(2960);
  12836. } else {
  12837. disable(2960);
  12838. }
  12839. }
  12840. },
  12841. setMask: function setMask(stencilMask) {
  12842. if (currentStencilMask !== stencilMask && !locked) {
  12843. gl.stencilMask(stencilMask);
  12844. currentStencilMask = stencilMask;
  12845. }
  12846. },
  12847. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12848. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12849. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12850. currentStencilFunc = stencilFunc;
  12851. currentStencilRef = stencilRef;
  12852. currentStencilFuncMask = stencilMask;
  12853. }
  12854. },
  12855. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12856. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12857. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12858. currentStencilFail = stencilFail;
  12859. currentStencilZFail = stencilZFail;
  12860. currentStencilZPass = stencilZPass;
  12861. }
  12862. },
  12863. setLocked: function setLocked(lock) {
  12864. locked = lock;
  12865. },
  12866. setClear: function setClear(stencil) {
  12867. if (currentStencilClear !== stencil) {
  12868. gl.clearStencil(stencil);
  12869. currentStencilClear = stencil;
  12870. }
  12871. },
  12872. reset: function reset() {
  12873. locked = false;
  12874. currentStencilMask = null;
  12875. currentStencilFunc = null;
  12876. currentStencilRef = null;
  12877. currentStencilFuncMask = null;
  12878. currentStencilFail = null;
  12879. currentStencilZFail = null;
  12880. currentStencilZPass = null;
  12881. currentStencilClear = null;
  12882. }
  12883. };
  12884. } //
  12885. var colorBuffer = new ColorBuffer();
  12886. var depthBuffer = new DepthBuffer();
  12887. var stencilBuffer = new StencilBuffer();
  12888. var enabledCapabilities = {};
  12889. var currentProgram = null;
  12890. var currentBlendingEnabled = null;
  12891. var currentBlending = null;
  12892. var currentBlendEquation = null;
  12893. var currentBlendSrc = null;
  12894. var currentBlendDst = null;
  12895. var currentBlendEquationAlpha = null;
  12896. var currentBlendSrcAlpha = null;
  12897. var currentBlendDstAlpha = null;
  12898. var currentPremultipledAlpha = false;
  12899. var currentFlipSided = null;
  12900. var currentCullFace = null;
  12901. var currentLineWidth = null;
  12902. var currentPolygonOffsetFactor = null;
  12903. var currentPolygonOffsetUnits = null;
  12904. var maxTextures = gl.getParameter(35661);
  12905. var lineWidthAvailable = false;
  12906. var version = 0;
  12907. var glVersion = gl.getParameter(7938);
  12908. if (glVersion.indexOf('WebGL') !== -1) {
  12909. version = parseFloat(/^WebGL (\d)/.exec(glVersion)[1]);
  12910. lineWidthAvailable = version >= 1.0;
  12911. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12912. version = parseFloat(/^OpenGL ES (\d)/.exec(glVersion)[1]);
  12913. lineWidthAvailable = version >= 2.0;
  12914. }
  12915. var currentTextureSlot = null;
  12916. var currentBoundTextures = {};
  12917. var currentScissor = new Vector4();
  12918. var currentViewport = new Vector4();
  12919. function createTexture(type, target, count) {
  12920. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12921. var texture = gl.createTexture();
  12922. gl.bindTexture(type, texture);
  12923. gl.texParameteri(type, 10241, 9728);
  12924. gl.texParameteri(type, 10240, 9728);
  12925. for (var i = 0; i < count; i++) {
  12926. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12927. }
  12928. return texture;
  12929. }
  12930. var emptyTextures = {};
  12931. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12932. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12933. colorBuffer.setClear(0, 0, 0, 1);
  12934. depthBuffer.setClear(1);
  12935. stencilBuffer.setClear(0);
  12936. enable(2929);
  12937. depthBuffer.setFunc(LessEqualDepth);
  12938. setFlipSided(false);
  12939. setCullFace(CullFaceBack);
  12940. enable(2884);
  12941. setBlending(NoBlending); //
  12942. function enable(id) {
  12943. if (enabledCapabilities[id] !== true) {
  12944. gl.enable(id);
  12945. enabledCapabilities[id] = true;
  12946. }
  12947. }
  12948. function disable(id) {
  12949. if (enabledCapabilities[id] !== false) {
  12950. gl.disable(id);
  12951. enabledCapabilities[id] = false;
  12952. }
  12953. }
  12954. function useProgram(program) {
  12955. if (currentProgram !== program) {
  12956. gl.useProgram(program);
  12957. currentProgram = program;
  12958. return true;
  12959. }
  12960. return false;
  12961. }
  12962. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  12963. if (isWebGL2) {
  12964. equationToGL[MinEquation] = 32775;
  12965. equationToGL[MaxEquation] = 32776;
  12966. } else {
  12967. var extension = extensions.get('EXT_blend_minmax');
  12968. if (extension !== null) {
  12969. equationToGL[MinEquation] = extension.MIN_EXT;
  12970. equationToGL[MaxEquation] = extension.MAX_EXT;
  12971. }
  12972. }
  12973. 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);
  12974. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  12975. if (blending === NoBlending) {
  12976. if (currentBlendingEnabled) {
  12977. disable(3042);
  12978. currentBlendingEnabled = false;
  12979. }
  12980. return;
  12981. }
  12982. if (!currentBlendingEnabled) {
  12983. enable(3042);
  12984. currentBlendingEnabled = true;
  12985. }
  12986. if (blending !== CustomBlending) {
  12987. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  12988. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  12989. gl.blendEquation(32774);
  12990. currentBlendEquation = AddEquation;
  12991. currentBlendEquationAlpha = AddEquation;
  12992. }
  12993. if (premultipliedAlpha) {
  12994. switch (blending) {
  12995. case NormalBlending:
  12996. gl.blendFuncSeparate(1, 771, 1, 771);
  12997. break;
  12998. case AdditiveBlending:
  12999. gl.blendFunc(1, 1);
  13000. break;
  13001. case SubtractiveBlending:
  13002. gl.blendFuncSeparate(0, 0, 769, 771);
  13003. break;
  13004. case MultiplyBlending:
  13005. gl.blendFuncSeparate(0, 768, 0, 770);
  13006. break;
  13007. default:
  13008. console.error('THREE.WebGLState: Invalid blending: ', blending);
  13009. break;
  13010. }
  13011. } else {
  13012. switch (blending) {
  13013. case NormalBlending:
  13014. gl.blendFuncSeparate(770, 771, 1, 771);
  13015. break;
  13016. case AdditiveBlending:
  13017. gl.blendFunc(770, 1);
  13018. break;
  13019. case SubtractiveBlending:
  13020. gl.blendFunc(0, 769);
  13021. break;
  13022. case MultiplyBlending:
  13023. gl.blendFunc(0, 768);
  13024. break;
  13025. default:
  13026. console.error('THREE.WebGLState: Invalid blending: ', blending);
  13027. break;
  13028. }
  13029. }
  13030. currentBlendSrc = null;
  13031. currentBlendDst = null;
  13032. currentBlendSrcAlpha = null;
  13033. currentBlendDstAlpha = null;
  13034. currentBlending = blending;
  13035. currentPremultipledAlpha = premultipliedAlpha;
  13036. }
  13037. return;
  13038. } // custom blending
  13039. blendEquationAlpha = blendEquationAlpha || blendEquation;
  13040. blendSrcAlpha = blendSrcAlpha || blendSrc;
  13041. blendDstAlpha = blendDstAlpha || blendDst;
  13042. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  13043. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  13044. currentBlendEquation = blendEquation;
  13045. currentBlendEquationAlpha = blendEquationAlpha;
  13046. }
  13047. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  13048. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  13049. currentBlendSrc = blendSrc;
  13050. currentBlendDst = blendDst;
  13051. currentBlendSrcAlpha = blendSrcAlpha;
  13052. currentBlendDstAlpha = blendDstAlpha;
  13053. }
  13054. currentBlending = blending;
  13055. currentPremultipledAlpha = null;
  13056. }
  13057. function setMaterial(material, frontFaceCW) {
  13058. material.side === DoubleSide ? disable(2884) : enable(2884);
  13059. var flipSided = material.side === BackSide;
  13060. if (frontFaceCW) flipSided = !flipSided;
  13061. setFlipSided(flipSided);
  13062. 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);
  13063. depthBuffer.setFunc(material.depthFunc);
  13064. depthBuffer.setTest(material.depthTest);
  13065. depthBuffer.setMask(material.depthWrite);
  13066. colorBuffer.setMask(material.colorWrite);
  13067. var stencilWrite = material.stencilWrite;
  13068. stencilBuffer.setTest(stencilWrite);
  13069. if (stencilWrite) {
  13070. stencilBuffer.setMask(material.stencilWriteMask);
  13071. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  13072. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  13073. }
  13074. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  13075. } //
  13076. function setFlipSided(flipSided) {
  13077. if (currentFlipSided !== flipSided) {
  13078. if (flipSided) {
  13079. gl.frontFace(2304);
  13080. } else {
  13081. gl.frontFace(2305);
  13082. }
  13083. currentFlipSided = flipSided;
  13084. }
  13085. }
  13086. function setCullFace(cullFace) {
  13087. if (cullFace !== CullFaceNone) {
  13088. enable(2884);
  13089. if (cullFace !== currentCullFace) {
  13090. if (cullFace === CullFaceBack) {
  13091. gl.cullFace(1029);
  13092. } else if (cullFace === CullFaceFront) {
  13093. gl.cullFace(1028);
  13094. } else {
  13095. gl.cullFace(1032);
  13096. }
  13097. }
  13098. } else {
  13099. disable(2884);
  13100. }
  13101. currentCullFace = cullFace;
  13102. }
  13103. function setLineWidth(width) {
  13104. if (width !== currentLineWidth) {
  13105. if (lineWidthAvailable) gl.lineWidth(width);
  13106. currentLineWidth = width;
  13107. }
  13108. }
  13109. function setPolygonOffset(polygonOffset, factor, units) {
  13110. if (polygonOffset) {
  13111. enable(32823);
  13112. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  13113. gl.polygonOffset(factor, units);
  13114. currentPolygonOffsetFactor = factor;
  13115. currentPolygonOffsetUnits = units;
  13116. }
  13117. } else {
  13118. disable(32823);
  13119. }
  13120. }
  13121. function setScissorTest(scissorTest) {
  13122. if (scissorTest) {
  13123. enable(3089);
  13124. } else {
  13125. disable(3089);
  13126. }
  13127. } // texture
  13128. function activeTexture(webglSlot) {
  13129. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  13130. if (currentTextureSlot !== webglSlot) {
  13131. gl.activeTexture(webglSlot);
  13132. currentTextureSlot = webglSlot;
  13133. }
  13134. }
  13135. function bindTexture(webglType, webglTexture) {
  13136. if (currentTextureSlot === null) {
  13137. activeTexture();
  13138. }
  13139. var boundTexture = currentBoundTextures[currentTextureSlot];
  13140. if (boundTexture === undefined) {
  13141. boundTexture = {
  13142. type: undefined,
  13143. texture: undefined
  13144. };
  13145. currentBoundTextures[currentTextureSlot] = boundTexture;
  13146. }
  13147. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  13148. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  13149. boundTexture.type = webglType;
  13150. boundTexture.texture = webglTexture;
  13151. }
  13152. }
  13153. function unbindTexture() {
  13154. var boundTexture = currentBoundTextures[currentTextureSlot];
  13155. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  13156. gl.bindTexture(boundTexture.type, null);
  13157. boundTexture.type = undefined;
  13158. boundTexture.texture = undefined;
  13159. }
  13160. }
  13161. function compressedTexImage2D() {
  13162. try {
  13163. gl.compressedTexImage2D.apply(gl, arguments);
  13164. } catch (error) {
  13165. console.error('THREE.WebGLState:', error);
  13166. }
  13167. }
  13168. function texImage2D() {
  13169. try {
  13170. gl.texImage2D.apply(gl, arguments);
  13171. } catch (error) {
  13172. console.error('THREE.WebGLState:', error);
  13173. }
  13174. }
  13175. function texImage3D() {
  13176. try {
  13177. gl.texImage3D.apply(gl, arguments);
  13178. } catch (error) {
  13179. console.error('THREE.WebGLState:', error);
  13180. }
  13181. } //
  13182. function scissor(scissor) {
  13183. if (currentScissor.equals(scissor) === false) {
  13184. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  13185. currentScissor.copy(scissor);
  13186. }
  13187. }
  13188. function viewport(viewport) {
  13189. if (currentViewport.equals(viewport) === false) {
  13190. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  13191. currentViewport.copy(viewport);
  13192. }
  13193. } //
  13194. function reset() {
  13195. enabledCapabilities = {};
  13196. currentTextureSlot = null;
  13197. currentBoundTextures = {};
  13198. currentProgram = null;
  13199. currentBlendingEnabled = null;
  13200. currentBlending = null;
  13201. currentBlendEquation = null;
  13202. currentBlendSrc = null;
  13203. currentBlendDst = null;
  13204. currentBlendEquationAlpha = null;
  13205. currentBlendSrcAlpha = null;
  13206. currentBlendDstAlpha = null;
  13207. currentPremultipledAlpha = false;
  13208. currentFlipSided = null;
  13209. currentCullFace = null;
  13210. currentLineWidth = null;
  13211. currentPolygonOffsetFactor = null;
  13212. currentPolygonOffsetUnits = null;
  13213. colorBuffer.reset();
  13214. depthBuffer.reset();
  13215. stencilBuffer.reset();
  13216. }
  13217. return {
  13218. buffers: {
  13219. color: colorBuffer,
  13220. depth: depthBuffer,
  13221. stencil: stencilBuffer
  13222. },
  13223. enable: enable,
  13224. disable: disable,
  13225. useProgram: useProgram,
  13226. setBlending: setBlending,
  13227. setMaterial: setMaterial,
  13228. setFlipSided: setFlipSided,
  13229. setCullFace: setCullFace,
  13230. setLineWidth: setLineWidth,
  13231. setPolygonOffset: setPolygonOffset,
  13232. setScissorTest: setScissorTest,
  13233. activeTexture: activeTexture,
  13234. bindTexture: bindTexture,
  13235. unbindTexture: unbindTexture,
  13236. compressedTexImage2D: compressedTexImage2D,
  13237. texImage2D: texImage2D,
  13238. texImage3D: texImage3D,
  13239. scissor: scissor,
  13240. viewport: viewport,
  13241. reset: reset
  13242. };
  13243. }
  13244. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  13245. var _wrappingToGL, _filterToGL;
  13246. var isWebGL2 = capabilities.isWebGL2;
  13247. var maxTextures = capabilities.maxTextures;
  13248. var maxCubemapSize = capabilities.maxCubemapSize;
  13249. var maxTextureSize = capabilities.maxTextureSize;
  13250. var maxSamples = capabilities.maxSamples;
  13251. var _videoTextures = new WeakMap();
  13252. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  13253. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  13254. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  13255. var useOffscreenCanvas = false;
  13256. try {
  13257. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext('2d') !== null;
  13258. } catch (err) {// Ignore any errors
  13259. }
  13260. function createCanvas(width, height) {
  13261. // Use OffscreenCanvas when available. Specially needed in web workers
  13262. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  13263. }
  13264. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  13265. var scale = 1; // handle case if texture exceeds max size
  13266. if (image.width > maxSize || image.height > maxSize) {
  13267. scale = maxSize / Math.max(image.width, image.height);
  13268. } // only perform resize if necessary
  13269. if (scale < 1 || needsPowerOfTwo === true) {
  13270. // only perform resize for certain image types
  13271. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  13272. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  13273. var width = floor(scale * image.width);
  13274. var height = floor(scale * image.height);
  13275. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  13276. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  13277. canvas.width = width;
  13278. canvas.height = height;
  13279. var context = canvas.getContext('2d');
  13280. context.drawImage(image, 0, 0, width, height);
  13281. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  13282. return canvas;
  13283. } else {
  13284. if ('data' in image) {
  13285. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  13286. }
  13287. return image;
  13288. }
  13289. }
  13290. return image;
  13291. }
  13292. function isPowerOfTwo(image) {
  13293. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  13294. }
  13295. function textureNeedsPowerOfTwo(texture) {
  13296. if (isWebGL2) return false;
  13297. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13298. }
  13299. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  13300. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13301. }
  13302. function generateMipmap(target, texture, width, height) {
  13303. _gl.generateMipmap(target);
  13304. var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  13305. textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
  13306. }
  13307. function getInternalFormat(internalFormatName, glFormat, glType) {
  13308. if (isWebGL2 === false) return glFormat;
  13309. if (internalFormatName !== null) {
  13310. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  13311. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  13312. }
  13313. var internalFormat = glFormat;
  13314. if (glFormat === 6403) {
  13315. if (glType === 5126) internalFormat = 33326;
  13316. if (glType === 5131) internalFormat = 33325;
  13317. if (glType === 5121) internalFormat = 33321;
  13318. }
  13319. if (glFormat === 6407) {
  13320. if (glType === 5126) internalFormat = 34837;
  13321. if (glType === 5131) internalFormat = 34843;
  13322. if (glType === 5121) internalFormat = 32849;
  13323. }
  13324. if (glFormat === 6408) {
  13325. if (glType === 5126) internalFormat = 34836;
  13326. if (glType === 5131) internalFormat = 34842;
  13327. if (glType === 5121) internalFormat = 32856;
  13328. }
  13329. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  13330. extensions.get('EXT_color_buffer_float');
  13331. }
  13332. return internalFormat;
  13333. } // Fallback filters for non-power-of-2 textures
  13334. function filterFallback(f) {
  13335. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  13336. return 9728;
  13337. }
  13338. return 9729;
  13339. } //
  13340. function onTextureDispose(event) {
  13341. var texture = event.target;
  13342. texture.removeEventListener('dispose', onTextureDispose);
  13343. deallocateTexture(texture);
  13344. if (texture.isVideoTexture) {
  13345. _videoTextures.delete(texture);
  13346. }
  13347. info.memory.textures--;
  13348. }
  13349. function onRenderTargetDispose(event) {
  13350. var renderTarget = event.target;
  13351. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  13352. deallocateRenderTarget(renderTarget);
  13353. info.memory.textures--;
  13354. } //
  13355. function deallocateTexture(texture) {
  13356. var textureProperties = properties.get(texture);
  13357. if (textureProperties.__webglInit === undefined) return;
  13358. _gl.deleteTexture(textureProperties.__webglTexture);
  13359. properties.remove(texture);
  13360. }
  13361. function deallocateRenderTarget(renderTarget) {
  13362. var renderTargetProperties = properties.get(renderTarget);
  13363. var textureProperties = properties.get(renderTarget.texture);
  13364. if (!renderTarget) return;
  13365. if (textureProperties.__webglTexture !== undefined) {
  13366. _gl.deleteTexture(textureProperties.__webglTexture);
  13367. }
  13368. if (renderTarget.depthTexture) {
  13369. renderTarget.depthTexture.dispose();
  13370. }
  13371. if (renderTarget.isWebGLCubeRenderTarget) {
  13372. for (var i = 0; i < 6; i++) {
  13373. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  13374. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  13375. }
  13376. } else {
  13377. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  13378. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  13379. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  13380. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  13381. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  13382. }
  13383. properties.remove(renderTarget.texture);
  13384. properties.remove(renderTarget);
  13385. } //
  13386. var textureUnits = 0;
  13387. function resetTextureUnits() {
  13388. textureUnits = 0;
  13389. }
  13390. function allocateTextureUnit() {
  13391. var textureUnit = textureUnits;
  13392. if (textureUnit >= maxTextures) {
  13393. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  13394. }
  13395. textureUnits += 1;
  13396. return textureUnit;
  13397. } //
  13398. function setTexture2D(texture, slot) {
  13399. var textureProperties = properties.get(texture);
  13400. if (texture.isVideoTexture) updateVideoTexture(texture);
  13401. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13402. var image = texture.image;
  13403. if (image === undefined) {
  13404. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  13405. } else if (image.complete === false) {
  13406. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  13407. } else {
  13408. uploadTexture(textureProperties, texture, slot);
  13409. return;
  13410. }
  13411. }
  13412. state.activeTexture(33984 + slot);
  13413. state.bindTexture(3553, textureProperties.__webglTexture);
  13414. }
  13415. function setTexture2DArray(texture, slot) {
  13416. var textureProperties = properties.get(texture);
  13417. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13418. uploadTexture(textureProperties, texture, slot);
  13419. return;
  13420. }
  13421. state.activeTexture(33984 + slot);
  13422. state.bindTexture(35866, textureProperties.__webglTexture);
  13423. }
  13424. function setTexture3D(texture, slot) {
  13425. var textureProperties = properties.get(texture);
  13426. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13427. uploadTexture(textureProperties, texture, slot);
  13428. return;
  13429. }
  13430. state.activeTexture(33984 + slot);
  13431. state.bindTexture(32879, textureProperties.__webglTexture);
  13432. }
  13433. function setTextureCube(texture, slot) {
  13434. var textureProperties = properties.get(texture);
  13435. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13436. uploadCubeTexture(textureProperties, texture, slot);
  13437. return;
  13438. }
  13439. state.activeTexture(33984 + slot);
  13440. state.bindTexture(34067, textureProperties.__webglTexture);
  13441. }
  13442. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  13443. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  13444. function setTextureParameters(textureType, texture, supportsMips) {
  13445. if (supportsMips) {
  13446. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  13447. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  13448. if (textureType === 32879 || textureType === 35866) {
  13449. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  13450. }
  13451. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  13452. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  13453. } else {
  13454. _gl.texParameteri(textureType, 10242, 33071);
  13455. _gl.texParameteri(textureType, 10243, 33071);
  13456. if (textureType === 32879 || textureType === 35866) {
  13457. _gl.texParameteri(textureType, 32882, 33071);
  13458. }
  13459. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  13460. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  13461. }
  13462. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  13463. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  13464. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  13465. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  13466. }
  13467. }
  13468. var extension = extensions.get('EXT_texture_filter_anisotropic');
  13469. if (extension) {
  13470. if (texture.type === FloatType && extensions.get('OES_texture_float_linear') === null) return;
  13471. if (texture.type === HalfFloatType && (isWebGL2 || extensions.get('OES_texture_half_float_linear')) === null) return;
  13472. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  13473. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  13474. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  13475. }
  13476. }
  13477. }
  13478. function initTexture(textureProperties, texture) {
  13479. if (textureProperties.__webglInit === undefined) {
  13480. textureProperties.__webglInit = true;
  13481. texture.addEventListener('dispose', onTextureDispose);
  13482. textureProperties.__webglTexture = _gl.createTexture();
  13483. info.memory.textures++;
  13484. }
  13485. }
  13486. function uploadTexture(textureProperties, texture, slot) {
  13487. var textureType = 3553;
  13488. if (texture.isDataTexture2DArray) textureType = 35866;
  13489. if (texture.isDataTexture3D) textureType = 32879;
  13490. initTexture(textureProperties, texture);
  13491. state.activeTexture(33984 + slot);
  13492. state.bindTexture(textureType, textureProperties.__webglTexture);
  13493. _gl.pixelStorei(37440, texture.flipY);
  13494. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13495. _gl.pixelStorei(3317, texture.unpackAlignment);
  13496. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  13497. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  13498. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  13499. glFormat = utils.convert(texture.format);
  13500. var glType = utils.convert(texture.type),
  13501. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13502. setTextureParameters(textureType, texture, supportsMips);
  13503. var mipmap;
  13504. var mipmaps = texture.mipmaps;
  13505. if (texture.isDepthTexture) {
  13506. // populate depth texture with dummy data
  13507. glInternalFormat = 6402;
  13508. if (isWebGL2) {
  13509. if (texture.type === FloatType) {
  13510. glInternalFormat = 36012;
  13511. } else if (texture.type === UnsignedIntType) {
  13512. glInternalFormat = 33190;
  13513. } else if (texture.type === UnsignedInt248Type) {
  13514. glInternalFormat = 35056;
  13515. } else {
  13516. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  13517. }
  13518. } else {
  13519. if (texture.type === FloatType) {
  13520. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  13521. }
  13522. } // validation checks for WebGL 1
  13523. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  13524. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13525. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  13526. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13527. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  13528. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  13529. texture.type = UnsignedShortType;
  13530. glType = utils.convert(texture.type);
  13531. }
  13532. }
  13533. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  13534. // Depth stencil textures need the DEPTH_STENCIL internal format
  13535. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13536. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13537. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  13538. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13539. if (texture.type !== UnsignedInt248Type) {
  13540. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  13541. texture.type = UnsignedInt248Type;
  13542. glType = utils.convert(texture.type);
  13543. }
  13544. } //
  13545. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  13546. } else if (texture.isDataTexture) {
  13547. // use manually created mipmaps if available
  13548. // if there are no manual mipmaps
  13549. // set 0 level mipmap and then use GL to generate other mipmap levels
  13550. if (mipmaps.length > 0 && supportsMips) {
  13551. for (var i = 0, il = mipmaps.length; i < il; i++) {
  13552. mipmap = mipmaps[i];
  13553. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13554. }
  13555. texture.generateMipmaps = false;
  13556. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13557. } else {
  13558. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  13559. textureProperties.__maxMipLevel = 0;
  13560. }
  13561. } else if (texture.isCompressedTexture) {
  13562. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  13563. mipmap = mipmaps[_i];
  13564. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13565. if (glFormat !== null) {
  13566. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13567. } else {
  13568. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  13569. }
  13570. } else {
  13571. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13572. }
  13573. }
  13574. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13575. } else if (texture.isDataTexture2DArray) {
  13576. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13577. textureProperties.__maxMipLevel = 0;
  13578. } else if (texture.isDataTexture3D) {
  13579. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13580. textureProperties.__maxMipLevel = 0;
  13581. } else {
  13582. // regular Texture (image, video, canvas)
  13583. // use manually created mipmaps if available
  13584. // if there are no manual mipmaps
  13585. // set 0 level mipmap and then use GL to generate other mipmap levels
  13586. if (mipmaps.length > 0 && supportsMips) {
  13587. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  13588. mipmap = mipmaps[_i2];
  13589. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  13590. }
  13591. texture.generateMipmaps = false;
  13592. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13593. } else {
  13594. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  13595. textureProperties.__maxMipLevel = 0;
  13596. }
  13597. }
  13598. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13599. generateMipmap(textureType, texture, image.width, image.height);
  13600. }
  13601. textureProperties.__version = texture.version;
  13602. if (texture.onUpdate) texture.onUpdate(texture);
  13603. }
  13604. function uploadCubeTexture(textureProperties, texture, slot) {
  13605. if (texture.image.length !== 6) return;
  13606. initTexture(textureProperties, texture);
  13607. state.activeTexture(33984 + slot);
  13608. state.bindTexture(34067, textureProperties.__webglTexture);
  13609. _gl.pixelStorei(37440, texture.flipY);
  13610. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13611. _gl.pixelStorei(3317, texture.unpackAlignment);
  13612. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  13613. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  13614. var cubeImage = [];
  13615. for (var i = 0; i < 6; i++) {
  13616. if (!isCompressed && !isDataTexture) {
  13617. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  13618. } else {
  13619. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  13620. }
  13621. }
  13622. var image = cubeImage[0],
  13623. supportsMips = isPowerOfTwo(image) || isWebGL2,
  13624. glFormat = utils.convert(texture.format),
  13625. glType = utils.convert(texture.type),
  13626. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13627. setTextureParameters(34067, texture, supportsMips);
  13628. var mipmaps;
  13629. if (isCompressed) {
  13630. for (var _i3 = 0; _i3 < 6; _i3++) {
  13631. mipmaps = cubeImage[_i3].mipmaps;
  13632. for (var j = 0; j < mipmaps.length; j++) {
  13633. var mipmap = mipmaps[j];
  13634. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13635. if (glFormat !== null) {
  13636. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13637. } else {
  13638. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  13639. }
  13640. } else {
  13641. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13642. }
  13643. }
  13644. }
  13645. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13646. } else {
  13647. mipmaps = texture.mipmaps;
  13648. for (var _i4 = 0; _i4 < 6; _i4++) {
  13649. if (isDataTexture) {
  13650. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  13651. for (var _j = 0; _j < mipmaps.length; _j++) {
  13652. var _mipmap = mipmaps[_j];
  13653. var mipmapImage = _mipmap.image[_i4].image;
  13654. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  13655. }
  13656. } else {
  13657. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  13658. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  13659. var _mipmap2 = mipmaps[_j2];
  13660. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  13661. }
  13662. }
  13663. }
  13664. textureProperties.__maxMipLevel = mipmaps.length;
  13665. }
  13666. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13667. // We assume images for cube map have the same size.
  13668. generateMipmap(34067, texture, image.width, image.height);
  13669. }
  13670. textureProperties.__version = texture.version;
  13671. if (texture.onUpdate) texture.onUpdate(texture);
  13672. } // Render targets
  13673. // Setup storage for target texture and bind it to correct framebuffer
  13674. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  13675. var glFormat = utils.convert(renderTarget.texture.format);
  13676. var glType = utils.convert(renderTarget.texture.type);
  13677. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13678. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  13679. _gl.bindFramebuffer(36160, framebuffer);
  13680. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(renderTarget.texture).__webglTexture, 0);
  13681. _gl.bindFramebuffer(36160, null);
  13682. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13683. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  13684. _gl.bindRenderbuffer(36161, renderbuffer);
  13685. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  13686. var glInternalFormat = 33189;
  13687. if (isMultisample) {
  13688. var depthTexture = renderTarget.depthTexture;
  13689. if (depthTexture && depthTexture.isDepthTexture) {
  13690. if (depthTexture.type === FloatType) {
  13691. glInternalFormat = 36012;
  13692. } else if (depthTexture.type === UnsignedIntType) {
  13693. glInternalFormat = 33190;
  13694. }
  13695. }
  13696. var samples = getRenderTargetSamples(renderTarget);
  13697. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13698. } else {
  13699. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  13700. }
  13701. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  13702. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  13703. if (isMultisample) {
  13704. var _samples = getRenderTargetSamples(renderTarget);
  13705. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  13706. } else {
  13707. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  13708. }
  13709. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  13710. } else {
  13711. var glFormat = utils.convert(renderTarget.texture.format);
  13712. var glType = utils.convert(renderTarget.texture.type);
  13713. var _glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13714. if (isMultisample) {
  13715. var _samples2 = getRenderTargetSamples(renderTarget);
  13716. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  13717. } else {
  13718. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  13719. }
  13720. }
  13721. _gl.bindRenderbuffer(36161, null);
  13722. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  13723. function setupDepthTexture(framebuffer, renderTarget) {
  13724. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  13725. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  13726. _gl.bindFramebuffer(36160, framebuffer);
  13727. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  13728. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  13729. } // upload an empty depth texture with framebuffer size
  13730. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  13731. renderTarget.depthTexture.image.width = renderTarget.width;
  13732. renderTarget.depthTexture.image.height = renderTarget.height;
  13733. renderTarget.depthTexture.needsUpdate = true;
  13734. }
  13735. setTexture2D(renderTarget.depthTexture, 0);
  13736. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  13737. if (renderTarget.depthTexture.format === DepthFormat) {
  13738. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  13739. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  13740. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  13741. } else {
  13742. throw new Error('Unknown depthTexture format');
  13743. }
  13744. } // Setup GL resources for a non-texture depth buffer
  13745. function setupDepthRenderbuffer(renderTarget) {
  13746. var renderTargetProperties = properties.get(renderTarget);
  13747. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13748. if (renderTarget.depthTexture) {
  13749. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  13750. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  13751. } else {
  13752. if (isCube) {
  13753. renderTargetProperties.__webglDepthbuffer = [];
  13754. for (var i = 0; i < 6; i++) {
  13755. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  13756. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  13757. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  13758. }
  13759. } else {
  13760. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  13761. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13762. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  13763. }
  13764. }
  13765. _gl.bindFramebuffer(36160, null);
  13766. } // Set up GL resources for the render target
  13767. function setupRenderTarget(renderTarget) {
  13768. var renderTargetProperties = properties.get(renderTarget);
  13769. var textureProperties = properties.get(renderTarget.texture);
  13770. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  13771. textureProperties.__webglTexture = _gl.createTexture();
  13772. info.memory.textures++;
  13773. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13774. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  13775. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  13776. if (isWebGL2 && renderTarget.texture.format === RGBFormat && (renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType)) {
  13777. renderTarget.texture.format = RGBAFormat;
  13778. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  13779. } // Setup framebuffer
  13780. if (isCube) {
  13781. renderTargetProperties.__webglFramebuffer = [];
  13782. for (var i = 0; i < 6; i++) {
  13783. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  13784. }
  13785. } else {
  13786. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13787. if (isMultisample) {
  13788. if (isWebGL2) {
  13789. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13790. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13791. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  13792. var glFormat = utils.convert(renderTarget.texture.format);
  13793. var glType = utils.convert(renderTarget.texture.type);
  13794. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13795. var samples = getRenderTargetSamples(renderTarget);
  13796. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13797. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13798. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13799. _gl.bindRenderbuffer(36161, null);
  13800. if (renderTarget.depthBuffer) {
  13801. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13802. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13803. }
  13804. _gl.bindFramebuffer(36160, null);
  13805. } else {
  13806. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13807. }
  13808. }
  13809. } // Setup color buffer
  13810. if (isCube) {
  13811. state.bindTexture(34067, textureProperties.__webglTexture);
  13812. setTextureParameters(34067, renderTarget.texture, supportsMips);
  13813. for (var _i5 = 0; _i5 < 6; _i5++) {
  13814. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13815. }
  13816. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13817. generateMipmap(34067, renderTarget.texture, renderTarget.width, renderTarget.height);
  13818. }
  13819. state.bindTexture(34067, null);
  13820. } else {
  13821. state.bindTexture(3553, textureProperties.__webglTexture);
  13822. setTextureParameters(3553, renderTarget.texture, supportsMips);
  13823. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553);
  13824. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13825. generateMipmap(3553, renderTarget.texture, renderTarget.width, renderTarget.height);
  13826. }
  13827. state.bindTexture(3553, null);
  13828. } // Setup depth and stencil buffers
  13829. if (renderTarget.depthBuffer) {
  13830. setupDepthRenderbuffer(renderTarget);
  13831. }
  13832. }
  13833. function updateRenderTargetMipmap(renderTarget) {
  13834. var texture = renderTarget.texture;
  13835. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13836. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13837. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13838. var webglTexture = properties.get(texture).__webglTexture;
  13839. state.bindTexture(target, webglTexture);
  13840. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13841. state.bindTexture(target, null);
  13842. }
  13843. }
  13844. function updateMultisampleRenderTarget(renderTarget) {
  13845. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13846. if (isWebGL2) {
  13847. var renderTargetProperties = properties.get(renderTarget);
  13848. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13849. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13850. var width = renderTarget.width;
  13851. var height = renderTarget.height;
  13852. var mask = 16384;
  13853. if (renderTarget.depthBuffer) mask |= 256;
  13854. if (renderTarget.stencilBuffer) mask |= 1024;
  13855. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13856. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13857. } else {
  13858. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13859. }
  13860. }
  13861. }
  13862. function getRenderTargetSamples(renderTarget) {
  13863. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13864. }
  13865. function updateVideoTexture(texture) {
  13866. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13867. if (_videoTextures.get(texture) !== frame) {
  13868. _videoTextures.set(texture, frame);
  13869. texture.update();
  13870. }
  13871. } // backwards compatibility
  13872. var warnedTexture2D = false;
  13873. var warnedTextureCube = false;
  13874. function safeSetTexture2D(texture, slot) {
  13875. if (texture && texture.isWebGLRenderTarget) {
  13876. if (warnedTexture2D === false) {
  13877. console.warn('THREE.WebGLTextures.safeSetTexture2D: don\'t use render targets as textures. Use their .texture property instead.');
  13878. warnedTexture2D = true;
  13879. }
  13880. texture = texture.texture;
  13881. }
  13882. setTexture2D(texture, slot);
  13883. }
  13884. function safeSetTextureCube(texture, slot) {
  13885. if (texture && texture.isWebGLCubeRenderTarget) {
  13886. if (warnedTextureCube === false) {
  13887. console.warn('THREE.WebGLTextures.safeSetTextureCube: don\'t use cube render targets as textures. Use their .texture property instead.');
  13888. warnedTextureCube = true;
  13889. }
  13890. texture = texture.texture;
  13891. }
  13892. setTextureCube(texture, slot);
  13893. } //
  13894. this.allocateTextureUnit = allocateTextureUnit;
  13895. this.resetTextureUnits = resetTextureUnits;
  13896. this.setTexture2D = setTexture2D;
  13897. this.setTexture2DArray = setTexture2DArray;
  13898. this.setTexture3D = setTexture3D;
  13899. this.setTextureCube = setTextureCube;
  13900. this.setupRenderTarget = setupRenderTarget;
  13901. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13902. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13903. this.safeSetTexture2D = safeSetTexture2D;
  13904. this.safeSetTextureCube = safeSetTextureCube;
  13905. }
  13906. function WebGLUtils(gl, extensions, capabilities) {
  13907. var isWebGL2 = capabilities.isWebGL2;
  13908. function convert(p) {
  13909. var extension;
  13910. if (p === UnsignedByteType) return 5121;
  13911. if (p === UnsignedShort4444Type) return 32819;
  13912. if (p === UnsignedShort5551Type) return 32820;
  13913. if (p === UnsignedShort565Type) return 33635;
  13914. if (p === ByteType) return 5120;
  13915. if (p === ShortType) return 5122;
  13916. if (p === UnsignedShortType) return 5123;
  13917. if (p === IntType) return 5124;
  13918. if (p === UnsignedIntType) return 5125;
  13919. if (p === FloatType) return 5126;
  13920. if (p === HalfFloatType) {
  13921. if (isWebGL2) return 5131;
  13922. extension = extensions.get('OES_texture_half_float');
  13923. if (extension !== null) {
  13924. return extension.HALF_FLOAT_OES;
  13925. } else {
  13926. return null;
  13927. }
  13928. }
  13929. if (p === AlphaFormat) return 6406;
  13930. if (p === RGBFormat) return 6407;
  13931. if (p === RGBAFormat) return 6408;
  13932. if (p === LuminanceFormat) return 6409;
  13933. if (p === LuminanceAlphaFormat) return 6410;
  13934. if (p === DepthFormat) return 6402;
  13935. if (p === DepthStencilFormat) return 34041;
  13936. if (p === RedFormat) return 6403; // WebGL2 formats.
  13937. if (p === RedIntegerFormat) return 36244;
  13938. if (p === RGFormat) return 33319;
  13939. if (p === RGIntegerFormat) return 33320;
  13940. if (p === RGBIntegerFormat) return 36248;
  13941. if (p === RGBAIntegerFormat) return 36249;
  13942. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  13943. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  13944. if (extension !== null) {
  13945. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13946. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13947. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13948. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13949. } else {
  13950. return null;
  13951. }
  13952. }
  13953. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  13954. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  13955. if (extension !== null) {
  13956. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13957. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13958. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13959. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13960. } else {
  13961. return null;
  13962. }
  13963. }
  13964. if (p === RGB_ETC1_Format) {
  13965. extension = extensions.get('WEBGL_compressed_texture_etc1');
  13966. if (extension !== null) {
  13967. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13968. } else {
  13969. return null;
  13970. }
  13971. }
  13972. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  13973. extension = extensions.get('WEBGL_compressed_texture_etc');
  13974. if (extension !== null) {
  13975. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  13976. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13977. }
  13978. }
  13979. 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) {
  13980. extension = extensions.get('WEBGL_compressed_texture_astc');
  13981. if (extension !== null) {
  13982. // TODO Complete?
  13983. return p;
  13984. } else {
  13985. return null;
  13986. }
  13987. }
  13988. if (p === RGBA_BPTC_Format) {
  13989. extension = extensions.get('EXT_texture_compression_bptc');
  13990. if (extension !== null) {
  13991. // TODO Complete?
  13992. return p;
  13993. } else {
  13994. return null;
  13995. }
  13996. }
  13997. if (p === UnsignedInt248Type) {
  13998. if (isWebGL2) return 34042;
  13999. extension = extensions.get('WEBGL_depth_texture');
  14000. if (extension !== null) {
  14001. return extension.UNSIGNED_INT_24_8_WEBGL;
  14002. } else {
  14003. return null;
  14004. }
  14005. }
  14006. }
  14007. return {
  14008. convert: convert
  14009. };
  14010. }
  14011. function ArrayCamera(array) {
  14012. if (array === void 0) {
  14013. array = [];
  14014. }
  14015. PerspectiveCamera.call(this);
  14016. this.cameras = array;
  14017. }
  14018. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  14019. constructor: ArrayCamera,
  14020. isArrayCamera: true
  14021. });
  14022. function Group() {
  14023. Object3D.call(this);
  14024. this.type = 'Group';
  14025. }
  14026. Group.prototype = Object.assign(Object.create(Object3D.prototype), {
  14027. constructor: Group,
  14028. isGroup: true
  14029. });
  14030. function WebXRController() {
  14031. this._targetRay = null;
  14032. this._grip = null;
  14033. this._hand = null;
  14034. }
  14035. Object.assign(WebXRController.prototype, {
  14036. constructor: WebXRController,
  14037. getHandSpace: function getHandSpace() {
  14038. if (this._hand === null) {
  14039. this._hand = new Group();
  14040. this._hand.matrixAutoUpdate = false;
  14041. this._hand.visible = false;
  14042. this._hand.joints = {};
  14043. this._hand.inputState = {
  14044. pinching: false
  14045. };
  14046. }
  14047. return this._hand;
  14048. },
  14049. getTargetRaySpace: function getTargetRaySpace() {
  14050. if (this._targetRay === null) {
  14051. this._targetRay = new Group();
  14052. this._targetRay.matrixAutoUpdate = false;
  14053. this._targetRay.visible = false;
  14054. }
  14055. return this._targetRay;
  14056. },
  14057. getGripSpace: function getGripSpace() {
  14058. if (this._grip === null) {
  14059. this._grip = new Group();
  14060. this._grip.matrixAutoUpdate = false;
  14061. this._grip.visible = false;
  14062. }
  14063. return this._grip;
  14064. },
  14065. dispatchEvent: function dispatchEvent(event) {
  14066. if (this._targetRay !== null) {
  14067. this._targetRay.dispatchEvent(event);
  14068. }
  14069. if (this._grip !== null) {
  14070. this._grip.dispatchEvent(event);
  14071. }
  14072. if (this._hand !== null) {
  14073. this._hand.dispatchEvent(event);
  14074. }
  14075. return this;
  14076. },
  14077. disconnect: function disconnect(inputSource) {
  14078. this.dispatchEvent({
  14079. type: 'disconnected',
  14080. data: inputSource
  14081. });
  14082. if (this._targetRay !== null) {
  14083. this._targetRay.visible = false;
  14084. }
  14085. if (this._grip !== null) {
  14086. this._grip.visible = false;
  14087. }
  14088. if (this._hand !== null) {
  14089. this._hand.visible = false;
  14090. }
  14091. return this;
  14092. },
  14093. update: function update(inputSource, frame, referenceSpace) {
  14094. var inputPose = null;
  14095. var gripPose = null;
  14096. var handPose = null;
  14097. var targetRay = this._targetRay;
  14098. var grip = this._grip;
  14099. var hand = this._hand;
  14100. if (inputSource && frame.session.visibilityState !== 'visible-blurred') {
  14101. if (hand && inputSource.hand) {
  14102. handPose = true;
  14103. for (var _iterator = _createForOfIteratorHelperLoose(inputSource.hand.values()), _step; !(_step = _iterator()).done;) {
  14104. var inputjoint = _step.value;
  14105. // Update the joints groups with the XRJoint poses
  14106. var jointPose = frame.getJointPose(inputjoint, referenceSpace);
  14107. if (hand.joints[inputjoint.jointName] === undefined) {
  14108. // The transform of this joint will be updated with the joint pose on each frame
  14109. var _joint = new Group();
  14110. _joint.matrixAutoUpdate = false;
  14111. _joint.visible = false;
  14112. hand.joints[inputjoint.jointName] = _joint; // ??
  14113. hand.add(_joint);
  14114. }
  14115. var joint = hand.joints[inputjoint.jointName];
  14116. if (jointPose !== null) {
  14117. joint.matrix.fromArray(jointPose.transform.matrix);
  14118. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  14119. joint.jointRadius = jointPose.radius;
  14120. }
  14121. joint.visible = jointPose !== null;
  14122. } // Custom events
  14123. // Check pinchz
  14124. var indexTip = hand.joints['index-finger-tip'];
  14125. var thumbTip = hand.joints['thumb-tip'];
  14126. var distance = indexTip.position.distanceTo(thumbTip.position);
  14127. var distanceToPinch = 0.02;
  14128. var threshold = 0.005;
  14129. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  14130. hand.inputState.pinching = false;
  14131. this.dispatchEvent({
  14132. type: 'pinchend',
  14133. handedness: inputSource.handedness,
  14134. target: this
  14135. });
  14136. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  14137. hand.inputState.pinching = true;
  14138. this.dispatchEvent({
  14139. type: 'pinchstart',
  14140. handedness: inputSource.handedness,
  14141. target: this
  14142. });
  14143. }
  14144. } else {
  14145. if (targetRay !== null) {
  14146. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  14147. if (inputPose !== null) {
  14148. targetRay.matrix.fromArray(inputPose.transform.matrix);
  14149. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  14150. }
  14151. }
  14152. if (grip !== null && inputSource.gripSpace) {
  14153. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  14154. if (gripPose !== null) {
  14155. grip.matrix.fromArray(gripPose.transform.matrix);
  14156. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  14157. }
  14158. }
  14159. }
  14160. }
  14161. if (targetRay !== null) {
  14162. targetRay.visible = inputPose !== null;
  14163. }
  14164. if (grip !== null) {
  14165. grip.visible = gripPose !== null;
  14166. }
  14167. if (hand !== null) {
  14168. hand.visible = handPose !== null;
  14169. }
  14170. return this;
  14171. }
  14172. });
  14173. function WebXRManager(renderer, gl) {
  14174. var scope = this;
  14175. var session = null;
  14176. var framebufferScaleFactor = 1.0;
  14177. var referenceSpace = null;
  14178. var referenceSpaceType = 'local-floor';
  14179. var pose = null;
  14180. var controllers = [];
  14181. var inputSourcesMap = new Map(); //
  14182. var cameraL = new PerspectiveCamera();
  14183. cameraL.layers.enable(1);
  14184. cameraL.viewport = new Vector4();
  14185. var cameraR = new PerspectiveCamera();
  14186. cameraR.layers.enable(2);
  14187. cameraR.viewport = new Vector4();
  14188. var cameras = [cameraL, cameraR];
  14189. var cameraVR = new ArrayCamera();
  14190. cameraVR.layers.enable(1);
  14191. cameraVR.layers.enable(2);
  14192. var _currentDepthNear = null;
  14193. var _currentDepthFar = null; //
  14194. this.enabled = false;
  14195. this.isPresenting = false;
  14196. this.getController = function (index) {
  14197. var controller = controllers[index];
  14198. if (controller === undefined) {
  14199. controller = new WebXRController();
  14200. controllers[index] = controller;
  14201. }
  14202. return controller.getTargetRaySpace();
  14203. };
  14204. this.getControllerGrip = function (index) {
  14205. var controller = controllers[index];
  14206. if (controller === undefined) {
  14207. controller = new WebXRController();
  14208. controllers[index] = controller;
  14209. }
  14210. return controller.getGripSpace();
  14211. };
  14212. this.getHand = function (index) {
  14213. var controller = controllers[index];
  14214. if (controller === undefined) {
  14215. controller = new WebXRController();
  14216. controllers[index] = controller;
  14217. }
  14218. return controller.getHandSpace();
  14219. }; //
  14220. function onSessionEvent(event) {
  14221. var controller = inputSourcesMap.get(event.inputSource);
  14222. if (controller) {
  14223. controller.dispatchEvent({
  14224. type: event.type,
  14225. data: event.inputSource
  14226. });
  14227. }
  14228. }
  14229. function onSessionEnd() {
  14230. inputSourcesMap.forEach(function (controller, inputSource) {
  14231. controller.disconnect(inputSource);
  14232. });
  14233. inputSourcesMap.clear();
  14234. _currentDepthNear = null;
  14235. _currentDepthFar = null; //
  14236. renderer.setFramebuffer(null);
  14237. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  14238. animation.stop();
  14239. scope.isPresenting = false;
  14240. scope.dispatchEvent({
  14241. type: 'sessionend'
  14242. });
  14243. }
  14244. this.setFramebufferScaleFactor = function (value) {
  14245. framebufferScaleFactor = value;
  14246. if (scope.isPresenting === true) {
  14247. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  14248. }
  14249. };
  14250. this.setReferenceSpaceType = function (value) {
  14251. referenceSpaceType = value;
  14252. if (scope.isPresenting === true) {
  14253. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  14254. }
  14255. };
  14256. this.getReferenceSpace = function () {
  14257. return referenceSpace;
  14258. };
  14259. this.getSession = function () {
  14260. return session;
  14261. };
  14262. this.setSession = /*#__PURE__*/function () {
  14263. var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(value) {
  14264. var attributes, layerInit, baseLayer;
  14265. return regeneratorRuntime.wrap(function _callee$(_context) {
  14266. while (1) {
  14267. switch (_context.prev = _context.next) {
  14268. case 0:
  14269. session = value;
  14270. if (!(session !== null)) {
  14271. _context.next = 24;
  14272. break;
  14273. }
  14274. session.addEventListener('select', onSessionEvent);
  14275. session.addEventListener('selectstart', onSessionEvent);
  14276. session.addEventListener('selectend', onSessionEvent);
  14277. session.addEventListener('squeeze', onSessionEvent);
  14278. session.addEventListener('squeezestart', onSessionEvent);
  14279. session.addEventListener('squeezeend', onSessionEvent);
  14280. session.addEventListener('end', onSessionEnd);
  14281. session.addEventListener('inputsourceschange', onInputSourcesChange);
  14282. attributes = gl.getContextAttributes();
  14283. if (!(attributes.xrCompatible !== true)) {
  14284. _context.next = 14;
  14285. break;
  14286. }
  14287. _context.next = 14;
  14288. return gl.makeXRCompatible();
  14289. case 14:
  14290. layerInit = {
  14291. antialias: attributes.antialias,
  14292. alpha: attributes.alpha,
  14293. depth: attributes.depth,
  14294. stencil: attributes.stencil,
  14295. framebufferScaleFactor: framebufferScaleFactor
  14296. }; // eslint-disable-next-line no-undef
  14297. baseLayer = new XRWebGLLayer(session, gl, layerInit);
  14298. session.updateRenderState({
  14299. baseLayer: baseLayer
  14300. });
  14301. _context.next = 19;
  14302. return session.requestReferenceSpace(referenceSpaceType);
  14303. case 19:
  14304. referenceSpace = _context.sent;
  14305. animation.setContext(session);
  14306. animation.start();
  14307. scope.isPresenting = true;
  14308. scope.dispatchEvent({
  14309. type: 'sessionstart'
  14310. });
  14311. case 24:
  14312. case "end":
  14313. return _context.stop();
  14314. }
  14315. }
  14316. }, _callee);
  14317. }));
  14318. return function (_x) {
  14319. return _ref.apply(this, arguments);
  14320. };
  14321. }();
  14322. function onInputSourcesChange(event) {
  14323. var inputSources = session.inputSources; // Assign inputSources to available controllers
  14324. for (var i = 0; i < controllers.length; i++) {
  14325. inputSourcesMap.set(inputSources[i], controllers[i]);
  14326. } // Notify disconnected
  14327. for (var _i = 0; _i < event.removed.length; _i++) {
  14328. var inputSource = event.removed[_i];
  14329. var controller = inputSourcesMap.get(inputSource);
  14330. if (controller) {
  14331. controller.dispatchEvent({
  14332. type: 'disconnected',
  14333. data: inputSource
  14334. });
  14335. inputSourcesMap.delete(inputSource);
  14336. }
  14337. } // Notify connected
  14338. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  14339. var _inputSource = event.added[_i2];
  14340. var _controller = inputSourcesMap.get(_inputSource);
  14341. if (_controller) {
  14342. _controller.dispatchEvent({
  14343. type: 'connected',
  14344. data: _inputSource
  14345. });
  14346. }
  14347. }
  14348. } //
  14349. var cameraLPos = new Vector3();
  14350. var cameraRPos = new Vector3();
  14351. /**
  14352. * Assumes 2 cameras that are parallel and share an X-axis, and that
  14353. * the cameras' projection and world matrices have already been set.
  14354. * And that near and far planes are identical for both cameras.
  14355. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  14356. */
  14357. function setProjectionFromUnion(camera, cameraL, cameraR) {
  14358. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  14359. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  14360. var ipd = cameraLPos.distanceTo(cameraRPos);
  14361. var projL = cameraL.projectionMatrix.elements;
  14362. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  14363. // most likely identical top and bottom frustum extents.
  14364. // Use the left camera for these values.
  14365. var near = projL[14] / (projL[10] - 1);
  14366. var far = projL[14] / (projL[10] + 1);
  14367. var topFov = (projL[9] + 1) / projL[5];
  14368. var bottomFov = (projL[9] - 1) / projL[5];
  14369. var leftFov = (projL[8] - 1) / projL[0];
  14370. var rightFov = (projR[8] + 1) / projR[0];
  14371. var left = near * leftFov;
  14372. var right = near * rightFov; // Calculate the new camera's position offset from the
  14373. // left camera. xOffset should be roughly half `ipd`.
  14374. var zOffset = ipd / (-leftFov + rightFov);
  14375. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  14376. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  14377. camera.translateX(xOffset);
  14378. camera.translateZ(zOffset);
  14379. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  14380. camera.matrixWorldInverse.copy(camera.matrixWorld).invert(); // Find the union of the frustum values of the cameras and scale
  14381. // the values so that the near plane's position does not change in world space,
  14382. // although must now be relative to the new union camera.
  14383. var near2 = near + zOffset;
  14384. var far2 = far + zOffset;
  14385. var left2 = left - xOffset;
  14386. var right2 = right + (ipd - xOffset);
  14387. var top2 = topFov * far / far2 * near2;
  14388. var bottom2 = bottomFov * far / far2 * near2;
  14389. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  14390. }
  14391. function updateCamera(camera, parent) {
  14392. if (parent === null) {
  14393. camera.matrixWorld.copy(camera.matrix);
  14394. } else {
  14395. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  14396. }
  14397. camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
  14398. }
  14399. this.getCamera = function (camera) {
  14400. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  14401. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  14402. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  14403. // Note that the new renderState won't apply until the next frame. See #18320
  14404. session.updateRenderState({
  14405. depthNear: cameraVR.near,
  14406. depthFar: cameraVR.far
  14407. });
  14408. _currentDepthNear = cameraVR.near;
  14409. _currentDepthFar = cameraVR.far;
  14410. }
  14411. var parent = camera.parent;
  14412. var cameras = cameraVR.cameras;
  14413. updateCamera(cameraVR, parent);
  14414. for (var i = 0; i < cameras.length; i++) {
  14415. updateCamera(cameras[i], parent);
  14416. } // update camera and its children
  14417. camera.matrixWorld.copy(cameraVR.matrixWorld);
  14418. camera.matrix.copy(cameraVR.matrix);
  14419. camera.matrix.decompose(camera.position, camera.quaternion, camera.scale);
  14420. var children = camera.children;
  14421. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  14422. children[_i3].updateMatrixWorld(true);
  14423. } // update projection matrix for proper view frustum culling
  14424. if (cameras.length === 2) {
  14425. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  14426. } else {
  14427. // assume single camera setup (AR)
  14428. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  14429. }
  14430. return cameraVR;
  14431. }; // Animation Loop
  14432. var onAnimationFrameCallback = null;
  14433. function onAnimationFrame(time, frame) {
  14434. pose = frame.getViewerPose(referenceSpace);
  14435. if (pose !== null) {
  14436. var views = pose.views;
  14437. var baseLayer = session.renderState.baseLayer;
  14438. renderer.setFramebuffer(baseLayer.framebuffer);
  14439. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  14440. if (views.length !== cameraVR.cameras.length) {
  14441. cameraVR.cameras.length = 0;
  14442. cameraVRNeedsUpdate = true;
  14443. }
  14444. for (var i = 0; i < views.length; i++) {
  14445. var view = views[i];
  14446. var viewport = baseLayer.getViewport(view);
  14447. var camera = cameras[i];
  14448. camera.matrix.fromArray(view.transform.matrix);
  14449. camera.projectionMatrix.fromArray(view.projectionMatrix);
  14450. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  14451. if (i === 0) {
  14452. cameraVR.matrix.copy(camera.matrix);
  14453. }
  14454. if (cameraVRNeedsUpdate === true) {
  14455. cameraVR.cameras.push(camera);
  14456. }
  14457. }
  14458. } //
  14459. var inputSources = session.inputSources;
  14460. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  14461. var controller = controllers[_i4];
  14462. var inputSource = inputSources[_i4];
  14463. controller.update(inputSource, frame, referenceSpace);
  14464. }
  14465. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  14466. }
  14467. var animation = new WebGLAnimation();
  14468. animation.setAnimationLoop(onAnimationFrame);
  14469. this.setAnimationLoop = function (callback) {
  14470. onAnimationFrameCallback = callback;
  14471. };
  14472. this.dispose = function () {};
  14473. }
  14474. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  14475. function WebGLMaterials(properties) {
  14476. function refreshFogUniforms(uniforms, fog) {
  14477. uniforms.fogColor.value.copy(fog.color);
  14478. if (fog.isFog) {
  14479. uniforms.fogNear.value = fog.near;
  14480. uniforms.fogFar.value = fog.far;
  14481. } else if (fog.isFogExp2) {
  14482. uniforms.fogDensity.value = fog.density;
  14483. }
  14484. }
  14485. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  14486. if (material.isMeshBasicMaterial) {
  14487. refreshUniformsCommon(uniforms, material);
  14488. } else if (material.isMeshLambertMaterial) {
  14489. refreshUniformsCommon(uniforms, material);
  14490. refreshUniformsLambert(uniforms, material);
  14491. } else if (material.isMeshToonMaterial) {
  14492. refreshUniformsCommon(uniforms, material);
  14493. refreshUniformsToon(uniforms, material);
  14494. } else if (material.isMeshPhongMaterial) {
  14495. refreshUniformsCommon(uniforms, material);
  14496. refreshUniformsPhong(uniforms, material);
  14497. } else if (material.isMeshStandardMaterial) {
  14498. refreshUniformsCommon(uniforms, material);
  14499. if (material.isMeshPhysicalMaterial) {
  14500. refreshUniformsPhysical(uniforms, material);
  14501. } else {
  14502. refreshUniformsStandard(uniforms, material);
  14503. }
  14504. } else if (material.isMeshMatcapMaterial) {
  14505. refreshUniformsCommon(uniforms, material);
  14506. refreshUniformsMatcap(uniforms, material);
  14507. } else if (material.isMeshDepthMaterial) {
  14508. refreshUniformsCommon(uniforms, material);
  14509. refreshUniformsDepth(uniforms, material);
  14510. } else if (material.isMeshDistanceMaterial) {
  14511. refreshUniformsCommon(uniforms, material);
  14512. refreshUniformsDistance(uniforms, material);
  14513. } else if (material.isMeshNormalMaterial) {
  14514. refreshUniformsCommon(uniforms, material);
  14515. refreshUniformsNormal(uniforms, material);
  14516. } else if (material.isLineBasicMaterial) {
  14517. refreshUniformsLine(uniforms, material);
  14518. if (material.isLineDashedMaterial) {
  14519. refreshUniformsDash(uniforms, material);
  14520. }
  14521. } else if (material.isPointsMaterial) {
  14522. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  14523. } else if (material.isSpriteMaterial) {
  14524. refreshUniformsSprites(uniforms, material);
  14525. } else if (material.isShadowMaterial) {
  14526. uniforms.color.value.copy(material.color);
  14527. uniforms.opacity.value = material.opacity;
  14528. } else if (material.isShaderMaterial) {
  14529. material.uniformsNeedUpdate = false; // #15581
  14530. }
  14531. }
  14532. function refreshUniformsCommon(uniforms, material) {
  14533. uniforms.opacity.value = material.opacity;
  14534. if (material.color) {
  14535. uniforms.diffuse.value.copy(material.color);
  14536. }
  14537. if (material.emissive) {
  14538. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  14539. }
  14540. if (material.map) {
  14541. uniforms.map.value = material.map;
  14542. }
  14543. if (material.alphaMap) {
  14544. uniforms.alphaMap.value = material.alphaMap;
  14545. }
  14546. if (material.specularMap) {
  14547. uniforms.specularMap.value = material.specularMap;
  14548. }
  14549. var envMap = properties.get(material).envMap;
  14550. if (envMap) {
  14551. uniforms.envMap.value = envMap;
  14552. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  14553. uniforms.reflectivity.value = material.reflectivity;
  14554. uniforms.refractionRatio.value = material.refractionRatio;
  14555. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  14556. if (maxMipLevel !== undefined) {
  14557. uniforms.maxMipLevel.value = maxMipLevel;
  14558. }
  14559. }
  14560. if (material.lightMap) {
  14561. uniforms.lightMap.value = material.lightMap;
  14562. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14563. }
  14564. if (material.aoMap) {
  14565. uniforms.aoMap.value = material.aoMap;
  14566. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14567. } // uv repeat and offset setting priorities
  14568. // 1. color map
  14569. // 2. specular map
  14570. // 3. displacementMap map
  14571. // 4. normal map
  14572. // 5. bump map
  14573. // 6. roughnessMap map
  14574. // 7. metalnessMap map
  14575. // 8. alphaMap map
  14576. // 9. emissiveMap map
  14577. // 10. clearcoat map
  14578. // 11. clearcoat normal map
  14579. // 12. clearcoat roughnessMap map
  14580. var uvScaleMap;
  14581. if (material.map) {
  14582. uvScaleMap = material.map;
  14583. } else if (material.specularMap) {
  14584. uvScaleMap = material.specularMap;
  14585. } else if (material.displacementMap) {
  14586. uvScaleMap = material.displacementMap;
  14587. } else if (material.normalMap) {
  14588. uvScaleMap = material.normalMap;
  14589. } else if (material.bumpMap) {
  14590. uvScaleMap = material.bumpMap;
  14591. } else if (material.roughnessMap) {
  14592. uvScaleMap = material.roughnessMap;
  14593. } else if (material.metalnessMap) {
  14594. uvScaleMap = material.metalnessMap;
  14595. } else if (material.alphaMap) {
  14596. uvScaleMap = material.alphaMap;
  14597. } else if (material.emissiveMap) {
  14598. uvScaleMap = material.emissiveMap;
  14599. } else if (material.clearcoatMap) {
  14600. uvScaleMap = material.clearcoatMap;
  14601. } else if (material.clearcoatNormalMap) {
  14602. uvScaleMap = material.clearcoatNormalMap;
  14603. } else if (material.clearcoatRoughnessMap) {
  14604. uvScaleMap = material.clearcoatRoughnessMap;
  14605. }
  14606. if (uvScaleMap !== undefined) {
  14607. // backwards compatibility
  14608. if (uvScaleMap.isWebGLRenderTarget) {
  14609. uvScaleMap = uvScaleMap.texture;
  14610. }
  14611. if (uvScaleMap.matrixAutoUpdate === true) {
  14612. uvScaleMap.updateMatrix();
  14613. }
  14614. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14615. } // uv repeat and offset setting priorities for uv2
  14616. // 1. ao map
  14617. // 2. light map
  14618. var uv2ScaleMap;
  14619. if (material.aoMap) {
  14620. uv2ScaleMap = material.aoMap;
  14621. } else if (material.lightMap) {
  14622. uv2ScaleMap = material.lightMap;
  14623. }
  14624. if (uv2ScaleMap !== undefined) {
  14625. // backwards compatibility
  14626. if (uv2ScaleMap.isWebGLRenderTarget) {
  14627. uv2ScaleMap = uv2ScaleMap.texture;
  14628. }
  14629. if (uv2ScaleMap.matrixAutoUpdate === true) {
  14630. uv2ScaleMap.updateMatrix();
  14631. }
  14632. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  14633. }
  14634. }
  14635. function refreshUniformsLine(uniforms, material) {
  14636. uniforms.diffuse.value.copy(material.color);
  14637. uniforms.opacity.value = material.opacity;
  14638. }
  14639. function refreshUniformsDash(uniforms, material) {
  14640. uniforms.dashSize.value = material.dashSize;
  14641. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14642. uniforms.scale.value = material.scale;
  14643. }
  14644. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  14645. uniforms.diffuse.value.copy(material.color);
  14646. uniforms.opacity.value = material.opacity;
  14647. uniforms.size.value = material.size * pixelRatio;
  14648. uniforms.scale.value = height * 0.5;
  14649. if (material.map) {
  14650. uniforms.map.value = material.map;
  14651. }
  14652. if (material.alphaMap) {
  14653. uniforms.alphaMap.value = material.alphaMap;
  14654. } // uv repeat and offset setting priorities
  14655. // 1. color map
  14656. // 2. alpha map
  14657. var uvScaleMap;
  14658. if (material.map) {
  14659. uvScaleMap = material.map;
  14660. } else if (material.alphaMap) {
  14661. uvScaleMap = material.alphaMap;
  14662. }
  14663. if (uvScaleMap !== undefined) {
  14664. if (uvScaleMap.matrixAutoUpdate === true) {
  14665. uvScaleMap.updateMatrix();
  14666. }
  14667. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14668. }
  14669. }
  14670. function refreshUniformsSprites(uniforms, material) {
  14671. uniforms.diffuse.value.copy(material.color);
  14672. uniforms.opacity.value = material.opacity;
  14673. uniforms.rotation.value = material.rotation;
  14674. if (material.map) {
  14675. uniforms.map.value = material.map;
  14676. }
  14677. if (material.alphaMap) {
  14678. uniforms.alphaMap.value = material.alphaMap;
  14679. } // uv repeat and offset setting priorities
  14680. // 1. color map
  14681. // 2. alpha map
  14682. var uvScaleMap;
  14683. if (material.map) {
  14684. uvScaleMap = material.map;
  14685. } else if (material.alphaMap) {
  14686. uvScaleMap = material.alphaMap;
  14687. }
  14688. if (uvScaleMap !== undefined) {
  14689. if (uvScaleMap.matrixAutoUpdate === true) {
  14690. uvScaleMap.updateMatrix();
  14691. }
  14692. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14693. }
  14694. }
  14695. function refreshUniformsLambert(uniforms, material) {
  14696. if (material.emissiveMap) {
  14697. uniforms.emissiveMap.value = material.emissiveMap;
  14698. }
  14699. }
  14700. function refreshUniformsPhong(uniforms, material) {
  14701. uniforms.specular.value.copy(material.specular);
  14702. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  14703. if (material.emissiveMap) {
  14704. uniforms.emissiveMap.value = material.emissiveMap;
  14705. }
  14706. if (material.bumpMap) {
  14707. uniforms.bumpMap.value = material.bumpMap;
  14708. uniforms.bumpScale.value = material.bumpScale;
  14709. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14710. }
  14711. if (material.normalMap) {
  14712. uniforms.normalMap.value = material.normalMap;
  14713. uniforms.normalScale.value.copy(material.normalScale);
  14714. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14715. }
  14716. if (material.displacementMap) {
  14717. uniforms.displacementMap.value = material.displacementMap;
  14718. uniforms.displacementScale.value = material.displacementScale;
  14719. uniforms.displacementBias.value = material.displacementBias;
  14720. }
  14721. }
  14722. function refreshUniformsToon(uniforms, material) {
  14723. if (material.gradientMap) {
  14724. uniforms.gradientMap.value = material.gradientMap;
  14725. }
  14726. if (material.emissiveMap) {
  14727. uniforms.emissiveMap.value = material.emissiveMap;
  14728. }
  14729. if (material.bumpMap) {
  14730. uniforms.bumpMap.value = material.bumpMap;
  14731. uniforms.bumpScale.value = material.bumpScale;
  14732. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14733. }
  14734. if (material.normalMap) {
  14735. uniforms.normalMap.value = material.normalMap;
  14736. uniforms.normalScale.value.copy(material.normalScale);
  14737. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14738. }
  14739. if (material.displacementMap) {
  14740. uniforms.displacementMap.value = material.displacementMap;
  14741. uniforms.displacementScale.value = material.displacementScale;
  14742. uniforms.displacementBias.value = material.displacementBias;
  14743. }
  14744. }
  14745. function refreshUniformsStandard(uniforms, material) {
  14746. uniforms.roughness.value = material.roughness;
  14747. uniforms.metalness.value = material.metalness;
  14748. if (material.roughnessMap) {
  14749. uniforms.roughnessMap.value = material.roughnessMap;
  14750. }
  14751. if (material.metalnessMap) {
  14752. uniforms.metalnessMap.value = material.metalnessMap;
  14753. }
  14754. if (material.emissiveMap) {
  14755. uniforms.emissiveMap.value = material.emissiveMap;
  14756. }
  14757. if (material.bumpMap) {
  14758. uniforms.bumpMap.value = material.bumpMap;
  14759. uniforms.bumpScale.value = material.bumpScale;
  14760. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14761. }
  14762. if (material.normalMap) {
  14763. uniforms.normalMap.value = material.normalMap;
  14764. uniforms.normalScale.value.copy(material.normalScale);
  14765. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14766. }
  14767. if (material.displacementMap) {
  14768. uniforms.displacementMap.value = material.displacementMap;
  14769. uniforms.displacementScale.value = material.displacementScale;
  14770. uniforms.displacementBias.value = material.displacementBias;
  14771. }
  14772. var envMap = properties.get(material).envMap;
  14773. if (envMap) {
  14774. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14775. uniforms.envMapIntensity.value = material.envMapIntensity;
  14776. }
  14777. }
  14778. function refreshUniformsPhysical(uniforms, material) {
  14779. refreshUniformsStandard(uniforms, material);
  14780. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14781. uniforms.clearcoat.value = material.clearcoat;
  14782. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14783. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  14784. if (material.clearcoatMap) {
  14785. uniforms.clearcoatMap.value = material.clearcoatMap;
  14786. }
  14787. if (material.clearcoatRoughnessMap) {
  14788. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14789. }
  14790. if (material.clearcoatNormalMap) {
  14791. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  14792. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14793. if (material.side === BackSide) {
  14794. uniforms.clearcoatNormalScale.value.negate();
  14795. }
  14796. }
  14797. uniforms.transmission.value = material.transmission;
  14798. if (material.transmissionMap) {
  14799. uniforms.transmissionMap.value = material.transmissionMap;
  14800. }
  14801. }
  14802. function refreshUniformsMatcap(uniforms, material) {
  14803. if (material.matcap) {
  14804. uniforms.matcap.value = material.matcap;
  14805. }
  14806. if (material.bumpMap) {
  14807. uniforms.bumpMap.value = material.bumpMap;
  14808. uniforms.bumpScale.value = material.bumpScale;
  14809. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14810. }
  14811. if (material.normalMap) {
  14812. uniforms.normalMap.value = material.normalMap;
  14813. uniforms.normalScale.value.copy(material.normalScale);
  14814. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14815. }
  14816. if (material.displacementMap) {
  14817. uniforms.displacementMap.value = material.displacementMap;
  14818. uniforms.displacementScale.value = material.displacementScale;
  14819. uniforms.displacementBias.value = material.displacementBias;
  14820. }
  14821. }
  14822. function refreshUniformsDepth(uniforms, material) {
  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 refreshUniformsDistance(uniforms, material) {
  14830. if (material.displacementMap) {
  14831. uniforms.displacementMap.value = material.displacementMap;
  14832. uniforms.displacementScale.value = material.displacementScale;
  14833. uniforms.displacementBias.value = material.displacementBias;
  14834. }
  14835. uniforms.referencePosition.value.copy(material.referencePosition);
  14836. uniforms.nearDistance.value = material.nearDistance;
  14837. uniforms.farDistance.value = material.farDistance;
  14838. }
  14839. function refreshUniformsNormal(uniforms, material) {
  14840. if (material.bumpMap) {
  14841. uniforms.bumpMap.value = material.bumpMap;
  14842. uniforms.bumpScale.value = material.bumpScale;
  14843. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14844. }
  14845. if (material.normalMap) {
  14846. uniforms.normalMap.value = material.normalMap;
  14847. uniforms.normalScale.value.copy(material.normalScale);
  14848. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14849. }
  14850. if (material.displacementMap) {
  14851. uniforms.displacementMap.value = material.displacementMap;
  14852. uniforms.displacementScale.value = material.displacementScale;
  14853. uniforms.displacementBias.value = material.displacementBias;
  14854. }
  14855. }
  14856. return {
  14857. refreshFogUniforms: refreshFogUniforms,
  14858. refreshMaterialUniforms: refreshMaterialUniforms
  14859. };
  14860. }
  14861. function createCanvasElement() {
  14862. var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  14863. canvas.style.display = 'block';
  14864. return canvas;
  14865. }
  14866. function WebGLRenderer(parameters) {
  14867. parameters = parameters || {};
  14868. var _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  14869. _context = parameters.context !== undefined ? parameters.context : null,
  14870. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14871. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14872. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14873. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14874. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14875. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14876. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14877. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14878. var currentRenderList = null;
  14879. var currentRenderState = null; // render() can be called from within a callback triggered by another render.
  14880. // We track this so that the nested render call gets its state isolated from the parent render call.
  14881. var renderStateStack = []; // public properties
  14882. this.domElement = _canvas; // Debug configuration container
  14883. this.debug = {
  14884. /**
  14885. * Enables error checking and reporting when shader programs are being compiled
  14886. * @type {boolean}
  14887. */
  14888. checkShaderErrors: true
  14889. }; // clearing
  14890. this.autoClear = true;
  14891. this.autoClearColor = true;
  14892. this.autoClearDepth = true;
  14893. this.autoClearStencil = true; // scene graph
  14894. this.sortObjects = true; // user-defined clipping
  14895. this.clippingPlanes = [];
  14896. this.localClippingEnabled = false; // physically based shading
  14897. this.gammaFactor = 2.0; // for backwards compatibility
  14898. this.outputEncoding = LinearEncoding; // physical lights
  14899. this.physicallyCorrectLights = false; // tone mapping
  14900. this.toneMapping = NoToneMapping;
  14901. this.toneMappingExposure = 1.0; // morphs
  14902. this.maxMorphTargets = 8;
  14903. this.maxMorphNormals = 4; // internal properties
  14904. var _this = this;
  14905. var _isContextLost = false; // internal state cache
  14906. var _framebuffer = null;
  14907. var _currentActiveCubeFace = 0;
  14908. var _currentActiveMipmapLevel = 0;
  14909. var _currentRenderTarget = null;
  14910. var _currentFramebuffer = null;
  14911. var _currentMaterialId = -1;
  14912. var _currentCamera = null;
  14913. var _currentViewport = new Vector4();
  14914. var _currentScissor = new Vector4();
  14915. var _currentScissorTest = null; //
  14916. var _width = _canvas.width;
  14917. var _height = _canvas.height;
  14918. var _pixelRatio = 1;
  14919. var _opaqueSort = null;
  14920. var _transparentSort = null;
  14921. var _viewport = new Vector4(0, 0, _width, _height);
  14922. var _scissor = new Vector4(0, 0, _width, _height);
  14923. var _scissorTest = false; // frustum
  14924. var _frustum = new Frustum(); // clipping
  14925. var _clippingEnabled = false;
  14926. var _localClippingEnabled = false; // camera matrices cache
  14927. var _projScreenMatrix = new Matrix4();
  14928. var _vector3 = new Vector3();
  14929. var _emptyScene = {
  14930. background: null,
  14931. fog: null,
  14932. environment: null,
  14933. overrideMaterial: null,
  14934. isScene: true
  14935. };
  14936. function getTargetPixelRatio() {
  14937. return _currentRenderTarget === null ? _pixelRatio : 1;
  14938. } // initialize
  14939. var _gl = _context;
  14940. function getContext(contextNames, contextAttributes) {
  14941. for (var i = 0; i < contextNames.length; i++) {
  14942. var contextName = contextNames[i];
  14943. var context = _canvas.getContext(contextName, contextAttributes);
  14944. if (context !== null) return context;
  14945. }
  14946. return null;
  14947. }
  14948. try {
  14949. var contextAttributes = {
  14950. alpha: _alpha,
  14951. depth: _depth,
  14952. stencil: _stencil,
  14953. antialias: _antialias,
  14954. premultipliedAlpha: _premultipliedAlpha,
  14955. preserveDrawingBuffer: _preserveDrawingBuffer,
  14956. powerPreference: _powerPreference,
  14957. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  14958. }; // event listeners must be registered before WebGL context is created, see #12753
  14959. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  14960. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  14961. if (_gl === null) {
  14962. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  14963. if (_this.isWebGL1Renderer === true) {
  14964. contextNames.shift();
  14965. }
  14966. _gl = getContext(contextNames, contextAttributes);
  14967. if (_gl === null) {
  14968. if (getContext(contextNames)) {
  14969. throw new Error('Error creating WebGL context with your selected attributes.');
  14970. } else {
  14971. throw new Error('Error creating WebGL context.');
  14972. }
  14973. }
  14974. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14975. if (_gl.getShaderPrecisionFormat === undefined) {
  14976. _gl.getShaderPrecisionFormat = function () {
  14977. return {
  14978. 'rangeMin': 1,
  14979. 'rangeMax': 1,
  14980. 'precision': 1
  14981. };
  14982. };
  14983. }
  14984. } catch (error) {
  14985. console.error('THREE.WebGLRenderer: ' + error.message);
  14986. throw error;
  14987. }
  14988. var extensions, capabilities, state, info;
  14989. var properties, textures, cubemaps, attributes, geometries, objects;
  14990. var programCache, materials, renderLists, renderStates, clipping;
  14991. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14992. var utils, bindingStates;
  14993. function initGLContext() {
  14994. extensions = new WebGLExtensions(_gl);
  14995. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  14996. extensions.init(capabilities);
  14997. utils = new WebGLUtils(_gl, extensions, capabilities);
  14998. state = new WebGLState(_gl, extensions, capabilities);
  14999. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  15000. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  15001. info = new WebGLInfo(_gl);
  15002. properties = new WebGLProperties();
  15003. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  15004. cubemaps = new WebGLCubeMaps(_this);
  15005. attributes = new WebGLAttributes(_gl, capabilities);
  15006. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  15007. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  15008. objects = new WebGLObjects(_gl, geometries, attributes, info);
  15009. morphtargets = new WebGLMorphtargets(_gl);
  15010. clipping = new WebGLClipping(properties);
  15011. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  15012. materials = new WebGLMaterials(properties);
  15013. renderLists = new WebGLRenderLists(properties);
  15014. renderStates = new WebGLRenderStates(extensions, capabilities);
  15015. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  15016. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  15017. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  15018. info.programs = programCache.programs;
  15019. _this.capabilities = capabilities;
  15020. _this.extensions = extensions;
  15021. _this.properties = properties;
  15022. _this.renderLists = renderLists;
  15023. _this.state = state;
  15024. _this.info = info;
  15025. }
  15026. initGLContext(); // xr
  15027. var xr = new WebXRManager(_this, _gl);
  15028. this.xr = xr; // shadow map
  15029. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  15030. this.shadowMap = shadowMap; // API
  15031. this.getContext = function () {
  15032. return _gl;
  15033. };
  15034. this.getContextAttributes = function () {
  15035. return _gl.getContextAttributes();
  15036. };
  15037. this.forceContextLoss = function () {
  15038. var extension = extensions.get('WEBGL_lose_context');
  15039. if (extension) extension.loseContext();
  15040. };
  15041. this.forceContextRestore = function () {
  15042. var extension = extensions.get('WEBGL_lose_context');
  15043. if (extension) extension.restoreContext();
  15044. };
  15045. this.getPixelRatio = function () {
  15046. return _pixelRatio;
  15047. };
  15048. this.setPixelRatio = function (value) {
  15049. if (value === undefined) return;
  15050. _pixelRatio = value;
  15051. this.setSize(_width, _height, false);
  15052. };
  15053. this.getSize = function (target) {
  15054. if (target === undefined) {
  15055. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  15056. target = new Vector2();
  15057. }
  15058. return target.set(_width, _height);
  15059. };
  15060. this.setSize = function (width, height, updateStyle) {
  15061. if (xr.isPresenting) {
  15062. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  15063. return;
  15064. }
  15065. _width = width;
  15066. _height = height;
  15067. _canvas.width = Math.floor(width * _pixelRatio);
  15068. _canvas.height = Math.floor(height * _pixelRatio);
  15069. if (updateStyle !== false) {
  15070. _canvas.style.width = width + 'px';
  15071. _canvas.style.height = height + 'px';
  15072. }
  15073. this.setViewport(0, 0, width, height);
  15074. };
  15075. this.getDrawingBufferSize = function (target) {
  15076. if (target === undefined) {
  15077. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  15078. target = new Vector2();
  15079. }
  15080. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  15081. };
  15082. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  15083. _width = width;
  15084. _height = height;
  15085. _pixelRatio = pixelRatio;
  15086. _canvas.width = Math.floor(width * pixelRatio);
  15087. _canvas.height = Math.floor(height * pixelRatio);
  15088. this.setViewport(0, 0, width, height);
  15089. };
  15090. this.getCurrentViewport = function (target) {
  15091. if (target === undefined) {
  15092. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  15093. target = new Vector4();
  15094. }
  15095. return target.copy(_currentViewport);
  15096. };
  15097. this.getViewport = function (target) {
  15098. return target.copy(_viewport);
  15099. };
  15100. this.setViewport = function (x, y, width, height) {
  15101. if (x.isVector4) {
  15102. _viewport.set(x.x, x.y, x.z, x.w);
  15103. } else {
  15104. _viewport.set(x, y, width, height);
  15105. }
  15106. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  15107. };
  15108. this.getScissor = function (target) {
  15109. return target.copy(_scissor);
  15110. };
  15111. this.setScissor = function (x, y, width, height) {
  15112. if (x.isVector4) {
  15113. _scissor.set(x.x, x.y, x.z, x.w);
  15114. } else {
  15115. _scissor.set(x, y, width, height);
  15116. }
  15117. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  15118. };
  15119. this.getScissorTest = function () {
  15120. return _scissorTest;
  15121. };
  15122. this.setScissorTest = function (boolean) {
  15123. state.setScissorTest(_scissorTest = boolean);
  15124. };
  15125. this.setOpaqueSort = function (method) {
  15126. _opaqueSort = method;
  15127. };
  15128. this.setTransparentSort = function (method) {
  15129. _transparentSort = method;
  15130. }; // Clearing
  15131. this.getClearColor = function (target) {
  15132. if (target === undefined) {
  15133. console.warn('WebGLRenderer: .getClearColor() now requires a Color as an argument');
  15134. target = new Color();
  15135. }
  15136. return target.copy(background.getClearColor());
  15137. };
  15138. this.setClearColor = function () {
  15139. background.setClearColor.apply(background, arguments);
  15140. };
  15141. this.getClearAlpha = function () {
  15142. return background.getClearAlpha();
  15143. };
  15144. this.setClearAlpha = function () {
  15145. background.setClearAlpha.apply(background, arguments);
  15146. };
  15147. this.clear = function (color, depth, stencil) {
  15148. var bits = 0;
  15149. if (color === undefined || color) bits |= 16384;
  15150. if (depth === undefined || depth) bits |= 256;
  15151. if (stencil === undefined || stencil) bits |= 1024;
  15152. _gl.clear(bits);
  15153. };
  15154. this.clearColor = function () {
  15155. this.clear(true, false, false);
  15156. };
  15157. this.clearDepth = function () {
  15158. this.clear(false, true, false);
  15159. };
  15160. this.clearStencil = function () {
  15161. this.clear(false, false, true);
  15162. }; //
  15163. this.dispose = function () {
  15164. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  15165. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  15166. renderLists.dispose();
  15167. renderStates.dispose();
  15168. properties.dispose();
  15169. cubemaps.dispose();
  15170. objects.dispose();
  15171. bindingStates.dispose();
  15172. xr.dispose();
  15173. animation.stop();
  15174. }; // Events
  15175. function onContextLost(event) {
  15176. event.preventDefault();
  15177. console.log('THREE.WebGLRenderer: Context Lost.');
  15178. _isContextLost = true;
  15179. }
  15180. function onContextRestore()
  15181. /* event */
  15182. {
  15183. console.log('THREE.WebGLRenderer: Context Restored.');
  15184. _isContextLost = false;
  15185. initGLContext();
  15186. }
  15187. function onMaterialDispose(event) {
  15188. var material = event.target;
  15189. material.removeEventListener('dispose', onMaterialDispose);
  15190. deallocateMaterial(material);
  15191. } // Buffer deallocation
  15192. function deallocateMaterial(material) {
  15193. releaseMaterialProgramReference(material);
  15194. properties.remove(material);
  15195. }
  15196. function releaseMaterialProgramReference(material) {
  15197. var programInfo = properties.get(material).program;
  15198. if (programInfo !== undefined) {
  15199. programCache.releaseProgram(programInfo);
  15200. }
  15201. } // Buffer rendering
  15202. function renderObjectImmediate(object, program) {
  15203. object.render(function (object) {
  15204. _this.renderBufferImmediate(object, program);
  15205. });
  15206. }
  15207. this.renderBufferImmediate = function (object, program) {
  15208. bindingStates.initAttributes();
  15209. var buffers = properties.get(object);
  15210. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  15211. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  15212. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  15213. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  15214. var programAttributes = program.getAttributes();
  15215. if (object.hasPositions) {
  15216. _gl.bindBuffer(34962, buffers.position);
  15217. _gl.bufferData(34962, object.positionArray, 35048);
  15218. bindingStates.enableAttribute(programAttributes.position);
  15219. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  15220. }
  15221. if (object.hasNormals) {
  15222. _gl.bindBuffer(34962, buffers.normal);
  15223. _gl.bufferData(34962, object.normalArray, 35048);
  15224. bindingStates.enableAttribute(programAttributes.normal);
  15225. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  15226. }
  15227. if (object.hasUvs) {
  15228. _gl.bindBuffer(34962, buffers.uv);
  15229. _gl.bufferData(34962, object.uvArray, 35048);
  15230. bindingStates.enableAttribute(programAttributes.uv);
  15231. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  15232. }
  15233. if (object.hasColors) {
  15234. _gl.bindBuffer(34962, buffers.color);
  15235. _gl.bufferData(34962, object.colorArray, 35048);
  15236. bindingStates.enableAttribute(programAttributes.color);
  15237. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  15238. }
  15239. bindingStates.disableUnusedAttributes();
  15240. _gl.drawArrays(4, 0, object.count);
  15241. object.count = 0;
  15242. };
  15243. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  15244. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  15245. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  15246. var program = setProgram(camera, scene, material, object);
  15247. state.setMaterial(material, frontFaceCW); //
  15248. var index = geometry.index;
  15249. var position = geometry.attributes.position; //
  15250. if (index === null) {
  15251. if (position === undefined || position.count === 0) return;
  15252. } else if (index.count === 0) {
  15253. return;
  15254. } //
  15255. var rangeFactor = 1;
  15256. if (material.wireframe === true) {
  15257. index = geometries.getWireframeAttribute(geometry);
  15258. rangeFactor = 2;
  15259. }
  15260. if (material.morphTargets || material.morphNormals) {
  15261. morphtargets.update(object, geometry, material, program);
  15262. }
  15263. bindingStates.setup(object, material, program, geometry, index);
  15264. var attribute;
  15265. var renderer = bufferRenderer;
  15266. if (index !== null) {
  15267. attribute = attributes.get(index);
  15268. renderer = indexedBufferRenderer;
  15269. renderer.setIndex(attribute);
  15270. } //
  15271. var dataCount = index !== null ? index.count : position.count;
  15272. var rangeStart = geometry.drawRange.start * rangeFactor;
  15273. var rangeCount = geometry.drawRange.count * rangeFactor;
  15274. var groupStart = group !== null ? group.start * rangeFactor : 0;
  15275. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  15276. var drawStart = Math.max(rangeStart, groupStart);
  15277. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  15278. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  15279. if (drawCount === 0) return; //
  15280. if (object.isMesh) {
  15281. if (material.wireframe === true) {
  15282. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  15283. renderer.setMode(1);
  15284. } else {
  15285. renderer.setMode(4);
  15286. }
  15287. } else if (object.isLine) {
  15288. var lineWidth = material.linewidth;
  15289. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  15290. state.setLineWidth(lineWidth * getTargetPixelRatio());
  15291. if (object.isLineSegments) {
  15292. renderer.setMode(1);
  15293. } else if (object.isLineLoop) {
  15294. renderer.setMode(2);
  15295. } else {
  15296. renderer.setMode(3);
  15297. }
  15298. } else if (object.isPoints) {
  15299. renderer.setMode(0);
  15300. } else if (object.isSprite) {
  15301. renderer.setMode(4);
  15302. }
  15303. if (object.isInstancedMesh) {
  15304. renderer.renderInstances(drawStart, drawCount, object.count);
  15305. } else if (geometry.isInstancedBufferGeometry) {
  15306. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  15307. renderer.renderInstances(drawStart, drawCount, instanceCount);
  15308. } else {
  15309. renderer.render(drawStart, drawCount);
  15310. }
  15311. }; // Compile
  15312. this.compile = function (scene, camera) {
  15313. currentRenderState = renderStates.get(scene);
  15314. currentRenderState.init();
  15315. scene.traverseVisible(function (object) {
  15316. if (object.isLight && object.layers.test(camera.layers)) {
  15317. currentRenderState.pushLight(object);
  15318. if (object.castShadow) {
  15319. currentRenderState.pushShadow(object);
  15320. }
  15321. }
  15322. });
  15323. currentRenderState.setupLights();
  15324. var compiled = new WeakMap();
  15325. scene.traverse(function (object) {
  15326. var material = object.material;
  15327. if (material) {
  15328. if (Array.isArray(material)) {
  15329. for (var i = 0; i < material.length; i++) {
  15330. var material2 = material[i];
  15331. if (compiled.has(material2) === false) {
  15332. initMaterial(material2, scene, object);
  15333. compiled.set(material2);
  15334. }
  15335. }
  15336. } else if (compiled.has(material) === false) {
  15337. initMaterial(material, scene, object);
  15338. compiled.set(material);
  15339. }
  15340. }
  15341. });
  15342. }; // Animation Loop
  15343. var onAnimationFrameCallback = null;
  15344. function onAnimationFrame(time) {
  15345. if (xr.isPresenting) return;
  15346. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  15347. }
  15348. var animation = new WebGLAnimation();
  15349. animation.setAnimationLoop(onAnimationFrame);
  15350. if (typeof window !== 'undefined') animation.setContext(window);
  15351. this.setAnimationLoop = function (callback) {
  15352. onAnimationFrameCallback = callback;
  15353. xr.setAnimationLoop(callback);
  15354. callback === null ? animation.stop() : animation.start();
  15355. }; // Rendering
  15356. this.render = function (scene, camera) {
  15357. var renderTarget, forceClear;
  15358. if (arguments[2] !== undefined) {
  15359. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  15360. renderTarget = arguments[2];
  15361. }
  15362. if (arguments[3] !== undefined) {
  15363. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  15364. forceClear = arguments[3];
  15365. }
  15366. if (camera !== undefined && camera.isCamera !== true) {
  15367. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  15368. return;
  15369. }
  15370. if (_isContextLost === true) return; // reset caching for this frame
  15371. bindingStates.resetDefaultState();
  15372. _currentMaterialId = -1;
  15373. _currentCamera = null; // update scene graph
  15374. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  15375. if (camera.parent === null) camera.updateMatrixWorld();
  15376. if (xr.enabled === true && xr.isPresenting === true) {
  15377. camera = xr.getCamera(camera);
  15378. } //
  15379. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  15380. currentRenderState = renderStates.get(scene, renderStateStack.length);
  15381. currentRenderState.init();
  15382. renderStateStack.push(currentRenderState);
  15383. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  15384. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  15385. _localClippingEnabled = this.localClippingEnabled;
  15386. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  15387. currentRenderList = renderLists.get(scene, camera);
  15388. currentRenderList.init();
  15389. projectObject(scene, camera, 0, _this.sortObjects);
  15390. currentRenderList.finish();
  15391. if (_this.sortObjects === true) {
  15392. currentRenderList.sort(_opaqueSort, _transparentSort);
  15393. } //
  15394. if (_clippingEnabled === true) clipping.beginShadows();
  15395. var shadowsArray = currentRenderState.state.shadowsArray;
  15396. shadowMap.render(shadowsArray, scene, camera);
  15397. currentRenderState.setupLights();
  15398. currentRenderState.setupLightsView(camera);
  15399. if (_clippingEnabled === true) clipping.endShadows(); //
  15400. if (this.info.autoReset === true) this.info.reset();
  15401. if (renderTarget !== undefined) {
  15402. this.setRenderTarget(renderTarget);
  15403. } //
  15404. background.render(currentRenderList, scene, camera, forceClear); // render scene
  15405. var opaqueObjects = currentRenderList.opaque;
  15406. var transparentObjects = currentRenderList.transparent;
  15407. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  15408. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  15409. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  15410. if (_currentRenderTarget !== null) {
  15411. // Generate mipmap if we're using any kind of mipmap filtering
  15412. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  15413. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  15414. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  15415. state.buffers.depth.setTest(true);
  15416. state.buffers.depth.setMask(true);
  15417. state.buffers.color.setMask(true);
  15418. state.setPolygonOffset(false); // _gl.finish();
  15419. renderStateStack.pop();
  15420. if (renderStateStack.length > 0) {
  15421. currentRenderState = renderStateStack[renderStateStack.length - 1];
  15422. } else {
  15423. currentRenderState = null;
  15424. }
  15425. currentRenderList = null;
  15426. };
  15427. function projectObject(object, camera, groupOrder, sortObjects) {
  15428. if (object.visible === false) return;
  15429. var visible = object.layers.test(camera.layers);
  15430. if (visible) {
  15431. if (object.isGroup) {
  15432. groupOrder = object.renderOrder;
  15433. } else if (object.isLOD) {
  15434. if (object.autoUpdate === true) object.update(camera);
  15435. } else if (object.isLight) {
  15436. currentRenderState.pushLight(object);
  15437. if (object.castShadow) {
  15438. currentRenderState.pushShadow(object);
  15439. }
  15440. } else if (object.isSprite) {
  15441. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  15442. if (sortObjects) {
  15443. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15444. }
  15445. var geometry = objects.update(object);
  15446. var material = object.material;
  15447. if (material.visible) {
  15448. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  15449. }
  15450. }
  15451. } else if (object.isImmediateRenderObject) {
  15452. if (sortObjects) {
  15453. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15454. }
  15455. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  15456. } else if (object.isMesh || object.isLine || object.isPoints) {
  15457. if (object.isSkinnedMesh) {
  15458. // update skeleton only once in a frame
  15459. if (object.skeleton.frame !== info.render.frame) {
  15460. object.skeleton.update();
  15461. object.skeleton.frame = info.render.frame;
  15462. }
  15463. }
  15464. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  15465. if (sortObjects) {
  15466. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15467. }
  15468. var _geometry = objects.update(object);
  15469. var _material = object.material;
  15470. if (Array.isArray(_material)) {
  15471. var groups = _geometry.groups;
  15472. for (var i = 0, l = groups.length; i < l; i++) {
  15473. var group = groups[i];
  15474. var groupMaterial = _material[group.materialIndex];
  15475. if (groupMaterial && groupMaterial.visible) {
  15476. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  15477. }
  15478. }
  15479. } else if (_material.visible) {
  15480. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  15481. }
  15482. }
  15483. }
  15484. }
  15485. var children = object.children;
  15486. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  15487. projectObject(children[_i], camera, groupOrder, sortObjects);
  15488. }
  15489. }
  15490. function renderObjects(renderList, scene, camera) {
  15491. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  15492. for (var i = 0, l = renderList.length; i < l; i++) {
  15493. var renderItem = renderList[i];
  15494. var object = renderItem.object;
  15495. var geometry = renderItem.geometry;
  15496. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  15497. var group = renderItem.group;
  15498. if (camera.isArrayCamera) {
  15499. var cameras = camera.cameras;
  15500. for (var j = 0, jl = cameras.length; j < jl; j++) {
  15501. var camera2 = cameras[j];
  15502. if (object.layers.test(camera2.layers)) {
  15503. state.viewport(_currentViewport.copy(camera2.viewport));
  15504. currentRenderState.setupLightsView(camera2);
  15505. renderObject(object, scene, camera2, geometry, material, group);
  15506. }
  15507. }
  15508. } else {
  15509. renderObject(object, scene, camera, geometry, material, group);
  15510. }
  15511. }
  15512. }
  15513. function renderObject(object, scene, camera, geometry, material, group) {
  15514. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  15515. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  15516. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  15517. if (object.isImmediateRenderObject) {
  15518. var program = setProgram(camera, scene, material, object);
  15519. state.setMaterial(material);
  15520. bindingStates.reset();
  15521. renderObjectImmediate(object, program);
  15522. } else {
  15523. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  15524. }
  15525. object.onAfterRender(_this, scene, camera, geometry, material, group);
  15526. }
  15527. function initMaterial(material, scene, object) {
  15528. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15529. var materialProperties = properties.get(material);
  15530. var lights = currentRenderState.state.lights;
  15531. var shadowsArray = currentRenderState.state.shadowsArray;
  15532. var lightsStateVersion = lights.state.version;
  15533. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  15534. var programCacheKey = programCache.getProgramCacheKey(parameters);
  15535. var program = materialProperties.program;
  15536. var programChange = true; // always update environment and fog - changing these trigger an initMaterial call, but it's possible that the program doesn't change
  15537. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  15538. materialProperties.fog = scene.fog;
  15539. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment);
  15540. if (program === undefined) {
  15541. // new material
  15542. material.addEventListener('dispose', onMaterialDispose);
  15543. } else if (program.cacheKey !== programCacheKey) {
  15544. // changed glsl or parameters
  15545. releaseMaterialProgramReference(material);
  15546. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  15547. programChange = false;
  15548. } else if (parameters.shaderID !== undefined) {
  15549. // same glsl and uniform list
  15550. return;
  15551. } else {
  15552. // only rebuild uniform list
  15553. programChange = false;
  15554. }
  15555. if (programChange) {
  15556. parameters.uniforms = programCache.getUniforms(material);
  15557. material.onBeforeCompile(parameters, _this);
  15558. program = programCache.acquireProgram(parameters, programCacheKey);
  15559. materialProperties.program = program;
  15560. materialProperties.uniforms = parameters.uniforms;
  15561. materialProperties.outputEncoding = parameters.outputEncoding;
  15562. }
  15563. var uniforms = materialProperties.uniforms;
  15564. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  15565. materialProperties.numClippingPlanes = clipping.numPlanes;
  15566. materialProperties.numIntersection = clipping.numIntersection;
  15567. uniforms.clippingPlanes = clipping.uniform;
  15568. } // store the light setup it was created for
  15569. materialProperties.needsLights = materialNeedsLights(material);
  15570. materialProperties.lightsStateVersion = lightsStateVersion;
  15571. if (materialProperties.needsLights) {
  15572. // wire up the material to this renderer's lighting state
  15573. uniforms.ambientLightColor.value = lights.state.ambient;
  15574. uniforms.lightProbe.value = lights.state.probe;
  15575. uniforms.directionalLights.value = lights.state.directional;
  15576. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  15577. uniforms.spotLights.value = lights.state.spot;
  15578. uniforms.spotLightShadows.value = lights.state.spotShadow;
  15579. uniforms.rectAreaLights.value = lights.state.rectArea;
  15580. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  15581. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  15582. uniforms.pointLights.value = lights.state.point;
  15583. uniforms.pointLightShadows.value = lights.state.pointShadow;
  15584. uniforms.hemisphereLights.value = lights.state.hemi;
  15585. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  15586. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  15587. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  15588. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  15589. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  15590. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  15591. }
  15592. var progUniforms = materialProperties.program.getUniforms();
  15593. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  15594. materialProperties.uniformsList = uniformsList;
  15595. }
  15596. function setProgram(camera, scene, material, object) {
  15597. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15598. textures.resetTextureUnits();
  15599. var fog = scene.fog;
  15600. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  15601. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  15602. var envMap = cubemaps.get(material.envMap || environment);
  15603. var materialProperties = properties.get(material);
  15604. var lights = currentRenderState.state.lights;
  15605. if (_clippingEnabled === true) {
  15606. if (_localClippingEnabled === true || camera !== _currentCamera) {
  15607. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  15608. // object instead of the material, once it becomes feasible
  15609. // (#8465, #8379)
  15610. clipping.setState(material, camera, useCache);
  15611. }
  15612. }
  15613. if (material.version === materialProperties.__version) {
  15614. if (material.fog && materialProperties.fog !== fog) {
  15615. initMaterial(material, scene, object);
  15616. } else if (materialProperties.environment !== environment) {
  15617. initMaterial(material, scene, object);
  15618. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  15619. initMaterial(material, scene, object);
  15620. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  15621. initMaterial(material, scene, object);
  15622. } else if (materialProperties.outputEncoding !== encoding) {
  15623. initMaterial(material, scene, object);
  15624. } else if (materialProperties.envMap !== envMap) {
  15625. initMaterial(material, scene, object);
  15626. }
  15627. } else {
  15628. initMaterial(material, scene, object);
  15629. materialProperties.__version = material.version;
  15630. }
  15631. var refreshProgram = false;
  15632. var refreshMaterial = false;
  15633. var refreshLights = false;
  15634. var program = materialProperties.program,
  15635. p_uniforms = program.getUniforms(),
  15636. m_uniforms = materialProperties.uniforms;
  15637. if (state.useProgram(program.program)) {
  15638. refreshProgram = true;
  15639. refreshMaterial = true;
  15640. refreshLights = true;
  15641. }
  15642. if (material.id !== _currentMaterialId) {
  15643. _currentMaterialId = material.id;
  15644. refreshMaterial = true;
  15645. }
  15646. if (refreshProgram || _currentCamera !== camera) {
  15647. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  15648. if (capabilities.logarithmicDepthBuffer) {
  15649. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  15650. }
  15651. if (_currentCamera !== camera) {
  15652. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  15653. // now, in case this material supports lights - or later, when
  15654. // the next material that does gets activated:
  15655. refreshMaterial = true; // set to true on material change
  15656. refreshLights = true; // remains set until update done
  15657. } // load material specific uniforms
  15658. // (shader material also gets them for the sake of genericity)
  15659. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  15660. var uCamPos = p_uniforms.map.cameraPosition;
  15661. if (uCamPos !== undefined) {
  15662. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  15663. }
  15664. }
  15665. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  15666. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  15667. }
  15668. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  15669. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  15670. }
  15671. } // skinning uniforms must be set even if material didn't change
  15672. // auto-setting of texture unit for bone texture must go before other textures
  15673. // otherwise textures used for skinning can take over texture units reserved for other material textures
  15674. if (material.skinning) {
  15675. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  15676. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  15677. var skeleton = object.skeleton;
  15678. if (skeleton) {
  15679. var bones = skeleton.bones;
  15680. if (capabilities.floatVertexTextures) {
  15681. if (skeleton.boneTexture === null) {
  15682. // layout (1 matrix = 4 pixels)
  15683. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15684. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15685. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15686. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15687. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15688. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  15689. size = MathUtils.ceilPowerOfTwo(size);
  15690. size = Math.max(size, 4);
  15691. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  15692. boneMatrices.set(skeleton.boneMatrices); // copy current values
  15693. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  15694. skeleton.boneMatrices = boneMatrices;
  15695. skeleton.boneTexture = boneTexture;
  15696. skeleton.boneTextureSize = size;
  15697. }
  15698. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  15699. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  15700. } else {
  15701. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  15702. }
  15703. }
  15704. }
  15705. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  15706. materialProperties.receiveShadow = object.receiveShadow;
  15707. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  15708. }
  15709. if (refreshMaterial) {
  15710. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  15711. if (materialProperties.needsLights) {
  15712. // the current material requires lighting info
  15713. // note: all lighting uniforms are always set correctly
  15714. // they simply reference the renderer's state for their
  15715. // values
  15716. //
  15717. // use the current material's .needsUpdate flags to set
  15718. // the GL state when required
  15719. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  15720. } // refresh uniforms common to several materials
  15721. if (fog && material.fog) {
  15722. materials.refreshFogUniforms(m_uniforms, fog);
  15723. }
  15724. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  15725. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15726. }
  15727. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  15728. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15729. material.uniformsNeedUpdate = false;
  15730. }
  15731. if (material.isSpriteMaterial) {
  15732. p_uniforms.setValue(_gl, 'center', object.center);
  15733. } // common matrices
  15734. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  15735. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  15736. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  15737. return program;
  15738. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15739. function markUniformsLightsNeedsUpdate(uniforms, value) {
  15740. uniforms.ambientLightColor.needsUpdate = value;
  15741. uniforms.lightProbe.needsUpdate = value;
  15742. uniforms.directionalLights.needsUpdate = value;
  15743. uniforms.directionalLightShadows.needsUpdate = value;
  15744. uniforms.pointLights.needsUpdate = value;
  15745. uniforms.pointLightShadows.needsUpdate = value;
  15746. uniforms.spotLights.needsUpdate = value;
  15747. uniforms.spotLightShadows.needsUpdate = value;
  15748. uniforms.rectAreaLights.needsUpdate = value;
  15749. uniforms.hemisphereLights.needsUpdate = value;
  15750. }
  15751. function materialNeedsLights(material) {
  15752. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  15753. } //
  15754. this.setFramebuffer = function (value) {
  15755. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  15756. _framebuffer = value;
  15757. };
  15758. this.getActiveCubeFace = function () {
  15759. return _currentActiveCubeFace;
  15760. };
  15761. this.getActiveMipmapLevel = function () {
  15762. return _currentActiveMipmapLevel;
  15763. };
  15764. this.getRenderList = function () {
  15765. return currentRenderList;
  15766. };
  15767. this.setRenderList = function (renderList) {
  15768. currentRenderList = renderList;
  15769. };
  15770. this.getRenderTarget = function () {
  15771. return _currentRenderTarget;
  15772. };
  15773. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  15774. if (activeCubeFace === void 0) {
  15775. activeCubeFace = 0;
  15776. }
  15777. if (activeMipmapLevel === void 0) {
  15778. activeMipmapLevel = 0;
  15779. }
  15780. _currentRenderTarget = renderTarget;
  15781. _currentActiveCubeFace = activeCubeFace;
  15782. _currentActiveMipmapLevel = activeMipmapLevel;
  15783. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  15784. textures.setupRenderTarget(renderTarget);
  15785. }
  15786. var framebuffer = _framebuffer;
  15787. var isCube = false;
  15788. if (renderTarget) {
  15789. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  15790. if (renderTarget.isWebGLCubeRenderTarget) {
  15791. framebuffer = __webglFramebuffer[activeCubeFace];
  15792. isCube = true;
  15793. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  15794. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  15795. } else {
  15796. framebuffer = __webglFramebuffer;
  15797. }
  15798. _currentViewport.copy(renderTarget.viewport);
  15799. _currentScissor.copy(renderTarget.scissor);
  15800. _currentScissorTest = renderTarget.scissorTest;
  15801. } else {
  15802. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  15803. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  15804. _currentScissorTest = _scissorTest;
  15805. }
  15806. if (_currentFramebuffer !== framebuffer) {
  15807. _gl.bindFramebuffer(36160, framebuffer);
  15808. _currentFramebuffer = framebuffer;
  15809. }
  15810. state.viewport(_currentViewport);
  15811. state.scissor(_currentScissor);
  15812. state.setScissorTest(_currentScissorTest);
  15813. if (isCube) {
  15814. var textureProperties = properties.get(renderTarget.texture);
  15815. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  15816. }
  15817. };
  15818. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15819. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15820. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15821. return;
  15822. }
  15823. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15824. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15825. framebuffer = framebuffer[activeCubeFaceIndex];
  15826. }
  15827. if (framebuffer) {
  15828. var restore = false;
  15829. if (framebuffer !== _currentFramebuffer) {
  15830. _gl.bindFramebuffer(36160, framebuffer);
  15831. restore = true;
  15832. }
  15833. try {
  15834. var texture = renderTarget.texture;
  15835. var textureFormat = texture.format;
  15836. var textureType = texture.type;
  15837. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15838. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15839. return;
  15840. }
  15841. var halfFloatSupportedByExt = textureType === HalfFloatType && (extensions.has('EXT_color_buffer_half_float') || capabilities.isWebGL2 && extensions.has('EXT_color_buffer_float'));
  15842. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15843. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.has('OES_texture_float') || extensions.has('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15844. !halfFloatSupportedByExt) {
  15845. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15846. return;
  15847. }
  15848. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15849. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15850. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15851. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15852. }
  15853. } else {
  15854. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15855. }
  15856. } finally {
  15857. if (restore) {
  15858. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15859. }
  15860. }
  15861. }
  15862. };
  15863. this.copyFramebufferToTexture = function (position, texture, level) {
  15864. if (level === void 0) {
  15865. level = 0;
  15866. }
  15867. var levelScale = Math.pow(2, -level);
  15868. var width = Math.floor(texture.image.width * levelScale);
  15869. var height = Math.floor(texture.image.height * levelScale);
  15870. var glFormat = utils.convert(texture.format);
  15871. textures.setTexture2D(texture, 0);
  15872. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15873. state.unbindTexture();
  15874. };
  15875. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15876. if (level === void 0) {
  15877. level = 0;
  15878. }
  15879. var width = srcTexture.image.width;
  15880. var height = srcTexture.image.height;
  15881. var glFormat = utils.convert(dstTexture.format);
  15882. var glType = utils.convert(dstTexture.type);
  15883. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  15884. // parameters, make sure they are correct for the dstTexture
  15885. _gl.pixelStorei(37440, dstTexture.flipY);
  15886. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  15887. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  15888. if (srcTexture.isDataTexture) {
  15889. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  15890. } else {
  15891. if (srcTexture.isCompressedTexture) {
  15892. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  15893. } else {
  15894. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  15895. }
  15896. } // Generate mipmaps only when copying level 0
  15897. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  15898. state.unbindTexture();
  15899. };
  15900. this.initTexture = function (texture) {
  15901. textures.setTexture2D(texture, 0);
  15902. state.unbindTexture();
  15903. };
  15904. this.resetState = function () {
  15905. state.reset();
  15906. bindingStates.reset();
  15907. };
  15908. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15909. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15910. detail: this
  15911. })); // eslint-disable-line no-undef
  15912. }
  15913. }
  15914. function WebGL1Renderer(parameters) {
  15915. WebGLRenderer.call(this, parameters);
  15916. }
  15917. WebGL1Renderer.prototype = Object.assign(Object.create(WebGLRenderer.prototype), {
  15918. constructor: WebGL1Renderer,
  15919. isWebGL1Renderer: true
  15920. });
  15921. var FogExp2 = /*#__PURE__*/function () {
  15922. function FogExp2(color, density) {
  15923. Object.defineProperty(this, 'isFogExp2', {
  15924. value: true
  15925. });
  15926. this.name = '';
  15927. this.color = new Color(color);
  15928. this.density = density !== undefined ? density : 0.00025;
  15929. }
  15930. var _proto = FogExp2.prototype;
  15931. _proto.clone = function clone() {
  15932. return new FogExp2(this.color, this.density);
  15933. };
  15934. _proto.toJSON = function toJSON()
  15935. /* meta */
  15936. {
  15937. return {
  15938. type: 'FogExp2',
  15939. color: this.color.getHex(),
  15940. density: this.density
  15941. };
  15942. };
  15943. return FogExp2;
  15944. }();
  15945. var Fog = /*#__PURE__*/function () {
  15946. function Fog(color, near, far) {
  15947. Object.defineProperty(this, 'isFog', {
  15948. value: true
  15949. });
  15950. this.name = '';
  15951. this.color = new Color(color);
  15952. this.near = near !== undefined ? near : 1;
  15953. this.far = far !== undefined ? far : 1000;
  15954. }
  15955. var _proto = Fog.prototype;
  15956. _proto.clone = function clone() {
  15957. return new Fog(this.color, this.near, this.far);
  15958. };
  15959. _proto.toJSON = function toJSON()
  15960. /* meta */
  15961. {
  15962. return {
  15963. type: 'Fog',
  15964. color: this.color.getHex(),
  15965. near: this.near,
  15966. far: this.far
  15967. };
  15968. };
  15969. return Fog;
  15970. }();
  15971. var Scene = /*#__PURE__*/function (_Object3D) {
  15972. _inheritsLoose(Scene, _Object3D);
  15973. function Scene() {
  15974. var _this;
  15975. _this = _Object3D.call(this) || this;
  15976. Object.defineProperty(_assertThisInitialized(_this), 'isScene', {
  15977. value: true
  15978. });
  15979. _this.type = 'Scene';
  15980. _this.background = null;
  15981. _this.environment = null;
  15982. _this.fog = null;
  15983. _this.overrideMaterial = null;
  15984. _this.autoUpdate = true; // checked by the renderer
  15985. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15986. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15987. detail: _assertThisInitialized(_this)
  15988. })); // eslint-disable-line no-undef
  15989. }
  15990. return _this;
  15991. }
  15992. var _proto = Scene.prototype;
  15993. _proto.copy = function copy(source, recursive) {
  15994. _Object3D.prototype.copy.call(this, source, recursive);
  15995. if (source.background !== null) this.background = source.background.clone();
  15996. if (source.environment !== null) this.environment = source.environment.clone();
  15997. if (source.fog !== null) this.fog = source.fog.clone();
  15998. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  15999. this.autoUpdate = source.autoUpdate;
  16000. this.matrixAutoUpdate = source.matrixAutoUpdate;
  16001. return this;
  16002. };
  16003. _proto.toJSON = function toJSON(meta) {
  16004. var data = _Object3D.prototype.toJSON.call(this, meta);
  16005. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  16006. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  16007. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  16008. return data;
  16009. };
  16010. return Scene;
  16011. }(Object3D);
  16012. function InterleavedBuffer(array, stride) {
  16013. this.array = array;
  16014. this.stride = stride;
  16015. this.count = array !== undefined ? array.length / stride : 0;
  16016. this.usage = StaticDrawUsage;
  16017. this.updateRange = {
  16018. offset: 0,
  16019. count: -1
  16020. };
  16021. this.version = 0;
  16022. this.uuid = MathUtils.generateUUID();
  16023. }
  16024. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  16025. set: function set(value) {
  16026. if (value === true) this.version++;
  16027. }
  16028. });
  16029. Object.assign(InterleavedBuffer.prototype, {
  16030. isInterleavedBuffer: true,
  16031. onUploadCallback: function onUploadCallback() {},
  16032. setUsage: function setUsage(value) {
  16033. this.usage = value;
  16034. return this;
  16035. },
  16036. copy: function copy(source) {
  16037. this.array = new source.array.constructor(source.array);
  16038. this.count = source.count;
  16039. this.stride = source.stride;
  16040. this.usage = source.usage;
  16041. return this;
  16042. },
  16043. copyAt: function copyAt(index1, attribute, index2) {
  16044. index1 *= this.stride;
  16045. index2 *= attribute.stride;
  16046. for (var i = 0, l = this.stride; i < l; i++) {
  16047. this.array[index1 + i] = attribute.array[index2 + i];
  16048. }
  16049. return this;
  16050. },
  16051. set: function set(value, offset) {
  16052. if (offset === void 0) {
  16053. offset = 0;
  16054. }
  16055. this.array.set(value, offset);
  16056. return this;
  16057. },
  16058. clone: function clone(data) {
  16059. if (data.arrayBuffers === undefined) {
  16060. data.arrayBuffers = {};
  16061. }
  16062. if (this.array.buffer._uuid === undefined) {
  16063. this.array.buffer._uuid = MathUtils.generateUUID();
  16064. }
  16065. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  16066. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  16067. }
  16068. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  16069. var ib = new InterleavedBuffer(array, this.stride);
  16070. ib.setUsage(this.usage);
  16071. return ib;
  16072. },
  16073. onUpload: function onUpload(callback) {
  16074. this.onUploadCallback = callback;
  16075. return this;
  16076. },
  16077. toJSON: function toJSON(data) {
  16078. if (data.arrayBuffers === undefined) {
  16079. data.arrayBuffers = {};
  16080. } // generate UUID for array buffer if necessary
  16081. if (this.array.buffer._uuid === undefined) {
  16082. this.array.buffer._uuid = MathUtils.generateUUID();
  16083. }
  16084. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  16085. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  16086. } //
  16087. return {
  16088. uuid: this.uuid,
  16089. buffer: this.array.buffer._uuid,
  16090. type: this.array.constructor.name,
  16091. stride: this.stride
  16092. };
  16093. }
  16094. });
  16095. var _vector$6 = new Vector3();
  16096. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  16097. this.name = '';
  16098. this.data = interleavedBuffer;
  16099. this.itemSize = itemSize;
  16100. this.offset = offset;
  16101. this.normalized = normalized === true;
  16102. }
  16103. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  16104. count: {
  16105. get: function get() {
  16106. return this.data.count;
  16107. }
  16108. },
  16109. array: {
  16110. get: function get() {
  16111. return this.data.array;
  16112. }
  16113. },
  16114. needsUpdate: {
  16115. set: function set(value) {
  16116. this.data.needsUpdate = value;
  16117. }
  16118. }
  16119. });
  16120. Object.assign(InterleavedBufferAttribute.prototype, {
  16121. isInterleavedBufferAttribute: true,
  16122. applyMatrix4: function applyMatrix4(m) {
  16123. for (var i = 0, l = this.data.count; i < l; i++) {
  16124. _vector$6.x = this.getX(i);
  16125. _vector$6.y = this.getY(i);
  16126. _vector$6.z = this.getZ(i);
  16127. _vector$6.applyMatrix4(m);
  16128. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  16129. }
  16130. return this;
  16131. },
  16132. setX: function setX(index, x) {
  16133. this.data.array[index * this.data.stride + this.offset] = x;
  16134. return this;
  16135. },
  16136. setY: function setY(index, y) {
  16137. this.data.array[index * this.data.stride + this.offset + 1] = y;
  16138. return this;
  16139. },
  16140. setZ: function setZ(index, z) {
  16141. this.data.array[index * this.data.stride + this.offset + 2] = z;
  16142. return this;
  16143. },
  16144. setW: function setW(index, w) {
  16145. this.data.array[index * this.data.stride + this.offset + 3] = w;
  16146. return this;
  16147. },
  16148. getX: function getX(index) {
  16149. return this.data.array[index * this.data.stride + this.offset];
  16150. },
  16151. getY: function getY(index) {
  16152. return this.data.array[index * this.data.stride + this.offset + 1];
  16153. },
  16154. getZ: function getZ(index) {
  16155. return this.data.array[index * this.data.stride + this.offset + 2];
  16156. },
  16157. getW: function getW(index) {
  16158. return this.data.array[index * this.data.stride + this.offset + 3];
  16159. },
  16160. setXY: function setXY(index, x, y) {
  16161. index = index * this.data.stride + this.offset;
  16162. this.data.array[index + 0] = x;
  16163. this.data.array[index + 1] = y;
  16164. return this;
  16165. },
  16166. setXYZ: function setXYZ(index, x, y, z) {
  16167. index = index * this.data.stride + this.offset;
  16168. this.data.array[index + 0] = x;
  16169. this.data.array[index + 1] = y;
  16170. this.data.array[index + 2] = z;
  16171. return this;
  16172. },
  16173. setXYZW: function setXYZW(index, x, y, z, w) {
  16174. index = index * this.data.stride + this.offset;
  16175. this.data.array[index + 0] = x;
  16176. this.data.array[index + 1] = y;
  16177. this.data.array[index + 2] = z;
  16178. this.data.array[index + 3] = w;
  16179. return this;
  16180. },
  16181. clone: function clone(data) {
  16182. if (data === undefined) {
  16183. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  16184. var array = [];
  16185. for (var i = 0; i < this.count; i++) {
  16186. var index = i * this.data.stride + this.offset;
  16187. for (var j = 0; j < this.itemSize; j++) {
  16188. array.push(this.data.array[index + j]);
  16189. }
  16190. }
  16191. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  16192. } else {
  16193. if (data.interleavedBuffers === undefined) {
  16194. data.interleavedBuffers = {};
  16195. }
  16196. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  16197. data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
  16198. }
  16199. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  16200. }
  16201. },
  16202. toJSON: function toJSON(data) {
  16203. if (data === undefined) {
  16204. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  16205. var array = [];
  16206. for (var i = 0; i < this.count; i++) {
  16207. var index = i * this.data.stride + this.offset;
  16208. for (var j = 0; j < this.itemSize; j++) {
  16209. array.push(this.data.array[index + j]);
  16210. }
  16211. } // deinterleave data and save it as an ordinary buffer attribute for now
  16212. return {
  16213. itemSize: this.itemSize,
  16214. type: this.array.constructor.name,
  16215. array: array,
  16216. normalized: this.normalized
  16217. };
  16218. } else {
  16219. // save as true interlaved attribtue
  16220. if (data.interleavedBuffers === undefined) {
  16221. data.interleavedBuffers = {};
  16222. }
  16223. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  16224. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  16225. }
  16226. return {
  16227. isInterleavedBufferAttribute: true,
  16228. itemSize: this.itemSize,
  16229. data: this.data.uuid,
  16230. offset: this.offset,
  16231. normalized: this.normalized
  16232. };
  16233. }
  16234. }
  16235. });
  16236. /**
  16237. * parameters = {
  16238. * color: <hex>,
  16239. * map: new THREE.Texture( <Image> ),
  16240. * alphaMap: new THREE.Texture( <Image> ),
  16241. * rotation: <float>,
  16242. * sizeAttenuation: <bool>
  16243. * }
  16244. */
  16245. function SpriteMaterial(parameters) {
  16246. Material.call(this);
  16247. this.type = 'SpriteMaterial';
  16248. this.color = new Color(0xffffff);
  16249. this.map = null;
  16250. this.alphaMap = null;
  16251. this.rotation = 0;
  16252. this.sizeAttenuation = true;
  16253. this.transparent = true;
  16254. this.setValues(parameters);
  16255. }
  16256. SpriteMaterial.prototype = Object.create(Material.prototype);
  16257. SpriteMaterial.prototype.constructor = SpriteMaterial;
  16258. SpriteMaterial.prototype.isSpriteMaterial = true;
  16259. SpriteMaterial.prototype.copy = function (source) {
  16260. Material.prototype.copy.call(this, source);
  16261. this.color.copy(source.color);
  16262. this.map = source.map;
  16263. this.alphaMap = source.alphaMap;
  16264. this.rotation = source.rotation;
  16265. this.sizeAttenuation = source.sizeAttenuation;
  16266. return this;
  16267. };
  16268. var _geometry;
  16269. var _intersectPoint = new Vector3();
  16270. var _worldScale = new Vector3();
  16271. var _mvPosition = new Vector3();
  16272. var _alignedPosition = new Vector2();
  16273. var _rotatedPosition = new Vector2();
  16274. var _viewWorldMatrix = new Matrix4();
  16275. var _vA$1 = new Vector3();
  16276. var _vB$1 = new Vector3();
  16277. var _vC$1 = new Vector3();
  16278. var _uvA$1 = new Vector2();
  16279. var _uvB$1 = new Vector2();
  16280. var _uvC$1 = new Vector2();
  16281. function Sprite(material) {
  16282. Object3D.call(this);
  16283. this.type = 'Sprite';
  16284. if (_geometry === undefined) {
  16285. _geometry = new BufferGeometry();
  16286. 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]);
  16287. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  16288. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  16289. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  16290. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  16291. }
  16292. this.geometry = _geometry;
  16293. this.material = material !== undefined ? material : new SpriteMaterial();
  16294. this.center = new Vector2(0.5, 0.5);
  16295. }
  16296. Sprite.prototype = Object.assign(Object.create(Object3D.prototype), {
  16297. constructor: Sprite,
  16298. isSprite: true,
  16299. raycast: function raycast(raycaster, intersects) {
  16300. if (raycaster.camera === null) {
  16301. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  16302. }
  16303. _worldScale.setFromMatrixScale(this.matrixWorld);
  16304. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  16305. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  16306. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  16307. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  16308. _worldScale.multiplyScalar(-_mvPosition.z);
  16309. }
  16310. var rotation = this.material.rotation;
  16311. var sin, cos;
  16312. if (rotation !== 0) {
  16313. cos = Math.cos(rotation);
  16314. sin = Math.sin(rotation);
  16315. }
  16316. var center = this.center;
  16317. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16318. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16319. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16320. _uvA$1.set(0, 0);
  16321. _uvB$1.set(1, 0);
  16322. _uvC$1.set(1, 1); // check first triangle
  16323. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  16324. if (intersect === null) {
  16325. // check second triangle
  16326. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16327. _uvB$1.set(0, 1);
  16328. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  16329. if (intersect === null) {
  16330. return;
  16331. }
  16332. }
  16333. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  16334. if (distance < raycaster.near || distance > raycaster.far) return;
  16335. intersects.push({
  16336. distance: distance,
  16337. point: _intersectPoint.clone(),
  16338. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  16339. face: null,
  16340. object: this
  16341. });
  16342. },
  16343. copy: function copy(source) {
  16344. Object3D.prototype.copy.call(this, source);
  16345. if (source.center !== undefined) this.center.copy(source.center);
  16346. this.material = source.material;
  16347. return this;
  16348. }
  16349. });
  16350. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  16351. // compute position in camera space
  16352. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  16353. if (sin !== undefined) {
  16354. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  16355. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  16356. } else {
  16357. _rotatedPosition.copy(_alignedPosition);
  16358. }
  16359. vertexPosition.copy(mvPosition);
  16360. vertexPosition.x += _rotatedPosition.x;
  16361. vertexPosition.y += _rotatedPosition.y; // transform to world space
  16362. vertexPosition.applyMatrix4(_viewWorldMatrix);
  16363. }
  16364. var _v1$4 = new Vector3();
  16365. var _v2$2 = new Vector3();
  16366. function LOD() {
  16367. Object3D.call(this);
  16368. this._currentLevel = 0;
  16369. this.type = 'LOD';
  16370. Object.defineProperties(this, {
  16371. levels: {
  16372. enumerable: true,
  16373. value: []
  16374. }
  16375. });
  16376. this.autoUpdate = true;
  16377. }
  16378. LOD.prototype = Object.assign(Object.create(Object3D.prototype), {
  16379. constructor: LOD,
  16380. isLOD: true,
  16381. copy: function copy(source) {
  16382. Object3D.prototype.copy.call(this, source, false);
  16383. var levels = source.levels;
  16384. for (var i = 0, l = levels.length; i < l; i++) {
  16385. var level = levels[i];
  16386. this.addLevel(level.object.clone(), level.distance);
  16387. }
  16388. this.autoUpdate = source.autoUpdate;
  16389. return this;
  16390. },
  16391. addLevel: function addLevel(object, distance) {
  16392. if (distance === void 0) {
  16393. distance = 0;
  16394. }
  16395. distance = Math.abs(distance);
  16396. var levels = this.levels;
  16397. var l;
  16398. for (l = 0; l < levels.length; l++) {
  16399. if (distance < levels[l].distance) {
  16400. break;
  16401. }
  16402. }
  16403. levels.splice(l, 0, {
  16404. distance: distance,
  16405. object: object
  16406. });
  16407. this.add(object);
  16408. return this;
  16409. },
  16410. getCurrentLevel: function getCurrentLevel() {
  16411. return this._currentLevel;
  16412. },
  16413. getObjectForDistance: function getObjectForDistance(distance) {
  16414. var levels = this.levels;
  16415. if (levels.length > 0) {
  16416. var i, l;
  16417. for (i = 1, l = levels.length; i < l; i++) {
  16418. if (distance < levels[i].distance) {
  16419. break;
  16420. }
  16421. }
  16422. return levels[i - 1].object;
  16423. }
  16424. return null;
  16425. },
  16426. raycast: function raycast(raycaster, intersects) {
  16427. var levels = this.levels;
  16428. if (levels.length > 0) {
  16429. _v1$4.setFromMatrixPosition(this.matrixWorld);
  16430. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  16431. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  16432. }
  16433. },
  16434. update: function update(camera) {
  16435. var levels = this.levels;
  16436. if (levels.length > 1) {
  16437. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  16438. _v2$2.setFromMatrixPosition(this.matrixWorld);
  16439. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  16440. levels[0].object.visible = true;
  16441. var i, l;
  16442. for (i = 1, l = levels.length; i < l; i++) {
  16443. if (distance >= levels[i].distance) {
  16444. levels[i - 1].object.visible = false;
  16445. levels[i].object.visible = true;
  16446. } else {
  16447. break;
  16448. }
  16449. }
  16450. this._currentLevel = i - 1;
  16451. for (; i < l; i++) {
  16452. levels[i].object.visible = false;
  16453. }
  16454. }
  16455. },
  16456. toJSON: function toJSON(meta) {
  16457. var data = Object3D.prototype.toJSON.call(this, meta);
  16458. if (this.autoUpdate === false) data.object.autoUpdate = false;
  16459. data.object.levels = [];
  16460. var levels = this.levels;
  16461. for (var i = 0, l = levels.length; i < l; i++) {
  16462. var level = levels[i];
  16463. data.object.levels.push({
  16464. object: level.object.uuid,
  16465. distance: level.distance
  16466. });
  16467. }
  16468. return data;
  16469. }
  16470. });
  16471. var _basePosition = new Vector3();
  16472. var _skinIndex = new Vector4();
  16473. var _skinWeight = new Vector4();
  16474. var _vector$7 = new Vector3();
  16475. var _matrix$1 = new Matrix4();
  16476. function SkinnedMesh(geometry, material) {
  16477. if (geometry && geometry.isGeometry) {
  16478. console.error('THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16479. }
  16480. Mesh.call(this, geometry, material);
  16481. this.type = 'SkinnedMesh';
  16482. this.bindMode = 'attached';
  16483. this.bindMatrix = new Matrix4();
  16484. this.bindMatrixInverse = new Matrix4();
  16485. }
  16486. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16487. constructor: SkinnedMesh,
  16488. isSkinnedMesh: true,
  16489. copy: function copy(source) {
  16490. Mesh.prototype.copy.call(this, source);
  16491. this.bindMode = source.bindMode;
  16492. this.bindMatrix.copy(source.bindMatrix);
  16493. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  16494. this.skeleton = source.skeleton;
  16495. return this;
  16496. },
  16497. bind: function bind(skeleton, bindMatrix) {
  16498. this.skeleton = skeleton;
  16499. if (bindMatrix === undefined) {
  16500. this.updateMatrixWorld(true);
  16501. this.skeleton.calculateInverses();
  16502. bindMatrix = this.matrixWorld;
  16503. }
  16504. this.bindMatrix.copy(bindMatrix);
  16505. this.bindMatrixInverse.copy(bindMatrix).invert();
  16506. },
  16507. pose: function pose() {
  16508. this.skeleton.pose();
  16509. },
  16510. normalizeSkinWeights: function normalizeSkinWeights() {
  16511. var vector = new Vector4();
  16512. var skinWeight = this.geometry.attributes.skinWeight;
  16513. for (var i = 0, l = skinWeight.count; i < l; i++) {
  16514. vector.x = skinWeight.getX(i);
  16515. vector.y = skinWeight.getY(i);
  16516. vector.z = skinWeight.getZ(i);
  16517. vector.w = skinWeight.getW(i);
  16518. var scale = 1.0 / vector.manhattanLength();
  16519. if (scale !== Infinity) {
  16520. vector.multiplyScalar(scale);
  16521. } else {
  16522. vector.set(1, 0, 0, 0); // do something reasonable
  16523. }
  16524. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  16525. }
  16526. },
  16527. updateMatrixWorld: function updateMatrixWorld(force) {
  16528. Mesh.prototype.updateMatrixWorld.call(this, force);
  16529. if (this.bindMode === 'attached') {
  16530. this.bindMatrixInverse.copy(this.matrixWorld).invert();
  16531. } else if (this.bindMode === 'detached') {
  16532. this.bindMatrixInverse.copy(this.bindMatrix).invert();
  16533. } else {
  16534. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  16535. }
  16536. },
  16537. boneTransform: function boneTransform(index, target) {
  16538. var skeleton = this.skeleton;
  16539. var geometry = this.geometry;
  16540. _skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  16541. _skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  16542. _basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  16543. target.set(0, 0, 0);
  16544. for (var i = 0; i < 4; i++) {
  16545. var weight = _skinWeight.getComponent(i);
  16546. if (weight !== 0) {
  16547. var boneIndex = _skinIndex.getComponent(i);
  16548. _matrix$1.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  16549. target.addScaledVector(_vector$7.copy(_basePosition).applyMatrix4(_matrix$1), weight);
  16550. }
  16551. }
  16552. return target.applyMatrix4(this.bindMatrixInverse);
  16553. }
  16554. });
  16555. function Bone() {
  16556. Object3D.call(this);
  16557. this.type = 'Bone';
  16558. }
  16559. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  16560. constructor: Bone,
  16561. isBone: true
  16562. });
  16563. var _offsetMatrix = new Matrix4();
  16564. var _identityMatrix = new Matrix4();
  16565. function Skeleton(bones, boneInverses) {
  16566. if (bones === void 0) {
  16567. bones = [];
  16568. }
  16569. if (boneInverses === void 0) {
  16570. boneInverses = [];
  16571. }
  16572. this.uuid = MathUtils.generateUUID();
  16573. this.bones = bones.slice(0);
  16574. this.boneInverses = boneInverses;
  16575. this.boneMatrices = null;
  16576. this.boneTexture = null;
  16577. this.boneTextureSize = 0;
  16578. this.frame = -1;
  16579. this.init();
  16580. }
  16581. Object.assign(Skeleton.prototype, {
  16582. init: function init() {
  16583. var bones = this.bones;
  16584. var boneInverses = this.boneInverses;
  16585. this.boneMatrices = new Float32Array(bones.length * 16); // calculate inverse bone matrices if necessary
  16586. if (boneInverses.length === 0) {
  16587. this.calculateInverses();
  16588. } else {
  16589. // handle special case
  16590. if (bones.length !== boneInverses.length) {
  16591. console.warn('THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.');
  16592. this.boneInverses = [];
  16593. for (var i = 0, il = this.bones.length; i < il; i++) {
  16594. this.boneInverses.push(new Matrix4());
  16595. }
  16596. }
  16597. }
  16598. },
  16599. calculateInverses: function calculateInverses() {
  16600. this.boneInverses.length = 0;
  16601. for (var i = 0, il = this.bones.length; i < il; i++) {
  16602. var inverse = new Matrix4();
  16603. if (this.bones[i]) {
  16604. inverse.copy(this.bones[i].matrixWorld).invert();
  16605. }
  16606. this.boneInverses.push(inverse);
  16607. }
  16608. },
  16609. pose: function pose() {
  16610. // recover the bind-time world matrices
  16611. for (var i = 0, il = this.bones.length; i < il; i++) {
  16612. var bone = this.bones[i];
  16613. if (bone) {
  16614. bone.matrixWorld.copy(this.boneInverses[i]).invert();
  16615. }
  16616. } // compute the local matrices, positions, rotations and scales
  16617. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  16618. var _bone = this.bones[_i];
  16619. if (_bone) {
  16620. if (_bone.parent && _bone.parent.isBone) {
  16621. _bone.matrix.copy(_bone.parent.matrixWorld).invert();
  16622. _bone.matrix.multiply(_bone.matrixWorld);
  16623. } else {
  16624. _bone.matrix.copy(_bone.matrixWorld);
  16625. }
  16626. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  16627. }
  16628. }
  16629. },
  16630. update: function update() {
  16631. var bones = this.bones;
  16632. var boneInverses = this.boneInverses;
  16633. var boneMatrices = this.boneMatrices;
  16634. var boneTexture = this.boneTexture; // flatten bone matrices to array
  16635. for (var i = 0, il = bones.length; i < il; i++) {
  16636. // compute the offset between the current and the original transform
  16637. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  16638. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  16639. _offsetMatrix.toArray(boneMatrices, i * 16);
  16640. }
  16641. if (boneTexture !== null) {
  16642. boneTexture.needsUpdate = true;
  16643. }
  16644. },
  16645. clone: function clone() {
  16646. return new Skeleton(this.bones, this.boneInverses);
  16647. },
  16648. getBoneByName: function getBoneByName(name) {
  16649. for (var i = 0, il = this.bones.length; i < il; i++) {
  16650. var bone = this.bones[i];
  16651. if (bone.name === name) {
  16652. return bone;
  16653. }
  16654. }
  16655. return undefined;
  16656. },
  16657. dispose: function dispose() {
  16658. if (this.boneTexture !== null) {
  16659. this.boneTexture.dispose();
  16660. this.boneTexture = null;
  16661. }
  16662. },
  16663. fromJSON: function fromJSON(json, bones) {
  16664. this.uuid = json.uuid;
  16665. for (var i = 0, l = json.bones.length; i < l; i++) {
  16666. var uuid = json.bones[i];
  16667. var bone = bones[uuid];
  16668. if (bone === undefined) {
  16669. console.warn('THREE.Skeleton: No bone found with UUID:', uuid);
  16670. bone = new Bone();
  16671. }
  16672. this.bones.push(bone);
  16673. this.boneInverses.push(new Matrix4().fromArray(json.boneInverses[i]));
  16674. }
  16675. this.init();
  16676. return this;
  16677. },
  16678. toJSON: function toJSON() {
  16679. var data = {
  16680. metadata: {
  16681. version: 4.5,
  16682. type: 'Skeleton',
  16683. generator: 'Skeleton.toJSON'
  16684. },
  16685. bones: [],
  16686. boneInverses: []
  16687. };
  16688. data.uuid = this.uuid;
  16689. var bones = this.bones;
  16690. var boneInverses = this.boneInverses;
  16691. for (var i = 0, l = bones.length; i < l; i++) {
  16692. var bone = bones[i];
  16693. data.bones.push(bone.uuid);
  16694. var boneInverse = boneInverses[i];
  16695. data.boneInverses.push(boneInverse.toArray());
  16696. }
  16697. return data;
  16698. }
  16699. });
  16700. var _instanceLocalMatrix = new Matrix4();
  16701. var _instanceWorldMatrix = new Matrix4();
  16702. var _instanceIntersects = [];
  16703. var _mesh = new Mesh();
  16704. function InstancedMesh(geometry, material, count) {
  16705. Mesh.call(this, geometry, material);
  16706. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  16707. this.instanceColor = null;
  16708. this.count = count;
  16709. this.frustumCulled = false;
  16710. }
  16711. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16712. constructor: InstancedMesh,
  16713. isInstancedMesh: true,
  16714. copy: function copy(source) {
  16715. Mesh.prototype.copy.call(this, source);
  16716. this.instanceMatrix.copy(source.instanceMatrix);
  16717. if (source.instanceColor !== null) this.instanceColor = source.instanceColor.clone();
  16718. this.count = source.count;
  16719. return this;
  16720. },
  16721. getColorAt: function getColorAt(index, color) {
  16722. color.fromArray(this.instanceColor.array, index * 3);
  16723. },
  16724. getMatrixAt: function getMatrixAt(index, matrix) {
  16725. matrix.fromArray(this.instanceMatrix.array, index * 16);
  16726. },
  16727. raycast: function raycast(raycaster, intersects) {
  16728. var matrixWorld = this.matrixWorld;
  16729. var raycastTimes = this.count;
  16730. _mesh.geometry = this.geometry;
  16731. _mesh.material = this.material;
  16732. if (_mesh.material === undefined) return;
  16733. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  16734. // calculate the world matrix for each instance
  16735. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  16736. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  16737. _mesh.matrixWorld = _instanceWorldMatrix;
  16738. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  16739. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  16740. var intersect = _instanceIntersects[i];
  16741. intersect.instanceId = instanceId;
  16742. intersect.object = this;
  16743. intersects.push(intersect);
  16744. }
  16745. _instanceIntersects.length = 0;
  16746. }
  16747. },
  16748. setColorAt: function setColorAt(index, color) {
  16749. if (this.instanceColor === null) {
  16750. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  16751. }
  16752. color.toArray(this.instanceColor.array, index * 3);
  16753. },
  16754. setMatrixAt: function setMatrixAt(index, matrix) {
  16755. matrix.toArray(this.instanceMatrix.array, index * 16);
  16756. },
  16757. updateMorphTargets: function updateMorphTargets() {},
  16758. dispose: function dispose() {
  16759. this.dispatchEvent({
  16760. type: 'dispose'
  16761. });
  16762. }
  16763. });
  16764. /**
  16765. * parameters = {
  16766. * color: <hex>,
  16767. * opacity: <float>,
  16768. *
  16769. * linewidth: <float>,
  16770. * linecap: "round",
  16771. * linejoin: "round"
  16772. * }
  16773. */
  16774. function LineBasicMaterial(parameters) {
  16775. Material.call(this);
  16776. this.type = 'LineBasicMaterial';
  16777. this.color = new Color(0xffffff);
  16778. this.linewidth = 1;
  16779. this.linecap = 'round';
  16780. this.linejoin = 'round';
  16781. this.morphTargets = false;
  16782. this.setValues(parameters);
  16783. }
  16784. LineBasicMaterial.prototype = Object.create(Material.prototype);
  16785. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  16786. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16787. LineBasicMaterial.prototype.copy = function (source) {
  16788. Material.prototype.copy.call(this, source);
  16789. this.color.copy(source.color);
  16790. this.linewidth = source.linewidth;
  16791. this.linecap = source.linecap;
  16792. this.linejoin = source.linejoin;
  16793. this.morphTargets = source.morphTargets;
  16794. return this;
  16795. };
  16796. var _start = new Vector3();
  16797. var _end = new Vector3();
  16798. var _inverseMatrix$1 = new Matrix4();
  16799. var _ray$1 = new Ray();
  16800. var _sphere$2 = new Sphere();
  16801. function Line(geometry, material) {
  16802. if (geometry === void 0) {
  16803. geometry = new BufferGeometry();
  16804. }
  16805. if (material === void 0) {
  16806. material = new LineBasicMaterial();
  16807. }
  16808. Object3D.call(this);
  16809. this.type = 'Line';
  16810. this.geometry = geometry;
  16811. this.material = material;
  16812. this.updateMorphTargets();
  16813. }
  16814. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  16815. constructor: Line,
  16816. isLine: true,
  16817. copy: function copy(source) {
  16818. Object3D.prototype.copy.call(this, source);
  16819. this.material = source.material;
  16820. this.geometry = source.geometry;
  16821. return this;
  16822. },
  16823. computeLineDistances: function computeLineDistances() {
  16824. var geometry = this.geometry;
  16825. if (geometry.isBufferGeometry) {
  16826. // we assume non-indexed geometry
  16827. if (geometry.index === null) {
  16828. var positionAttribute = geometry.attributes.position;
  16829. var lineDistances = [0];
  16830. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  16831. _start.fromBufferAttribute(positionAttribute, i - 1);
  16832. _end.fromBufferAttribute(positionAttribute, i);
  16833. lineDistances[i] = lineDistances[i - 1];
  16834. lineDistances[i] += _start.distanceTo(_end);
  16835. }
  16836. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16837. } else {
  16838. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16839. }
  16840. } else if (geometry.isGeometry) {
  16841. console.error('THREE.Line.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16842. }
  16843. return this;
  16844. },
  16845. raycast: function raycast(raycaster, intersects) {
  16846. var geometry = this.geometry;
  16847. var matrixWorld = this.matrixWorld;
  16848. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  16849. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16850. _sphere$2.copy(geometry.boundingSphere);
  16851. _sphere$2.applyMatrix4(matrixWorld);
  16852. _sphere$2.radius += threshold;
  16853. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  16854. _inverseMatrix$1.copy(matrixWorld).invert();
  16855. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  16856. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16857. var localThresholdSq = localThreshold * localThreshold;
  16858. var vStart = new Vector3();
  16859. var vEnd = new Vector3();
  16860. var interSegment = new Vector3();
  16861. var interRay = new Vector3();
  16862. var step = this.isLineSegments ? 2 : 1;
  16863. if (geometry.isBufferGeometry) {
  16864. var index = geometry.index;
  16865. var attributes = geometry.attributes;
  16866. var positionAttribute = attributes.position;
  16867. if (index !== null) {
  16868. var indices = index.array;
  16869. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  16870. var a = indices[i];
  16871. var b = indices[i + 1];
  16872. vStart.fromBufferAttribute(positionAttribute, a);
  16873. vEnd.fromBufferAttribute(positionAttribute, b);
  16874. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16875. if (distSq > localThresholdSq) continue;
  16876. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16877. var distance = raycaster.ray.origin.distanceTo(interRay);
  16878. if (distance < raycaster.near || distance > raycaster.far) continue;
  16879. intersects.push({
  16880. distance: distance,
  16881. // What do we want? intersection point on the ray or on the segment??
  16882. // point: raycaster.ray.at( distance ),
  16883. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16884. index: i,
  16885. face: null,
  16886. faceIndex: null,
  16887. object: this
  16888. });
  16889. }
  16890. } else {
  16891. for (var _i = 0, _l = positionAttribute.count - 1; _i < _l; _i += step) {
  16892. vStart.fromBufferAttribute(positionAttribute, _i);
  16893. vEnd.fromBufferAttribute(positionAttribute, _i + 1);
  16894. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16895. if (_distSq > localThresholdSq) continue;
  16896. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16897. var _distance = raycaster.ray.origin.distanceTo(interRay);
  16898. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  16899. intersects.push({
  16900. distance: _distance,
  16901. // What do we want? intersection point on the ray or on the segment??
  16902. // point: raycaster.ray.at( distance ),
  16903. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16904. index: _i,
  16905. face: null,
  16906. faceIndex: null,
  16907. object: this
  16908. });
  16909. }
  16910. }
  16911. } else if (geometry.isGeometry) {
  16912. console.error('THREE.Line.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16913. }
  16914. },
  16915. updateMorphTargets: function updateMorphTargets() {
  16916. var geometry = this.geometry;
  16917. if (geometry.isBufferGeometry) {
  16918. var morphAttributes = geometry.morphAttributes;
  16919. var keys = Object.keys(morphAttributes);
  16920. if (keys.length > 0) {
  16921. var morphAttribute = morphAttributes[keys[0]];
  16922. if (morphAttribute !== undefined) {
  16923. this.morphTargetInfluences = [];
  16924. this.morphTargetDictionary = {};
  16925. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16926. var name = morphAttribute[m].name || String(m);
  16927. this.morphTargetInfluences.push(0);
  16928. this.morphTargetDictionary[name] = m;
  16929. }
  16930. }
  16931. }
  16932. } else {
  16933. var morphTargets = geometry.morphTargets;
  16934. if (morphTargets !== undefined && morphTargets.length > 0) {
  16935. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16936. }
  16937. }
  16938. }
  16939. });
  16940. var _start$1 = new Vector3();
  16941. var _end$1 = new Vector3();
  16942. function LineSegments(geometry, material) {
  16943. Line.call(this, geometry, material);
  16944. this.type = 'LineSegments';
  16945. }
  16946. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  16947. constructor: LineSegments,
  16948. isLineSegments: true,
  16949. computeLineDistances: function computeLineDistances() {
  16950. var geometry = this.geometry;
  16951. if (geometry.isBufferGeometry) {
  16952. // we assume non-indexed geometry
  16953. if (geometry.index === null) {
  16954. var positionAttribute = geometry.attributes.position;
  16955. var lineDistances = [];
  16956. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  16957. _start$1.fromBufferAttribute(positionAttribute, i);
  16958. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  16959. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  16960. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  16961. }
  16962. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16963. } else {
  16964. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16965. }
  16966. } else if (geometry.isGeometry) {
  16967. console.error('THREE.LineSegments.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16968. }
  16969. return this;
  16970. }
  16971. });
  16972. function LineLoop(geometry, material) {
  16973. Line.call(this, geometry, material);
  16974. this.type = 'LineLoop';
  16975. }
  16976. LineLoop.prototype = Object.assign(Object.create(Line.prototype), {
  16977. constructor: LineLoop,
  16978. isLineLoop: true
  16979. });
  16980. /**
  16981. * parameters = {
  16982. * color: <hex>,
  16983. * opacity: <float>,
  16984. * map: new THREE.Texture( <Image> ),
  16985. * alphaMap: new THREE.Texture( <Image> ),
  16986. *
  16987. * size: <float>,
  16988. * sizeAttenuation: <bool>
  16989. *
  16990. * morphTargets: <bool>
  16991. * }
  16992. */
  16993. function PointsMaterial(parameters) {
  16994. Material.call(this);
  16995. this.type = 'PointsMaterial';
  16996. this.color = new Color(0xffffff);
  16997. this.map = null;
  16998. this.alphaMap = null;
  16999. this.size = 1;
  17000. this.sizeAttenuation = true;
  17001. this.morphTargets = false;
  17002. this.setValues(parameters);
  17003. }
  17004. PointsMaterial.prototype = Object.create(Material.prototype);
  17005. PointsMaterial.prototype.constructor = PointsMaterial;
  17006. PointsMaterial.prototype.isPointsMaterial = true;
  17007. PointsMaterial.prototype.copy = function (source) {
  17008. Material.prototype.copy.call(this, source);
  17009. this.color.copy(source.color);
  17010. this.map = source.map;
  17011. this.alphaMap = source.alphaMap;
  17012. this.size = source.size;
  17013. this.sizeAttenuation = source.sizeAttenuation;
  17014. this.morphTargets = source.morphTargets;
  17015. return this;
  17016. };
  17017. var _inverseMatrix$2 = new Matrix4();
  17018. var _ray$2 = new Ray();
  17019. var _sphere$3 = new Sphere();
  17020. var _position$1 = new Vector3();
  17021. function Points(geometry, material) {
  17022. if (geometry === void 0) {
  17023. geometry = new BufferGeometry();
  17024. }
  17025. if (material === void 0) {
  17026. material = new PointsMaterial();
  17027. }
  17028. Object3D.call(this);
  17029. this.type = 'Points';
  17030. this.geometry = geometry;
  17031. this.material = material;
  17032. this.updateMorphTargets();
  17033. }
  17034. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  17035. constructor: Points,
  17036. isPoints: true,
  17037. copy: function copy(source) {
  17038. Object3D.prototype.copy.call(this, source);
  17039. this.material = source.material;
  17040. this.geometry = source.geometry;
  17041. return this;
  17042. },
  17043. raycast: function raycast(raycaster, intersects) {
  17044. var geometry = this.geometry;
  17045. var matrixWorld = this.matrixWorld;
  17046. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  17047. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  17048. _sphere$3.copy(geometry.boundingSphere);
  17049. _sphere$3.applyMatrix4(matrixWorld);
  17050. _sphere$3.radius += threshold;
  17051. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  17052. _inverseMatrix$2.copy(matrixWorld).invert();
  17053. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  17054. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  17055. var localThresholdSq = localThreshold * localThreshold;
  17056. if (geometry.isBufferGeometry) {
  17057. var index = geometry.index;
  17058. var attributes = geometry.attributes;
  17059. var positionAttribute = attributes.position;
  17060. if (index !== null) {
  17061. var indices = index.array;
  17062. for (var i = 0, il = indices.length; i < il; i++) {
  17063. var a = indices[i];
  17064. _position$1.fromBufferAttribute(positionAttribute, a);
  17065. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  17066. }
  17067. } else {
  17068. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  17069. _position$1.fromBufferAttribute(positionAttribute, _i);
  17070. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  17071. }
  17072. }
  17073. } else {
  17074. console.error('THREE.Points.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17075. }
  17076. },
  17077. updateMorphTargets: function updateMorphTargets() {
  17078. var geometry = this.geometry;
  17079. if (geometry.isBufferGeometry) {
  17080. var morphAttributes = geometry.morphAttributes;
  17081. var keys = Object.keys(morphAttributes);
  17082. if (keys.length > 0) {
  17083. var morphAttribute = morphAttributes[keys[0]];
  17084. if (morphAttribute !== undefined) {
  17085. this.morphTargetInfluences = [];
  17086. this.morphTargetDictionary = {};
  17087. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  17088. var name = morphAttribute[m].name || String(m);
  17089. this.morphTargetInfluences.push(0);
  17090. this.morphTargetDictionary[name] = m;
  17091. }
  17092. }
  17093. }
  17094. } else {
  17095. var morphTargets = geometry.morphTargets;
  17096. if (morphTargets !== undefined && morphTargets.length > 0) {
  17097. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  17098. }
  17099. }
  17100. }
  17101. });
  17102. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  17103. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  17104. if (rayPointDistanceSq < localThresholdSq) {
  17105. var intersectPoint = new Vector3();
  17106. _ray$2.closestPointToPoint(point, intersectPoint);
  17107. intersectPoint.applyMatrix4(matrixWorld);
  17108. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  17109. if (distance < raycaster.near || distance > raycaster.far) return;
  17110. intersects.push({
  17111. distance: distance,
  17112. distanceToRay: Math.sqrt(rayPointDistanceSq),
  17113. point: intersectPoint,
  17114. index: index,
  17115. face: null,
  17116. object: object
  17117. });
  17118. }
  17119. }
  17120. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  17121. Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17122. this.format = format !== undefined ? format : RGBFormat;
  17123. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  17124. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  17125. this.generateMipmaps = false;
  17126. var scope = this;
  17127. function updateVideo() {
  17128. scope.needsUpdate = true;
  17129. video.requestVideoFrameCallback(updateVideo);
  17130. }
  17131. if ('requestVideoFrameCallback' in video) {
  17132. video.requestVideoFrameCallback(updateVideo);
  17133. }
  17134. }
  17135. VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
  17136. constructor: VideoTexture,
  17137. clone: function clone() {
  17138. return new this.constructor(this.image).copy(this);
  17139. },
  17140. isVideoTexture: true,
  17141. update: function update() {
  17142. var video = this.image;
  17143. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  17144. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  17145. this.needsUpdate = true;
  17146. }
  17147. }
  17148. });
  17149. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  17150. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  17151. this.image = {
  17152. width: width,
  17153. height: height
  17154. };
  17155. this.mipmaps = mipmaps; // no flipping for cube textures
  17156. // (also flipping doesn't work for compressed textures )
  17157. this.flipY = false; // can't generate mipmaps for compressed textures
  17158. // mips must be embedded in DDS files
  17159. this.generateMipmaps = false;
  17160. }
  17161. CompressedTexture.prototype = Object.create(Texture.prototype);
  17162. CompressedTexture.prototype.constructor = CompressedTexture;
  17163. CompressedTexture.prototype.isCompressedTexture = true;
  17164. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  17165. Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17166. this.needsUpdate = true;
  17167. }
  17168. CanvasTexture.prototype = Object.create(Texture.prototype);
  17169. CanvasTexture.prototype.constructor = CanvasTexture;
  17170. CanvasTexture.prototype.isCanvasTexture = true;
  17171. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  17172. format = format !== undefined ? format : DepthFormat;
  17173. if (format !== DepthFormat && format !== DepthStencilFormat) {
  17174. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  17175. }
  17176. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  17177. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  17178. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17179. this.image = {
  17180. width: width,
  17181. height: height
  17182. };
  17183. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  17184. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  17185. this.flipY = false;
  17186. this.generateMipmaps = false;
  17187. }
  17188. DepthTexture.prototype = Object.create(Texture.prototype);
  17189. DepthTexture.prototype.constructor = DepthTexture;
  17190. DepthTexture.prototype.isDepthTexture = true;
  17191. var CircleGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17192. _inheritsLoose(CircleGeometry, _BufferGeometry);
  17193. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  17194. var _this;
  17195. if (radius === void 0) {
  17196. radius = 1;
  17197. }
  17198. if (segments === void 0) {
  17199. segments = 8;
  17200. }
  17201. if (thetaStart === void 0) {
  17202. thetaStart = 0;
  17203. }
  17204. if (thetaLength === void 0) {
  17205. thetaLength = Math.PI * 2;
  17206. }
  17207. _this = _BufferGeometry.call(this) || this;
  17208. _this.type = 'CircleGeometry';
  17209. _this.parameters = {
  17210. radius: radius,
  17211. segments: segments,
  17212. thetaStart: thetaStart,
  17213. thetaLength: thetaLength
  17214. };
  17215. segments = Math.max(3, segments); // buffers
  17216. var indices = [];
  17217. var vertices = [];
  17218. var normals = [];
  17219. var uvs = []; // helper variables
  17220. var vertex = new Vector3();
  17221. var uv = new Vector2(); // center point
  17222. vertices.push(0, 0, 0);
  17223. normals.push(0, 0, 1);
  17224. uvs.push(0.5, 0.5);
  17225. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  17226. var segment = thetaStart + s / segments * thetaLength; // vertex
  17227. vertex.x = radius * Math.cos(segment);
  17228. vertex.y = radius * Math.sin(segment);
  17229. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17230. normals.push(0, 0, 1); // uvs
  17231. uv.x = (vertices[i] / radius + 1) / 2;
  17232. uv.y = (vertices[i + 1] / radius + 1) / 2;
  17233. uvs.push(uv.x, uv.y);
  17234. } // indices
  17235. for (var _i = 1; _i <= segments; _i++) {
  17236. indices.push(_i, _i + 1, 0);
  17237. } // build geometry
  17238. _this.setIndex(indices);
  17239. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17240. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17241. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17242. return _this;
  17243. }
  17244. return CircleGeometry;
  17245. }(BufferGeometry);
  17246. var CylinderGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17247. _inheritsLoose(CylinderGeometry, _BufferGeometry);
  17248. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17249. var _this;
  17250. if (radiusTop === void 0) {
  17251. radiusTop = 1;
  17252. }
  17253. if (radiusBottom === void 0) {
  17254. radiusBottom = 1;
  17255. }
  17256. if (height === void 0) {
  17257. height = 1;
  17258. }
  17259. if (radialSegments === void 0) {
  17260. radialSegments = 8;
  17261. }
  17262. if (heightSegments === void 0) {
  17263. heightSegments = 1;
  17264. }
  17265. if (openEnded === void 0) {
  17266. openEnded = false;
  17267. }
  17268. if (thetaStart === void 0) {
  17269. thetaStart = 0;
  17270. }
  17271. if (thetaLength === void 0) {
  17272. thetaLength = Math.PI * 2;
  17273. }
  17274. _this = _BufferGeometry.call(this) || this;
  17275. _this.type = 'CylinderGeometry';
  17276. _this.parameters = {
  17277. radiusTop: radiusTop,
  17278. radiusBottom: radiusBottom,
  17279. height: height,
  17280. radialSegments: radialSegments,
  17281. heightSegments: heightSegments,
  17282. openEnded: openEnded,
  17283. thetaStart: thetaStart,
  17284. thetaLength: thetaLength
  17285. };
  17286. var scope = _assertThisInitialized(_this);
  17287. radialSegments = Math.floor(radialSegments);
  17288. heightSegments = Math.floor(heightSegments); // buffers
  17289. var indices = [];
  17290. var vertices = [];
  17291. var normals = [];
  17292. var uvs = []; // helper variables
  17293. var index = 0;
  17294. var indexArray = [];
  17295. var halfHeight = height / 2;
  17296. var groupStart = 0; // generate geometry
  17297. generateTorso();
  17298. if (openEnded === false) {
  17299. if (radiusTop > 0) generateCap(true);
  17300. if (radiusBottom > 0) generateCap(false);
  17301. } // build geometry
  17302. _this.setIndex(indices);
  17303. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17304. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17305. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17306. function generateTorso() {
  17307. var normal = new Vector3();
  17308. var vertex = new Vector3();
  17309. var groupCount = 0; // this will be used to calculate the normal
  17310. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  17311. for (var y = 0; y <= heightSegments; y++) {
  17312. var indexRow = [];
  17313. var v = y / heightSegments; // calculate the radius of the current row
  17314. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  17315. for (var x = 0; x <= radialSegments; x++) {
  17316. var u = x / radialSegments;
  17317. var theta = u * thetaLength + thetaStart;
  17318. var sinTheta = Math.sin(theta);
  17319. var cosTheta = Math.cos(theta); // vertex
  17320. vertex.x = radius * sinTheta;
  17321. vertex.y = -v * height + halfHeight;
  17322. vertex.z = radius * cosTheta;
  17323. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17324. normal.set(sinTheta, slope, cosTheta).normalize();
  17325. normals.push(normal.x, normal.y, normal.z); // uv
  17326. uvs.push(u, 1 - v); // save index of vertex in respective row
  17327. indexRow.push(index++);
  17328. } // now save vertices of the row in our index array
  17329. indexArray.push(indexRow);
  17330. } // generate indices
  17331. for (var _x = 0; _x < radialSegments; _x++) {
  17332. for (var _y = 0; _y < heightSegments; _y++) {
  17333. // we use the index array to access the correct indices
  17334. var a = indexArray[_y][_x];
  17335. var b = indexArray[_y + 1][_x];
  17336. var c = indexArray[_y + 1][_x + 1];
  17337. var d = indexArray[_y][_x + 1]; // faces
  17338. indices.push(a, b, d);
  17339. indices.push(b, c, d); // update group counter
  17340. groupCount += 6;
  17341. }
  17342. } // add a group to the geometry. this will ensure multi material support
  17343. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  17344. groupStart += groupCount;
  17345. }
  17346. function generateCap(top) {
  17347. // save the index of the first center vertex
  17348. var centerIndexStart = index;
  17349. var uv = new Vector2();
  17350. var vertex = new Vector3();
  17351. var groupCount = 0;
  17352. var radius = top === true ? radiusTop : radiusBottom;
  17353. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  17354. // because the geometry needs one set of uvs per face,
  17355. // we must generate a center vertex per face/segment
  17356. for (var x = 1; x <= radialSegments; x++) {
  17357. // vertex
  17358. vertices.push(0, halfHeight * sign, 0); // normal
  17359. normals.push(0, sign, 0); // uv
  17360. uvs.push(0.5, 0.5); // increase index
  17361. index++;
  17362. } // save the index of the last center vertex
  17363. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  17364. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  17365. var u = _x2 / radialSegments;
  17366. var theta = u * thetaLength + thetaStart;
  17367. var cosTheta = Math.cos(theta);
  17368. var sinTheta = Math.sin(theta); // vertex
  17369. vertex.x = radius * sinTheta;
  17370. vertex.y = halfHeight * sign;
  17371. vertex.z = radius * cosTheta;
  17372. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17373. normals.push(0, sign, 0); // uv
  17374. uv.x = cosTheta * 0.5 + 0.5;
  17375. uv.y = sinTheta * 0.5 * sign + 0.5;
  17376. uvs.push(uv.x, uv.y); // increase index
  17377. index++;
  17378. } // generate indices
  17379. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  17380. var c = centerIndexStart + _x3;
  17381. var i = centerIndexEnd + _x3;
  17382. if (top === true) {
  17383. // face top
  17384. indices.push(i, i + 1, c);
  17385. } else {
  17386. // face bottom
  17387. indices.push(i + 1, i, c);
  17388. }
  17389. groupCount += 3;
  17390. } // add a group to the geometry. this will ensure multi material support
  17391. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  17392. groupStart += groupCount;
  17393. }
  17394. return _this;
  17395. }
  17396. return CylinderGeometry;
  17397. }(BufferGeometry);
  17398. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  17399. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  17400. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17401. var _this;
  17402. if (radius === void 0) {
  17403. radius = 1;
  17404. }
  17405. if (height === void 0) {
  17406. height = 1;
  17407. }
  17408. if (radialSegments === void 0) {
  17409. radialSegments = 8;
  17410. }
  17411. if (heightSegments === void 0) {
  17412. heightSegments = 1;
  17413. }
  17414. if (openEnded === void 0) {
  17415. openEnded = false;
  17416. }
  17417. if (thetaStart === void 0) {
  17418. thetaStart = 0;
  17419. }
  17420. if (thetaLength === void 0) {
  17421. thetaLength = Math.PI * 2;
  17422. }
  17423. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17424. _this.type = 'ConeGeometry';
  17425. _this.parameters = {
  17426. radius: radius,
  17427. height: height,
  17428. radialSegments: radialSegments,
  17429. heightSegments: heightSegments,
  17430. openEnded: openEnded,
  17431. thetaStart: thetaStart,
  17432. thetaLength: thetaLength
  17433. };
  17434. return _this;
  17435. }
  17436. return ConeGeometry;
  17437. }(CylinderGeometry);
  17438. var PolyhedronGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17439. _inheritsLoose(PolyhedronGeometry, _BufferGeometry);
  17440. function PolyhedronGeometry(vertices, indices, radius, detail) {
  17441. var _this;
  17442. if (radius === void 0) {
  17443. radius = 1;
  17444. }
  17445. if (detail === void 0) {
  17446. detail = 0;
  17447. }
  17448. _this = _BufferGeometry.call(this) || this;
  17449. _this.type = 'PolyhedronGeometry';
  17450. _this.parameters = {
  17451. vertices: vertices,
  17452. indices: indices,
  17453. radius: radius,
  17454. detail: detail
  17455. }; // default buffer data
  17456. var vertexBuffer = [];
  17457. var uvBuffer = []; // the subdivision creates the vertex buffer data
  17458. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  17459. applyRadius(radius); // finally, create the uv data
  17460. generateUVs(); // build non-indexed geometry
  17461. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  17462. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  17463. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  17464. if (detail === 0) {
  17465. _this.computeVertexNormals(); // flat normals
  17466. } else {
  17467. _this.normalizeNormals(); // smooth normals
  17468. } // helper functions
  17469. function subdivide(detail) {
  17470. var a = new Vector3();
  17471. var b = new Vector3();
  17472. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  17473. for (var i = 0; i < indices.length; i += 3) {
  17474. // get the vertices of the face
  17475. getVertexByIndex(indices[i + 0], a);
  17476. getVertexByIndex(indices[i + 1], b);
  17477. getVertexByIndex(indices[i + 2], c); // perform subdivision
  17478. subdivideFace(a, b, c, detail);
  17479. }
  17480. }
  17481. function subdivideFace(a, b, c, detail) {
  17482. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  17483. var v = []; // construct all of the vertices for this subdivision
  17484. for (var i = 0; i <= cols; i++) {
  17485. v[i] = [];
  17486. var aj = a.clone().lerp(c, i / cols);
  17487. var bj = b.clone().lerp(c, i / cols);
  17488. var rows = cols - i;
  17489. for (var j = 0; j <= rows; j++) {
  17490. if (j === 0 && i === cols) {
  17491. v[i][j] = aj;
  17492. } else {
  17493. v[i][j] = aj.clone().lerp(bj, j / rows);
  17494. }
  17495. }
  17496. } // construct all of the faces
  17497. for (var _i = 0; _i < cols; _i++) {
  17498. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  17499. var k = Math.floor(_j / 2);
  17500. if (_j % 2 === 0) {
  17501. pushVertex(v[_i][k + 1]);
  17502. pushVertex(v[_i + 1][k]);
  17503. pushVertex(v[_i][k]);
  17504. } else {
  17505. pushVertex(v[_i][k + 1]);
  17506. pushVertex(v[_i + 1][k + 1]);
  17507. pushVertex(v[_i + 1][k]);
  17508. }
  17509. }
  17510. }
  17511. }
  17512. function applyRadius(radius) {
  17513. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  17514. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17515. vertex.x = vertexBuffer[i + 0];
  17516. vertex.y = vertexBuffer[i + 1];
  17517. vertex.z = vertexBuffer[i + 2];
  17518. vertex.normalize().multiplyScalar(radius);
  17519. vertexBuffer[i + 0] = vertex.x;
  17520. vertexBuffer[i + 1] = vertex.y;
  17521. vertexBuffer[i + 2] = vertex.z;
  17522. }
  17523. }
  17524. function generateUVs() {
  17525. var vertex = new Vector3();
  17526. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17527. vertex.x = vertexBuffer[i + 0];
  17528. vertex.y = vertexBuffer[i + 1];
  17529. vertex.z = vertexBuffer[i + 2];
  17530. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17531. var v = inclination(vertex) / Math.PI + 0.5;
  17532. uvBuffer.push(u, 1 - v);
  17533. }
  17534. correctUVs();
  17535. correctSeam();
  17536. }
  17537. function correctSeam() {
  17538. // handle case when face straddles the seam, see #3269
  17539. for (var i = 0; i < uvBuffer.length; i += 6) {
  17540. // uv data of a single face
  17541. var x0 = uvBuffer[i + 0];
  17542. var x1 = uvBuffer[i + 2];
  17543. var x2 = uvBuffer[i + 4];
  17544. var max = Math.max(x0, x1, x2);
  17545. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17546. if (max > 0.9 && min < 0.1) {
  17547. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17548. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17549. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17550. }
  17551. }
  17552. }
  17553. function pushVertex(vertex) {
  17554. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17555. }
  17556. function getVertexByIndex(index, vertex) {
  17557. var stride = index * 3;
  17558. vertex.x = vertices[stride + 0];
  17559. vertex.y = vertices[stride + 1];
  17560. vertex.z = vertices[stride + 2];
  17561. }
  17562. function correctUVs() {
  17563. var a = new Vector3();
  17564. var b = new Vector3();
  17565. var c = new Vector3();
  17566. var centroid = new Vector3();
  17567. var uvA = new Vector2();
  17568. var uvB = new Vector2();
  17569. var uvC = new Vector2();
  17570. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17571. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17572. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17573. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17574. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17575. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17576. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17577. centroid.copy(a).add(b).add(c).divideScalar(3);
  17578. var azi = azimuth(centroid);
  17579. correctUV(uvA, j + 0, a, azi);
  17580. correctUV(uvB, j + 2, b, azi);
  17581. correctUV(uvC, j + 4, c, azi);
  17582. }
  17583. }
  17584. function correctUV(uv, stride, vector, azimuth) {
  17585. if (azimuth < 0 && uv.x === 1) {
  17586. uvBuffer[stride] = uv.x - 1;
  17587. }
  17588. if (vector.x === 0 && vector.z === 0) {
  17589. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17590. }
  17591. } // Angle around the Y axis, counter-clockwise when looking from above.
  17592. function azimuth(vector) {
  17593. return Math.atan2(vector.z, -vector.x);
  17594. } // Angle above the XZ plane.
  17595. function inclination(vector) {
  17596. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17597. }
  17598. return _this;
  17599. }
  17600. return PolyhedronGeometry;
  17601. }(BufferGeometry);
  17602. var DodecahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  17603. _inheritsLoose(DodecahedronGeometry, _PolyhedronGeometry);
  17604. function DodecahedronGeometry(radius, detail) {
  17605. var _this;
  17606. if (radius === void 0) {
  17607. radius = 1;
  17608. }
  17609. if (detail === void 0) {
  17610. detail = 0;
  17611. }
  17612. var t = (1 + Math.sqrt(5)) / 2;
  17613. var r = 1 / t;
  17614. var vertices = [// (±1, ±1, ±1)
  17615. -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/φ, ±φ)
  17616. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17617. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17618. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17619. 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];
  17620. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  17621. _this.type = 'DodecahedronGeometry';
  17622. _this.parameters = {
  17623. radius: radius,
  17624. detail: detail
  17625. };
  17626. return _this;
  17627. }
  17628. return DodecahedronGeometry;
  17629. }(PolyhedronGeometry);
  17630. var _v0$2 = new Vector3();
  17631. var _v1$5 = new Vector3();
  17632. var _normal$1 = new Vector3();
  17633. var _triangle = new Triangle();
  17634. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17635. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17636. function EdgesGeometry(geometry, thresholdAngle) {
  17637. var _this;
  17638. _this = _BufferGeometry.call(this) || this;
  17639. _this.type = 'EdgesGeometry';
  17640. _this.parameters = {
  17641. thresholdAngle: thresholdAngle
  17642. };
  17643. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  17644. if (geometry.isGeometry === true) {
  17645. console.error('THREE.EdgesGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17646. return _assertThisInitialized(_this);
  17647. }
  17648. var precisionPoints = 4;
  17649. var precision = Math.pow(10, precisionPoints);
  17650. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  17651. var indexAttr = geometry.getIndex();
  17652. var positionAttr = geometry.getAttribute('position');
  17653. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  17654. var indexArr = [0, 0, 0];
  17655. var vertKeys = ['a', 'b', 'c'];
  17656. var hashes = new Array(3);
  17657. var edgeData = {};
  17658. var vertices = [];
  17659. for (var i = 0; i < indexCount; i += 3) {
  17660. if (indexAttr) {
  17661. indexArr[0] = indexAttr.getX(i);
  17662. indexArr[1] = indexAttr.getX(i + 1);
  17663. indexArr[2] = indexAttr.getX(i + 2);
  17664. } else {
  17665. indexArr[0] = i;
  17666. indexArr[1] = i + 1;
  17667. indexArr[2] = i + 2;
  17668. }
  17669. var a = _triangle.a,
  17670. b = _triangle.b,
  17671. c = _triangle.c;
  17672. a.fromBufferAttribute(positionAttr, indexArr[0]);
  17673. b.fromBufferAttribute(positionAttr, indexArr[1]);
  17674. c.fromBufferAttribute(positionAttr, indexArr[2]);
  17675. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  17676. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  17677. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  17678. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  17679. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  17680. continue;
  17681. } // iterate over every edge
  17682. for (var j = 0; j < 3; j++) {
  17683. // get the first and next vertex making up the edge
  17684. var jNext = (j + 1) % 3;
  17685. var vecHash0 = hashes[j];
  17686. var vecHash1 = hashes[jNext];
  17687. var v0 = _triangle[vertKeys[j]];
  17688. var v1 = _triangle[vertKeys[jNext]];
  17689. var hash = vecHash0 + "_" + vecHash1;
  17690. var reverseHash = vecHash1 + "_" + vecHash0;
  17691. if (reverseHash in edgeData && edgeData[reverseHash]) {
  17692. // if we found a sibling edge add it into the vertex array if
  17693. // it meets the angle threshold and delete the edge from the map.
  17694. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  17695. vertices.push(v0.x, v0.y, v0.z);
  17696. vertices.push(v1.x, v1.y, v1.z);
  17697. }
  17698. edgeData[reverseHash] = null;
  17699. } else if (!(hash in edgeData)) {
  17700. // if we've already got an edge here then skip adding a new one
  17701. edgeData[hash] = {
  17702. index0: indexArr[j],
  17703. index1: indexArr[jNext],
  17704. normal: _normal$1.clone()
  17705. };
  17706. }
  17707. }
  17708. } // iterate over all remaining, unmatched edges and add them to the vertex array
  17709. for (var key in edgeData) {
  17710. if (edgeData[key]) {
  17711. var _edgeData$key = edgeData[key],
  17712. index0 = _edgeData$key.index0,
  17713. index1 = _edgeData$key.index1;
  17714. _v0$2.fromBufferAttribute(positionAttr, index0);
  17715. _v1$5.fromBufferAttribute(positionAttr, index1);
  17716. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  17717. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  17718. }
  17719. }
  17720. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17721. return _this;
  17722. }
  17723. return EdgesGeometry;
  17724. }(BufferGeometry);
  17725. /**
  17726. * Port from https://github.com/mapbox/earcut (v2.2.2)
  17727. */
  17728. var Earcut = {
  17729. triangulate: function triangulate(data, holeIndices, dim) {
  17730. dim = dim || 2;
  17731. var hasHoles = holeIndices && holeIndices.length;
  17732. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  17733. var outerNode = linkedList(data, 0, outerLen, dim, true);
  17734. var triangles = [];
  17735. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  17736. var minX, minY, maxX, maxY, x, y, invSize;
  17737. 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
  17738. if (data.length > 80 * dim) {
  17739. minX = maxX = data[0];
  17740. minY = maxY = data[1];
  17741. for (var i = dim; i < outerLen; i += dim) {
  17742. x = data[i];
  17743. y = data[i + 1];
  17744. if (x < minX) minX = x;
  17745. if (y < minY) minY = y;
  17746. if (x > maxX) maxX = x;
  17747. if (y > maxY) maxY = y;
  17748. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17749. invSize = Math.max(maxX - minX, maxY - minY);
  17750. invSize = invSize !== 0 ? 1 / invSize : 0;
  17751. }
  17752. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  17753. return triangles;
  17754. }
  17755. }; // create a circular doubly linked list from polygon points in the specified winding order
  17756. function linkedList(data, start, end, dim, clockwise) {
  17757. var i, last;
  17758. if (clockwise === signedArea(data, start, end, dim) > 0) {
  17759. for (i = start; i < end; i += dim) {
  17760. last = insertNode(i, data[i], data[i + 1], last);
  17761. }
  17762. } else {
  17763. for (i = end - dim; i >= start; i -= dim) {
  17764. last = insertNode(i, data[i], data[i + 1], last);
  17765. }
  17766. }
  17767. if (last && equals(last, last.next)) {
  17768. removeNode(last);
  17769. last = last.next;
  17770. }
  17771. return last;
  17772. } // eliminate colinear or duplicate points
  17773. function filterPoints(start, end) {
  17774. if (!start) return start;
  17775. if (!end) end = start;
  17776. var p = start,
  17777. again;
  17778. do {
  17779. again = false;
  17780. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  17781. removeNode(p);
  17782. p = end = p.prev;
  17783. if (p === p.next) break;
  17784. again = true;
  17785. } else {
  17786. p = p.next;
  17787. }
  17788. } while (again || p !== end);
  17789. return end;
  17790. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  17791. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  17792. if (!ear) return; // interlink polygon nodes in z-order
  17793. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  17794. var stop = ear,
  17795. prev,
  17796. next; // iterate through ears, slicing them one by one
  17797. while (ear.prev !== ear.next) {
  17798. prev = ear.prev;
  17799. next = ear.next;
  17800. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  17801. // cut off the triangle
  17802. triangles.push(prev.i / dim);
  17803. triangles.push(ear.i / dim);
  17804. triangles.push(next.i / dim);
  17805. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  17806. ear = next.next;
  17807. stop = next.next;
  17808. continue;
  17809. }
  17810. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  17811. if (ear === stop) {
  17812. // try filtering points and slicing again
  17813. if (!pass) {
  17814. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  17815. } else if (pass === 1) {
  17816. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  17817. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  17818. } else if (pass === 2) {
  17819. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  17820. }
  17821. break;
  17822. }
  17823. }
  17824. } // check whether a polygon node forms a valid ear with adjacent nodes
  17825. function isEar(ear) {
  17826. var a = ear.prev,
  17827. b = ear,
  17828. c = ear.next;
  17829. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17830. // now make sure we don't have other points inside the potential ear
  17831. var p = ear.next.next;
  17832. while (p !== ear.prev) {
  17833. 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;
  17834. p = p.next;
  17835. }
  17836. return true;
  17837. }
  17838. function isEarHashed(ear, minX, minY, invSize) {
  17839. var a = ear.prev,
  17840. b = ear,
  17841. c = ear.next;
  17842. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17843. // triangle bbox; min & max are calculated like this for speed
  17844. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  17845. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  17846. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  17847. 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;
  17848. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  17849. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  17850. var p = ear.prevZ,
  17851. n = ear.nextZ; // look for points inside the triangle in both directions
  17852. while (p && p.z >= minZ && n && n.z <= maxZ) {
  17853. 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;
  17854. p = p.prevZ;
  17855. if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0) return false;
  17856. n = n.nextZ;
  17857. } // look for remaining points in decreasing z-order
  17858. while (p && p.z >= minZ) {
  17859. 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;
  17860. p = p.prevZ;
  17861. } // look for remaining points in increasing z-order
  17862. while (n && n.z <= maxZ) {
  17863. 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;
  17864. n = n.nextZ;
  17865. }
  17866. return true;
  17867. } // go through all polygon nodes and cure small local self-intersections
  17868. function cureLocalIntersections(start, triangles, dim) {
  17869. var p = start;
  17870. do {
  17871. var a = p.prev,
  17872. b = p.next.next;
  17873. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  17874. triangles.push(a.i / dim);
  17875. triangles.push(p.i / dim);
  17876. triangles.push(b.i / dim); // remove two nodes involved
  17877. removeNode(p);
  17878. removeNode(p.next);
  17879. p = start = b;
  17880. }
  17881. p = p.next;
  17882. } while (p !== start);
  17883. return filterPoints(p);
  17884. } // try splitting polygon into two and triangulate them independently
  17885. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  17886. // look for a valid diagonal that divides the polygon into two
  17887. var a = start;
  17888. do {
  17889. var b = a.next.next;
  17890. while (b !== a.prev) {
  17891. if (a.i !== b.i && isValidDiagonal(a, b)) {
  17892. // split the polygon in two by the diagonal
  17893. var c = splitPolygon(a, b); // filter colinear points around the cuts
  17894. a = filterPoints(a, a.next);
  17895. c = filterPoints(c, c.next); // run earcut on each half
  17896. earcutLinked(a, triangles, dim, minX, minY, invSize);
  17897. earcutLinked(c, triangles, dim, minX, minY, invSize);
  17898. return;
  17899. }
  17900. b = b.next;
  17901. }
  17902. a = a.next;
  17903. } while (a !== start);
  17904. } // link every hole into the outer loop, producing a single-ring polygon without holes
  17905. function eliminateHoles(data, holeIndices, outerNode, dim) {
  17906. var queue = [];
  17907. var i, len, start, end, list;
  17908. for (i = 0, len = holeIndices.length; i < len; i++) {
  17909. start = holeIndices[i] * dim;
  17910. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  17911. list = linkedList(data, start, end, dim, false);
  17912. if (list === list.next) list.steiner = true;
  17913. queue.push(getLeftmost(list));
  17914. }
  17915. queue.sort(compareX); // process holes from left to right
  17916. for (i = 0; i < queue.length; i++) {
  17917. eliminateHole(queue[i], outerNode);
  17918. outerNode = filterPoints(outerNode, outerNode.next);
  17919. }
  17920. return outerNode;
  17921. }
  17922. function compareX(a, b) {
  17923. return a.x - b.x;
  17924. } // find a bridge between vertices that connects hole with an outer ring and and link it
  17925. function eliminateHole(hole, outerNode) {
  17926. outerNode = findHoleBridge(hole, outerNode);
  17927. if (outerNode) {
  17928. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  17929. filterPoints(outerNode, outerNode.next);
  17930. filterPoints(b, b.next);
  17931. }
  17932. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17933. function findHoleBridge(hole, outerNode) {
  17934. var p = outerNode;
  17935. var hx = hole.x;
  17936. var hy = hole.y;
  17937. var qx = -Infinity,
  17938. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  17939. // segment's endpoint with lesser x will be potential connection point
  17940. do {
  17941. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  17942. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  17943. if (x <= hx && x > qx) {
  17944. qx = x;
  17945. if (x === hx) {
  17946. if (hy === p.y) return p;
  17947. if (hy === p.next.y) return p.next;
  17948. }
  17949. m = p.x < p.next.x ? p : p.next;
  17950. }
  17951. }
  17952. p = p.next;
  17953. } while (p !== outerNode);
  17954. if (!m) return null;
  17955. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  17956. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17957. // if there are no points found, we have a valid connection;
  17958. // otherwise choose the point of the minimum angle with the ray as connection point
  17959. var stop = m,
  17960. mx = m.x,
  17961. my = m.y;
  17962. var tanMin = Infinity,
  17963. tan;
  17964. p = m;
  17965. do {
  17966. 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)) {
  17967. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  17968. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  17969. m = p;
  17970. tanMin = tan;
  17971. }
  17972. }
  17973. p = p.next;
  17974. } while (p !== stop);
  17975. return m;
  17976. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  17977. function sectorContainsSector(m, p) {
  17978. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  17979. } // interlink polygon nodes in z-order
  17980. function indexCurve(start, minX, minY, invSize) {
  17981. var p = start;
  17982. do {
  17983. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  17984. p.prevZ = p.prev;
  17985. p.nextZ = p.next;
  17986. p = p.next;
  17987. } while (p !== start);
  17988. p.prevZ.nextZ = null;
  17989. p.prevZ = null;
  17990. sortLinked(p);
  17991. } // Simon Tatham's linked list merge sort algorithm
  17992. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17993. function sortLinked(list) {
  17994. var i,
  17995. p,
  17996. q,
  17997. e,
  17998. tail,
  17999. numMerges,
  18000. pSize,
  18001. qSize,
  18002. inSize = 1;
  18003. do {
  18004. p = list;
  18005. list = null;
  18006. tail = null;
  18007. numMerges = 0;
  18008. while (p) {
  18009. numMerges++;
  18010. q = p;
  18011. pSize = 0;
  18012. for (i = 0; i < inSize; i++) {
  18013. pSize++;
  18014. q = q.nextZ;
  18015. if (!q) break;
  18016. }
  18017. qSize = inSize;
  18018. while (pSize > 0 || qSize > 0 && q) {
  18019. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  18020. e = p;
  18021. p = p.nextZ;
  18022. pSize--;
  18023. } else {
  18024. e = q;
  18025. q = q.nextZ;
  18026. qSize--;
  18027. }
  18028. if (tail) tail.nextZ = e;else list = e;
  18029. e.prevZ = tail;
  18030. tail = e;
  18031. }
  18032. p = q;
  18033. }
  18034. tail.nextZ = null;
  18035. inSize *= 2;
  18036. } while (numMerges > 1);
  18037. return list;
  18038. } // z-order of a point given coords and inverse of the longer side of data bbox
  18039. function zOrder(x, y, minX, minY, invSize) {
  18040. // coords are transformed into non-negative 15-bit integer range
  18041. x = 32767 * (x - minX) * invSize;
  18042. y = 32767 * (y - minY) * invSize;
  18043. x = (x | x << 8) & 0x00FF00FF;
  18044. x = (x | x << 4) & 0x0F0F0F0F;
  18045. x = (x | x << 2) & 0x33333333;
  18046. x = (x | x << 1) & 0x55555555;
  18047. y = (y | y << 8) & 0x00FF00FF;
  18048. y = (y | y << 4) & 0x0F0F0F0F;
  18049. y = (y | y << 2) & 0x33333333;
  18050. y = (y | y << 1) & 0x55555555;
  18051. return x | y << 1;
  18052. } // find the leftmost node of a polygon ring
  18053. function getLeftmost(start) {
  18054. var p = start,
  18055. leftmost = start;
  18056. do {
  18057. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  18058. p = p.next;
  18059. } while (p !== start);
  18060. return leftmost;
  18061. } // check if a point lies within a convex triangle
  18062. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  18063. 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;
  18064. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18065. function isValidDiagonal(a, b) {
  18066. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  18067. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  18068. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  18069. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  18070. } // signed area of a triangle
  18071. function area(p, q, r) {
  18072. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  18073. } // check if two points are equal
  18074. function equals(p1, p2) {
  18075. return p1.x === p2.x && p1.y === p2.y;
  18076. } // check if two segments intersect
  18077. function intersects(p1, q1, p2, q2) {
  18078. var o1 = sign(area(p1, q1, p2));
  18079. var o2 = sign(area(p1, q1, q2));
  18080. var o3 = sign(area(p2, q2, p1));
  18081. var o4 = sign(area(p2, q2, q1));
  18082. if (o1 !== o2 && o3 !== o4) return true; // general case
  18083. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18084. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18085. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18086. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18087. return false;
  18088. } // for collinear points p, q, r, check if point q lies on segment pr
  18089. function onSegment(p, q, r) {
  18090. 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);
  18091. }
  18092. function sign(num) {
  18093. return num > 0 ? 1 : num < 0 ? -1 : 0;
  18094. } // check if a polygon diagonal intersects any polygon segments
  18095. function intersectsPolygon(a, b) {
  18096. var p = a;
  18097. do {
  18098. 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;
  18099. p = p.next;
  18100. } while (p !== a);
  18101. return false;
  18102. } // check if a polygon diagonal is locally inside the polygon
  18103. function locallyInside(a, b) {
  18104. 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;
  18105. } // check if the middle point of a polygon diagonal is inside the polygon
  18106. function middleInside(a, b) {
  18107. var p = a,
  18108. inside = false;
  18109. var px = (a.x + b.x) / 2,
  18110. py = (a.y + b.y) / 2;
  18111. do {
  18112. 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;
  18113. p = p.next;
  18114. } while (p !== a);
  18115. return inside;
  18116. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18117. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18118. function splitPolygon(a, b) {
  18119. var a2 = new Node(a.i, a.x, a.y),
  18120. b2 = new Node(b.i, b.x, b.y),
  18121. an = a.next,
  18122. bp = b.prev;
  18123. a.next = b;
  18124. b.prev = a;
  18125. a2.next = an;
  18126. an.prev = a2;
  18127. b2.next = a2;
  18128. a2.prev = b2;
  18129. bp.next = b2;
  18130. b2.prev = bp;
  18131. return b2;
  18132. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  18133. function insertNode(i, x, y, last) {
  18134. var p = new Node(i, x, y);
  18135. if (!last) {
  18136. p.prev = p;
  18137. p.next = p;
  18138. } else {
  18139. p.next = last.next;
  18140. p.prev = last;
  18141. last.next.prev = p;
  18142. last.next = p;
  18143. }
  18144. return p;
  18145. }
  18146. function removeNode(p) {
  18147. p.next.prev = p.prev;
  18148. p.prev.next = p.next;
  18149. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  18150. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  18151. }
  18152. function Node(i, x, y) {
  18153. // vertex index in coordinates array
  18154. this.i = i; // vertex coordinates
  18155. this.x = x;
  18156. this.y = y; // previous and next vertex nodes in a polygon ring
  18157. this.prev = null;
  18158. this.next = null; // z-order curve value
  18159. this.z = null; // previous and next nodes in z-order
  18160. this.prevZ = null;
  18161. this.nextZ = null; // indicates whether this is a steiner point
  18162. this.steiner = false;
  18163. }
  18164. function signedArea(data, start, end, dim) {
  18165. var sum = 0;
  18166. for (var i = start, j = end - dim; i < end; i += dim) {
  18167. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  18168. j = i;
  18169. }
  18170. return sum;
  18171. }
  18172. var ShapeUtils = {
  18173. // calculate area of the contour polygon
  18174. area: function area(contour) {
  18175. var n = contour.length;
  18176. var a = 0.0;
  18177. for (var p = n - 1, q = 0; q < n; p = q++) {
  18178. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  18179. }
  18180. return a * 0.5;
  18181. },
  18182. isClockWise: function isClockWise(pts) {
  18183. return ShapeUtils.area(pts) < 0;
  18184. },
  18185. triangulateShape: function triangulateShape(contour, holes) {
  18186. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18187. var holeIndices = []; // array of hole indices
  18188. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18189. removeDupEndPts(contour);
  18190. addContour(vertices, contour); //
  18191. var holeIndex = contour.length;
  18192. holes.forEach(removeDupEndPts);
  18193. for (var i = 0; i < holes.length; i++) {
  18194. holeIndices.push(holeIndex);
  18195. holeIndex += holes[i].length;
  18196. addContour(vertices, holes[i]);
  18197. } //
  18198. var triangles = Earcut.triangulate(vertices, holeIndices); //
  18199. for (var _i = 0; _i < triangles.length; _i += 3) {
  18200. faces.push(triangles.slice(_i, _i + 3));
  18201. }
  18202. return faces;
  18203. }
  18204. };
  18205. function removeDupEndPts(points) {
  18206. var l = points.length;
  18207. if (l > 2 && points[l - 1].equals(points[0])) {
  18208. points.pop();
  18209. }
  18210. }
  18211. function addContour(vertices, contour) {
  18212. for (var i = 0; i < contour.length; i++) {
  18213. vertices.push(contour[i].x);
  18214. vertices.push(contour[i].y);
  18215. }
  18216. }
  18217. var ExtrudeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18218. _inheritsLoose(ExtrudeGeometry, _BufferGeometry);
  18219. function ExtrudeGeometry(shapes, options) {
  18220. var _this;
  18221. _this = _BufferGeometry.call(this) || this;
  18222. _this.type = 'ExtrudeGeometry';
  18223. _this.parameters = {
  18224. shapes: shapes,
  18225. options: options
  18226. };
  18227. shapes = Array.isArray(shapes) ? shapes : [shapes];
  18228. var scope = _assertThisInitialized(_this);
  18229. var verticesArray = [];
  18230. var uvArray = [];
  18231. for (var i = 0, l = shapes.length; i < l; i++) {
  18232. var shape = shapes[i];
  18233. addShape(shape);
  18234. } // build geometry
  18235. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  18236. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  18237. _this.computeVertexNormals(); // functions
  18238. function addShape(shape) {
  18239. var placeholder = []; // options
  18240. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18241. var steps = options.steps !== undefined ? options.steps : 1;
  18242. var depth = options.depth !== undefined ? options.depth : 100;
  18243. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18244. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18245. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18246. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18247. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18248. var extrudePath = options.extrudePath;
  18249. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  18250. if (options.amount !== undefined) {
  18251. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  18252. depth = options.amount;
  18253. } //
  18254. var extrudePts,
  18255. extrudeByPath = false;
  18256. var splineTube, binormal, normal, position2;
  18257. if (extrudePath) {
  18258. extrudePts = extrudePath.getSpacedPoints(steps);
  18259. extrudeByPath = true;
  18260. bevelEnabled = false; // bevels not supported for path extrusion
  18261. // SETUP TNB variables
  18262. // TODO1 - have a .isClosed in spline?
  18263. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18264. binormal = new Vector3();
  18265. normal = new Vector3();
  18266. position2 = new Vector3();
  18267. } // Safeguards if bevels are not enabled
  18268. if (!bevelEnabled) {
  18269. bevelSegments = 0;
  18270. bevelThickness = 0;
  18271. bevelSize = 0;
  18272. bevelOffset = 0;
  18273. } // Variables initialization
  18274. var shapePoints = shape.extractPoints(curveSegments);
  18275. var vertices = shapePoints.shape;
  18276. var holes = shapePoints.holes;
  18277. var reverse = !ShapeUtils.isClockWise(vertices);
  18278. if (reverse) {
  18279. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18280. for (var h = 0, hl = holes.length; h < hl; h++) {
  18281. var ahole = holes[h];
  18282. if (ShapeUtils.isClockWise(ahole)) {
  18283. holes[h] = ahole.reverse();
  18284. }
  18285. }
  18286. }
  18287. var faces = ShapeUtils.triangulateShape(vertices, holes);
  18288. /* Vertices */
  18289. var contour = vertices; // vertices has all points but contour has only points of circumference
  18290. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  18291. var _ahole = holes[_h];
  18292. vertices = vertices.concat(_ahole);
  18293. }
  18294. function scalePt2(pt, vec, size) {
  18295. if (!vec) console.error('THREE.ExtrudeGeometry: vec does not exist');
  18296. return vec.clone().multiplyScalar(size).add(pt);
  18297. }
  18298. var vlen = vertices.length,
  18299. flen = faces.length; // Find directions for point movement
  18300. function getBevelVec(inPt, inPrev, inNext) {
  18301. // computes for inPt the corresponding point inPt' on a new contour
  18302. // shifted by 1 unit (length of normalized vector) to the left
  18303. // if we walk along contour clockwise, this new contour is outside the old one
  18304. //
  18305. // inPt' is the intersection of the two lines parallel to the two
  18306. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18307. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18308. // good reading for geometry algorithms (here: line-line intersection)
  18309. // http://geomalgorithms.com/a05-_intersect-1.html
  18310. var v_prev_x = inPt.x - inPrev.x,
  18311. v_prev_y = inPt.y - inPrev.y;
  18312. var v_next_x = inNext.x - inPt.x,
  18313. v_next_y = inNext.y - inPt.y;
  18314. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  18315. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  18316. if (Math.abs(collinear0) > Number.EPSILON) {
  18317. // not collinear
  18318. // length of vectors for normalizing
  18319. var v_prev_len = Math.sqrt(v_prev_lensq);
  18320. 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
  18321. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  18322. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  18323. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  18324. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  18325. 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
  18326. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  18327. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  18328. // but prevent crazy spikes
  18329. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  18330. if (v_trans_lensq <= 2) {
  18331. return new Vector2(v_trans_x, v_trans_y);
  18332. } else {
  18333. shrink_by = Math.sqrt(v_trans_lensq / 2);
  18334. }
  18335. } else {
  18336. // handle special case of collinear edges
  18337. var direction_eq = false; // assumes: opposite
  18338. if (v_prev_x > Number.EPSILON) {
  18339. if (v_next_x > Number.EPSILON) {
  18340. direction_eq = true;
  18341. }
  18342. } else {
  18343. if (v_prev_x < -Number.EPSILON) {
  18344. if (v_next_x < -Number.EPSILON) {
  18345. direction_eq = true;
  18346. }
  18347. } else {
  18348. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  18349. direction_eq = true;
  18350. }
  18351. }
  18352. }
  18353. if (direction_eq) {
  18354. // console.log("Warning: lines are a straight sequence");
  18355. v_trans_x = -v_prev_y;
  18356. v_trans_y = v_prev_x;
  18357. shrink_by = Math.sqrt(v_prev_lensq);
  18358. } else {
  18359. // console.log("Warning: lines are a straight spike");
  18360. v_trans_x = v_prev_x;
  18361. v_trans_y = v_prev_y;
  18362. shrink_by = Math.sqrt(v_prev_lensq / 2);
  18363. }
  18364. }
  18365. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  18366. }
  18367. var contourMovements = [];
  18368. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  18369. if (j === il) j = 0;
  18370. if (k === il) k = 0; // (j)---(i)---(k)
  18371. // console.log('i,j,k', i, j , k)
  18372. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  18373. }
  18374. var holesMovements = [];
  18375. var oneHoleMovements,
  18376. verticesMovements = contourMovements.concat();
  18377. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  18378. var _ahole2 = holes[_h2];
  18379. oneHoleMovements = [];
  18380. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  18381. if (_j === _il) _j = 0;
  18382. if (_k === _il) _k = 0; // (j)---(i)---(k)
  18383. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  18384. }
  18385. holesMovements.push(oneHoleMovements);
  18386. verticesMovements = verticesMovements.concat(oneHoleMovements);
  18387. } // Loop bevelSegments, 1 for the front, 1 for the back
  18388. for (var b = 0; b < bevelSegments; b++) {
  18389. //for ( b = bevelSegments; b > 0; b -- ) {
  18390. var t = b / bevelSegments;
  18391. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  18392. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  18393. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  18394. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  18395. v(vert.x, vert.y, -z);
  18396. } // expand holes
  18397. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  18398. var _ahole3 = holes[_h3];
  18399. oneHoleMovements = holesMovements[_h3];
  18400. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  18401. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  18402. v(_vert.x, _vert.y, -z);
  18403. }
  18404. }
  18405. }
  18406. var bs = bevelSize + bevelOffset; // Back facing vertices
  18407. for (var _i5 = 0; _i5 < vlen; _i5++) {
  18408. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  18409. if (!extrudeByPath) {
  18410. v(_vert2.x, _vert2.y, 0);
  18411. } else {
  18412. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18413. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  18414. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  18415. position2.copy(extrudePts[0]).add(normal).add(binormal);
  18416. v(position2.x, position2.y, position2.z);
  18417. }
  18418. } // Add stepped vertices...
  18419. // Including front facing vertices
  18420. for (var s = 1; s <= steps; s++) {
  18421. for (var _i6 = 0; _i6 < vlen; _i6++) {
  18422. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  18423. if (!extrudeByPath) {
  18424. v(_vert3.x, _vert3.y, depth / steps * s);
  18425. } else {
  18426. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18427. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  18428. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  18429. position2.copy(extrudePts[s]).add(normal).add(binormal);
  18430. v(position2.x, position2.y, position2.z);
  18431. }
  18432. }
  18433. } // Add bevel segments planes
  18434. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18435. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  18436. var _t = _b / bevelSegments;
  18437. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  18438. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  18439. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  18440. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  18441. v(_vert4.x, _vert4.y, depth + _z);
  18442. } // expand holes
  18443. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  18444. var _ahole4 = holes[_h4];
  18445. oneHoleMovements = holesMovements[_h4];
  18446. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  18447. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  18448. if (!extrudeByPath) {
  18449. v(_vert5.x, _vert5.y, depth + _z);
  18450. } else {
  18451. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  18452. }
  18453. }
  18454. }
  18455. }
  18456. /* Faces */
  18457. // Top and bottom faces
  18458. buildLidFaces(); // Sides faces
  18459. buildSideFaces(); ///// Internal functions
  18460. function buildLidFaces() {
  18461. var start = verticesArray.length / 3;
  18462. if (bevelEnabled) {
  18463. var layer = 0; // steps + 1
  18464. var offset = vlen * layer; // Bottom faces
  18465. for (var _i9 = 0; _i9 < flen; _i9++) {
  18466. var face = faces[_i9];
  18467. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  18468. }
  18469. layer = steps + bevelSegments * 2;
  18470. offset = vlen * layer; // Top faces
  18471. for (var _i10 = 0; _i10 < flen; _i10++) {
  18472. var _face = faces[_i10];
  18473. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  18474. }
  18475. } else {
  18476. // Bottom faces
  18477. for (var _i11 = 0; _i11 < flen; _i11++) {
  18478. var _face2 = faces[_i11];
  18479. f3(_face2[2], _face2[1], _face2[0]);
  18480. } // Top faces
  18481. for (var _i12 = 0; _i12 < flen; _i12++) {
  18482. var _face3 = faces[_i12];
  18483. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  18484. }
  18485. }
  18486. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  18487. } // Create faces for the z-sides of the shape
  18488. function buildSideFaces() {
  18489. var start = verticesArray.length / 3;
  18490. var layeroffset = 0;
  18491. sidewalls(contour, layeroffset);
  18492. layeroffset += contour.length;
  18493. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  18494. var _ahole5 = holes[_h5];
  18495. sidewalls(_ahole5, layeroffset); //, true
  18496. layeroffset += _ahole5.length;
  18497. }
  18498. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  18499. }
  18500. function sidewalls(contour, layeroffset) {
  18501. var i = contour.length;
  18502. while (--i >= 0) {
  18503. var _j2 = i;
  18504. var _k2 = i - 1;
  18505. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  18506. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  18507. var slen1 = vlen * _s;
  18508. var slen2 = vlen * (_s + 1);
  18509. var a = layeroffset + _j2 + slen1,
  18510. _b2 = layeroffset + _k2 + slen1,
  18511. c = layeroffset + _k2 + slen2,
  18512. d = layeroffset + _j2 + slen2;
  18513. f4(a, _b2, c, d);
  18514. }
  18515. }
  18516. }
  18517. function v(x, y, z) {
  18518. placeholder.push(x);
  18519. placeholder.push(y);
  18520. placeholder.push(z);
  18521. }
  18522. function f3(a, b, c) {
  18523. addVertex(a);
  18524. addVertex(b);
  18525. addVertex(c);
  18526. var nextIndex = verticesArray.length / 3;
  18527. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18528. addUV(uvs[0]);
  18529. addUV(uvs[1]);
  18530. addUV(uvs[2]);
  18531. }
  18532. function f4(a, b, c, d) {
  18533. addVertex(a);
  18534. addVertex(b);
  18535. addVertex(d);
  18536. addVertex(b);
  18537. addVertex(c);
  18538. addVertex(d);
  18539. var nextIndex = verticesArray.length / 3;
  18540. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18541. addUV(uvs[0]);
  18542. addUV(uvs[1]);
  18543. addUV(uvs[3]);
  18544. addUV(uvs[1]);
  18545. addUV(uvs[2]);
  18546. addUV(uvs[3]);
  18547. }
  18548. function addVertex(index) {
  18549. verticesArray.push(placeholder[index * 3 + 0]);
  18550. verticesArray.push(placeholder[index * 3 + 1]);
  18551. verticesArray.push(placeholder[index * 3 + 2]);
  18552. }
  18553. function addUV(vector2) {
  18554. uvArray.push(vector2.x);
  18555. uvArray.push(vector2.y);
  18556. }
  18557. }
  18558. return _this;
  18559. }
  18560. var _proto = ExtrudeGeometry.prototype;
  18561. _proto.toJSON = function toJSON() {
  18562. var data = BufferGeometry.prototype.toJSON.call(this);
  18563. var shapes = this.parameters.shapes;
  18564. var options = this.parameters.options;
  18565. return _toJSON(shapes, options, data);
  18566. };
  18567. return ExtrudeGeometry;
  18568. }(BufferGeometry);
  18569. var WorldUVGenerator = {
  18570. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18571. var a_x = vertices[indexA * 3];
  18572. var a_y = vertices[indexA * 3 + 1];
  18573. var b_x = vertices[indexB * 3];
  18574. var b_y = vertices[indexB * 3 + 1];
  18575. var c_x = vertices[indexC * 3];
  18576. var c_y = vertices[indexC * 3 + 1];
  18577. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18578. },
  18579. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18580. var a_x = vertices[indexA * 3];
  18581. var a_y = vertices[indexA * 3 + 1];
  18582. var a_z = vertices[indexA * 3 + 2];
  18583. var b_x = vertices[indexB * 3];
  18584. var b_y = vertices[indexB * 3 + 1];
  18585. var b_z = vertices[indexB * 3 + 2];
  18586. var c_x = vertices[indexC * 3];
  18587. var c_y = vertices[indexC * 3 + 1];
  18588. var c_z = vertices[indexC * 3 + 2];
  18589. var d_x = vertices[indexD * 3];
  18590. var d_y = vertices[indexD * 3 + 1];
  18591. var d_z = vertices[indexD * 3 + 2];
  18592. if (Math.abs(a_y - b_y) < 0.01) {
  18593. 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)];
  18594. } else {
  18595. 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)];
  18596. }
  18597. }
  18598. };
  18599. function _toJSON(shapes, options, data) {
  18600. data.shapes = [];
  18601. if (Array.isArray(shapes)) {
  18602. for (var i = 0, l = shapes.length; i < l; i++) {
  18603. var shape = shapes[i];
  18604. data.shapes.push(shape.uuid);
  18605. }
  18606. } else {
  18607. data.shapes.push(shapes.uuid);
  18608. }
  18609. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18610. return data;
  18611. }
  18612. var IcosahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18613. _inheritsLoose(IcosahedronGeometry, _PolyhedronGeometry);
  18614. function IcosahedronGeometry(radius, detail) {
  18615. var _this;
  18616. if (radius === void 0) {
  18617. radius = 1;
  18618. }
  18619. if (detail === void 0) {
  18620. detail = 0;
  18621. }
  18622. var t = (1 + Math.sqrt(5)) / 2;
  18623. 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];
  18624. 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];
  18625. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18626. _this.type = 'IcosahedronGeometry';
  18627. _this.parameters = {
  18628. radius: radius,
  18629. detail: detail
  18630. };
  18631. return _this;
  18632. }
  18633. return IcosahedronGeometry;
  18634. }(PolyhedronGeometry);
  18635. var LatheGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18636. _inheritsLoose(LatheGeometry, _BufferGeometry);
  18637. function LatheGeometry(points, segments, phiStart, phiLength) {
  18638. var _this;
  18639. if (segments === void 0) {
  18640. segments = 12;
  18641. }
  18642. if (phiStart === void 0) {
  18643. phiStart = 0;
  18644. }
  18645. if (phiLength === void 0) {
  18646. phiLength = Math.PI * 2;
  18647. }
  18648. _this = _BufferGeometry.call(this) || this;
  18649. _this.type = 'LatheGeometry';
  18650. _this.parameters = {
  18651. points: points,
  18652. segments: segments,
  18653. phiStart: phiStart,
  18654. phiLength: phiLength
  18655. };
  18656. segments = Math.floor(segments); // clamp phiLength so it's in range of [ 0, 2PI ]
  18657. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  18658. var indices = [];
  18659. var vertices = [];
  18660. var uvs = []; // helper variables
  18661. var inverseSegments = 1.0 / segments;
  18662. var vertex = new Vector3();
  18663. var uv = new Vector2(); // generate vertices and uvs
  18664. for (var i = 0; i <= segments; i++) {
  18665. var phi = phiStart + i * inverseSegments * phiLength;
  18666. var sin = Math.sin(phi);
  18667. var cos = Math.cos(phi);
  18668. for (var j = 0; j <= points.length - 1; j++) {
  18669. // vertex
  18670. vertex.x = points[j].x * sin;
  18671. vertex.y = points[j].y;
  18672. vertex.z = points[j].x * cos;
  18673. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  18674. uv.x = i / segments;
  18675. uv.y = j / (points.length - 1);
  18676. uvs.push(uv.x, uv.y);
  18677. }
  18678. } // indices
  18679. for (var _i = 0; _i < segments; _i++) {
  18680. for (var _j = 0; _j < points.length - 1; _j++) {
  18681. var base = _j + _i * points.length;
  18682. var a = base;
  18683. var b = base + points.length;
  18684. var c = base + points.length + 1;
  18685. var d = base + 1; // faces
  18686. indices.push(a, b, d);
  18687. indices.push(b, c, d);
  18688. }
  18689. } // build geometry
  18690. _this.setIndex(indices);
  18691. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18692. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  18693. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  18694. // because the corresponding vertices are identical (but still have different UVs).
  18695. if (phiLength === Math.PI * 2) {
  18696. var normals = _this.attributes.normal.array;
  18697. var n1 = new Vector3();
  18698. var n2 = new Vector3();
  18699. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  18700. var _base = segments * points.length * 3;
  18701. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  18702. // select the normal of the vertex in the first line
  18703. n1.x = normals[_j2 + 0];
  18704. n1.y = normals[_j2 + 1];
  18705. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  18706. n2.x = normals[_base + _j2 + 0];
  18707. n2.y = normals[_base + _j2 + 1];
  18708. n2.z = normals[_base + _j2 + 2]; // average normals
  18709. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  18710. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  18711. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  18712. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  18713. }
  18714. }
  18715. return _this;
  18716. }
  18717. return LatheGeometry;
  18718. }(BufferGeometry);
  18719. var OctahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18720. _inheritsLoose(OctahedronGeometry, _PolyhedronGeometry);
  18721. function OctahedronGeometry(radius, detail) {
  18722. var _this;
  18723. if (radius === void 0) {
  18724. radius = 1;
  18725. }
  18726. if (detail === void 0) {
  18727. detail = 0;
  18728. }
  18729. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  18730. 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];
  18731. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18732. _this.type = 'OctahedronGeometry';
  18733. _this.parameters = {
  18734. radius: radius,
  18735. detail: detail
  18736. };
  18737. return _this;
  18738. }
  18739. return OctahedronGeometry;
  18740. }(PolyhedronGeometry);
  18741. /**
  18742. * Parametric Surfaces Geometry
  18743. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18744. */
  18745. function ParametricGeometry(func, slices, stacks) {
  18746. BufferGeometry.call(this);
  18747. this.type = 'ParametricGeometry';
  18748. this.parameters = {
  18749. func: func,
  18750. slices: slices,
  18751. stacks: stacks
  18752. }; // buffers
  18753. var indices = [];
  18754. var vertices = [];
  18755. var normals = [];
  18756. var uvs = [];
  18757. var EPS = 0.00001;
  18758. var normal = new Vector3();
  18759. var p0 = new Vector3(),
  18760. p1 = new Vector3();
  18761. var pu = new Vector3(),
  18762. pv = new Vector3();
  18763. if (func.length < 3) {
  18764. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  18765. } // generate vertices, normals and uvs
  18766. var sliceCount = slices + 1;
  18767. for (var i = 0; i <= stacks; i++) {
  18768. var v = i / stacks;
  18769. for (var j = 0; j <= slices; j++) {
  18770. var u = j / slices; // vertex
  18771. func(u, v, p0);
  18772. vertices.push(p0.x, p0.y, p0.z); // normal
  18773. // approximate tangent vectors via finite differences
  18774. if (u - EPS >= 0) {
  18775. func(u - EPS, v, p1);
  18776. pu.subVectors(p0, p1);
  18777. } else {
  18778. func(u + EPS, v, p1);
  18779. pu.subVectors(p1, p0);
  18780. }
  18781. if (v - EPS >= 0) {
  18782. func(u, v - EPS, p1);
  18783. pv.subVectors(p0, p1);
  18784. } else {
  18785. func(u, v + EPS, p1);
  18786. pv.subVectors(p1, p0);
  18787. } // cross product of tangent vectors returns surface normal
  18788. normal.crossVectors(pu, pv).normalize();
  18789. normals.push(normal.x, normal.y, normal.z); // uv
  18790. uvs.push(u, v);
  18791. }
  18792. } // generate indices
  18793. for (var _i = 0; _i < stacks; _i++) {
  18794. for (var _j = 0; _j < slices; _j++) {
  18795. var a = _i * sliceCount + _j;
  18796. var b = _i * sliceCount + _j + 1;
  18797. var c = (_i + 1) * sliceCount + _j + 1;
  18798. var d = (_i + 1) * sliceCount + _j; // faces one and two
  18799. indices.push(a, b, d);
  18800. indices.push(b, c, d);
  18801. }
  18802. } // build geometry
  18803. this.setIndex(indices);
  18804. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18805. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18806. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18807. }
  18808. ParametricGeometry.prototype = Object.create(BufferGeometry.prototype);
  18809. ParametricGeometry.prototype.constructor = ParametricGeometry;
  18810. var RingGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18811. _inheritsLoose(RingGeometry, _BufferGeometry);
  18812. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  18813. var _this;
  18814. if (innerRadius === void 0) {
  18815. innerRadius = 0.5;
  18816. }
  18817. if (outerRadius === void 0) {
  18818. outerRadius = 1;
  18819. }
  18820. if (thetaSegments === void 0) {
  18821. thetaSegments = 8;
  18822. }
  18823. if (phiSegments === void 0) {
  18824. phiSegments = 1;
  18825. }
  18826. if (thetaStart === void 0) {
  18827. thetaStart = 0;
  18828. }
  18829. if (thetaLength === void 0) {
  18830. thetaLength = Math.PI * 2;
  18831. }
  18832. _this = _BufferGeometry.call(this) || this;
  18833. _this.type = 'RingGeometry';
  18834. _this.parameters = {
  18835. innerRadius: innerRadius,
  18836. outerRadius: outerRadius,
  18837. thetaSegments: thetaSegments,
  18838. phiSegments: phiSegments,
  18839. thetaStart: thetaStart,
  18840. thetaLength: thetaLength
  18841. };
  18842. thetaSegments = Math.max(3, thetaSegments);
  18843. phiSegments = Math.max(1, phiSegments); // buffers
  18844. var indices = [];
  18845. var vertices = [];
  18846. var normals = [];
  18847. var uvs = []; // some helper variables
  18848. var radius = innerRadius;
  18849. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  18850. var vertex = new Vector3();
  18851. var uv = new Vector2(); // generate vertices, normals and uvs
  18852. for (var j = 0; j <= phiSegments; j++) {
  18853. for (var i = 0; i <= thetaSegments; i++) {
  18854. // values are generate from the inside of the ring to the outside
  18855. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  18856. vertex.x = radius * Math.cos(segment);
  18857. vertex.y = radius * Math.sin(segment);
  18858. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  18859. normals.push(0, 0, 1); // uv
  18860. uv.x = (vertex.x / outerRadius + 1) / 2;
  18861. uv.y = (vertex.y / outerRadius + 1) / 2;
  18862. uvs.push(uv.x, uv.y);
  18863. } // increase the radius for next row of vertices
  18864. radius += radiusStep;
  18865. } // indices
  18866. for (var _j = 0; _j < phiSegments; _j++) {
  18867. var thetaSegmentLevel = _j * (thetaSegments + 1);
  18868. for (var _i = 0; _i < thetaSegments; _i++) {
  18869. var _segment = _i + thetaSegmentLevel;
  18870. var a = _segment;
  18871. var b = _segment + thetaSegments + 1;
  18872. var c = _segment + thetaSegments + 2;
  18873. var d = _segment + 1; // faces
  18874. indices.push(a, b, d);
  18875. indices.push(b, c, d);
  18876. }
  18877. } // build geometry
  18878. _this.setIndex(indices);
  18879. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18880. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18881. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18882. return _this;
  18883. }
  18884. return RingGeometry;
  18885. }(BufferGeometry);
  18886. var ShapeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18887. _inheritsLoose(ShapeGeometry, _BufferGeometry);
  18888. function ShapeGeometry(shapes, curveSegments) {
  18889. var _this;
  18890. if (curveSegments === void 0) {
  18891. curveSegments = 12;
  18892. }
  18893. _this = _BufferGeometry.call(this) || this;
  18894. _this.type = 'ShapeGeometry';
  18895. _this.parameters = {
  18896. shapes: shapes,
  18897. curveSegments: curveSegments
  18898. }; // buffers
  18899. var indices = [];
  18900. var vertices = [];
  18901. var normals = [];
  18902. var uvs = []; // helper variables
  18903. var groupStart = 0;
  18904. var groupCount = 0; // allow single and array values for "shapes" parameter
  18905. if (Array.isArray(shapes) === false) {
  18906. addShape(shapes);
  18907. } else {
  18908. for (var i = 0; i < shapes.length; i++) {
  18909. addShape(shapes[i]);
  18910. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  18911. groupStart += groupCount;
  18912. groupCount = 0;
  18913. }
  18914. } // build geometry
  18915. _this.setIndex(indices);
  18916. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18917. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18918. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  18919. function addShape(shape) {
  18920. var indexOffset = vertices.length / 3;
  18921. var points = shape.extractPoints(curveSegments);
  18922. var shapeVertices = points.shape;
  18923. var shapeHoles = points.holes; // check direction of vertices
  18924. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  18925. shapeVertices = shapeVertices.reverse();
  18926. }
  18927. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  18928. var shapeHole = shapeHoles[_i];
  18929. if (ShapeUtils.isClockWise(shapeHole) === true) {
  18930. shapeHoles[_i] = shapeHole.reverse();
  18931. }
  18932. }
  18933. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  18934. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  18935. var _shapeHole = shapeHoles[_i2];
  18936. shapeVertices = shapeVertices.concat(_shapeHole);
  18937. } // vertices, normals, uvs
  18938. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  18939. var vertex = shapeVertices[_i3];
  18940. vertices.push(vertex.x, vertex.y, 0);
  18941. normals.push(0, 0, 1);
  18942. uvs.push(vertex.x, vertex.y); // world uvs
  18943. } // incides
  18944. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  18945. var face = faces[_i4];
  18946. var a = face[0] + indexOffset;
  18947. var b = face[1] + indexOffset;
  18948. var c = face[2] + indexOffset;
  18949. indices.push(a, b, c);
  18950. groupCount += 3;
  18951. }
  18952. }
  18953. return _this;
  18954. }
  18955. var _proto = ShapeGeometry.prototype;
  18956. _proto.toJSON = function toJSON() {
  18957. var data = BufferGeometry.prototype.toJSON.call(this);
  18958. var shapes = this.parameters.shapes;
  18959. return _toJSON$1(shapes, data);
  18960. };
  18961. return ShapeGeometry;
  18962. }(BufferGeometry);
  18963. function _toJSON$1(shapes, data) {
  18964. data.shapes = [];
  18965. if (Array.isArray(shapes)) {
  18966. for (var i = 0, l = shapes.length; i < l; i++) {
  18967. var shape = shapes[i];
  18968. data.shapes.push(shape.uuid);
  18969. }
  18970. } else {
  18971. data.shapes.push(shapes.uuid);
  18972. }
  18973. return data;
  18974. }
  18975. var SphereGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18976. _inheritsLoose(SphereGeometry, _BufferGeometry);
  18977. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  18978. var _this;
  18979. if (radius === void 0) {
  18980. radius = 1;
  18981. }
  18982. if (widthSegments === void 0) {
  18983. widthSegments = 8;
  18984. }
  18985. if (heightSegments === void 0) {
  18986. heightSegments = 6;
  18987. }
  18988. if (phiStart === void 0) {
  18989. phiStart = 0;
  18990. }
  18991. if (phiLength === void 0) {
  18992. phiLength = Math.PI * 2;
  18993. }
  18994. if (thetaStart === void 0) {
  18995. thetaStart = 0;
  18996. }
  18997. if (thetaLength === void 0) {
  18998. thetaLength = Math.PI;
  18999. }
  19000. _this = _BufferGeometry.call(this) || this;
  19001. _this.type = 'SphereGeometry';
  19002. _this.parameters = {
  19003. radius: radius,
  19004. widthSegments: widthSegments,
  19005. heightSegments: heightSegments,
  19006. phiStart: phiStart,
  19007. phiLength: phiLength,
  19008. thetaStart: thetaStart,
  19009. thetaLength: thetaLength
  19010. };
  19011. widthSegments = Math.max(3, Math.floor(widthSegments));
  19012. heightSegments = Math.max(2, Math.floor(heightSegments));
  19013. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  19014. var index = 0;
  19015. var grid = [];
  19016. var vertex = new Vector3();
  19017. var normal = new Vector3(); // buffers
  19018. var indices = [];
  19019. var vertices = [];
  19020. var normals = [];
  19021. var uvs = []; // generate vertices, normals and uvs
  19022. for (var iy = 0; iy <= heightSegments; iy++) {
  19023. var verticesRow = [];
  19024. var v = iy / heightSegments; // special case for the poles
  19025. var uOffset = 0;
  19026. if (iy == 0 && thetaStart == 0) {
  19027. uOffset = 0.5 / widthSegments;
  19028. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  19029. uOffset = -0.5 / widthSegments;
  19030. }
  19031. for (var ix = 0; ix <= widthSegments; ix++) {
  19032. var u = ix / widthSegments; // vertex
  19033. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19034. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  19035. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19036. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19037. normal.copy(vertex).normalize();
  19038. normals.push(normal.x, normal.y, normal.z); // uv
  19039. uvs.push(u + uOffset, 1 - v);
  19040. verticesRow.push(index++);
  19041. }
  19042. grid.push(verticesRow);
  19043. } // indices
  19044. for (var _iy = 0; _iy < heightSegments; _iy++) {
  19045. for (var _ix = 0; _ix < widthSegments; _ix++) {
  19046. var a = grid[_iy][_ix + 1];
  19047. var b = grid[_iy][_ix];
  19048. var c = grid[_iy + 1][_ix];
  19049. var d = grid[_iy + 1][_ix + 1];
  19050. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  19051. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  19052. }
  19053. } // build geometry
  19054. _this.setIndex(indices);
  19055. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19056. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19057. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19058. return _this;
  19059. }
  19060. return SphereGeometry;
  19061. }(BufferGeometry);
  19062. var TetrahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  19063. _inheritsLoose(TetrahedronGeometry, _PolyhedronGeometry);
  19064. function TetrahedronGeometry(radius, detail) {
  19065. var _this;
  19066. if (radius === void 0) {
  19067. radius = 1;
  19068. }
  19069. if (detail === void 0) {
  19070. detail = 0;
  19071. }
  19072. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  19073. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  19074. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  19075. _this.type = 'TetrahedronGeometry';
  19076. _this.parameters = {
  19077. radius: radius,
  19078. detail: detail
  19079. };
  19080. return _this;
  19081. }
  19082. return TetrahedronGeometry;
  19083. }(PolyhedronGeometry);
  19084. var TextGeometry = /*#__PURE__*/function (_ExtrudeGeometry) {
  19085. _inheritsLoose(TextGeometry, _ExtrudeGeometry);
  19086. function TextGeometry(text, parameters) {
  19087. var _this;
  19088. if (parameters === void 0) {
  19089. parameters = {};
  19090. }
  19091. var font = parameters.font;
  19092. if (!(font && font.isFont)) {
  19093. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  19094. return new BufferGeometry() || _assertThisInitialized(_this);
  19095. }
  19096. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  19097. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  19098. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  19099. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  19100. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  19101. _this = _ExtrudeGeometry.call(this, shapes, parameters) || this;
  19102. _this.type = 'TextGeometry';
  19103. return _this;
  19104. }
  19105. return TextGeometry;
  19106. }(ExtrudeGeometry);
  19107. var TorusGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19108. _inheritsLoose(TorusGeometry, _BufferGeometry);
  19109. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19110. var _this;
  19111. if (radius === void 0) {
  19112. radius = 1;
  19113. }
  19114. if (tube === void 0) {
  19115. tube = 0.4;
  19116. }
  19117. if (radialSegments === void 0) {
  19118. radialSegments = 8;
  19119. }
  19120. if (tubularSegments === void 0) {
  19121. tubularSegments = 6;
  19122. }
  19123. if (arc === void 0) {
  19124. arc = Math.PI * 2;
  19125. }
  19126. _this = _BufferGeometry.call(this) || this;
  19127. _this.type = 'TorusGeometry';
  19128. _this.parameters = {
  19129. radius: radius,
  19130. tube: tube,
  19131. radialSegments: radialSegments,
  19132. tubularSegments: tubularSegments,
  19133. arc: arc
  19134. };
  19135. radialSegments = Math.floor(radialSegments);
  19136. tubularSegments = Math.floor(tubularSegments); // buffers
  19137. var indices = [];
  19138. var vertices = [];
  19139. var normals = [];
  19140. var uvs = []; // helper variables
  19141. var center = new Vector3();
  19142. var vertex = new Vector3();
  19143. var normal = new Vector3(); // generate vertices, normals and uvs
  19144. for (var j = 0; j <= radialSegments; j++) {
  19145. for (var i = 0; i <= tubularSegments; i++) {
  19146. var u = i / tubularSegments * arc;
  19147. var v = j / radialSegments * Math.PI * 2; // vertex
  19148. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  19149. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  19150. vertex.z = tube * Math.sin(v);
  19151. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19152. center.x = radius * Math.cos(u);
  19153. center.y = radius * Math.sin(u);
  19154. normal.subVectors(vertex, center).normalize();
  19155. normals.push(normal.x, normal.y, normal.z); // uv
  19156. uvs.push(i / tubularSegments);
  19157. uvs.push(j / radialSegments);
  19158. }
  19159. } // generate indices
  19160. for (var _j = 1; _j <= radialSegments; _j++) {
  19161. for (var _i = 1; _i <= tubularSegments; _i++) {
  19162. // indices
  19163. var a = (tubularSegments + 1) * _j + _i - 1;
  19164. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  19165. var c = (tubularSegments + 1) * (_j - 1) + _i;
  19166. var d = (tubularSegments + 1) * _j + _i; // faces
  19167. indices.push(a, b, d);
  19168. indices.push(b, c, d);
  19169. }
  19170. } // build geometry
  19171. _this.setIndex(indices);
  19172. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19173. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19174. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19175. return _this;
  19176. }
  19177. return TorusGeometry;
  19178. }(BufferGeometry);
  19179. var TorusKnotGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19180. _inheritsLoose(TorusKnotGeometry, _BufferGeometry);
  19181. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  19182. var _this;
  19183. if (radius === void 0) {
  19184. radius = 1;
  19185. }
  19186. if (tube === void 0) {
  19187. tube = 0.4;
  19188. }
  19189. if (tubularSegments === void 0) {
  19190. tubularSegments = 64;
  19191. }
  19192. if (radialSegments === void 0) {
  19193. radialSegments = 8;
  19194. }
  19195. if (p === void 0) {
  19196. p = 2;
  19197. }
  19198. if (q === void 0) {
  19199. q = 3;
  19200. }
  19201. _this = _BufferGeometry.call(this) || this;
  19202. _this.type = 'TorusKnotGeometry';
  19203. _this.parameters = {
  19204. radius: radius,
  19205. tube: tube,
  19206. tubularSegments: tubularSegments,
  19207. radialSegments: radialSegments,
  19208. p: p,
  19209. q: q
  19210. };
  19211. tubularSegments = Math.floor(tubularSegments);
  19212. radialSegments = Math.floor(radialSegments); // buffers
  19213. var indices = [];
  19214. var vertices = [];
  19215. var normals = [];
  19216. var uvs = []; // helper variables
  19217. var vertex = new Vector3();
  19218. var normal = new Vector3();
  19219. var P1 = new Vector3();
  19220. var P2 = new Vector3();
  19221. var B = new Vector3();
  19222. var T = new Vector3();
  19223. var N = new Vector3(); // generate vertices, normals and uvs
  19224. for (var i = 0; i <= tubularSegments; ++i) {
  19225. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19226. 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.
  19227. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19228. calculatePositionOnCurve(u, p, q, radius, P1);
  19229. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  19230. T.subVectors(P2, P1);
  19231. N.addVectors(P2, P1);
  19232. B.crossVectors(T, N);
  19233. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  19234. B.normalize();
  19235. N.normalize();
  19236. for (var j = 0; j <= radialSegments; ++j) {
  19237. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19238. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19239. var v = j / radialSegments * Math.PI * 2;
  19240. var cx = -tube * Math.cos(v);
  19241. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  19242. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19243. vertex.x = P1.x + (cx * N.x + cy * B.x);
  19244. vertex.y = P1.y + (cx * N.y + cy * B.y);
  19245. vertex.z = P1.z + (cx * N.z + cy * B.z);
  19246. 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)
  19247. normal.subVectors(vertex, P1).normalize();
  19248. normals.push(normal.x, normal.y, normal.z); // uv
  19249. uvs.push(i / tubularSegments);
  19250. uvs.push(j / radialSegments);
  19251. }
  19252. } // generate indices
  19253. for (var _j = 1; _j <= tubularSegments; _j++) {
  19254. for (var _i = 1; _i <= radialSegments; _i++) {
  19255. // indices
  19256. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  19257. var b = (radialSegments + 1) * _j + (_i - 1);
  19258. var c = (radialSegments + 1) * _j + _i;
  19259. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  19260. indices.push(a, b, d);
  19261. indices.push(b, c, d);
  19262. }
  19263. } // build geometry
  19264. _this.setIndex(indices);
  19265. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19266. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19267. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  19268. function calculatePositionOnCurve(u, p, q, radius, position) {
  19269. var cu = Math.cos(u);
  19270. var su = Math.sin(u);
  19271. var quOverP = q / p * u;
  19272. var cs = Math.cos(quOverP);
  19273. position.x = radius * (2 + cs) * 0.5 * cu;
  19274. position.y = radius * (2 + cs) * su * 0.5;
  19275. position.z = radius * Math.sin(quOverP) * 0.5;
  19276. }
  19277. return _this;
  19278. }
  19279. return TorusKnotGeometry;
  19280. }(BufferGeometry);
  19281. var TubeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19282. _inheritsLoose(TubeGeometry, _BufferGeometry);
  19283. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed) {
  19284. var _this;
  19285. if (tubularSegments === void 0) {
  19286. tubularSegments = 64;
  19287. }
  19288. if (radius === void 0) {
  19289. radius = 1;
  19290. }
  19291. if (radialSegments === void 0) {
  19292. radialSegments = 8;
  19293. }
  19294. if (closed === void 0) {
  19295. closed = false;
  19296. }
  19297. _this = _BufferGeometry.call(this) || this;
  19298. _this.type = 'TubeGeometry';
  19299. _this.parameters = {
  19300. path: path,
  19301. tubularSegments: tubularSegments,
  19302. radius: radius,
  19303. radialSegments: radialSegments,
  19304. closed: closed
  19305. };
  19306. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  19307. _this.tangents = frames.tangents;
  19308. _this.normals = frames.normals;
  19309. _this.binormals = frames.binormals; // helper variables
  19310. var vertex = new Vector3();
  19311. var normal = new Vector3();
  19312. var uv = new Vector2();
  19313. var P = new Vector3(); // buffer
  19314. var vertices = [];
  19315. var normals = [];
  19316. var uvs = [];
  19317. var indices = []; // create buffer data
  19318. generateBufferData(); // build geometry
  19319. _this.setIndex(indices);
  19320. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19321. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19322. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  19323. function generateBufferData() {
  19324. for (var i = 0; i < tubularSegments; i++) {
  19325. generateSegment(i);
  19326. } // if the geometry is not closed, generate the last row of vertices and normals
  19327. // at the regular position on the given path
  19328. //
  19329. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19330. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  19331. // this makes it easy compute correct values for closed geometries
  19332. generateUVs(); // finally create faces
  19333. generateIndices();
  19334. }
  19335. function generateSegment(i) {
  19336. // we use getPointAt to sample evenly distributed points from the given path
  19337. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  19338. var N = frames.normals[i];
  19339. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  19340. for (var j = 0; j <= radialSegments; j++) {
  19341. var v = j / radialSegments * Math.PI * 2;
  19342. var sin = Math.sin(v);
  19343. var cos = -Math.cos(v); // normal
  19344. normal.x = cos * N.x + sin * B.x;
  19345. normal.y = cos * N.y + sin * B.y;
  19346. normal.z = cos * N.z + sin * B.z;
  19347. normal.normalize();
  19348. normals.push(normal.x, normal.y, normal.z); // vertex
  19349. vertex.x = P.x + radius * normal.x;
  19350. vertex.y = P.y + radius * normal.y;
  19351. vertex.z = P.z + radius * normal.z;
  19352. vertices.push(vertex.x, vertex.y, vertex.z);
  19353. }
  19354. }
  19355. function generateIndices() {
  19356. for (var j = 1; j <= tubularSegments; j++) {
  19357. for (var i = 1; i <= radialSegments; i++) {
  19358. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  19359. var b = (radialSegments + 1) * j + (i - 1);
  19360. var c = (radialSegments + 1) * j + i;
  19361. var d = (radialSegments + 1) * (j - 1) + i; // faces
  19362. indices.push(a, b, d);
  19363. indices.push(b, c, d);
  19364. }
  19365. }
  19366. }
  19367. function generateUVs() {
  19368. for (var i = 0; i <= tubularSegments; i++) {
  19369. for (var j = 0; j <= radialSegments; j++) {
  19370. uv.x = i / tubularSegments;
  19371. uv.y = j / radialSegments;
  19372. uvs.push(uv.x, uv.y);
  19373. }
  19374. }
  19375. }
  19376. return _this;
  19377. }
  19378. var _proto = TubeGeometry.prototype;
  19379. _proto.toJSON = function toJSON() {
  19380. var data = BufferGeometry.prototype.toJSON.call(this);
  19381. data.path = this.parameters.path.toJSON();
  19382. return data;
  19383. };
  19384. return TubeGeometry;
  19385. }(BufferGeometry);
  19386. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19387. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  19388. function WireframeGeometry(geometry) {
  19389. var _this;
  19390. _this = _BufferGeometry.call(this) || this;
  19391. _this.type = 'WireframeGeometry';
  19392. if (geometry.isGeometry === true) {
  19393. console.error('THREE.WireframeGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  19394. return _assertThisInitialized(_this);
  19395. } // buffer
  19396. var vertices = []; // helper variables
  19397. var edge = [0, 0],
  19398. edges = {};
  19399. var vertex = new Vector3();
  19400. if (geometry.index !== null) {
  19401. // indexed BufferGeometry
  19402. var position = geometry.attributes.position;
  19403. var indices = geometry.index;
  19404. var groups = geometry.groups;
  19405. if (groups.length === 0) {
  19406. groups = [{
  19407. start: 0,
  19408. count: indices.count,
  19409. materialIndex: 0
  19410. }];
  19411. } // create a data structure that contains all eges without duplicates
  19412. for (var o = 0, ol = groups.length; o < ol; ++o) {
  19413. var group = groups[o];
  19414. var start = group.start;
  19415. var count = group.count;
  19416. for (var i = start, l = start + count; i < l; i += 3) {
  19417. for (var j = 0; j < 3; j++) {
  19418. var edge1 = indices.getX(i + j);
  19419. var edge2 = indices.getX(i + (j + 1) % 3);
  19420. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  19421. edge[1] = Math.max(edge1, edge2);
  19422. var key = edge[0] + ',' + edge[1];
  19423. if (edges[key] === undefined) {
  19424. edges[key] = {
  19425. index1: edge[0],
  19426. index2: edge[1]
  19427. };
  19428. }
  19429. }
  19430. }
  19431. } // generate vertices
  19432. for (var _key in edges) {
  19433. var e = edges[_key];
  19434. vertex.fromBufferAttribute(position, e.index1);
  19435. vertices.push(vertex.x, vertex.y, vertex.z);
  19436. vertex.fromBufferAttribute(position, e.index2);
  19437. vertices.push(vertex.x, vertex.y, vertex.z);
  19438. }
  19439. } else {
  19440. // non-indexed BufferGeometry
  19441. var _position = geometry.attributes.position;
  19442. for (var _i = 0, _l = _position.count / 3; _i < _l; _i++) {
  19443. for (var _j = 0; _j < 3; _j++) {
  19444. // three edges per triangle, an edge is represented as (index1, index2)
  19445. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  19446. var index1 = 3 * _i + _j;
  19447. vertex.fromBufferAttribute(_position, index1);
  19448. vertices.push(vertex.x, vertex.y, vertex.z);
  19449. var index2 = 3 * _i + (_j + 1) % 3;
  19450. vertex.fromBufferAttribute(_position, index2);
  19451. vertices.push(vertex.x, vertex.y, vertex.z);
  19452. }
  19453. }
  19454. } // build geometry
  19455. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19456. return _this;
  19457. }
  19458. return WireframeGeometry;
  19459. }(BufferGeometry);
  19460. var Geometries = /*#__PURE__*/Object.freeze({
  19461. __proto__: null,
  19462. BoxGeometry: BoxGeometry,
  19463. BoxBufferGeometry: BoxGeometry,
  19464. CircleGeometry: CircleGeometry,
  19465. CircleBufferGeometry: CircleGeometry,
  19466. ConeGeometry: ConeGeometry,
  19467. ConeBufferGeometry: ConeGeometry,
  19468. CylinderGeometry: CylinderGeometry,
  19469. CylinderBufferGeometry: CylinderGeometry,
  19470. DodecahedronGeometry: DodecahedronGeometry,
  19471. DodecahedronBufferGeometry: DodecahedronGeometry,
  19472. EdgesGeometry: EdgesGeometry,
  19473. ExtrudeGeometry: ExtrudeGeometry,
  19474. ExtrudeBufferGeometry: ExtrudeGeometry,
  19475. IcosahedronGeometry: IcosahedronGeometry,
  19476. IcosahedronBufferGeometry: IcosahedronGeometry,
  19477. LatheGeometry: LatheGeometry,
  19478. LatheBufferGeometry: LatheGeometry,
  19479. OctahedronGeometry: OctahedronGeometry,
  19480. OctahedronBufferGeometry: OctahedronGeometry,
  19481. ParametricGeometry: ParametricGeometry,
  19482. ParametricBufferGeometry: ParametricGeometry,
  19483. PlaneGeometry: PlaneGeometry,
  19484. PlaneBufferGeometry: PlaneGeometry,
  19485. PolyhedronGeometry: PolyhedronGeometry,
  19486. PolyhedronBufferGeometry: PolyhedronGeometry,
  19487. RingGeometry: RingGeometry,
  19488. RingBufferGeometry: RingGeometry,
  19489. ShapeGeometry: ShapeGeometry,
  19490. ShapeBufferGeometry: ShapeGeometry,
  19491. SphereGeometry: SphereGeometry,
  19492. SphereBufferGeometry: SphereGeometry,
  19493. TetrahedronGeometry: TetrahedronGeometry,
  19494. TetrahedronBufferGeometry: TetrahedronGeometry,
  19495. TextGeometry: TextGeometry,
  19496. TextBufferGeometry: TextGeometry,
  19497. TorusGeometry: TorusGeometry,
  19498. TorusBufferGeometry: TorusGeometry,
  19499. TorusKnotGeometry: TorusKnotGeometry,
  19500. TorusKnotBufferGeometry: TorusKnotGeometry,
  19501. TubeGeometry: TubeGeometry,
  19502. TubeBufferGeometry: TubeGeometry,
  19503. WireframeGeometry: WireframeGeometry
  19504. });
  19505. /**
  19506. * parameters = {
  19507. * color: <THREE.Color>
  19508. * }
  19509. */
  19510. function ShadowMaterial(parameters) {
  19511. Material.call(this);
  19512. this.type = 'ShadowMaterial';
  19513. this.color = new Color(0x000000);
  19514. this.transparent = true;
  19515. this.setValues(parameters);
  19516. }
  19517. ShadowMaterial.prototype = Object.create(Material.prototype);
  19518. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19519. ShadowMaterial.prototype.isShadowMaterial = true;
  19520. ShadowMaterial.prototype.copy = function (source) {
  19521. Material.prototype.copy.call(this, source);
  19522. this.color.copy(source.color);
  19523. return this;
  19524. };
  19525. function RawShaderMaterial(parameters) {
  19526. ShaderMaterial.call(this, parameters);
  19527. this.type = 'RawShaderMaterial';
  19528. }
  19529. RawShaderMaterial.prototype = Object.create(ShaderMaterial.prototype);
  19530. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19531. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19532. /**
  19533. * parameters = {
  19534. * color: <hex>,
  19535. * roughness: <float>,
  19536. * metalness: <float>,
  19537. * opacity: <float>,
  19538. *
  19539. * map: new THREE.Texture( <Image> ),
  19540. *
  19541. * lightMap: new THREE.Texture( <Image> ),
  19542. * lightMapIntensity: <float>
  19543. *
  19544. * aoMap: new THREE.Texture( <Image> ),
  19545. * aoMapIntensity: <float>
  19546. *
  19547. * emissive: <hex>,
  19548. * emissiveIntensity: <float>
  19549. * emissiveMap: new THREE.Texture( <Image> ),
  19550. *
  19551. * bumpMap: new THREE.Texture( <Image> ),
  19552. * bumpScale: <float>,
  19553. *
  19554. * normalMap: new THREE.Texture( <Image> ),
  19555. * normalMapType: THREE.TangentSpaceNormalMap,
  19556. * normalScale: <Vector2>,
  19557. *
  19558. * displacementMap: new THREE.Texture( <Image> ),
  19559. * displacementScale: <float>,
  19560. * displacementBias: <float>,
  19561. *
  19562. * roughnessMap: new THREE.Texture( <Image> ),
  19563. *
  19564. * metalnessMap: new THREE.Texture( <Image> ),
  19565. *
  19566. * alphaMap: new THREE.Texture( <Image> ),
  19567. *
  19568. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19569. * envMapIntensity: <float>
  19570. *
  19571. * refractionRatio: <float>,
  19572. *
  19573. * wireframe: <boolean>,
  19574. * wireframeLinewidth: <float>,
  19575. *
  19576. * skinning: <bool>,
  19577. * morphTargets: <bool>,
  19578. * morphNormals: <bool>
  19579. * }
  19580. */
  19581. function MeshStandardMaterial(parameters) {
  19582. Material.call(this);
  19583. this.defines = {
  19584. 'STANDARD': ''
  19585. };
  19586. this.type = 'MeshStandardMaterial';
  19587. this.color = new Color(0xffffff); // diffuse
  19588. this.roughness = 1.0;
  19589. this.metalness = 0.0;
  19590. this.map = null;
  19591. this.lightMap = null;
  19592. this.lightMapIntensity = 1.0;
  19593. this.aoMap = null;
  19594. this.aoMapIntensity = 1.0;
  19595. this.emissive = new Color(0x000000);
  19596. this.emissiveIntensity = 1.0;
  19597. this.emissiveMap = null;
  19598. this.bumpMap = null;
  19599. this.bumpScale = 1;
  19600. this.normalMap = null;
  19601. this.normalMapType = TangentSpaceNormalMap;
  19602. this.normalScale = new Vector2(1, 1);
  19603. this.displacementMap = null;
  19604. this.displacementScale = 1;
  19605. this.displacementBias = 0;
  19606. this.roughnessMap = null;
  19607. this.metalnessMap = null;
  19608. this.alphaMap = null;
  19609. this.envMap = null;
  19610. this.envMapIntensity = 1.0;
  19611. this.refractionRatio = 0.98;
  19612. this.wireframe = false;
  19613. this.wireframeLinewidth = 1;
  19614. this.wireframeLinecap = 'round';
  19615. this.wireframeLinejoin = 'round';
  19616. this.skinning = false;
  19617. this.morphTargets = false;
  19618. this.morphNormals = false;
  19619. this.vertexTangents = false;
  19620. this.setValues(parameters);
  19621. }
  19622. MeshStandardMaterial.prototype = Object.create(Material.prototype);
  19623. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19624. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19625. MeshStandardMaterial.prototype.copy = function (source) {
  19626. Material.prototype.copy.call(this, source);
  19627. this.defines = {
  19628. 'STANDARD': ''
  19629. };
  19630. this.color.copy(source.color);
  19631. this.roughness = source.roughness;
  19632. this.metalness = source.metalness;
  19633. this.map = source.map;
  19634. this.lightMap = source.lightMap;
  19635. this.lightMapIntensity = source.lightMapIntensity;
  19636. this.aoMap = source.aoMap;
  19637. this.aoMapIntensity = source.aoMapIntensity;
  19638. this.emissive.copy(source.emissive);
  19639. this.emissiveMap = source.emissiveMap;
  19640. this.emissiveIntensity = source.emissiveIntensity;
  19641. this.bumpMap = source.bumpMap;
  19642. this.bumpScale = source.bumpScale;
  19643. this.normalMap = source.normalMap;
  19644. this.normalMapType = source.normalMapType;
  19645. this.normalScale.copy(source.normalScale);
  19646. this.displacementMap = source.displacementMap;
  19647. this.displacementScale = source.displacementScale;
  19648. this.displacementBias = source.displacementBias;
  19649. this.roughnessMap = source.roughnessMap;
  19650. this.metalnessMap = source.metalnessMap;
  19651. this.alphaMap = source.alphaMap;
  19652. this.envMap = source.envMap;
  19653. this.envMapIntensity = source.envMapIntensity;
  19654. this.refractionRatio = source.refractionRatio;
  19655. this.wireframe = source.wireframe;
  19656. this.wireframeLinewidth = source.wireframeLinewidth;
  19657. this.wireframeLinecap = source.wireframeLinecap;
  19658. this.wireframeLinejoin = source.wireframeLinejoin;
  19659. this.skinning = source.skinning;
  19660. this.morphTargets = source.morphTargets;
  19661. this.morphNormals = source.morphNormals;
  19662. this.vertexTangents = source.vertexTangents;
  19663. return this;
  19664. };
  19665. /**
  19666. * parameters = {
  19667. * clearcoat: <float>,
  19668. * clearcoatMap: new THREE.Texture( <Image> ),
  19669. * clearcoatRoughness: <float>,
  19670. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  19671. * clearcoatNormalScale: <Vector2>,
  19672. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  19673. *
  19674. * reflectivity: <float>,
  19675. * ior: <float>,
  19676. *
  19677. * sheen: <Color>,
  19678. *
  19679. * transmission: <float>,
  19680. * transmissionMap: new THREE.Texture( <Image> )
  19681. * }
  19682. */
  19683. function MeshPhysicalMaterial(parameters) {
  19684. MeshStandardMaterial.call(this);
  19685. this.defines = {
  19686. 'STANDARD': '',
  19687. 'PHYSICAL': ''
  19688. };
  19689. this.type = 'MeshPhysicalMaterial';
  19690. this.clearcoat = 0.0;
  19691. this.clearcoatMap = null;
  19692. this.clearcoatRoughness = 0.0;
  19693. this.clearcoatRoughnessMap = null;
  19694. this.clearcoatNormalScale = new Vector2(1, 1);
  19695. this.clearcoatNormalMap = null;
  19696. this.reflectivity = 0.5; // maps to F0 = 0.04
  19697. Object.defineProperty(this, 'ior', {
  19698. get: function get() {
  19699. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  19700. },
  19701. set: function set(ior) {
  19702. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  19703. }
  19704. });
  19705. this.sheen = null; // null will disable sheen bsdf
  19706. this.transmission = 0.0;
  19707. this.transmissionMap = null;
  19708. this.setValues(parameters);
  19709. }
  19710. MeshPhysicalMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
  19711. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  19712. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19713. MeshPhysicalMaterial.prototype.copy = function (source) {
  19714. MeshStandardMaterial.prototype.copy.call(this, source);
  19715. this.defines = {
  19716. 'STANDARD': '',
  19717. 'PHYSICAL': ''
  19718. };
  19719. this.clearcoat = source.clearcoat;
  19720. this.clearcoatMap = source.clearcoatMap;
  19721. this.clearcoatRoughness = source.clearcoatRoughness;
  19722. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  19723. this.clearcoatNormalMap = source.clearcoatNormalMap;
  19724. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  19725. this.reflectivity = source.reflectivity;
  19726. if (source.sheen) {
  19727. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  19728. } else {
  19729. this.sheen = null;
  19730. }
  19731. this.transmission = source.transmission;
  19732. this.transmissionMap = source.transmissionMap;
  19733. return this;
  19734. };
  19735. /**
  19736. * parameters = {
  19737. * color: <hex>,
  19738. * specular: <hex>,
  19739. * shininess: <float>,
  19740. * opacity: <float>,
  19741. *
  19742. * map: new THREE.Texture( <Image> ),
  19743. *
  19744. * lightMap: new THREE.Texture( <Image> ),
  19745. * lightMapIntensity: <float>
  19746. *
  19747. * aoMap: new THREE.Texture( <Image> ),
  19748. * aoMapIntensity: <float>
  19749. *
  19750. * emissive: <hex>,
  19751. * emissiveIntensity: <float>
  19752. * emissiveMap: new THREE.Texture( <Image> ),
  19753. *
  19754. * bumpMap: new THREE.Texture( <Image> ),
  19755. * bumpScale: <float>,
  19756. *
  19757. * normalMap: new THREE.Texture( <Image> ),
  19758. * normalMapType: THREE.TangentSpaceNormalMap,
  19759. * normalScale: <Vector2>,
  19760. *
  19761. * displacementMap: new THREE.Texture( <Image> ),
  19762. * displacementScale: <float>,
  19763. * displacementBias: <float>,
  19764. *
  19765. * specularMap: new THREE.Texture( <Image> ),
  19766. *
  19767. * alphaMap: new THREE.Texture( <Image> ),
  19768. *
  19769. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19770. * combine: THREE.MultiplyOperation,
  19771. * reflectivity: <float>,
  19772. * refractionRatio: <float>,
  19773. *
  19774. * wireframe: <boolean>,
  19775. * wireframeLinewidth: <float>,
  19776. *
  19777. * skinning: <bool>,
  19778. * morphTargets: <bool>,
  19779. * morphNormals: <bool>
  19780. * }
  19781. */
  19782. function MeshPhongMaterial(parameters) {
  19783. Material.call(this);
  19784. this.type = 'MeshPhongMaterial';
  19785. this.color = new Color(0xffffff); // diffuse
  19786. this.specular = new Color(0x111111);
  19787. this.shininess = 30;
  19788. this.map = null;
  19789. this.lightMap = null;
  19790. this.lightMapIntensity = 1.0;
  19791. this.aoMap = null;
  19792. this.aoMapIntensity = 1.0;
  19793. this.emissive = new Color(0x000000);
  19794. this.emissiveIntensity = 1.0;
  19795. this.emissiveMap = null;
  19796. this.bumpMap = null;
  19797. this.bumpScale = 1;
  19798. this.normalMap = null;
  19799. this.normalMapType = TangentSpaceNormalMap;
  19800. this.normalScale = new Vector2(1, 1);
  19801. this.displacementMap = null;
  19802. this.displacementScale = 1;
  19803. this.displacementBias = 0;
  19804. this.specularMap = null;
  19805. this.alphaMap = null;
  19806. this.envMap = null;
  19807. this.combine = MultiplyOperation;
  19808. this.reflectivity = 1;
  19809. this.refractionRatio = 0.98;
  19810. this.wireframe = false;
  19811. this.wireframeLinewidth = 1;
  19812. this.wireframeLinecap = 'round';
  19813. this.wireframeLinejoin = 'round';
  19814. this.skinning = false;
  19815. this.morphTargets = false;
  19816. this.morphNormals = false;
  19817. this.setValues(parameters);
  19818. }
  19819. MeshPhongMaterial.prototype = Object.create(Material.prototype);
  19820. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  19821. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  19822. MeshPhongMaterial.prototype.copy = function (source) {
  19823. Material.prototype.copy.call(this, source);
  19824. this.color.copy(source.color);
  19825. this.specular.copy(source.specular);
  19826. this.shininess = source.shininess;
  19827. this.map = source.map;
  19828. this.lightMap = source.lightMap;
  19829. this.lightMapIntensity = source.lightMapIntensity;
  19830. this.aoMap = source.aoMap;
  19831. this.aoMapIntensity = source.aoMapIntensity;
  19832. this.emissive.copy(source.emissive);
  19833. this.emissiveMap = source.emissiveMap;
  19834. this.emissiveIntensity = source.emissiveIntensity;
  19835. this.bumpMap = source.bumpMap;
  19836. this.bumpScale = source.bumpScale;
  19837. this.normalMap = source.normalMap;
  19838. this.normalMapType = source.normalMapType;
  19839. this.normalScale.copy(source.normalScale);
  19840. this.displacementMap = source.displacementMap;
  19841. this.displacementScale = source.displacementScale;
  19842. this.displacementBias = source.displacementBias;
  19843. this.specularMap = source.specularMap;
  19844. this.alphaMap = source.alphaMap;
  19845. this.envMap = source.envMap;
  19846. this.combine = source.combine;
  19847. this.reflectivity = source.reflectivity;
  19848. this.refractionRatio = source.refractionRatio;
  19849. this.wireframe = source.wireframe;
  19850. this.wireframeLinewidth = source.wireframeLinewidth;
  19851. this.wireframeLinecap = source.wireframeLinecap;
  19852. this.wireframeLinejoin = source.wireframeLinejoin;
  19853. this.skinning = source.skinning;
  19854. this.morphTargets = source.morphTargets;
  19855. this.morphNormals = source.morphNormals;
  19856. return this;
  19857. };
  19858. /**
  19859. * parameters = {
  19860. * color: <hex>,
  19861. *
  19862. * map: new THREE.Texture( <Image> ),
  19863. * gradientMap: new THREE.Texture( <Image> ),
  19864. *
  19865. * lightMap: new THREE.Texture( <Image> ),
  19866. * lightMapIntensity: <float>
  19867. *
  19868. * aoMap: new THREE.Texture( <Image> ),
  19869. * aoMapIntensity: <float>
  19870. *
  19871. * emissive: <hex>,
  19872. * emissiveIntensity: <float>
  19873. * emissiveMap: new THREE.Texture( <Image> ),
  19874. *
  19875. * bumpMap: new THREE.Texture( <Image> ),
  19876. * bumpScale: <float>,
  19877. *
  19878. * normalMap: new THREE.Texture( <Image> ),
  19879. * normalMapType: THREE.TangentSpaceNormalMap,
  19880. * normalScale: <Vector2>,
  19881. *
  19882. * displacementMap: new THREE.Texture( <Image> ),
  19883. * displacementScale: <float>,
  19884. * displacementBias: <float>,
  19885. *
  19886. * alphaMap: new THREE.Texture( <Image> ),
  19887. *
  19888. * wireframe: <boolean>,
  19889. * wireframeLinewidth: <float>,
  19890. *
  19891. * skinning: <bool>,
  19892. * morphTargets: <bool>,
  19893. * morphNormals: <bool>
  19894. * }
  19895. */
  19896. function MeshToonMaterial(parameters) {
  19897. Material.call(this);
  19898. this.defines = {
  19899. 'TOON': ''
  19900. };
  19901. this.type = 'MeshToonMaterial';
  19902. this.color = new Color(0xffffff);
  19903. this.map = null;
  19904. this.gradientMap = null;
  19905. this.lightMap = null;
  19906. this.lightMapIntensity = 1.0;
  19907. this.aoMap = null;
  19908. this.aoMapIntensity = 1.0;
  19909. this.emissive = new Color(0x000000);
  19910. this.emissiveIntensity = 1.0;
  19911. this.emissiveMap = null;
  19912. this.bumpMap = null;
  19913. this.bumpScale = 1;
  19914. this.normalMap = null;
  19915. this.normalMapType = TangentSpaceNormalMap;
  19916. this.normalScale = new Vector2(1, 1);
  19917. this.displacementMap = null;
  19918. this.displacementScale = 1;
  19919. this.displacementBias = 0;
  19920. this.alphaMap = null;
  19921. this.wireframe = false;
  19922. this.wireframeLinewidth = 1;
  19923. this.wireframeLinecap = 'round';
  19924. this.wireframeLinejoin = 'round';
  19925. this.skinning = false;
  19926. this.morphTargets = false;
  19927. this.morphNormals = false;
  19928. this.setValues(parameters);
  19929. }
  19930. MeshToonMaterial.prototype = Object.create(Material.prototype);
  19931. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  19932. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  19933. MeshToonMaterial.prototype.copy = function (source) {
  19934. Material.prototype.copy.call(this, source);
  19935. this.color.copy(source.color);
  19936. this.map = source.map;
  19937. this.gradientMap = source.gradientMap;
  19938. this.lightMap = source.lightMap;
  19939. this.lightMapIntensity = source.lightMapIntensity;
  19940. this.aoMap = source.aoMap;
  19941. this.aoMapIntensity = source.aoMapIntensity;
  19942. this.emissive.copy(source.emissive);
  19943. this.emissiveMap = source.emissiveMap;
  19944. this.emissiveIntensity = source.emissiveIntensity;
  19945. this.bumpMap = source.bumpMap;
  19946. this.bumpScale = source.bumpScale;
  19947. this.normalMap = source.normalMap;
  19948. this.normalMapType = source.normalMapType;
  19949. this.normalScale.copy(source.normalScale);
  19950. this.displacementMap = source.displacementMap;
  19951. this.displacementScale = source.displacementScale;
  19952. this.displacementBias = source.displacementBias;
  19953. this.alphaMap = source.alphaMap;
  19954. this.wireframe = source.wireframe;
  19955. this.wireframeLinewidth = source.wireframeLinewidth;
  19956. this.wireframeLinecap = source.wireframeLinecap;
  19957. this.wireframeLinejoin = source.wireframeLinejoin;
  19958. this.skinning = source.skinning;
  19959. this.morphTargets = source.morphTargets;
  19960. this.morphNormals = source.morphNormals;
  19961. return this;
  19962. };
  19963. /**
  19964. * parameters = {
  19965. * opacity: <float>,
  19966. *
  19967. * bumpMap: new THREE.Texture( <Image> ),
  19968. * bumpScale: <float>,
  19969. *
  19970. * normalMap: new THREE.Texture( <Image> ),
  19971. * normalMapType: THREE.TangentSpaceNormalMap,
  19972. * normalScale: <Vector2>,
  19973. *
  19974. * displacementMap: new THREE.Texture( <Image> ),
  19975. * displacementScale: <float>,
  19976. * displacementBias: <float>,
  19977. *
  19978. * wireframe: <boolean>,
  19979. * wireframeLinewidth: <float>
  19980. *
  19981. * skinning: <bool>,
  19982. * morphTargets: <bool>,
  19983. * morphNormals: <bool>
  19984. * }
  19985. */
  19986. function MeshNormalMaterial(parameters) {
  19987. Material.call(this);
  19988. this.type = 'MeshNormalMaterial';
  19989. this.bumpMap = null;
  19990. this.bumpScale = 1;
  19991. this.normalMap = null;
  19992. this.normalMapType = TangentSpaceNormalMap;
  19993. this.normalScale = new Vector2(1, 1);
  19994. this.displacementMap = null;
  19995. this.displacementScale = 1;
  19996. this.displacementBias = 0;
  19997. this.wireframe = false;
  19998. this.wireframeLinewidth = 1;
  19999. this.fog = false;
  20000. this.skinning = false;
  20001. this.morphTargets = false;
  20002. this.morphNormals = false;
  20003. this.setValues(parameters);
  20004. }
  20005. MeshNormalMaterial.prototype = Object.create(Material.prototype);
  20006. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  20007. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20008. MeshNormalMaterial.prototype.copy = function (source) {
  20009. Material.prototype.copy.call(this, source);
  20010. this.bumpMap = source.bumpMap;
  20011. this.bumpScale = source.bumpScale;
  20012. this.normalMap = source.normalMap;
  20013. this.normalMapType = source.normalMapType;
  20014. this.normalScale.copy(source.normalScale);
  20015. this.displacementMap = source.displacementMap;
  20016. this.displacementScale = source.displacementScale;
  20017. this.displacementBias = source.displacementBias;
  20018. this.wireframe = source.wireframe;
  20019. this.wireframeLinewidth = source.wireframeLinewidth;
  20020. this.skinning = source.skinning;
  20021. this.morphTargets = source.morphTargets;
  20022. this.morphNormals = source.morphNormals;
  20023. return this;
  20024. };
  20025. /**
  20026. * parameters = {
  20027. * color: <hex>,
  20028. * opacity: <float>,
  20029. *
  20030. * map: new THREE.Texture( <Image> ),
  20031. *
  20032. * lightMap: new THREE.Texture( <Image> ),
  20033. * lightMapIntensity: <float>
  20034. *
  20035. * aoMap: new THREE.Texture( <Image> ),
  20036. * aoMapIntensity: <float>
  20037. *
  20038. * emissive: <hex>,
  20039. * emissiveIntensity: <float>
  20040. * emissiveMap: new THREE.Texture( <Image> ),
  20041. *
  20042. * specularMap: new THREE.Texture( <Image> ),
  20043. *
  20044. * alphaMap: new THREE.Texture( <Image> ),
  20045. *
  20046. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20047. * combine: THREE.Multiply,
  20048. * reflectivity: <float>,
  20049. * refractionRatio: <float>,
  20050. *
  20051. * wireframe: <boolean>,
  20052. * wireframeLinewidth: <float>,
  20053. *
  20054. * skinning: <bool>,
  20055. * morphTargets: <bool>,
  20056. * morphNormals: <bool>
  20057. * }
  20058. */
  20059. function MeshLambertMaterial(parameters) {
  20060. Material.call(this);
  20061. this.type = 'MeshLambertMaterial';
  20062. this.color = new Color(0xffffff); // diffuse
  20063. this.map = null;
  20064. this.lightMap = null;
  20065. this.lightMapIntensity = 1.0;
  20066. this.aoMap = null;
  20067. this.aoMapIntensity = 1.0;
  20068. this.emissive = new Color(0x000000);
  20069. this.emissiveIntensity = 1.0;
  20070. this.emissiveMap = null;
  20071. this.specularMap = null;
  20072. this.alphaMap = null;
  20073. this.envMap = null;
  20074. this.combine = MultiplyOperation;
  20075. this.reflectivity = 1;
  20076. this.refractionRatio = 0.98;
  20077. this.wireframe = false;
  20078. this.wireframeLinewidth = 1;
  20079. this.wireframeLinecap = 'round';
  20080. this.wireframeLinejoin = 'round';
  20081. this.skinning = false;
  20082. this.morphTargets = false;
  20083. this.morphNormals = false;
  20084. this.setValues(parameters);
  20085. }
  20086. MeshLambertMaterial.prototype = Object.create(Material.prototype);
  20087. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20088. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20089. MeshLambertMaterial.prototype.copy = function (source) {
  20090. Material.prototype.copy.call(this, source);
  20091. this.color.copy(source.color);
  20092. this.map = source.map;
  20093. this.lightMap = source.lightMap;
  20094. this.lightMapIntensity = source.lightMapIntensity;
  20095. this.aoMap = source.aoMap;
  20096. this.aoMapIntensity = source.aoMapIntensity;
  20097. this.emissive.copy(source.emissive);
  20098. this.emissiveMap = source.emissiveMap;
  20099. this.emissiveIntensity = source.emissiveIntensity;
  20100. this.specularMap = source.specularMap;
  20101. this.alphaMap = source.alphaMap;
  20102. this.envMap = source.envMap;
  20103. this.combine = source.combine;
  20104. this.reflectivity = source.reflectivity;
  20105. this.refractionRatio = source.refractionRatio;
  20106. this.wireframe = source.wireframe;
  20107. this.wireframeLinewidth = source.wireframeLinewidth;
  20108. this.wireframeLinecap = source.wireframeLinecap;
  20109. this.wireframeLinejoin = source.wireframeLinejoin;
  20110. this.skinning = source.skinning;
  20111. this.morphTargets = source.morphTargets;
  20112. this.morphNormals = source.morphNormals;
  20113. return this;
  20114. };
  20115. /**
  20116. * parameters = {
  20117. * color: <hex>,
  20118. * opacity: <float>,
  20119. *
  20120. * matcap: new THREE.Texture( <Image> ),
  20121. *
  20122. * map: new THREE.Texture( <Image> ),
  20123. *
  20124. * bumpMap: new THREE.Texture( <Image> ),
  20125. * bumpScale: <float>,
  20126. *
  20127. * normalMap: new THREE.Texture( <Image> ),
  20128. * normalMapType: THREE.TangentSpaceNormalMap,
  20129. * normalScale: <Vector2>,
  20130. *
  20131. * displacementMap: new THREE.Texture( <Image> ),
  20132. * displacementScale: <float>,
  20133. * displacementBias: <float>,
  20134. *
  20135. * alphaMap: new THREE.Texture( <Image> ),
  20136. *
  20137. * skinning: <bool>,
  20138. * morphTargets: <bool>,
  20139. * morphNormals: <bool>
  20140. * }
  20141. */
  20142. function MeshMatcapMaterial(parameters) {
  20143. Material.call(this);
  20144. this.defines = {
  20145. 'MATCAP': ''
  20146. };
  20147. this.type = 'MeshMatcapMaterial';
  20148. this.color = new Color(0xffffff); // diffuse
  20149. this.matcap = null;
  20150. this.map = null;
  20151. this.bumpMap = null;
  20152. this.bumpScale = 1;
  20153. this.normalMap = null;
  20154. this.normalMapType = TangentSpaceNormalMap;
  20155. this.normalScale = new Vector2(1, 1);
  20156. this.displacementMap = null;
  20157. this.displacementScale = 1;
  20158. this.displacementBias = 0;
  20159. this.alphaMap = null;
  20160. this.skinning = false;
  20161. this.morphTargets = false;
  20162. this.morphNormals = false;
  20163. this.setValues(parameters);
  20164. }
  20165. MeshMatcapMaterial.prototype = Object.create(Material.prototype);
  20166. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20167. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20168. MeshMatcapMaterial.prototype.copy = function (source) {
  20169. Material.prototype.copy.call(this, source);
  20170. this.defines = {
  20171. 'MATCAP': ''
  20172. };
  20173. this.color.copy(source.color);
  20174. this.matcap = source.matcap;
  20175. this.map = source.map;
  20176. this.bumpMap = source.bumpMap;
  20177. this.bumpScale = source.bumpScale;
  20178. this.normalMap = source.normalMap;
  20179. this.normalMapType = source.normalMapType;
  20180. this.normalScale.copy(source.normalScale);
  20181. this.displacementMap = source.displacementMap;
  20182. this.displacementScale = source.displacementScale;
  20183. this.displacementBias = source.displacementBias;
  20184. this.alphaMap = source.alphaMap;
  20185. this.skinning = source.skinning;
  20186. this.morphTargets = source.morphTargets;
  20187. this.morphNormals = source.morphNormals;
  20188. return this;
  20189. };
  20190. /**
  20191. * parameters = {
  20192. * color: <hex>,
  20193. * opacity: <float>,
  20194. *
  20195. * linewidth: <float>,
  20196. *
  20197. * scale: <float>,
  20198. * dashSize: <float>,
  20199. * gapSize: <float>
  20200. * }
  20201. */
  20202. function LineDashedMaterial(parameters) {
  20203. LineBasicMaterial.call(this);
  20204. this.type = 'LineDashedMaterial';
  20205. this.scale = 1;
  20206. this.dashSize = 3;
  20207. this.gapSize = 1;
  20208. this.setValues(parameters);
  20209. }
  20210. LineDashedMaterial.prototype = Object.create(LineBasicMaterial.prototype);
  20211. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20212. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20213. LineDashedMaterial.prototype.copy = function (source) {
  20214. LineBasicMaterial.prototype.copy.call(this, source);
  20215. this.scale = source.scale;
  20216. this.dashSize = source.dashSize;
  20217. this.gapSize = source.gapSize;
  20218. return this;
  20219. };
  20220. var Materials = /*#__PURE__*/Object.freeze({
  20221. __proto__: null,
  20222. ShadowMaterial: ShadowMaterial,
  20223. SpriteMaterial: SpriteMaterial,
  20224. RawShaderMaterial: RawShaderMaterial,
  20225. ShaderMaterial: ShaderMaterial,
  20226. PointsMaterial: PointsMaterial,
  20227. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20228. MeshStandardMaterial: MeshStandardMaterial,
  20229. MeshPhongMaterial: MeshPhongMaterial,
  20230. MeshToonMaterial: MeshToonMaterial,
  20231. MeshNormalMaterial: MeshNormalMaterial,
  20232. MeshLambertMaterial: MeshLambertMaterial,
  20233. MeshDepthMaterial: MeshDepthMaterial,
  20234. MeshDistanceMaterial: MeshDistanceMaterial,
  20235. MeshBasicMaterial: MeshBasicMaterial,
  20236. MeshMatcapMaterial: MeshMatcapMaterial,
  20237. LineDashedMaterial: LineDashedMaterial,
  20238. LineBasicMaterial: LineBasicMaterial,
  20239. Material: Material
  20240. });
  20241. var AnimationUtils = {
  20242. // same as Array.prototype.slice, but also works on typed arrays
  20243. arraySlice: function arraySlice(array, from, to) {
  20244. if (AnimationUtils.isTypedArray(array)) {
  20245. // in ios9 array.subarray(from, undefined) will return empty array
  20246. // but array.subarray(from) or array.subarray(from, len) is correct
  20247. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  20248. }
  20249. return array.slice(from, to);
  20250. },
  20251. // converts an array to a specific type
  20252. convertArray: function convertArray(array, type, forceClone) {
  20253. if (!array || // let 'undefined' and 'null' pass
  20254. !forceClone && array.constructor === type) return array;
  20255. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  20256. return new type(array); // create typed array
  20257. }
  20258. return Array.prototype.slice.call(array); // create Array
  20259. },
  20260. isTypedArray: function isTypedArray(object) {
  20261. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  20262. },
  20263. // returns an array by which times and values can be sorted
  20264. getKeyframeOrder: function getKeyframeOrder(times) {
  20265. function compareTime(i, j) {
  20266. return times[i] - times[j];
  20267. }
  20268. var n = times.length;
  20269. var result = new Array(n);
  20270. for (var i = 0; i !== n; ++i) {
  20271. result[i] = i;
  20272. }
  20273. result.sort(compareTime);
  20274. return result;
  20275. },
  20276. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20277. sortedArray: function sortedArray(values, stride, order) {
  20278. var nValues = values.length;
  20279. var result = new values.constructor(nValues);
  20280. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  20281. var srcOffset = order[i] * stride;
  20282. for (var j = 0; j !== stride; ++j) {
  20283. result[dstOffset++] = values[srcOffset + j];
  20284. }
  20285. }
  20286. return result;
  20287. },
  20288. // function for parsing AOS keyframe formats
  20289. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  20290. var i = 1,
  20291. key = jsonKeys[0];
  20292. while (key !== undefined && key[valuePropertyName] === undefined) {
  20293. key = jsonKeys[i++];
  20294. }
  20295. if (key === undefined) return; // no data
  20296. var value = key[valuePropertyName];
  20297. if (value === undefined) return; // no data
  20298. if (Array.isArray(value)) {
  20299. do {
  20300. value = key[valuePropertyName];
  20301. if (value !== undefined) {
  20302. times.push(key.time);
  20303. values.push.apply(values, value); // push all elements
  20304. }
  20305. key = jsonKeys[i++];
  20306. } while (key !== undefined);
  20307. } else if (value.toArray !== undefined) {
  20308. // ...assume THREE.Math-ish
  20309. do {
  20310. value = key[valuePropertyName];
  20311. if (value !== undefined) {
  20312. times.push(key.time);
  20313. value.toArray(values, values.length);
  20314. }
  20315. key = jsonKeys[i++];
  20316. } while (key !== undefined);
  20317. } else {
  20318. // otherwise push as-is
  20319. do {
  20320. value = key[valuePropertyName];
  20321. if (value !== undefined) {
  20322. times.push(key.time);
  20323. values.push(value);
  20324. }
  20325. key = jsonKeys[i++];
  20326. } while (key !== undefined);
  20327. }
  20328. },
  20329. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  20330. if (fps === void 0) {
  20331. fps = 30;
  20332. }
  20333. var clip = sourceClip.clone();
  20334. clip.name = name;
  20335. var tracks = [];
  20336. for (var i = 0; i < clip.tracks.length; ++i) {
  20337. var track = clip.tracks[i];
  20338. var valueSize = track.getValueSize();
  20339. var times = [];
  20340. var values = [];
  20341. for (var j = 0; j < track.times.length; ++j) {
  20342. var frame = track.times[j] * fps;
  20343. if (frame < startFrame || frame >= endFrame) continue;
  20344. times.push(track.times[j]);
  20345. for (var k = 0; k < valueSize; ++k) {
  20346. values.push(track.values[j * valueSize + k]);
  20347. }
  20348. }
  20349. if (times.length === 0) continue;
  20350. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  20351. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  20352. tracks.push(track);
  20353. }
  20354. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  20355. var minStartTime = Infinity;
  20356. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  20357. if (minStartTime > clip.tracks[_i].times[0]) {
  20358. minStartTime = clip.tracks[_i].times[0];
  20359. }
  20360. } // shift all tracks such that clip begins at t=0
  20361. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  20362. clip.tracks[_i2].shift(-1 * minStartTime);
  20363. }
  20364. clip.resetDuration();
  20365. return clip;
  20366. },
  20367. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  20368. if (referenceFrame === void 0) {
  20369. referenceFrame = 0;
  20370. }
  20371. if (referenceClip === void 0) {
  20372. referenceClip = targetClip;
  20373. }
  20374. if (fps === void 0) {
  20375. fps = 30;
  20376. }
  20377. if (fps <= 0) fps = 30;
  20378. var numTracks = referenceClip.tracks.length;
  20379. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  20380. var _loop = function _loop(i) {
  20381. var referenceTrack = referenceClip.tracks[i];
  20382. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  20383. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  20384. var targetTrack = targetClip.tracks.find(function (track) {
  20385. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  20386. });
  20387. if (targetTrack === undefined) return "continue";
  20388. var referenceOffset = 0;
  20389. var referenceValueSize = referenceTrack.getValueSize();
  20390. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20391. referenceOffset = referenceValueSize / 3;
  20392. }
  20393. var targetOffset = 0;
  20394. var targetValueSize = targetTrack.getValueSize();
  20395. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20396. targetOffset = targetValueSize / 3;
  20397. }
  20398. var lastIndex = referenceTrack.times.length - 1;
  20399. var referenceValue = void 0; // Find the value to subtract out of the track
  20400. if (referenceTime <= referenceTrack.times[0]) {
  20401. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  20402. var startIndex = referenceOffset;
  20403. var endIndex = referenceValueSize - referenceOffset;
  20404. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  20405. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  20406. // Reference frame is after the last keyframe, so just use the last keyframe
  20407. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  20408. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  20409. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  20410. } else {
  20411. // Interpolate to the reference value
  20412. var interpolant = referenceTrack.createInterpolant();
  20413. var _startIndex2 = referenceOffset;
  20414. var _endIndex2 = referenceValueSize - referenceOffset;
  20415. interpolant.evaluate(referenceTime);
  20416. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  20417. } // Conjugate the quaternion
  20418. if (referenceTrackType === 'quaternion') {
  20419. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  20420. referenceQuat.toArray(referenceValue);
  20421. } // Subtract the reference value from all of the track values
  20422. var numTimes = targetTrack.times.length;
  20423. for (var j = 0; j < numTimes; ++j) {
  20424. var valueStart = j * targetValueSize + targetOffset;
  20425. if (referenceTrackType === 'quaternion') {
  20426. // Multiply the conjugate for quaternion track types
  20427. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  20428. } else {
  20429. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  20430. for (var k = 0; k < valueEnd; ++k) {
  20431. targetTrack.values[valueStart + k] -= referenceValue[k];
  20432. }
  20433. }
  20434. }
  20435. };
  20436. for (var i = 0; i < numTracks; ++i) {
  20437. var _ret = _loop(i);
  20438. if (_ret === "continue") continue;
  20439. }
  20440. targetClip.blendMode = AdditiveAnimationBlendMode;
  20441. return targetClip;
  20442. }
  20443. };
  20444. /**
  20445. * Abstract base class of interpolants over parametric samples.
  20446. *
  20447. * The parameter domain is one dimensional, typically the time or a path
  20448. * along a curve defined by the data.
  20449. *
  20450. * The sample values can have any dimensionality and derived classes may
  20451. * apply special interpretations to the data.
  20452. *
  20453. * This class provides the interval seek in a Template Method, deferring
  20454. * the actual interpolation to derived classes.
  20455. *
  20456. * Time complexity is O(1) for linear access crossing at most two points
  20457. * and O(log N) for random access, where N is the number of positions.
  20458. *
  20459. * References:
  20460. *
  20461. * http://www.oodesign.com/template-method-pattern.html
  20462. *
  20463. */
  20464. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20465. this.parameterPositions = parameterPositions;
  20466. this._cachedIndex = 0;
  20467. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  20468. this.sampleValues = sampleValues;
  20469. this.valueSize = sampleSize;
  20470. }
  20471. Object.assign(Interpolant.prototype, {
  20472. evaluate: function evaluate(t) {
  20473. var pp = this.parameterPositions;
  20474. var i1 = this._cachedIndex,
  20475. t1 = pp[i1],
  20476. t0 = pp[i1 - 1];
  20477. validate_interval: {
  20478. seek: {
  20479. var right;
  20480. linear_scan: {
  20481. //- See http://jsperf.com/comparison-to-undefined/3
  20482. //- slower code:
  20483. //-
  20484. //- if ( t >= t1 || t1 === undefined ) {
  20485. forward_scan: if (!(t < t1)) {
  20486. for (var giveUpAt = i1 + 2;;) {
  20487. if (t1 === undefined) {
  20488. if (t < t0) break forward_scan; // after end
  20489. i1 = pp.length;
  20490. this._cachedIndex = i1;
  20491. return this.afterEnd_(i1 - 1, t, t0);
  20492. }
  20493. if (i1 === giveUpAt) break; // this loop
  20494. t0 = t1;
  20495. t1 = pp[++i1];
  20496. if (t < t1) {
  20497. // we have arrived at the sought interval
  20498. break seek;
  20499. }
  20500. } // prepare binary search on the right side of the index
  20501. right = pp.length;
  20502. break linear_scan;
  20503. } //- slower code:
  20504. //- if ( t < t0 || t0 === undefined ) {
  20505. if (!(t >= t0)) {
  20506. // looping?
  20507. var t1global = pp[1];
  20508. if (t < t1global) {
  20509. i1 = 2; // + 1, using the scan for the details
  20510. t0 = t1global;
  20511. } // linear reverse scan
  20512. for (var _giveUpAt = i1 - 2;;) {
  20513. if (t0 === undefined) {
  20514. // before start
  20515. this._cachedIndex = 0;
  20516. return this.beforeStart_(0, t, t1);
  20517. }
  20518. if (i1 === _giveUpAt) break; // this loop
  20519. t1 = t0;
  20520. t0 = pp[--i1 - 1];
  20521. if (t >= t0) {
  20522. // we have arrived at the sought interval
  20523. break seek;
  20524. }
  20525. } // prepare binary search on the left side of the index
  20526. right = i1;
  20527. i1 = 0;
  20528. break linear_scan;
  20529. } // the interval is valid
  20530. break validate_interval;
  20531. } // linear scan
  20532. // binary search
  20533. while (i1 < right) {
  20534. var mid = i1 + right >>> 1;
  20535. if (t < pp[mid]) {
  20536. right = mid;
  20537. } else {
  20538. i1 = mid + 1;
  20539. }
  20540. }
  20541. t1 = pp[i1];
  20542. t0 = pp[i1 - 1]; // check boundary cases, again
  20543. if (t0 === undefined) {
  20544. this._cachedIndex = 0;
  20545. return this.beforeStart_(0, t, t1);
  20546. }
  20547. if (t1 === undefined) {
  20548. i1 = pp.length;
  20549. this._cachedIndex = i1;
  20550. return this.afterEnd_(i1 - 1, t0, t);
  20551. }
  20552. } // seek
  20553. this._cachedIndex = i1;
  20554. this.intervalChanged_(i1, t0, t1);
  20555. } // validate_interval
  20556. return this.interpolate_(i1, t0, t, t1);
  20557. },
  20558. settings: null,
  20559. // optional, subclass-specific settings structure
  20560. // Note: The indirection allows central control of many interpolants.
  20561. // --- Protected interface
  20562. DefaultSettings_: {},
  20563. getSettings_: function getSettings_() {
  20564. return this.settings || this.DefaultSettings_;
  20565. },
  20566. copySampleValue_: function copySampleValue_(index) {
  20567. // copies a sample value to the result buffer
  20568. var result = this.resultBuffer,
  20569. values = this.sampleValues,
  20570. stride = this.valueSize,
  20571. offset = index * stride;
  20572. for (var i = 0; i !== stride; ++i) {
  20573. result[i] = values[offset + i];
  20574. }
  20575. return result;
  20576. },
  20577. // Template methods for derived classes:
  20578. interpolate_: function interpolate_()
  20579. /* i1, t0, t, t1 */
  20580. {
  20581. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  20582. },
  20583. intervalChanged_: function intervalChanged_()
  20584. /* i1, t0, t1 */
  20585. {// empty
  20586. }
  20587. }); // DECLARE ALIAS AFTER assign prototype
  20588. Object.assign(Interpolant.prototype, {
  20589. //( 0, t, t0 ), returns this.resultBuffer
  20590. beforeStart_: Interpolant.prototype.copySampleValue_,
  20591. //( N-1, tN-1, t ), returns this.resultBuffer
  20592. afterEnd_: Interpolant.prototype.copySampleValue_
  20593. });
  20594. /**
  20595. * Fast and simple cubic spline interpolant.
  20596. *
  20597. * It was derived from a Hermitian construction setting the first derivative
  20598. * at each sample position to the linear slope between neighboring positions
  20599. * over their parameter interval.
  20600. */
  20601. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20602. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20603. this._weightPrev = -0;
  20604. this._offsetPrev = -0;
  20605. this._weightNext = -0;
  20606. this._offsetNext = -0;
  20607. }
  20608. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20609. constructor: CubicInterpolant,
  20610. DefaultSettings_: {
  20611. endingStart: ZeroCurvatureEnding,
  20612. endingEnd: ZeroCurvatureEnding
  20613. },
  20614. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  20615. var pp = this.parameterPositions;
  20616. var iPrev = i1 - 2,
  20617. iNext = i1 + 1,
  20618. tPrev = pp[iPrev],
  20619. tNext = pp[iNext];
  20620. if (tPrev === undefined) {
  20621. switch (this.getSettings_().endingStart) {
  20622. case ZeroSlopeEnding:
  20623. // f'(t0) = 0
  20624. iPrev = i1;
  20625. tPrev = 2 * t0 - t1;
  20626. break;
  20627. case WrapAroundEnding:
  20628. // use the other end of the curve
  20629. iPrev = pp.length - 2;
  20630. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  20631. break;
  20632. default:
  20633. // ZeroCurvatureEnding
  20634. // f''(t0) = 0 a.k.a. Natural Spline
  20635. iPrev = i1;
  20636. tPrev = t1;
  20637. }
  20638. }
  20639. if (tNext === undefined) {
  20640. switch (this.getSettings_().endingEnd) {
  20641. case ZeroSlopeEnding:
  20642. // f'(tN) = 0
  20643. iNext = i1;
  20644. tNext = 2 * t1 - t0;
  20645. break;
  20646. case WrapAroundEnding:
  20647. // use the other end of the curve
  20648. iNext = 1;
  20649. tNext = t1 + pp[1] - pp[0];
  20650. break;
  20651. default:
  20652. // ZeroCurvatureEnding
  20653. // f''(tN) = 0, a.k.a. Natural Spline
  20654. iNext = i1 - 1;
  20655. tNext = t0;
  20656. }
  20657. }
  20658. var halfDt = (t1 - t0) * 0.5,
  20659. stride = this.valueSize;
  20660. this._weightPrev = halfDt / (t0 - tPrev);
  20661. this._weightNext = halfDt / (tNext - t1);
  20662. this._offsetPrev = iPrev * stride;
  20663. this._offsetNext = iNext * stride;
  20664. },
  20665. interpolate_: function interpolate_(i1, t0, t, t1) {
  20666. var result = this.resultBuffer,
  20667. values = this.sampleValues,
  20668. stride = this.valueSize,
  20669. o1 = i1 * stride,
  20670. o0 = o1 - stride,
  20671. oP = this._offsetPrev,
  20672. oN = this._offsetNext,
  20673. wP = this._weightPrev,
  20674. wN = this._weightNext,
  20675. p = (t - t0) / (t1 - t0),
  20676. pp = p * p,
  20677. ppp = pp * p; // evaluate polynomials
  20678. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  20679. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  20680. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  20681. var sN = wN * ppp - wN * pp; // combine data linearly
  20682. for (var i = 0; i !== stride; ++i) {
  20683. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  20684. }
  20685. return result;
  20686. }
  20687. });
  20688. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20689. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20690. }
  20691. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20692. constructor: LinearInterpolant,
  20693. interpolate_: function interpolate_(i1, t0, t, t1) {
  20694. var result = this.resultBuffer,
  20695. values = this.sampleValues,
  20696. stride = this.valueSize,
  20697. offset1 = i1 * stride,
  20698. offset0 = offset1 - stride,
  20699. weight1 = (t - t0) / (t1 - t0),
  20700. weight0 = 1 - weight1;
  20701. for (var i = 0; i !== stride; ++i) {
  20702. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  20703. }
  20704. return result;
  20705. }
  20706. });
  20707. /**
  20708. *
  20709. * Interpolant that evaluates to the sample value at the position preceeding
  20710. * the parameter.
  20711. */
  20712. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20713. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20714. }
  20715. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20716. constructor: DiscreteInterpolant,
  20717. interpolate_: function interpolate_(i1
  20718. /*, t0, t, t1 */
  20719. ) {
  20720. return this.copySampleValue_(i1 - 1);
  20721. }
  20722. });
  20723. function KeyframeTrack(name, times, values, interpolation) {
  20724. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  20725. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  20726. this.name = name;
  20727. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  20728. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  20729. this.setInterpolation(interpolation || this.DefaultInterpolation);
  20730. } // Static methods
  20731. Object.assign(KeyframeTrack, {
  20732. // Serialization (in static context, because of constructor invocation
  20733. // and automatic invocation of .toJSON):
  20734. toJSON: function toJSON(track) {
  20735. var trackType = track.constructor;
  20736. var json; // derived classes can define a static toJSON method
  20737. if (trackType.toJSON !== undefined) {
  20738. json = trackType.toJSON(track);
  20739. } else {
  20740. // by default, we assume the data can be serialized as-is
  20741. json = {
  20742. 'name': track.name,
  20743. 'times': AnimationUtils.convertArray(track.times, Array),
  20744. 'values': AnimationUtils.convertArray(track.values, Array)
  20745. };
  20746. var interpolation = track.getInterpolation();
  20747. if (interpolation !== track.DefaultInterpolation) {
  20748. json.interpolation = interpolation;
  20749. }
  20750. }
  20751. json.type = track.ValueTypeName; // mandatory
  20752. return json;
  20753. }
  20754. });
  20755. Object.assign(KeyframeTrack.prototype, {
  20756. constructor: KeyframeTrack,
  20757. TimeBufferType: Float32Array,
  20758. ValueBufferType: Float32Array,
  20759. DefaultInterpolation: InterpolateLinear,
  20760. InterpolantFactoryMethodDiscrete: function InterpolantFactoryMethodDiscrete(result) {
  20761. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  20762. },
  20763. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  20764. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  20765. },
  20766. InterpolantFactoryMethodSmooth: function InterpolantFactoryMethodSmooth(result) {
  20767. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  20768. },
  20769. setInterpolation: function setInterpolation(interpolation) {
  20770. var factoryMethod;
  20771. switch (interpolation) {
  20772. case InterpolateDiscrete:
  20773. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  20774. break;
  20775. case InterpolateLinear:
  20776. factoryMethod = this.InterpolantFactoryMethodLinear;
  20777. break;
  20778. case InterpolateSmooth:
  20779. factoryMethod = this.InterpolantFactoryMethodSmooth;
  20780. break;
  20781. }
  20782. if (factoryMethod === undefined) {
  20783. var message = 'unsupported interpolation for ' + this.ValueTypeName + ' keyframe track named ' + this.name;
  20784. if (this.createInterpolant === undefined) {
  20785. // fall back to default, unless the default itself is messed up
  20786. if (interpolation !== this.DefaultInterpolation) {
  20787. this.setInterpolation(this.DefaultInterpolation);
  20788. } else {
  20789. throw new Error(message); // fatal, in this case
  20790. }
  20791. }
  20792. console.warn('THREE.KeyframeTrack:', message);
  20793. return this;
  20794. }
  20795. this.createInterpolant = factoryMethod;
  20796. return this;
  20797. },
  20798. getInterpolation: function getInterpolation() {
  20799. switch (this.createInterpolant) {
  20800. case this.InterpolantFactoryMethodDiscrete:
  20801. return InterpolateDiscrete;
  20802. case this.InterpolantFactoryMethodLinear:
  20803. return InterpolateLinear;
  20804. case this.InterpolantFactoryMethodSmooth:
  20805. return InterpolateSmooth;
  20806. }
  20807. },
  20808. getValueSize: function getValueSize() {
  20809. return this.values.length / this.times.length;
  20810. },
  20811. // move all keyframes either forwards or backwards in time
  20812. shift: function shift(timeOffset) {
  20813. if (timeOffset !== 0.0) {
  20814. var times = this.times;
  20815. for (var i = 0, n = times.length; i !== n; ++i) {
  20816. times[i] += timeOffset;
  20817. }
  20818. }
  20819. return this;
  20820. },
  20821. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  20822. scale: function scale(timeScale) {
  20823. if (timeScale !== 1.0) {
  20824. var times = this.times;
  20825. for (var i = 0, n = times.length; i !== n; ++i) {
  20826. times[i] *= timeScale;
  20827. }
  20828. }
  20829. return this;
  20830. },
  20831. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  20832. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  20833. trim: function trim(startTime, endTime) {
  20834. var times = this.times,
  20835. nKeys = times.length;
  20836. var from = 0,
  20837. to = nKeys - 1;
  20838. while (from !== nKeys && times[from] < startTime) {
  20839. ++from;
  20840. }
  20841. while (to !== -1 && times[to] > endTime) {
  20842. --to;
  20843. }
  20844. ++to; // inclusive -> exclusive bound
  20845. if (from !== 0 || to !== nKeys) {
  20846. // empty tracks are forbidden, so keep at least one keyframe
  20847. if (from >= to) {
  20848. to = Math.max(to, 1);
  20849. from = to - 1;
  20850. }
  20851. var stride = this.getValueSize();
  20852. this.times = AnimationUtils.arraySlice(times, from, to);
  20853. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  20854. }
  20855. return this;
  20856. },
  20857. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  20858. validate: function validate() {
  20859. var valid = true;
  20860. var valueSize = this.getValueSize();
  20861. if (valueSize - Math.floor(valueSize) !== 0) {
  20862. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  20863. valid = false;
  20864. }
  20865. var times = this.times,
  20866. values = this.values,
  20867. nKeys = times.length;
  20868. if (nKeys === 0) {
  20869. console.error('THREE.KeyframeTrack: Track is empty.', this);
  20870. valid = false;
  20871. }
  20872. var prevTime = null;
  20873. for (var i = 0; i !== nKeys; i++) {
  20874. var currTime = times[i];
  20875. if (typeof currTime === 'number' && isNaN(currTime)) {
  20876. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  20877. valid = false;
  20878. break;
  20879. }
  20880. if (prevTime !== null && prevTime > currTime) {
  20881. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  20882. valid = false;
  20883. break;
  20884. }
  20885. prevTime = currTime;
  20886. }
  20887. if (values !== undefined) {
  20888. if (AnimationUtils.isTypedArray(values)) {
  20889. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  20890. var value = values[_i];
  20891. if (isNaN(value)) {
  20892. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  20893. valid = false;
  20894. break;
  20895. }
  20896. }
  20897. }
  20898. }
  20899. return valid;
  20900. },
  20901. // removes equivalent sequential keys as common in morph target sequences
  20902. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  20903. optimize: function optimize() {
  20904. // times or values may be shared with other tracks, so overwriting is unsafe
  20905. var times = AnimationUtils.arraySlice(this.times),
  20906. values = AnimationUtils.arraySlice(this.values),
  20907. stride = this.getValueSize(),
  20908. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  20909. lastIndex = times.length - 1;
  20910. var writeIndex = 1;
  20911. for (var i = 1; i < lastIndex; ++i) {
  20912. var keep = false;
  20913. var time = times[i];
  20914. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  20915. if (time !== timeNext && (i !== 1 || time !== times[0])) {
  20916. if (!smoothInterpolation) {
  20917. // remove unnecessary keyframes same as their neighbors
  20918. var offset = i * stride,
  20919. offsetP = offset - stride,
  20920. offsetN = offset + stride;
  20921. for (var j = 0; j !== stride; ++j) {
  20922. var value = values[offset + j];
  20923. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  20924. keep = true;
  20925. break;
  20926. }
  20927. }
  20928. } else {
  20929. keep = true;
  20930. }
  20931. } // in-place compaction
  20932. if (keep) {
  20933. if (i !== writeIndex) {
  20934. times[writeIndex] = times[i];
  20935. var readOffset = i * stride,
  20936. writeOffset = writeIndex * stride;
  20937. for (var _j = 0; _j !== stride; ++_j) {
  20938. values[writeOffset + _j] = values[readOffset + _j];
  20939. }
  20940. }
  20941. ++writeIndex;
  20942. }
  20943. } // flush last keyframe (compaction looks ahead)
  20944. if (lastIndex > 0) {
  20945. times[writeIndex] = times[lastIndex];
  20946. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  20947. values[_writeOffset + _j2] = values[_readOffset + _j2];
  20948. }
  20949. ++writeIndex;
  20950. }
  20951. if (writeIndex !== times.length) {
  20952. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  20953. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  20954. } else {
  20955. this.times = times;
  20956. this.values = values;
  20957. }
  20958. return this;
  20959. },
  20960. clone: function clone() {
  20961. var times = AnimationUtils.arraySlice(this.times, 0);
  20962. var values = AnimationUtils.arraySlice(this.values, 0);
  20963. var TypedKeyframeTrack = this.constructor;
  20964. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  20965. track.createInterpolant = this.createInterpolant;
  20966. return track;
  20967. }
  20968. });
  20969. /**
  20970. * A Track of Boolean keyframe values.
  20971. */
  20972. function BooleanKeyframeTrack(name, times, values) {
  20973. KeyframeTrack.call(this, name, times, values);
  20974. }
  20975. BooleanKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  20976. constructor: BooleanKeyframeTrack,
  20977. ValueTypeName: 'bool',
  20978. ValueBufferType: Array,
  20979. DefaultInterpolation: InterpolateDiscrete,
  20980. InterpolantFactoryMethodLinear: undefined,
  20981. InterpolantFactoryMethodSmooth: undefined // Note: Actually this track could have a optimized / compressed
  20982. // representation of a single value and a custom interpolant that
  20983. // computes "firstValue ^ isOdd( index )".
  20984. });
  20985. /**
  20986. * A Track of keyframe values that represent color.
  20987. */
  20988. function ColorKeyframeTrack(name, times, values, interpolation) {
  20989. KeyframeTrack.call(this, name, times, values, interpolation);
  20990. }
  20991. ColorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  20992. constructor: ColorKeyframeTrack,
  20993. ValueTypeName: 'color' // ValueBufferType is inherited
  20994. // DefaultInterpolation is inherited
  20995. // Note: Very basic implementation and nothing special yet.
  20996. // However, this is the place for color space parameterization.
  20997. });
  20998. /**
  20999. * A Track of numeric keyframe values.
  21000. */
  21001. function NumberKeyframeTrack(name, times, values, interpolation) {
  21002. KeyframeTrack.call(this, name, times, values, interpolation);
  21003. }
  21004. NumberKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21005. constructor: NumberKeyframeTrack,
  21006. ValueTypeName: 'number' // ValueBufferType is inherited
  21007. // DefaultInterpolation is inherited
  21008. });
  21009. /**
  21010. * Spherical linear unit quaternion interpolant.
  21011. */
  21012. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21013. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21014. }
  21015. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21016. constructor: QuaternionLinearInterpolant,
  21017. interpolate_: function interpolate_(i1, t0, t, t1) {
  21018. var result = this.resultBuffer,
  21019. values = this.sampleValues,
  21020. stride = this.valueSize,
  21021. alpha = (t - t0) / (t1 - t0);
  21022. var offset = i1 * stride;
  21023. for (var end = offset + stride; offset !== end; offset += 4) {
  21024. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  21025. }
  21026. return result;
  21027. }
  21028. });
  21029. /**
  21030. * A Track of quaternion keyframe values.
  21031. */
  21032. function QuaternionKeyframeTrack(name, times, values, interpolation) {
  21033. KeyframeTrack.call(this, name, times, values, interpolation);
  21034. }
  21035. QuaternionKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21036. constructor: QuaternionKeyframeTrack,
  21037. ValueTypeName: 'quaternion',
  21038. // ValueBufferType is inherited
  21039. DefaultInterpolation: InterpolateLinear,
  21040. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21041. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21042. },
  21043. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21044. });
  21045. /**
  21046. * A Track that interpolates Strings
  21047. */
  21048. function StringKeyframeTrack(name, times, values, interpolation) {
  21049. KeyframeTrack.call(this, name, times, values, interpolation);
  21050. }
  21051. StringKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21052. constructor: StringKeyframeTrack,
  21053. ValueTypeName: 'string',
  21054. ValueBufferType: Array,
  21055. DefaultInterpolation: InterpolateDiscrete,
  21056. InterpolantFactoryMethodLinear: undefined,
  21057. InterpolantFactoryMethodSmooth: undefined
  21058. });
  21059. /**
  21060. * A Track of vectored keyframe values.
  21061. */
  21062. function VectorKeyframeTrack(name, times, values, interpolation) {
  21063. KeyframeTrack.call(this, name, times, values, interpolation);
  21064. }
  21065. VectorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21066. constructor: VectorKeyframeTrack,
  21067. ValueTypeName: 'vector' // ValueBufferType is inherited
  21068. // DefaultInterpolation is inherited
  21069. });
  21070. function AnimationClip(name, duration, tracks, blendMode) {
  21071. if (duration === void 0) {
  21072. duration = -1;
  21073. }
  21074. if (blendMode === void 0) {
  21075. blendMode = NormalAnimationBlendMode;
  21076. }
  21077. this.name = name;
  21078. this.tracks = tracks;
  21079. this.duration = duration;
  21080. this.blendMode = blendMode;
  21081. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  21082. if (this.duration < 0) {
  21083. this.resetDuration();
  21084. }
  21085. }
  21086. function getTrackTypeForValueTypeName(typeName) {
  21087. switch (typeName.toLowerCase()) {
  21088. case 'scalar':
  21089. case 'double':
  21090. case 'float':
  21091. case 'number':
  21092. case 'integer':
  21093. return NumberKeyframeTrack;
  21094. case 'vector':
  21095. case 'vector2':
  21096. case 'vector3':
  21097. case 'vector4':
  21098. return VectorKeyframeTrack;
  21099. case 'color':
  21100. return ColorKeyframeTrack;
  21101. case 'quaternion':
  21102. return QuaternionKeyframeTrack;
  21103. case 'bool':
  21104. case 'boolean':
  21105. return BooleanKeyframeTrack;
  21106. case 'string':
  21107. return StringKeyframeTrack;
  21108. }
  21109. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  21110. }
  21111. function parseKeyframeTrack(json) {
  21112. if (json.type === undefined) {
  21113. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  21114. }
  21115. var trackType = getTrackTypeForValueTypeName(json.type);
  21116. if (json.times === undefined) {
  21117. var times = [],
  21118. values = [];
  21119. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  21120. json.times = times;
  21121. json.values = values;
  21122. } // derived classes can define a static parse method
  21123. if (trackType.parse !== undefined) {
  21124. return trackType.parse(json);
  21125. } else {
  21126. // by default, we assume a constructor compatible with the base
  21127. return new trackType(json.name, json.times, json.values, json.interpolation);
  21128. }
  21129. }
  21130. Object.assign(AnimationClip, {
  21131. parse: function parse(json) {
  21132. var tracks = [],
  21133. jsonTracks = json.tracks,
  21134. frameTime = 1.0 / (json.fps || 1.0);
  21135. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  21136. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  21137. }
  21138. var clip = new AnimationClip(json.name, json.duration, tracks, json.blendMode);
  21139. clip.uuid = json.uuid;
  21140. return clip;
  21141. },
  21142. toJSON: function toJSON(clip) {
  21143. var tracks = [],
  21144. clipTracks = clip.tracks;
  21145. var json = {
  21146. 'name': clip.name,
  21147. 'duration': clip.duration,
  21148. 'tracks': tracks,
  21149. 'uuid': clip.uuid,
  21150. 'blendMode': clip.blendMode
  21151. };
  21152. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  21153. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  21154. }
  21155. return json;
  21156. },
  21157. CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  21158. var numMorphTargets = morphTargetSequence.length;
  21159. var tracks = [];
  21160. for (var i = 0; i < numMorphTargets; i++) {
  21161. var times = [];
  21162. var values = [];
  21163. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  21164. values.push(0, 1, 0);
  21165. var order = AnimationUtils.getKeyframeOrder(times);
  21166. times = AnimationUtils.sortedArray(times, 1, order);
  21167. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  21168. // last frame as well for perfect loop.
  21169. if (!noLoop && times[0] === 0) {
  21170. times.push(numMorphTargets);
  21171. values.push(values[0]);
  21172. }
  21173. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  21174. }
  21175. return new AnimationClip(name, -1, tracks);
  21176. },
  21177. findByName: function findByName(objectOrClipArray, name) {
  21178. var clipArray = objectOrClipArray;
  21179. if (!Array.isArray(objectOrClipArray)) {
  21180. var o = objectOrClipArray;
  21181. clipArray = o.geometry && o.geometry.animations || o.animations;
  21182. }
  21183. for (var i = 0; i < clipArray.length; i++) {
  21184. if (clipArray[i].name === name) {
  21185. return clipArray[i];
  21186. }
  21187. }
  21188. return null;
  21189. },
  21190. CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  21191. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  21192. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21193. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  21194. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21195. for (var i = 0, il = morphTargets.length; i < il; i++) {
  21196. var morphTarget = morphTargets[i];
  21197. var parts = morphTarget.name.match(pattern);
  21198. if (parts && parts.length > 1) {
  21199. var name = parts[1];
  21200. var animationMorphTargets = animationToMorphTargets[name];
  21201. if (!animationMorphTargets) {
  21202. animationToMorphTargets[name] = animationMorphTargets = [];
  21203. }
  21204. animationMorphTargets.push(morphTarget);
  21205. }
  21206. }
  21207. var clips = [];
  21208. for (var _name in animationToMorphTargets) {
  21209. clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  21210. }
  21211. return clips;
  21212. },
  21213. // parse the animation.hierarchy format
  21214. parseAnimation: function parseAnimation(animation, bones) {
  21215. if (!animation) {
  21216. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  21217. return null;
  21218. }
  21219. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  21220. // only return track if there are actually keys.
  21221. if (animationKeys.length !== 0) {
  21222. var times = [];
  21223. var values = [];
  21224. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  21225. if (times.length !== 0) {
  21226. destTracks.push(new trackType(trackName, times, values));
  21227. }
  21228. }
  21229. };
  21230. var tracks = [];
  21231. var clipName = animation.name || 'default';
  21232. var fps = animation.fps || 30;
  21233. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  21234. var duration = animation.length || -1;
  21235. var hierarchyTracks = animation.hierarchy || [];
  21236. for (var h = 0; h < hierarchyTracks.length; h++) {
  21237. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  21238. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  21239. if (animationKeys[0].morphTargets) {
  21240. // figure out all morph targets used in this track
  21241. var morphTargetNames = {};
  21242. var k = void 0;
  21243. for (k = 0; k < animationKeys.length; k++) {
  21244. if (animationKeys[k].morphTargets) {
  21245. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  21246. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  21247. }
  21248. }
  21249. } // create a track for each morph target with all zero
  21250. // morphTargetInfluences except for the keys in which
  21251. // the morphTarget is named.
  21252. for (var morphTargetName in morphTargetNames) {
  21253. var times = [];
  21254. var values = [];
  21255. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  21256. var animationKey = animationKeys[k];
  21257. times.push(animationKey.time);
  21258. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  21259. }
  21260. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  21261. }
  21262. duration = morphTargetNames.length * (fps || 1.0);
  21263. } else {
  21264. // ...assume skeletal animation
  21265. var boneName = '.bones[' + bones[h].name + ']';
  21266. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  21267. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  21268. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  21269. }
  21270. }
  21271. if (tracks.length === 0) {
  21272. return null;
  21273. }
  21274. var clip = new AnimationClip(clipName, duration, tracks, blendMode);
  21275. return clip;
  21276. }
  21277. });
  21278. Object.assign(AnimationClip.prototype, {
  21279. resetDuration: function resetDuration() {
  21280. var tracks = this.tracks;
  21281. var duration = 0;
  21282. for (var i = 0, n = tracks.length; i !== n; ++i) {
  21283. var track = this.tracks[i];
  21284. duration = Math.max(duration, track.times[track.times.length - 1]);
  21285. }
  21286. this.duration = duration;
  21287. return this;
  21288. },
  21289. trim: function trim() {
  21290. for (var i = 0; i < this.tracks.length; i++) {
  21291. this.tracks[i].trim(0, this.duration);
  21292. }
  21293. return this;
  21294. },
  21295. validate: function validate() {
  21296. var valid = true;
  21297. for (var i = 0; i < this.tracks.length; i++) {
  21298. valid = valid && this.tracks[i].validate();
  21299. }
  21300. return valid;
  21301. },
  21302. optimize: function optimize() {
  21303. for (var i = 0; i < this.tracks.length; i++) {
  21304. this.tracks[i].optimize();
  21305. }
  21306. return this;
  21307. },
  21308. clone: function clone() {
  21309. var tracks = [];
  21310. for (var i = 0; i < this.tracks.length; i++) {
  21311. tracks.push(this.tracks[i].clone());
  21312. }
  21313. return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
  21314. },
  21315. toJSON: function toJSON() {
  21316. return AnimationClip.toJSON(this);
  21317. }
  21318. });
  21319. var Cache = {
  21320. enabled: false,
  21321. files: {},
  21322. add: function add(key, file) {
  21323. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  21324. this.files[key] = file;
  21325. },
  21326. get: function get(key) {
  21327. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  21328. return this.files[key];
  21329. },
  21330. remove: function remove(key) {
  21331. delete this.files[key];
  21332. },
  21333. clear: function clear() {
  21334. this.files = {};
  21335. }
  21336. };
  21337. function LoadingManager(onLoad, onProgress, onError) {
  21338. var scope = this;
  21339. var isLoading = false;
  21340. var itemsLoaded = 0;
  21341. var itemsTotal = 0;
  21342. var urlModifier = undefined;
  21343. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  21344. // in the constructor
  21345. this.onStart = undefined;
  21346. this.onLoad = onLoad;
  21347. this.onProgress = onProgress;
  21348. this.onError = onError;
  21349. this.itemStart = function (url) {
  21350. itemsTotal++;
  21351. if (isLoading === false) {
  21352. if (scope.onStart !== undefined) {
  21353. scope.onStart(url, itemsLoaded, itemsTotal);
  21354. }
  21355. }
  21356. isLoading = true;
  21357. };
  21358. this.itemEnd = function (url) {
  21359. itemsLoaded++;
  21360. if (scope.onProgress !== undefined) {
  21361. scope.onProgress(url, itemsLoaded, itemsTotal);
  21362. }
  21363. if (itemsLoaded === itemsTotal) {
  21364. isLoading = false;
  21365. if (scope.onLoad !== undefined) {
  21366. scope.onLoad();
  21367. }
  21368. }
  21369. };
  21370. this.itemError = function (url) {
  21371. if (scope.onError !== undefined) {
  21372. scope.onError(url);
  21373. }
  21374. };
  21375. this.resolveURL = function (url) {
  21376. if (urlModifier) {
  21377. return urlModifier(url);
  21378. }
  21379. return url;
  21380. };
  21381. this.setURLModifier = function (transform) {
  21382. urlModifier = transform;
  21383. return this;
  21384. };
  21385. this.addHandler = function (regex, loader) {
  21386. handlers.push(regex, loader);
  21387. return this;
  21388. };
  21389. this.removeHandler = function (regex) {
  21390. var index = handlers.indexOf(regex);
  21391. if (index !== -1) {
  21392. handlers.splice(index, 2);
  21393. }
  21394. return this;
  21395. };
  21396. this.getHandler = function (file) {
  21397. for (var i = 0, l = handlers.length; i < l; i += 2) {
  21398. var regex = handlers[i];
  21399. var loader = handlers[i + 1];
  21400. if (regex.global) regex.lastIndex = 0; // see #17920
  21401. if (regex.test(file)) {
  21402. return loader;
  21403. }
  21404. }
  21405. return null;
  21406. };
  21407. }
  21408. var DefaultLoadingManager = new LoadingManager();
  21409. function Loader(manager) {
  21410. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  21411. this.crossOrigin = 'anonymous';
  21412. this.withCredentials = false;
  21413. this.path = '';
  21414. this.resourcePath = '';
  21415. this.requestHeader = {};
  21416. }
  21417. Object.assign(Loader.prototype, {
  21418. load: function load()
  21419. /* url, onLoad, onProgress, onError */
  21420. {},
  21421. loadAsync: function loadAsync(url, onProgress) {
  21422. var scope = this;
  21423. return new Promise(function (resolve, reject) {
  21424. scope.load(url, resolve, onProgress, reject);
  21425. });
  21426. },
  21427. parse: function parse()
  21428. /* data */
  21429. {},
  21430. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  21431. this.crossOrigin = crossOrigin;
  21432. return this;
  21433. },
  21434. setWithCredentials: function setWithCredentials(value) {
  21435. this.withCredentials = value;
  21436. return this;
  21437. },
  21438. setPath: function setPath(path) {
  21439. this.path = path;
  21440. return this;
  21441. },
  21442. setResourcePath: function setResourcePath(resourcePath) {
  21443. this.resourcePath = resourcePath;
  21444. return this;
  21445. },
  21446. setRequestHeader: function setRequestHeader(requestHeader) {
  21447. this.requestHeader = requestHeader;
  21448. return this;
  21449. }
  21450. });
  21451. var loading = {};
  21452. function FileLoader(manager) {
  21453. Loader.call(this, manager);
  21454. }
  21455. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21456. constructor: FileLoader,
  21457. load: function load(url, onLoad, onProgress, onError) {
  21458. if (url === undefined) url = '';
  21459. if (this.path !== undefined) url = this.path + url;
  21460. url = this.manager.resolveURL(url);
  21461. var scope = this;
  21462. var cached = Cache.get(url);
  21463. if (cached !== undefined) {
  21464. scope.manager.itemStart(url);
  21465. setTimeout(function () {
  21466. if (onLoad) onLoad(cached);
  21467. scope.manager.itemEnd(url);
  21468. }, 0);
  21469. return cached;
  21470. } // Check if request is duplicate
  21471. if (loading[url] !== undefined) {
  21472. loading[url].push({
  21473. onLoad: onLoad,
  21474. onProgress: onProgress,
  21475. onError: onError
  21476. });
  21477. return;
  21478. } // Check for data: URI
  21479. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  21480. var dataUriRegexResult = url.match(dataUriRegex);
  21481. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  21482. if (dataUriRegexResult) {
  21483. var mimeType = dataUriRegexResult[1];
  21484. var isBase64 = !!dataUriRegexResult[2];
  21485. var data = dataUriRegexResult[3];
  21486. data = decodeURIComponent(data);
  21487. if (isBase64) data = atob(data);
  21488. try {
  21489. var response;
  21490. var responseType = (this.responseType || '').toLowerCase();
  21491. switch (responseType) {
  21492. case 'arraybuffer':
  21493. case 'blob':
  21494. var view = new Uint8Array(data.length);
  21495. for (var i = 0; i < data.length; i++) {
  21496. view[i] = data.charCodeAt(i);
  21497. }
  21498. if (responseType === 'blob') {
  21499. response = new Blob([view.buffer], {
  21500. type: mimeType
  21501. });
  21502. } else {
  21503. response = view.buffer;
  21504. }
  21505. break;
  21506. case 'document':
  21507. var parser = new DOMParser();
  21508. response = parser.parseFromString(data, mimeType);
  21509. break;
  21510. case 'json':
  21511. response = JSON.parse(data);
  21512. break;
  21513. default:
  21514. // 'text' or other
  21515. response = data;
  21516. break;
  21517. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21518. setTimeout(function () {
  21519. if (onLoad) onLoad(response);
  21520. scope.manager.itemEnd(url);
  21521. }, 0);
  21522. } catch (error) {
  21523. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21524. setTimeout(function () {
  21525. if (onError) onError(error);
  21526. scope.manager.itemError(url);
  21527. scope.manager.itemEnd(url);
  21528. }, 0);
  21529. }
  21530. } else {
  21531. // Initialise array for duplicate requests
  21532. loading[url] = [];
  21533. loading[url].push({
  21534. onLoad: onLoad,
  21535. onProgress: onProgress,
  21536. onError: onError
  21537. });
  21538. request = new XMLHttpRequest();
  21539. request.open('GET', url, true);
  21540. request.addEventListener('load', function (event) {
  21541. var response = this.response;
  21542. var callbacks = loading[url];
  21543. delete loading[url];
  21544. if (this.status === 200 || this.status === 0) {
  21545. // Some browsers return HTTP Status 0 when using non-http protocol
  21546. // e.g. 'file://' or 'data://'. Handle as success.
  21547. 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
  21548. // error response bodies as proper responses to requests.
  21549. Cache.add(url, response);
  21550. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  21551. var callback = callbacks[_i];
  21552. if (callback.onLoad) callback.onLoad(response);
  21553. }
  21554. scope.manager.itemEnd(url);
  21555. } else {
  21556. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  21557. var _callback = callbacks[_i2];
  21558. if (_callback.onError) _callback.onError(event);
  21559. }
  21560. scope.manager.itemError(url);
  21561. scope.manager.itemEnd(url);
  21562. }
  21563. }, false);
  21564. request.addEventListener('progress', function (event) {
  21565. var callbacks = loading[url];
  21566. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  21567. var callback = callbacks[_i3];
  21568. if (callback.onProgress) callback.onProgress(event);
  21569. }
  21570. }, false);
  21571. request.addEventListener('error', function (event) {
  21572. var callbacks = loading[url];
  21573. delete loading[url];
  21574. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  21575. var callback = callbacks[_i4];
  21576. if (callback.onError) callback.onError(event);
  21577. }
  21578. scope.manager.itemError(url);
  21579. scope.manager.itemEnd(url);
  21580. }, false);
  21581. request.addEventListener('abort', function (event) {
  21582. var callbacks = loading[url];
  21583. delete loading[url];
  21584. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  21585. var callback = callbacks[_i5];
  21586. if (callback.onError) callback.onError(event);
  21587. }
  21588. scope.manager.itemError(url);
  21589. scope.manager.itemEnd(url);
  21590. }, false);
  21591. if (this.responseType !== undefined) request.responseType = this.responseType;
  21592. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  21593. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  21594. for (var header in this.requestHeader) {
  21595. request.setRequestHeader(header, this.requestHeader[header]);
  21596. }
  21597. request.send(null);
  21598. }
  21599. scope.manager.itemStart(url);
  21600. return request;
  21601. },
  21602. setResponseType: function setResponseType(value) {
  21603. this.responseType = value;
  21604. return this;
  21605. },
  21606. setMimeType: function setMimeType(value) {
  21607. this.mimeType = value;
  21608. return this;
  21609. }
  21610. });
  21611. function AnimationLoader(manager) {
  21612. Loader.call(this, manager);
  21613. }
  21614. AnimationLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21615. constructor: AnimationLoader,
  21616. load: function load(url, onLoad, onProgress, onError) {
  21617. var scope = this;
  21618. var loader = new FileLoader(scope.manager);
  21619. loader.setPath(scope.path);
  21620. loader.setRequestHeader(scope.requestHeader);
  21621. loader.setWithCredentials(scope.withCredentials);
  21622. loader.load(url, function (text) {
  21623. try {
  21624. onLoad(scope.parse(JSON.parse(text)));
  21625. } catch (e) {
  21626. if (onError) {
  21627. onError(e);
  21628. } else {
  21629. console.error(e);
  21630. }
  21631. scope.manager.itemError(url);
  21632. }
  21633. }, onProgress, onError);
  21634. },
  21635. parse: function parse(json) {
  21636. var animations = [];
  21637. for (var i = 0; i < json.length; i++) {
  21638. var clip = AnimationClip.parse(json[i]);
  21639. animations.push(clip);
  21640. }
  21641. return animations;
  21642. }
  21643. });
  21644. /**
  21645. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21646. *
  21647. * Sub classes have to implement the parse() method which will be used in load().
  21648. */
  21649. function CompressedTextureLoader(manager) {
  21650. Loader.call(this, manager);
  21651. }
  21652. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21653. constructor: CompressedTextureLoader,
  21654. load: function load(url, onLoad, onProgress, onError) {
  21655. var scope = this;
  21656. var images = [];
  21657. var texture = new CompressedTexture();
  21658. var loader = new FileLoader(this.manager);
  21659. loader.setPath(this.path);
  21660. loader.setResponseType('arraybuffer');
  21661. loader.setRequestHeader(this.requestHeader);
  21662. loader.setWithCredentials(scope.withCredentials);
  21663. var loaded = 0;
  21664. function loadTexture(i) {
  21665. loader.load(url[i], function (buffer) {
  21666. var texDatas = scope.parse(buffer, true);
  21667. images[i] = {
  21668. width: texDatas.width,
  21669. height: texDatas.height,
  21670. format: texDatas.format,
  21671. mipmaps: texDatas.mipmaps
  21672. };
  21673. loaded += 1;
  21674. if (loaded === 6) {
  21675. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  21676. texture.image = images;
  21677. texture.format = texDatas.format;
  21678. texture.needsUpdate = true;
  21679. if (onLoad) onLoad(texture);
  21680. }
  21681. }, onProgress, onError);
  21682. }
  21683. if (Array.isArray(url)) {
  21684. for (var i = 0, il = url.length; i < il; ++i) {
  21685. loadTexture(i);
  21686. }
  21687. } else {
  21688. // compressed cubemap texture stored in a single DDS file
  21689. loader.load(url, function (buffer) {
  21690. var texDatas = scope.parse(buffer, true);
  21691. if (texDatas.isCubemap) {
  21692. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21693. for (var f = 0; f < faces; f++) {
  21694. images[f] = {
  21695. mipmaps: []
  21696. };
  21697. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  21698. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  21699. images[f].format = texDatas.format;
  21700. images[f].width = texDatas.width;
  21701. images[f].height = texDatas.height;
  21702. }
  21703. }
  21704. texture.image = images;
  21705. } else {
  21706. texture.image.width = texDatas.width;
  21707. texture.image.height = texDatas.height;
  21708. texture.mipmaps = texDatas.mipmaps;
  21709. }
  21710. if (texDatas.mipmapCount === 1) {
  21711. texture.minFilter = LinearFilter;
  21712. }
  21713. texture.format = texDatas.format;
  21714. texture.needsUpdate = true;
  21715. if (onLoad) onLoad(texture);
  21716. }, onProgress, onError);
  21717. }
  21718. return texture;
  21719. }
  21720. });
  21721. function ImageLoader(manager) {
  21722. Loader.call(this, manager);
  21723. }
  21724. ImageLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21725. constructor: ImageLoader,
  21726. load: function load(url, onLoad, onProgress, onError) {
  21727. if (this.path !== undefined) url = this.path + url;
  21728. url = this.manager.resolveURL(url);
  21729. var scope = this;
  21730. var cached = Cache.get(url);
  21731. if (cached !== undefined) {
  21732. scope.manager.itemStart(url);
  21733. setTimeout(function () {
  21734. if (onLoad) onLoad(cached);
  21735. scope.manager.itemEnd(url);
  21736. }, 0);
  21737. return cached;
  21738. }
  21739. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  21740. function onImageLoad() {
  21741. image.removeEventListener('load', onImageLoad, false);
  21742. image.removeEventListener('error', onImageError, false);
  21743. Cache.add(url, this);
  21744. if (onLoad) onLoad(this);
  21745. scope.manager.itemEnd(url);
  21746. }
  21747. function onImageError(event) {
  21748. image.removeEventListener('load', onImageLoad, false);
  21749. image.removeEventListener('error', onImageError, false);
  21750. if (onError) onError(event);
  21751. scope.manager.itemError(url);
  21752. scope.manager.itemEnd(url);
  21753. }
  21754. image.addEventListener('load', onImageLoad, false);
  21755. image.addEventListener('error', onImageError, false);
  21756. if (url.substr(0, 5) !== 'data:') {
  21757. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  21758. }
  21759. scope.manager.itemStart(url);
  21760. image.src = url;
  21761. return image;
  21762. }
  21763. });
  21764. function CubeTextureLoader(manager) {
  21765. Loader.call(this, manager);
  21766. }
  21767. CubeTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21768. constructor: CubeTextureLoader,
  21769. load: function load(urls, onLoad, onProgress, onError) {
  21770. var texture = new CubeTexture();
  21771. var loader = new ImageLoader(this.manager);
  21772. loader.setCrossOrigin(this.crossOrigin);
  21773. loader.setPath(this.path);
  21774. var loaded = 0;
  21775. function loadTexture(i) {
  21776. loader.load(urls[i], function (image) {
  21777. texture.images[i] = image;
  21778. loaded++;
  21779. if (loaded === 6) {
  21780. texture.needsUpdate = true;
  21781. if (onLoad) onLoad(texture);
  21782. }
  21783. }, undefined, onError);
  21784. }
  21785. for (var i = 0; i < urls.length; ++i) {
  21786. loadTexture(i);
  21787. }
  21788. return texture;
  21789. }
  21790. });
  21791. /**
  21792. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  21793. *
  21794. * Sub classes have to implement the parse() method which will be used in load().
  21795. */
  21796. function DataTextureLoader(manager) {
  21797. Loader.call(this, manager);
  21798. }
  21799. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21800. constructor: DataTextureLoader,
  21801. load: function load(url, onLoad, onProgress, onError) {
  21802. var scope = this;
  21803. var texture = new DataTexture();
  21804. var loader = new FileLoader(this.manager);
  21805. loader.setResponseType('arraybuffer');
  21806. loader.setRequestHeader(this.requestHeader);
  21807. loader.setPath(this.path);
  21808. loader.setWithCredentials(scope.withCredentials);
  21809. loader.load(url, function (buffer) {
  21810. var texData = scope.parse(buffer);
  21811. if (!texData) return;
  21812. if (texData.image !== undefined) {
  21813. texture.image = texData.image;
  21814. } else if (texData.data !== undefined) {
  21815. texture.image.width = texData.width;
  21816. texture.image.height = texData.height;
  21817. texture.image.data = texData.data;
  21818. }
  21819. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  21820. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  21821. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  21822. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  21823. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  21824. if (texData.encoding !== undefined) {
  21825. texture.encoding = texData.encoding;
  21826. }
  21827. if (texData.flipY !== undefined) {
  21828. texture.flipY = texData.flipY;
  21829. }
  21830. if (texData.format !== undefined) {
  21831. texture.format = texData.format;
  21832. }
  21833. if (texData.type !== undefined) {
  21834. texture.type = texData.type;
  21835. }
  21836. if (texData.mipmaps !== undefined) {
  21837. texture.mipmaps = texData.mipmaps;
  21838. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  21839. }
  21840. if (texData.mipmapCount === 1) {
  21841. texture.minFilter = LinearFilter;
  21842. }
  21843. texture.needsUpdate = true;
  21844. if (onLoad) onLoad(texture, texData);
  21845. }, onProgress, onError);
  21846. return texture;
  21847. }
  21848. });
  21849. function TextureLoader(manager) {
  21850. Loader.call(this, manager);
  21851. }
  21852. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21853. constructor: TextureLoader,
  21854. load: function load(url, onLoad, onProgress, onError) {
  21855. var texture = new Texture();
  21856. var loader = new ImageLoader(this.manager);
  21857. loader.setCrossOrigin(this.crossOrigin);
  21858. loader.setPath(this.path);
  21859. loader.load(url, function (image) {
  21860. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  21861. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  21862. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  21863. texture.needsUpdate = true;
  21864. if (onLoad !== undefined) {
  21865. onLoad(texture);
  21866. }
  21867. }, onProgress, onError);
  21868. return texture;
  21869. }
  21870. });
  21871. /**
  21872. * Extensible curve object.
  21873. *
  21874. * Some common of curve methods:
  21875. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  21876. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  21877. * .getPoints(), .getSpacedPoints()
  21878. * .getLength()
  21879. * .updateArcLengths()
  21880. *
  21881. * This following curves inherit from THREE.Curve:
  21882. *
  21883. * -- 2D curves --
  21884. * THREE.ArcCurve
  21885. * THREE.CubicBezierCurve
  21886. * THREE.EllipseCurve
  21887. * THREE.LineCurve
  21888. * THREE.QuadraticBezierCurve
  21889. * THREE.SplineCurve
  21890. *
  21891. * -- 3D curves --
  21892. * THREE.CatmullRomCurve3
  21893. * THREE.CubicBezierCurve3
  21894. * THREE.LineCurve3
  21895. * THREE.QuadraticBezierCurve3
  21896. *
  21897. * A series of curves can be represented as a THREE.CurvePath.
  21898. *
  21899. **/
  21900. function Curve() {
  21901. this.type = 'Curve';
  21902. this.arcLengthDivisions = 200;
  21903. }
  21904. Object.assign(Curve.prototype, {
  21905. // Virtual base class method to overwrite and implement in subclasses
  21906. // - t [0 .. 1]
  21907. getPoint: function getPoint()
  21908. /* t, optionalTarget */
  21909. {
  21910. console.warn('THREE.Curve: .getPoint() not implemented.');
  21911. return null;
  21912. },
  21913. // Get point at relative position in curve according to arc length
  21914. // - u [0 .. 1]
  21915. getPointAt: function getPointAt(u, optionalTarget) {
  21916. var t = this.getUtoTmapping(u);
  21917. return this.getPoint(t, optionalTarget);
  21918. },
  21919. // Get sequence of points using getPoint( t )
  21920. getPoints: function getPoints(divisions) {
  21921. if (divisions === void 0) {
  21922. divisions = 5;
  21923. }
  21924. var points = [];
  21925. for (var d = 0; d <= divisions; d++) {
  21926. points.push(this.getPoint(d / divisions));
  21927. }
  21928. return points;
  21929. },
  21930. // Get sequence of points using getPointAt( u )
  21931. getSpacedPoints: function getSpacedPoints(divisions) {
  21932. if (divisions === void 0) {
  21933. divisions = 5;
  21934. }
  21935. var points = [];
  21936. for (var d = 0; d <= divisions; d++) {
  21937. points.push(this.getPointAt(d / divisions));
  21938. }
  21939. return points;
  21940. },
  21941. // Get total curve arc length
  21942. getLength: function getLength() {
  21943. var lengths = this.getLengths();
  21944. return lengths[lengths.length - 1];
  21945. },
  21946. // Get list of cumulative segment lengths
  21947. getLengths: function getLengths(divisions) {
  21948. if (divisions === undefined) divisions = this.arcLengthDivisions;
  21949. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  21950. return this.cacheArcLengths;
  21951. }
  21952. this.needsUpdate = false;
  21953. var cache = [];
  21954. var current,
  21955. last = this.getPoint(0);
  21956. var sum = 0;
  21957. cache.push(0);
  21958. for (var p = 1; p <= divisions; p++) {
  21959. current = this.getPoint(p / divisions);
  21960. sum += current.distanceTo(last);
  21961. cache.push(sum);
  21962. last = current;
  21963. }
  21964. this.cacheArcLengths = cache;
  21965. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  21966. },
  21967. updateArcLengths: function updateArcLengths() {
  21968. this.needsUpdate = true;
  21969. this.getLengths();
  21970. },
  21971. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  21972. getUtoTmapping: function getUtoTmapping(u, distance) {
  21973. var arcLengths = this.getLengths();
  21974. var i = 0;
  21975. var il = arcLengths.length;
  21976. var targetArcLength; // The targeted u distance value to get
  21977. if (distance) {
  21978. targetArcLength = distance;
  21979. } else {
  21980. targetArcLength = u * arcLengths[il - 1];
  21981. } // binary search for the index with largest value smaller than target u distance
  21982. var low = 0,
  21983. high = il - 1,
  21984. comparison;
  21985. while (low <= high) {
  21986. 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
  21987. comparison = arcLengths[i] - targetArcLength;
  21988. if (comparison < 0) {
  21989. low = i + 1;
  21990. } else if (comparison > 0) {
  21991. high = i - 1;
  21992. } else {
  21993. high = i;
  21994. break; // DONE
  21995. }
  21996. }
  21997. i = high;
  21998. if (arcLengths[i] === targetArcLength) {
  21999. return i / (il - 1);
  22000. } // we could get finer grain at lengths, or use simple interpolation between two points
  22001. var lengthBefore = arcLengths[i];
  22002. var lengthAfter = arcLengths[i + 1];
  22003. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  22004. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  22005. var t = (i + segmentFraction) / (il - 1);
  22006. return t;
  22007. },
  22008. // Returns a unit vector tangent at t
  22009. // In case any sub curve does not implement its tangent derivation,
  22010. // 2 points a small delta apart will be used to find its gradient
  22011. // which seems to give a reasonable approximation
  22012. getTangent: function getTangent(t, optionalTarget) {
  22013. var delta = 0.0001;
  22014. var t1 = t - delta;
  22015. var t2 = t + delta; // Capping in case of danger
  22016. if (t1 < 0) t1 = 0;
  22017. if (t2 > 1) t2 = 1;
  22018. var pt1 = this.getPoint(t1);
  22019. var pt2 = this.getPoint(t2);
  22020. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  22021. tangent.copy(pt2).sub(pt1).normalize();
  22022. return tangent;
  22023. },
  22024. getTangentAt: function getTangentAt(u, optionalTarget) {
  22025. var t = this.getUtoTmapping(u);
  22026. return this.getTangent(t, optionalTarget);
  22027. },
  22028. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  22029. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22030. var normal = new Vector3();
  22031. var tangents = [];
  22032. var normals = [];
  22033. var binormals = [];
  22034. var vec = new Vector3();
  22035. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  22036. for (var i = 0; i <= segments; i++) {
  22037. var u = i / segments;
  22038. tangents[i] = this.getTangentAt(u, new Vector3());
  22039. tangents[i].normalize();
  22040. } // select an initial normal vector perpendicular to the first tangent vector,
  22041. // and in the direction of the minimum tangent xyz component
  22042. normals[0] = new Vector3();
  22043. binormals[0] = new Vector3();
  22044. var min = Number.MAX_VALUE;
  22045. var tx = Math.abs(tangents[0].x);
  22046. var ty = Math.abs(tangents[0].y);
  22047. var tz = Math.abs(tangents[0].z);
  22048. if (tx <= min) {
  22049. min = tx;
  22050. normal.set(1, 0, 0);
  22051. }
  22052. if (ty <= min) {
  22053. min = ty;
  22054. normal.set(0, 1, 0);
  22055. }
  22056. if (tz <= min) {
  22057. normal.set(0, 0, 1);
  22058. }
  22059. vec.crossVectors(tangents[0], normal).normalize();
  22060. normals[0].crossVectors(tangents[0], vec);
  22061. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22062. for (var _i = 1; _i <= segments; _i++) {
  22063. normals[_i] = normals[_i - 1].clone();
  22064. binormals[_i] = binormals[_i - 1].clone();
  22065. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  22066. if (vec.length() > Number.EPSILON) {
  22067. vec.normalize();
  22068. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  22069. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  22070. }
  22071. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  22072. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22073. if (closed === true) {
  22074. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  22075. _theta /= segments;
  22076. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  22077. _theta = -_theta;
  22078. }
  22079. for (var _i2 = 1; _i2 <= segments; _i2++) {
  22080. // twist a little...
  22081. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  22082. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  22083. }
  22084. }
  22085. return {
  22086. tangents: tangents,
  22087. normals: normals,
  22088. binormals: binormals
  22089. };
  22090. },
  22091. clone: function clone() {
  22092. return new this.constructor().copy(this);
  22093. },
  22094. copy: function copy(source) {
  22095. this.arcLengthDivisions = source.arcLengthDivisions;
  22096. return this;
  22097. },
  22098. toJSON: function toJSON() {
  22099. var data = {
  22100. metadata: {
  22101. version: 4.5,
  22102. type: 'Curve',
  22103. generator: 'Curve.toJSON'
  22104. }
  22105. };
  22106. data.arcLengthDivisions = this.arcLengthDivisions;
  22107. data.type = this.type;
  22108. return data;
  22109. },
  22110. fromJSON: function fromJSON(json) {
  22111. this.arcLengthDivisions = json.arcLengthDivisions;
  22112. return this;
  22113. }
  22114. });
  22115. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22116. Curve.call(this);
  22117. this.type = 'EllipseCurve';
  22118. this.aX = aX || 0;
  22119. this.aY = aY || 0;
  22120. this.xRadius = xRadius || 1;
  22121. this.yRadius = yRadius || 1;
  22122. this.aStartAngle = aStartAngle || 0;
  22123. this.aEndAngle = aEndAngle || 2 * Math.PI;
  22124. this.aClockwise = aClockwise || false;
  22125. this.aRotation = aRotation || 0;
  22126. }
  22127. EllipseCurve.prototype = Object.create(Curve.prototype);
  22128. EllipseCurve.prototype.constructor = EllipseCurve;
  22129. EllipseCurve.prototype.isEllipseCurve = true;
  22130. EllipseCurve.prototype.getPoint = function (t, optionalTarget) {
  22131. var point = optionalTarget || new Vector2();
  22132. var twoPi = Math.PI * 2;
  22133. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22134. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  22135. while (deltaAngle < 0) {
  22136. deltaAngle += twoPi;
  22137. }
  22138. while (deltaAngle > twoPi) {
  22139. deltaAngle -= twoPi;
  22140. }
  22141. if (deltaAngle < Number.EPSILON) {
  22142. if (samePoints) {
  22143. deltaAngle = 0;
  22144. } else {
  22145. deltaAngle = twoPi;
  22146. }
  22147. }
  22148. if (this.aClockwise === true && !samePoints) {
  22149. if (deltaAngle === twoPi) {
  22150. deltaAngle = -twoPi;
  22151. } else {
  22152. deltaAngle = deltaAngle - twoPi;
  22153. }
  22154. }
  22155. var angle = this.aStartAngle + t * deltaAngle;
  22156. var x = this.aX + this.xRadius * Math.cos(angle);
  22157. var y = this.aY + this.yRadius * Math.sin(angle);
  22158. if (this.aRotation !== 0) {
  22159. var cos = Math.cos(this.aRotation);
  22160. var sin = Math.sin(this.aRotation);
  22161. var tx = x - this.aX;
  22162. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  22163. x = tx * cos - ty * sin + this.aX;
  22164. y = tx * sin + ty * cos + this.aY;
  22165. }
  22166. return point.set(x, y);
  22167. };
  22168. EllipseCurve.prototype.copy = function (source) {
  22169. Curve.prototype.copy.call(this, source);
  22170. this.aX = source.aX;
  22171. this.aY = source.aY;
  22172. this.xRadius = source.xRadius;
  22173. this.yRadius = source.yRadius;
  22174. this.aStartAngle = source.aStartAngle;
  22175. this.aEndAngle = source.aEndAngle;
  22176. this.aClockwise = source.aClockwise;
  22177. this.aRotation = source.aRotation;
  22178. return this;
  22179. };
  22180. EllipseCurve.prototype.toJSON = function () {
  22181. var data = Curve.prototype.toJSON.call(this);
  22182. data.aX = this.aX;
  22183. data.aY = this.aY;
  22184. data.xRadius = this.xRadius;
  22185. data.yRadius = this.yRadius;
  22186. data.aStartAngle = this.aStartAngle;
  22187. data.aEndAngle = this.aEndAngle;
  22188. data.aClockwise = this.aClockwise;
  22189. data.aRotation = this.aRotation;
  22190. return data;
  22191. };
  22192. EllipseCurve.prototype.fromJSON = function (json) {
  22193. Curve.prototype.fromJSON.call(this, json);
  22194. this.aX = json.aX;
  22195. this.aY = json.aY;
  22196. this.xRadius = json.xRadius;
  22197. this.yRadius = json.yRadius;
  22198. this.aStartAngle = json.aStartAngle;
  22199. this.aEndAngle = json.aEndAngle;
  22200. this.aClockwise = json.aClockwise;
  22201. this.aRotation = json.aRotation;
  22202. return this;
  22203. };
  22204. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22205. EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  22206. this.type = 'ArcCurve';
  22207. }
  22208. ArcCurve.prototype = Object.create(EllipseCurve.prototype);
  22209. ArcCurve.prototype.constructor = ArcCurve;
  22210. ArcCurve.prototype.isArcCurve = true;
  22211. /**
  22212. * Centripetal CatmullRom Curve - which is useful for avoiding
  22213. * cusps and self-intersections in non-uniform catmull rom curves.
  22214. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22215. *
  22216. * curve.type accepts centripetal(default), chordal and catmullrom
  22217. * curve.tension is used for catmullrom which defaults to 0.5
  22218. */
  22219. /*
  22220. Based on an optimized c++ solution in
  22221. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22222. - http://ideone.com/NoEbVM
  22223. This CubicPoly class could be used for reusing some variables and calculations,
  22224. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22225. which can be placed in CurveUtils.
  22226. */
  22227. function CubicPoly() {
  22228. var c0 = 0,
  22229. c1 = 0,
  22230. c2 = 0,
  22231. c3 = 0;
  22232. /*
  22233. * Compute coefficients for a cubic polynomial
  22234. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22235. * such that
  22236. * p(0) = x0, p(1) = x1
  22237. * and
  22238. * p'(0) = t0, p'(1) = t1.
  22239. */
  22240. function init(x0, x1, t0, t1) {
  22241. c0 = x0;
  22242. c1 = t0;
  22243. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  22244. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22245. }
  22246. return {
  22247. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  22248. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  22249. },
  22250. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  22251. // compute tangents when parameterized in [t1,t2]
  22252. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  22253. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  22254. t1 *= dt1;
  22255. t2 *= dt1;
  22256. init(x1, x2, t1, t2);
  22257. },
  22258. calc: function calc(t) {
  22259. var t2 = t * t;
  22260. var t3 = t2 * t;
  22261. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22262. }
  22263. };
  22264. } //
  22265. var tmp = new Vector3();
  22266. var px = new CubicPoly(),
  22267. py = new CubicPoly(),
  22268. pz = new CubicPoly();
  22269. function CatmullRomCurve3(points, closed, curveType, tension) {
  22270. if (points === void 0) {
  22271. points = [];
  22272. }
  22273. if (closed === void 0) {
  22274. closed = false;
  22275. }
  22276. if (curveType === void 0) {
  22277. curveType = 'centripetal';
  22278. }
  22279. if (tension === void 0) {
  22280. tension = 0.5;
  22281. }
  22282. Curve.call(this);
  22283. this.type = 'CatmullRomCurve3';
  22284. this.points = points;
  22285. this.closed = closed;
  22286. this.curveType = curveType;
  22287. this.tension = tension;
  22288. }
  22289. CatmullRomCurve3.prototype = Object.create(Curve.prototype);
  22290. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  22291. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22292. CatmullRomCurve3.prototype.getPoint = function (t, optionalTarget) {
  22293. if (optionalTarget === void 0) {
  22294. optionalTarget = new Vector3();
  22295. }
  22296. var point = optionalTarget;
  22297. var points = this.points;
  22298. var l = points.length;
  22299. var p = (l - (this.closed ? 0 : 1)) * t;
  22300. var intPoint = Math.floor(p);
  22301. var weight = p - intPoint;
  22302. if (this.closed) {
  22303. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  22304. } else if (weight === 0 && intPoint === l - 1) {
  22305. intPoint = l - 2;
  22306. weight = 1;
  22307. }
  22308. var p0, p3; // 4 points (p1 & p2 defined below)
  22309. if (this.closed || intPoint > 0) {
  22310. p0 = points[(intPoint - 1) % l];
  22311. } else {
  22312. // extrapolate first point
  22313. tmp.subVectors(points[0], points[1]).add(points[0]);
  22314. p0 = tmp;
  22315. }
  22316. var p1 = points[intPoint % l];
  22317. var p2 = points[(intPoint + 1) % l];
  22318. if (this.closed || intPoint + 2 < l) {
  22319. p3 = points[(intPoint + 2) % l];
  22320. } else {
  22321. // extrapolate last point
  22322. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  22323. p3 = tmp;
  22324. }
  22325. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  22326. // init Centripetal / Chordal Catmull-Rom
  22327. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22328. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  22329. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  22330. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  22331. if (dt1 < 1e-4) dt1 = 1.0;
  22332. if (dt0 < 1e-4) dt0 = dt1;
  22333. if (dt2 < 1e-4) dt2 = dt1;
  22334. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  22335. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  22336. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  22337. } else if (this.curveType === 'catmullrom') {
  22338. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  22339. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  22340. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  22341. }
  22342. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  22343. return point;
  22344. };
  22345. CatmullRomCurve3.prototype.copy = function (source) {
  22346. Curve.prototype.copy.call(this, source);
  22347. this.points = [];
  22348. for (var i = 0, l = source.points.length; i < l; i++) {
  22349. var point = source.points[i];
  22350. this.points.push(point.clone());
  22351. }
  22352. this.closed = source.closed;
  22353. this.curveType = source.curveType;
  22354. this.tension = source.tension;
  22355. return this;
  22356. };
  22357. CatmullRomCurve3.prototype.toJSON = function () {
  22358. var data = Curve.prototype.toJSON.call(this);
  22359. data.points = [];
  22360. for (var i = 0, l = this.points.length; i < l; i++) {
  22361. var point = this.points[i];
  22362. data.points.push(point.toArray());
  22363. }
  22364. data.closed = this.closed;
  22365. data.curveType = this.curveType;
  22366. data.tension = this.tension;
  22367. return data;
  22368. };
  22369. CatmullRomCurve3.prototype.fromJSON = function (json) {
  22370. Curve.prototype.fromJSON.call(this, json);
  22371. this.points = [];
  22372. for (var i = 0, l = json.points.length; i < l; i++) {
  22373. var point = json.points[i];
  22374. this.points.push(new Vector3().fromArray(point));
  22375. }
  22376. this.closed = json.closed;
  22377. this.curveType = json.curveType;
  22378. this.tension = json.tension;
  22379. return this;
  22380. };
  22381. /**
  22382. * Bezier Curves formulas obtained from
  22383. * http://en.wikipedia.org/wiki/Bézier_curve
  22384. */
  22385. function CatmullRom(t, p0, p1, p2, p3) {
  22386. var v0 = (p2 - p0) * 0.5;
  22387. var v1 = (p3 - p1) * 0.5;
  22388. var t2 = t * t;
  22389. var t3 = t * t2;
  22390. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  22391. } //
  22392. function QuadraticBezierP0(t, p) {
  22393. var k = 1 - t;
  22394. return k * k * p;
  22395. }
  22396. function QuadraticBezierP1(t, p) {
  22397. return 2 * (1 - t) * t * p;
  22398. }
  22399. function QuadraticBezierP2(t, p) {
  22400. return t * t * p;
  22401. }
  22402. function QuadraticBezier(t, p0, p1, p2) {
  22403. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  22404. } //
  22405. function CubicBezierP0(t, p) {
  22406. var k = 1 - t;
  22407. return k * k * k * p;
  22408. }
  22409. function CubicBezierP1(t, p) {
  22410. var k = 1 - t;
  22411. return 3 * k * k * t * p;
  22412. }
  22413. function CubicBezierP2(t, p) {
  22414. return 3 * (1 - t) * t * t * p;
  22415. }
  22416. function CubicBezierP3(t, p) {
  22417. return t * t * t * p;
  22418. }
  22419. function CubicBezier(t, p0, p1, p2, p3) {
  22420. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  22421. }
  22422. function CubicBezierCurve(v0, v1, v2, v3) {
  22423. if (v0 === void 0) {
  22424. v0 = new Vector2();
  22425. }
  22426. if (v1 === void 0) {
  22427. v1 = new Vector2();
  22428. }
  22429. if (v2 === void 0) {
  22430. v2 = new Vector2();
  22431. }
  22432. if (v3 === void 0) {
  22433. v3 = new Vector2();
  22434. }
  22435. Curve.call(this);
  22436. this.type = 'CubicBezierCurve';
  22437. this.v0 = v0;
  22438. this.v1 = v1;
  22439. this.v2 = v2;
  22440. this.v3 = v3;
  22441. }
  22442. CubicBezierCurve.prototype = Object.create(Curve.prototype);
  22443. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  22444. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  22445. CubicBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  22446. if (optionalTarget === void 0) {
  22447. optionalTarget = new Vector2();
  22448. }
  22449. var point = optionalTarget;
  22450. var v0 = this.v0,
  22451. v1 = this.v1,
  22452. v2 = this.v2,
  22453. v3 = this.v3;
  22454. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  22455. return point;
  22456. };
  22457. CubicBezierCurve.prototype.copy = function (source) {
  22458. Curve.prototype.copy.call(this, source);
  22459. this.v0.copy(source.v0);
  22460. this.v1.copy(source.v1);
  22461. this.v2.copy(source.v2);
  22462. this.v3.copy(source.v3);
  22463. return this;
  22464. };
  22465. CubicBezierCurve.prototype.toJSON = function () {
  22466. var data = Curve.prototype.toJSON.call(this);
  22467. data.v0 = this.v0.toArray();
  22468. data.v1 = this.v1.toArray();
  22469. data.v2 = this.v2.toArray();
  22470. data.v3 = this.v3.toArray();
  22471. return data;
  22472. };
  22473. CubicBezierCurve.prototype.fromJSON = function (json) {
  22474. Curve.prototype.fromJSON.call(this, json);
  22475. this.v0.fromArray(json.v0);
  22476. this.v1.fromArray(json.v1);
  22477. this.v2.fromArray(json.v2);
  22478. this.v3.fromArray(json.v3);
  22479. return this;
  22480. };
  22481. function CubicBezierCurve3(v0, v1, v2, v3) {
  22482. if (v0 === void 0) {
  22483. v0 = new Vector3();
  22484. }
  22485. if (v1 === void 0) {
  22486. v1 = new Vector3();
  22487. }
  22488. if (v2 === void 0) {
  22489. v2 = new Vector3();
  22490. }
  22491. if (v3 === void 0) {
  22492. v3 = new Vector3();
  22493. }
  22494. Curve.call(this);
  22495. this.type = 'CubicBezierCurve3';
  22496. this.v0 = v0;
  22497. this.v1 = v1;
  22498. this.v2 = v2;
  22499. this.v3 = v3;
  22500. }
  22501. CubicBezierCurve3.prototype = Object.create(Curve.prototype);
  22502. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  22503. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  22504. CubicBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  22505. if (optionalTarget === void 0) {
  22506. optionalTarget = new Vector3();
  22507. }
  22508. var point = optionalTarget;
  22509. var v0 = this.v0,
  22510. v1 = this.v1,
  22511. v2 = this.v2,
  22512. v3 = this.v3;
  22513. 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));
  22514. return point;
  22515. };
  22516. CubicBezierCurve3.prototype.copy = function (source) {
  22517. Curve.prototype.copy.call(this, source);
  22518. this.v0.copy(source.v0);
  22519. this.v1.copy(source.v1);
  22520. this.v2.copy(source.v2);
  22521. this.v3.copy(source.v3);
  22522. return this;
  22523. };
  22524. CubicBezierCurve3.prototype.toJSON = function () {
  22525. var data = Curve.prototype.toJSON.call(this);
  22526. data.v0 = this.v0.toArray();
  22527. data.v1 = this.v1.toArray();
  22528. data.v2 = this.v2.toArray();
  22529. data.v3 = this.v3.toArray();
  22530. return data;
  22531. };
  22532. CubicBezierCurve3.prototype.fromJSON = function (json) {
  22533. Curve.prototype.fromJSON.call(this, json);
  22534. this.v0.fromArray(json.v0);
  22535. this.v1.fromArray(json.v1);
  22536. this.v2.fromArray(json.v2);
  22537. this.v3.fromArray(json.v3);
  22538. return this;
  22539. };
  22540. function LineCurve(v1, v2) {
  22541. if (v1 === void 0) {
  22542. v1 = new Vector2();
  22543. }
  22544. if (v2 === void 0) {
  22545. v2 = new Vector2();
  22546. }
  22547. Curve.call(this);
  22548. this.type = 'LineCurve';
  22549. this.v1 = v1;
  22550. this.v2 = v2;
  22551. }
  22552. LineCurve.prototype = Object.create(Curve.prototype);
  22553. LineCurve.prototype.constructor = LineCurve;
  22554. LineCurve.prototype.isLineCurve = true;
  22555. LineCurve.prototype.getPoint = function (t, optionalTarget) {
  22556. if (optionalTarget === void 0) {
  22557. optionalTarget = new Vector2();
  22558. }
  22559. var point = optionalTarget;
  22560. if (t === 1) {
  22561. point.copy(this.v2);
  22562. } else {
  22563. point.copy(this.v2).sub(this.v1);
  22564. point.multiplyScalar(t).add(this.v1);
  22565. }
  22566. return point;
  22567. }; // Line curve is linear, so we can overwrite default getPointAt
  22568. LineCurve.prototype.getPointAt = function (u, optionalTarget) {
  22569. return this.getPoint(u, optionalTarget);
  22570. };
  22571. LineCurve.prototype.getTangent = function (t, optionalTarget) {
  22572. var tangent = optionalTarget || new Vector2();
  22573. tangent.copy(this.v2).sub(this.v1).normalize();
  22574. return tangent;
  22575. };
  22576. LineCurve.prototype.copy = function (source) {
  22577. Curve.prototype.copy.call(this, source);
  22578. this.v1.copy(source.v1);
  22579. this.v2.copy(source.v2);
  22580. return this;
  22581. };
  22582. LineCurve.prototype.toJSON = function () {
  22583. var data = Curve.prototype.toJSON.call(this);
  22584. data.v1 = this.v1.toArray();
  22585. data.v2 = this.v2.toArray();
  22586. return data;
  22587. };
  22588. LineCurve.prototype.fromJSON = function (json) {
  22589. Curve.prototype.fromJSON.call(this, json);
  22590. this.v1.fromArray(json.v1);
  22591. this.v2.fromArray(json.v2);
  22592. return this;
  22593. };
  22594. function LineCurve3(v1, v2) {
  22595. if (v1 === void 0) {
  22596. v1 = new Vector3();
  22597. }
  22598. if (v2 === void 0) {
  22599. v2 = new Vector3();
  22600. }
  22601. Curve.call(this);
  22602. this.type = 'LineCurve3';
  22603. this.v1 = v1;
  22604. this.v2 = v2;
  22605. }
  22606. LineCurve3.prototype = Object.create(Curve.prototype);
  22607. LineCurve3.prototype.constructor = LineCurve3;
  22608. LineCurve3.prototype.isLineCurve3 = true;
  22609. LineCurve3.prototype.getPoint = function (t, optionalTarget) {
  22610. if (optionalTarget === void 0) {
  22611. optionalTarget = new Vector3();
  22612. }
  22613. var point = optionalTarget;
  22614. if (t === 1) {
  22615. point.copy(this.v2);
  22616. } else {
  22617. point.copy(this.v2).sub(this.v1);
  22618. point.multiplyScalar(t).add(this.v1);
  22619. }
  22620. return point;
  22621. }; // Line curve is linear, so we can overwrite default getPointAt
  22622. LineCurve3.prototype.getPointAt = function (u, optionalTarget) {
  22623. return this.getPoint(u, optionalTarget);
  22624. };
  22625. LineCurve3.prototype.copy = function (source) {
  22626. Curve.prototype.copy.call(this, source);
  22627. this.v1.copy(source.v1);
  22628. this.v2.copy(source.v2);
  22629. return this;
  22630. };
  22631. LineCurve3.prototype.toJSON = function () {
  22632. var data = Curve.prototype.toJSON.call(this);
  22633. data.v1 = this.v1.toArray();
  22634. data.v2 = this.v2.toArray();
  22635. return data;
  22636. };
  22637. LineCurve3.prototype.fromJSON = function (json) {
  22638. Curve.prototype.fromJSON.call(this, json);
  22639. this.v1.fromArray(json.v1);
  22640. this.v2.fromArray(json.v2);
  22641. return this;
  22642. };
  22643. function QuadraticBezierCurve(v0, v1, v2) {
  22644. if (v0 === void 0) {
  22645. v0 = new Vector2();
  22646. }
  22647. if (v1 === void 0) {
  22648. v1 = new Vector2();
  22649. }
  22650. if (v2 === void 0) {
  22651. v2 = new Vector2();
  22652. }
  22653. Curve.call(this);
  22654. this.type = 'QuadraticBezierCurve';
  22655. this.v0 = v0;
  22656. this.v1 = v1;
  22657. this.v2 = v2;
  22658. }
  22659. QuadraticBezierCurve.prototype = Object.create(Curve.prototype);
  22660. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  22661. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  22662. QuadraticBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  22663. if (optionalTarget === void 0) {
  22664. optionalTarget = new Vector2();
  22665. }
  22666. var point = optionalTarget;
  22667. var v0 = this.v0,
  22668. v1 = this.v1,
  22669. v2 = this.v2;
  22670. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  22671. return point;
  22672. };
  22673. QuadraticBezierCurve.prototype.copy = function (source) {
  22674. Curve.prototype.copy.call(this, source);
  22675. this.v0.copy(source.v0);
  22676. this.v1.copy(source.v1);
  22677. this.v2.copy(source.v2);
  22678. return this;
  22679. };
  22680. QuadraticBezierCurve.prototype.toJSON = function () {
  22681. var data = Curve.prototype.toJSON.call(this);
  22682. data.v0 = this.v0.toArray();
  22683. data.v1 = this.v1.toArray();
  22684. data.v2 = this.v2.toArray();
  22685. return data;
  22686. };
  22687. QuadraticBezierCurve.prototype.fromJSON = function (json) {
  22688. Curve.prototype.fromJSON.call(this, json);
  22689. this.v0.fromArray(json.v0);
  22690. this.v1.fromArray(json.v1);
  22691. this.v2.fromArray(json.v2);
  22692. return this;
  22693. };
  22694. function QuadraticBezierCurve3(v0, v1, v2) {
  22695. if (v0 === void 0) {
  22696. v0 = new Vector3();
  22697. }
  22698. if (v1 === void 0) {
  22699. v1 = new Vector3();
  22700. }
  22701. if (v2 === void 0) {
  22702. v2 = new Vector3();
  22703. }
  22704. Curve.call(this);
  22705. this.type = 'QuadraticBezierCurve3';
  22706. this.v0 = v0;
  22707. this.v1 = v1;
  22708. this.v2 = v2;
  22709. }
  22710. QuadraticBezierCurve3.prototype = Object.create(Curve.prototype);
  22711. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  22712. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  22713. QuadraticBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  22714. if (optionalTarget === void 0) {
  22715. optionalTarget = new Vector3();
  22716. }
  22717. var point = optionalTarget;
  22718. var v0 = this.v0,
  22719. v1 = this.v1,
  22720. v2 = this.v2;
  22721. 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));
  22722. return point;
  22723. };
  22724. QuadraticBezierCurve3.prototype.copy = function (source) {
  22725. Curve.prototype.copy.call(this, source);
  22726. this.v0.copy(source.v0);
  22727. this.v1.copy(source.v1);
  22728. this.v2.copy(source.v2);
  22729. return this;
  22730. };
  22731. QuadraticBezierCurve3.prototype.toJSON = function () {
  22732. var data = Curve.prototype.toJSON.call(this);
  22733. data.v0 = this.v0.toArray();
  22734. data.v1 = this.v1.toArray();
  22735. data.v2 = this.v2.toArray();
  22736. return data;
  22737. };
  22738. QuadraticBezierCurve3.prototype.fromJSON = function (json) {
  22739. Curve.prototype.fromJSON.call(this, json);
  22740. this.v0.fromArray(json.v0);
  22741. this.v1.fromArray(json.v1);
  22742. this.v2.fromArray(json.v2);
  22743. return this;
  22744. };
  22745. function SplineCurve(points) {
  22746. if (points === void 0) {
  22747. points = [];
  22748. }
  22749. Curve.call(this);
  22750. this.type = 'SplineCurve';
  22751. this.points = points;
  22752. }
  22753. SplineCurve.prototype = Object.create(Curve.prototype);
  22754. SplineCurve.prototype.constructor = SplineCurve;
  22755. SplineCurve.prototype.isSplineCurve = true;
  22756. SplineCurve.prototype.getPoint = function (t, optionalTarget) {
  22757. if (optionalTarget === void 0) {
  22758. optionalTarget = new Vector2();
  22759. }
  22760. var point = optionalTarget;
  22761. var points = this.points;
  22762. var p = (points.length - 1) * t;
  22763. var intPoint = Math.floor(p);
  22764. var weight = p - intPoint;
  22765. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  22766. var p1 = points[intPoint];
  22767. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  22768. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  22769. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  22770. return point;
  22771. };
  22772. SplineCurve.prototype.copy = function (source) {
  22773. Curve.prototype.copy.call(this, source);
  22774. this.points = [];
  22775. for (var i = 0, l = source.points.length; i < l; i++) {
  22776. var point = source.points[i];
  22777. this.points.push(point.clone());
  22778. }
  22779. return this;
  22780. };
  22781. SplineCurve.prototype.toJSON = function () {
  22782. var data = Curve.prototype.toJSON.call(this);
  22783. data.points = [];
  22784. for (var i = 0, l = this.points.length; i < l; i++) {
  22785. var point = this.points[i];
  22786. data.points.push(point.toArray());
  22787. }
  22788. return data;
  22789. };
  22790. SplineCurve.prototype.fromJSON = function (json) {
  22791. Curve.prototype.fromJSON.call(this, json);
  22792. this.points = [];
  22793. for (var i = 0, l = json.points.length; i < l; i++) {
  22794. var point = json.points[i];
  22795. this.points.push(new Vector2().fromArray(point));
  22796. }
  22797. return this;
  22798. };
  22799. var Curves = /*#__PURE__*/Object.freeze({
  22800. __proto__: null,
  22801. ArcCurve: ArcCurve,
  22802. CatmullRomCurve3: CatmullRomCurve3,
  22803. CubicBezierCurve: CubicBezierCurve,
  22804. CubicBezierCurve3: CubicBezierCurve3,
  22805. EllipseCurve: EllipseCurve,
  22806. LineCurve: LineCurve,
  22807. LineCurve3: LineCurve3,
  22808. QuadraticBezierCurve: QuadraticBezierCurve,
  22809. QuadraticBezierCurve3: QuadraticBezierCurve3,
  22810. SplineCurve: SplineCurve
  22811. });
  22812. /**************************************************************
  22813. * Curved Path - a curve path is simply a array of connected
  22814. * curves, but retains the api of a curve
  22815. **************************************************************/
  22816. function CurvePath() {
  22817. Curve.call(this);
  22818. this.type = 'CurvePath';
  22819. this.curves = [];
  22820. this.autoClose = false; // Automatically closes the path
  22821. }
  22822. CurvePath.prototype = Object.assign(Object.create(Curve.prototype), {
  22823. constructor: CurvePath,
  22824. add: function add(curve) {
  22825. this.curves.push(curve);
  22826. },
  22827. closePath: function closePath() {
  22828. // Add a line curve if start and end of lines are not connected
  22829. var startPoint = this.curves[0].getPoint(0);
  22830. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  22831. if (!startPoint.equals(endPoint)) {
  22832. this.curves.push(new LineCurve(endPoint, startPoint));
  22833. }
  22834. },
  22835. // To get accurate point with reference to
  22836. // entire path distance at time t,
  22837. // following has to be done:
  22838. // 1. Length of each sub path have to be known
  22839. // 2. Locate and identify type of curve
  22840. // 3. Get t for the curve
  22841. // 4. Return curve.getPointAt(t')
  22842. getPoint: function getPoint(t) {
  22843. var d = t * this.getLength();
  22844. var curveLengths = this.getCurveLengths();
  22845. var i = 0; // To think about boundaries points.
  22846. while (i < curveLengths.length) {
  22847. if (curveLengths[i] >= d) {
  22848. var diff = curveLengths[i] - d;
  22849. var curve = this.curves[i];
  22850. var segmentLength = curve.getLength();
  22851. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  22852. return curve.getPointAt(u);
  22853. }
  22854. i++;
  22855. }
  22856. return null; // loop where sum != 0, sum > d , sum+1 <d
  22857. },
  22858. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  22859. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  22860. // getPoint() depends on getLength
  22861. getLength: function getLength() {
  22862. var lens = this.getCurveLengths();
  22863. return lens[lens.length - 1];
  22864. },
  22865. // cacheLengths must be recalculated.
  22866. updateArcLengths: function updateArcLengths() {
  22867. this.needsUpdate = true;
  22868. this.cacheLengths = null;
  22869. this.getCurveLengths();
  22870. },
  22871. // Compute lengths and cache them
  22872. // We cannot overwrite getLengths() because UtoT mapping uses it.
  22873. getCurveLengths: function getCurveLengths() {
  22874. // We use cache values if curves and cache array are same length
  22875. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  22876. return this.cacheLengths;
  22877. } // Get length of sub-curve
  22878. // Push sums into cached array
  22879. var lengths = [];
  22880. var sums = 0;
  22881. for (var i = 0, l = this.curves.length; i < l; i++) {
  22882. sums += this.curves[i].getLength();
  22883. lengths.push(sums);
  22884. }
  22885. this.cacheLengths = lengths;
  22886. return lengths;
  22887. },
  22888. getSpacedPoints: function getSpacedPoints(divisions) {
  22889. if (divisions === void 0) {
  22890. divisions = 40;
  22891. }
  22892. var points = [];
  22893. for (var i = 0; i <= divisions; i++) {
  22894. points.push(this.getPoint(i / divisions));
  22895. }
  22896. if (this.autoClose) {
  22897. points.push(points[0]);
  22898. }
  22899. return points;
  22900. },
  22901. getPoints: function getPoints(divisions) {
  22902. if (divisions === void 0) {
  22903. divisions = 12;
  22904. }
  22905. var points = [];
  22906. var last;
  22907. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  22908. var curve = curves[i];
  22909. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  22910. var pts = curve.getPoints(resolution);
  22911. for (var j = 0; j < pts.length; j++) {
  22912. var point = pts[j];
  22913. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  22914. points.push(point);
  22915. last = point;
  22916. }
  22917. }
  22918. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  22919. points.push(points[0]);
  22920. }
  22921. return points;
  22922. },
  22923. copy: function copy(source) {
  22924. Curve.prototype.copy.call(this, source);
  22925. this.curves = [];
  22926. for (var i = 0, l = source.curves.length; i < l; i++) {
  22927. var curve = source.curves[i];
  22928. this.curves.push(curve.clone());
  22929. }
  22930. this.autoClose = source.autoClose;
  22931. return this;
  22932. },
  22933. toJSON: function toJSON() {
  22934. var data = Curve.prototype.toJSON.call(this);
  22935. data.autoClose = this.autoClose;
  22936. data.curves = [];
  22937. for (var i = 0, l = this.curves.length; i < l; i++) {
  22938. var curve = this.curves[i];
  22939. data.curves.push(curve.toJSON());
  22940. }
  22941. return data;
  22942. },
  22943. fromJSON: function fromJSON(json) {
  22944. Curve.prototype.fromJSON.call(this, json);
  22945. this.autoClose = json.autoClose;
  22946. this.curves = [];
  22947. for (var i = 0, l = json.curves.length; i < l; i++) {
  22948. var curve = json.curves[i];
  22949. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  22950. }
  22951. return this;
  22952. }
  22953. });
  22954. function Path(points) {
  22955. CurvePath.call(this);
  22956. this.type = 'Path';
  22957. this.currentPoint = new Vector2();
  22958. if (points) {
  22959. this.setFromPoints(points);
  22960. }
  22961. }
  22962. Path.prototype = Object.assign(Object.create(CurvePath.prototype), {
  22963. constructor: Path,
  22964. setFromPoints: function setFromPoints(points) {
  22965. this.moveTo(points[0].x, points[0].y);
  22966. for (var i = 1, l = points.length; i < l; i++) {
  22967. this.lineTo(points[i].x, points[i].y);
  22968. }
  22969. return this;
  22970. },
  22971. moveTo: function moveTo(x, y) {
  22972. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  22973. return this;
  22974. },
  22975. lineTo: function lineTo(x, y) {
  22976. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  22977. this.curves.push(curve);
  22978. this.currentPoint.set(x, y);
  22979. return this;
  22980. },
  22981. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  22982. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  22983. this.curves.push(curve);
  22984. this.currentPoint.set(aX, aY);
  22985. return this;
  22986. },
  22987. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  22988. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  22989. this.curves.push(curve);
  22990. this.currentPoint.set(aX, aY);
  22991. return this;
  22992. },
  22993. splineThru: function splineThru(pts
  22994. /*Array of Vector*/
  22995. ) {
  22996. var npts = [this.currentPoint.clone()].concat(pts);
  22997. var curve = new SplineCurve(npts);
  22998. this.curves.push(curve);
  22999. this.currentPoint.copy(pts[pts.length - 1]);
  23000. return this;
  23001. },
  23002. arc: function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23003. var x0 = this.currentPoint.x;
  23004. var y0 = this.currentPoint.y;
  23005. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  23006. return this;
  23007. },
  23008. absarc: function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23009. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  23010. return this;
  23011. },
  23012. ellipse: function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23013. var x0 = this.currentPoint.x;
  23014. var y0 = this.currentPoint.y;
  23015. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23016. return this;
  23017. },
  23018. absellipse: function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23019. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23020. if (this.curves.length > 0) {
  23021. // if a previous curve is present, attempt to join
  23022. var firstPoint = curve.getPoint(0);
  23023. if (!firstPoint.equals(this.currentPoint)) {
  23024. this.lineTo(firstPoint.x, firstPoint.y);
  23025. }
  23026. }
  23027. this.curves.push(curve);
  23028. var lastPoint = curve.getPoint(1);
  23029. this.currentPoint.copy(lastPoint);
  23030. return this;
  23031. },
  23032. copy: function copy(source) {
  23033. CurvePath.prototype.copy.call(this, source);
  23034. this.currentPoint.copy(source.currentPoint);
  23035. return this;
  23036. },
  23037. toJSON: function toJSON() {
  23038. var data = CurvePath.prototype.toJSON.call(this);
  23039. data.currentPoint = this.currentPoint.toArray();
  23040. return data;
  23041. },
  23042. fromJSON: function fromJSON(json) {
  23043. CurvePath.prototype.fromJSON.call(this, json);
  23044. this.currentPoint.fromArray(json.currentPoint);
  23045. return this;
  23046. }
  23047. });
  23048. function Shape(points) {
  23049. Path.call(this, points);
  23050. this.uuid = MathUtils.generateUUID();
  23051. this.type = 'Shape';
  23052. this.holes = [];
  23053. }
  23054. Shape.prototype = Object.assign(Object.create(Path.prototype), {
  23055. constructor: Shape,
  23056. getPointsHoles: function getPointsHoles(divisions) {
  23057. var holesPts = [];
  23058. for (var i = 0, l = this.holes.length; i < l; i++) {
  23059. holesPts[i] = this.holes[i].getPoints(divisions);
  23060. }
  23061. return holesPts;
  23062. },
  23063. // get points of shape and holes (keypoints based on segments parameter)
  23064. extractPoints: function extractPoints(divisions) {
  23065. return {
  23066. shape: this.getPoints(divisions),
  23067. holes: this.getPointsHoles(divisions)
  23068. };
  23069. },
  23070. copy: function copy(source) {
  23071. Path.prototype.copy.call(this, source);
  23072. this.holes = [];
  23073. for (var i = 0, l = source.holes.length; i < l; i++) {
  23074. var hole = source.holes[i];
  23075. this.holes.push(hole.clone());
  23076. }
  23077. return this;
  23078. },
  23079. toJSON: function toJSON() {
  23080. var data = Path.prototype.toJSON.call(this);
  23081. data.uuid = this.uuid;
  23082. data.holes = [];
  23083. for (var i = 0, l = this.holes.length; i < l; i++) {
  23084. var hole = this.holes[i];
  23085. data.holes.push(hole.toJSON());
  23086. }
  23087. return data;
  23088. },
  23089. fromJSON: function fromJSON(json) {
  23090. Path.prototype.fromJSON.call(this, json);
  23091. this.uuid = json.uuid;
  23092. this.holes = [];
  23093. for (var i = 0, l = json.holes.length; i < l; i++) {
  23094. var hole = json.holes[i];
  23095. this.holes.push(new Path().fromJSON(hole));
  23096. }
  23097. return this;
  23098. }
  23099. });
  23100. function Light(color, intensity) {
  23101. if (intensity === void 0) {
  23102. intensity = 1;
  23103. }
  23104. Object3D.call(this);
  23105. this.type = 'Light';
  23106. this.color = new Color(color);
  23107. this.intensity = intensity;
  23108. }
  23109. Light.prototype = Object.assign(Object.create(Object3D.prototype), {
  23110. constructor: Light,
  23111. isLight: true,
  23112. copy: function copy(source) {
  23113. Object3D.prototype.copy.call(this, source);
  23114. this.color.copy(source.color);
  23115. this.intensity = source.intensity;
  23116. return this;
  23117. },
  23118. toJSON: function toJSON(meta) {
  23119. var data = Object3D.prototype.toJSON.call(this, meta);
  23120. data.object.color = this.color.getHex();
  23121. data.object.intensity = this.intensity;
  23122. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  23123. if (this.distance !== undefined) data.object.distance = this.distance;
  23124. if (this.angle !== undefined) data.object.angle = this.angle;
  23125. if (this.decay !== undefined) data.object.decay = this.decay;
  23126. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  23127. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  23128. return data;
  23129. }
  23130. });
  23131. function HemisphereLight(skyColor, groundColor, intensity) {
  23132. Light.call(this, skyColor, intensity);
  23133. this.type = 'HemisphereLight';
  23134. this.position.copy(Object3D.DefaultUp);
  23135. this.updateMatrix();
  23136. this.groundColor = new Color(groundColor);
  23137. }
  23138. HemisphereLight.prototype = Object.assign(Object.create(Light.prototype), {
  23139. constructor: HemisphereLight,
  23140. isHemisphereLight: true,
  23141. copy: function copy(source) {
  23142. Light.prototype.copy.call(this, source);
  23143. this.groundColor.copy(source.groundColor);
  23144. return this;
  23145. }
  23146. });
  23147. function LightShadow(camera) {
  23148. this.camera = camera;
  23149. this.bias = 0;
  23150. this.normalBias = 0;
  23151. this.radius = 1;
  23152. this.mapSize = new Vector2(512, 512);
  23153. this.map = null;
  23154. this.mapPass = null;
  23155. this.matrix = new Matrix4();
  23156. this.autoUpdate = true;
  23157. this.needsUpdate = false;
  23158. this._frustum = new Frustum();
  23159. this._frameExtents = new Vector2(1, 1);
  23160. this._viewportCount = 1;
  23161. this._viewports = [new Vector4(0, 0, 1, 1)];
  23162. }
  23163. Object.assign(LightShadow.prototype, {
  23164. _projScreenMatrix: new Matrix4(),
  23165. _lightPositionWorld: new Vector3(),
  23166. _lookTarget: new Vector3(),
  23167. getViewportCount: function getViewportCount() {
  23168. return this._viewportCount;
  23169. },
  23170. getFrustum: function getFrustum() {
  23171. return this._frustum;
  23172. },
  23173. updateMatrices: function updateMatrices(light) {
  23174. var shadowCamera = this.camera,
  23175. shadowMatrix = this.matrix,
  23176. projScreenMatrix = this._projScreenMatrix,
  23177. lookTarget = this._lookTarget,
  23178. lightPositionWorld = this._lightPositionWorld;
  23179. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23180. shadowCamera.position.copy(lightPositionWorld);
  23181. lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  23182. shadowCamera.lookAt(lookTarget);
  23183. shadowCamera.updateMatrixWorld();
  23184. projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  23185. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23186. 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);
  23187. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  23188. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  23189. },
  23190. getViewport: function getViewport(viewportIndex) {
  23191. return this._viewports[viewportIndex];
  23192. },
  23193. getFrameExtents: function getFrameExtents() {
  23194. return this._frameExtents;
  23195. },
  23196. copy: function copy(source) {
  23197. this.camera = source.camera.clone();
  23198. this.bias = source.bias;
  23199. this.radius = source.radius;
  23200. this.mapSize.copy(source.mapSize);
  23201. return this;
  23202. },
  23203. clone: function clone() {
  23204. return new this.constructor().copy(this);
  23205. },
  23206. toJSON: function toJSON() {
  23207. var object = {};
  23208. if (this.bias !== 0) object.bias = this.bias;
  23209. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  23210. if (this.radius !== 1) object.radius = this.radius;
  23211. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  23212. object.camera = this.camera.toJSON(false).object;
  23213. delete object.camera.matrix;
  23214. return object;
  23215. }
  23216. });
  23217. function SpotLightShadow() {
  23218. LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500));
  23219. this.focus = 1;
  23220. }
  23221. SpotLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23222. constructor: SpotLightShadow,
  23223. isSpotLightShadow: true,
  23224. updateMatrices: function updateMatrices(light) {
  23225. var camera = this.camera;
  23226. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23227. var aspect = this.mapSize.width / this.mapSize.height;
  23228. var far = light.distance || camera.far;
  23229. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  23230. camera.fov = fov;
  23231. camera.aspect = aspect;
  23232. camera.far = far;
  23233. camera.updateProjectionMatrix();
  23234. }
  23235. LightShadow.prototype.updateMatrices.call(this, light);
  23236. }
  23237. });
  23238. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  23239. Light.call(this, color, intensity);
  23240. this.type = 'SpotLight';
  23241. this.position.copy(Object3D.DefaultUp);
  23242. this.updateMatrix();
  23243. this.target = new Object3D();
  23244. Object.defineProperty(this, 'power', {
  23245. get: function get() {
  23246. // intensity = power per solid angle.
  23247. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23248. return this.intensity * Math.PI;
  23249. },
  23250. set: function set(power) {
  23251. // intensity = power per solid angle.
  23252. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23253. this.intensity = power / Math.PI;
  23254. }
  23255. });
  23256. this.distance = distance !== undefined ? distance : 0;
  23257. this.angle = angle !== undefined ? angle : Math.PI / 3;
  23258. this.penumbra = penumbra !== undefined ? penumbra : 0;
  23259. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23260. this.shadow = new SpotLightShadow();
  23261. }
  23262. SpotLight.prototype = Object.assign(Object.create(Light.prototype), {
  23263. constructor: SpotLight,
  23264. isSpotLight: true,
  23265. copy: function copy(source) {
  23266. Light.prototype.copy.call(this, source);
  23267. this.distance = source.distance;
  23268. this.angle = source.angle;
  23269. this.penumbra = source.penumbra;
  23270. this.decay = source.decay;
  23271. this.target = source.target.clone();
  23272. this.shadow = source.shadow.clone();
  23273. return this;
  23274. }
  23275. });
  23276. function PointLightShadow() {
  23277. LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500));
  23278. this._frameExtents = new Vector2(4, 2);
  23279. this._viewportCount = 6;
  23280. this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  23281. // following orientation:
  23282. //
  23283. // xzXZ
  23284. // y Y
  23285. //
  23286. // X - Positive x direction
  23287. // x - Negative x direction
  23288. // Y - Positive y direction
  23289. // y - Negative y direction
  23290. // Z - Positive z direction
  23291. // z - Negative z direction
  23292. // positive X
  23293. new Vector4(2, 1, 1, 1), // negative X
  23294. new Vector4(0, 1, 1, 1), // positive Z
  23295. new Vector4(3, 1, 1, 1), // negative Z
  23296. new Vector4(1, 1, 1, 1), // positive Y
  23297. new Vector4(3, 0, 1, 1), // negative Y
  23298. new Vector4(1, 0, 1, 1)];
  23299. 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)];
  23300. 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)];
  23301. }
  23302. PointLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23303. constructor: PointLightShadow,
  23304. isPointLightShadow: true,
  23305. updateMatrices: function updateMatrices(light, viewportIndex) {
  23306. if (viewportIndex === void 0) {
  23307. viewportIndex = 0;
  23308. }
  23309. var camera = this.camera,
  23310. shadowMatrix = this.matrix,
  23311. lightPositionWorld = this._lightPositionWorld,
  23312. lookTarget = this._lookTarget,
  23313. projScreenMatrix = this._projScreenMatrix;
  23314. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23315. camera.position.copy(lightPositionWorld);
  23316. lookTarget.copy(camera.position);
  23317. lookTarget.add(this._cubeDirections[viewportIndex]);
  23318. camera.up.copy(this._cubeUps[viewportIndex]);
  23319. camera.lookAt(lookTarget);
  23320. camera.updateMatrixWorld();
  23321. shadowMatrix.makeTranslation(-lightPositionWorld.x, -lightPositionWorld.y, -lightPositionWorld.z);
  23322. projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  23323. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23324. }
  23325. });
  23326. function PointLight(color, intensity, distance, decay) {
  23327. Light.call(this, color, intensity);
  23328. this.type = 'PointLight';
  23329. Object.defineProperty(this, 'power', {
  23330. get: function get() {
  23331. // intensity = power per solid angle.
  23332. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23333. return this.intensity * 4 * Math.PI;
  23334. },
  23335. set: function set(power) {
  23336. // intensity = power per solid angle.
  23337. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23338. this.intensity = power / (4 * Math.PI);
  23339. }
  23340. });
  23341. this.distance = distance !== undefined ? distance : 0;
  23342. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23343. this.shadow = new PointLightShadow();
  23344. }
  23345. PointLight.prototype = Object.assign(Object.create(Light.prototype), {
  23346. constructor: PointLight,
  23347. isPointLight: true,
  23348. copy: function copy(source) {
  23349. Light.prototype.copy.call(this, source);
  23350. this.distance = source.distance;
  23351. this.decay = source.decay;
  23352. this.shadow = source.shadow.clone();
  23353. return this;
  23354. }
  23355. });
  23356. function OrthographicCamera(left, right, top, bottom, near, far) {
  23357. if (left === void 0) {
  23358. left = -1;
  23359. }
  23360. if (right === void 0) {
  23361. right = 1;
  23362. }
  23363. if (top === void 0) {
  23364. top = 1;
  23365. }
  23366. if (bottom === void 0) {
  23367. bottom = -1;
  23368. }
  23369. if (near === void 0) {
  23370. near = 0.1;
  23371. }
  23372. if (far === void 0) {
  23373. far = 2000;
  23374. }
  23375. Camera.call(this);
  23376. this.type = 'OrthographicCamera';
  23377. this.zoom = 1;
  23378. this.view = null;
  23379. this.left = left;
  23380. this.right = right;
  23381. this.top = top;
  23382. this.bottom = bottom;
  23383. this.near = near;
  23384. this.far = far;
  23385. this.updateProjectionMatrix();
  23386. }
  23387. OrthographicCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  23388. constructor: OrthographicCamera,
  23389. isOrthographicCamera: true,
  23390. copy: function copy(source, recursive) {
  23391. Camera.prototype.copy.call(this, source, recursive);
  23392. this.left = source.left;
  23393. this.right = source.right;
  23394. this.top = source.top;
  23395. this.bottom = source.bottom;
  23396. this.near = source.near;
  23397. this.far = source.far;
  23398. this.zoom = source.zoom;
  23399. this.view = source.view === null ? null : Object.assign({}, source.view);
  23400. return this;
  23401. },
  23402. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  23403. if (this.view === null) {
  23404. this.view = {
  23405. enabled: true,
  23406. fullWidth: 1,
  23407. fullHeight: 1,
  23408. offsetX: 0,
  23409. offsetY: 0,
  23410. width: 1,
  23411. height: 1
  23412. };
  23413. }
  23414. this.view.enabled = true;
  23415. this.view.fullWidth = fullWidth;
  23416. this.view.fullHeight = fullHeight;
  23417. this.view.offsetX = x;
  23418. this.view.offsetY = y;
  23419. this.view.width = width;
  23420. this.view.height = height;
  23421. this.updateProjectionMatrix();
  23422. },
  23423. clearViewOffset: function clearViewOffset() {
  23424. if (this.view !== null) {
  23425. this.view.enabled = false;
  23426. }
  23427. this.updateProjectionMatrix();
  23428. },
  23429. updateProjectionMatrix: function updateProjectionMatrix() {
  23430. var dx = (this.right - this.left) / (2 * this.zoom);
  23431. var dy = (this.top - this.bottom) / (2 * this.zoom);
  23432. var cx = (this.right + this.left) / 2;
  23433. var cy = (this.top + this.bottom) / 2;
  23434. var left = cx - dx;
  23435. var right = cx + dx;
  23436. var top = cy + dy;
  23437. var bottom = cy - dy;
  23438. if (this.view !== null && this.view.enabled) {
  23439. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  23440. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  23441. left += scaleW * this.view.offsetX;
  23442. right = left + scaleW * this.view.width;
  23443. top -= scaleH * this.view.offsetY;
  23444. bottom = top - scaleH * this.view.height;
  23445. }
  23446. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  23447. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  23448. },
  23449. toJSON: function toJSON(meta) {
  23450. var data = Object3D.prototype.toJSON.call(this, meta);
  23451. data.object.zoom = this.zoom;
  23452. data.object.left = this.left;
  23453. data.object.right = this.right;
  23454. data.object.top = this.top;
  23455. data.object.bottom = this.bottom;
  23456. data.object.near = this.near;
  23457. data.object.far = this.far;
  23458. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  23459. return data;
  23460. }
  23461. });
  23462. function DirectionalLightShadow() {
  23463. LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500));
  23464. }
  23465. DirectionalLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23466. constructor: DirectionalLightShadow,
  23467. isDirectionalLightShadow: true,
  23468. updateMatrices: function updateMatrices(light) {
  23469. LightShadow.prototype.updateMatrices.call(this, light);
  23470. }
  23471. });
  23472. function DirectionalLight(color, intensity) {
  23473. Light.call(this, color, intensity);
  23474. this.type = 'DirectionalLight';
  23475. this.position.copy(Object3D.DefaultUp);
  23476. this.updateMatrix();
  23477. this.target = new Object3D();
  23478. this.shadow = new DirectionalLightShadow();
  23479. }
  23480. DirectionalLight.prototype = Object.assign(Object.create(Light.prototype), {
  23481. constructor: DirectionalLight,
  23482. isDirectionalLight: true,
  23483. copy: function copy(source) {
  23484. Light.prototype.copy.call(this, source);
  23485. this.target = source.target.clone();
  23486. this.shadow = source.shadow.clone();
  23487. return this;
  23488. }
  23489. });
  23490. function AmbientLight(color, intensity) {
  23491. Light.call(this, color, intensity);
  23492. this.type = 'AmbientLight';
  23493. }
  23494. AmbientLight.prototype = Object.assign(Object.create(Light.prototype), {
  23495. constructor: AmbientLight,
  23496. isAmbientLight: true
  23497. });
  23498. function RectAreaLight(color, intensity, width, height) {
  23499. Light.call(this, color, intensity);
  23500. this.type = 'RectAreaLight';
  23501. this.width = width !== undefined ? width : 10;
  23502. this.height = height !== undefined ? height : 10;
  23503. }
  23504. RectAreaLight.prototype = Object.assign(Object.create(Light.prototype), {
  23505. constructor: RectAreaLight,
  23506. isRectAreaLight: true,
  23507. copy: function copy(source) {
  23508. Light.prototype.copy.call(this, source);
  23509. this.width = source.width;
  23510. this.height = source.height;
  23511. return this;
  23512. },
  23513. toJSON: function toJSON(meta) {
  23514. var data = Light.prototype.toJSON.call(this, meta);
  23515. data.object.width = this.width;
  23516. data.object.height = this.height;
  23517. return data;
  23518. }
  23519. });
  23520. /**
  23521. * Primary reference:
  23522. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23523. *
  23524. * Secondary reference:
  23525. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23526. */
  23527. // 3-band SH defined by 9 coefficients
  23528. var SphericalHarmonics3 = /*#__PURE__*/function () {
  23529. function SphericalHarmonics3() {
  23530. Object.defineProperty(this, 'isSphericalHarmonics3', {
  23531. value: true
  23532. });
  23533. this.coefficients = [];
  23534. for (var i = 0; i < 9; i++) {
  23535. this.coefficients.push(new Vector3());
  23536. }
  23537. }
  23538. var _proto = SphericalHarmonics3.prototype;
  23539. _proto.set = function set(coefficients) {
  23540. for (var i = 0; i < 9; i++) {
  23541. this.coefficients[i].copy(coefficients[i]);
  23542. }
  23543. return this;
  23544. };
  23545. _proto.zero = function zero() {
  23546. for (var i = 0; i < 9; i++) {
  23547. this.coefficients[i].set(0, 0, 0);
  23548. }
  23549. return this;
  23550. } // get the radiance in the direction of the normal
  23551. // target is a Vector3
  23552. ;
  23553. _proto.getAt = function getAt(normal, target) {
  23554. // normal is assumed to be unit length
  23555. var x = normal.x,
  23556. y = normal.y,
  23557. z = normal.z;
  23558. var coeff = this.coefficients; // band 0
  23559. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  23560. target.addScaledVector(coeff[1], 0.488603 * y);
  23561. target.addScaledVector(coeff[2], 0.488603 * z);
  23562. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  23563. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  23564. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  23565. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  23566. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  23567. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  23568. return target;
  23569. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23570. // target is a Vector3
  23571. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23572. ;
  23573. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  23574. // normal is assumed to be unit length
  23575. var x = normal.x,
  23576. y = normal.y,
  23577. z = normal.z;
  23578. var coeff = this.coefficients; // band 0
  23579. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  23580. // band 1
  23581. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  23582. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  23583. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  23584. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  23585. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  23586. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  23587. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  23588. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  23589. return target;
  23590. };
  23591. _proto.add = function add(sh) {
  23592. for (var i = 0; i < 9; i++) {
  23593. this.coefficients[i].add(sh.coefficients[i]);
  23594. }
  23595. return this;
  23596. };
  23597. _proto.addScaledSH = function addScaledSH(sh, s) {
  23598. for (var i = 0; i < 9; i++) {
  23599. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  23600. }
  23601. return this;
  23602. };
  23603. _proto.scale = function scale(s) {
  23604. for (var i = 0; i < 9; i++) {
  23605. this.coefficients[i].multiplyScalar(s);
  23606. }
  23607. return this;
  23608. };
  23609. _proto.lerp = function lerp(sh, alpha) {
  23610. for (var i = 0; i < 9; i++) {
  23611. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  23612. }
  23613. return this;
  23614. };
  23615. _proto.equals = function equals(sh) {
  23616. for (var i = 0; i < 9; i++) {
  23617. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  23618. return false;
  23619. }
  23620. }
  23621. return true;
  23622. };
  23623. _proto.copy = function copy(sh) {
  23624. return this.set(sh.coefficients);
  23625. };
  23626. _proto.clone = function clone() {
  23627. return new this.constructor().copy(this);
  23628. };
  23629. _proto.fromArray = function fromArray(array, offset) {
  23630. if (offset === void 0) {
  23631. offset = 0;
  23632. }
  23633. var coefficients = this.coefficients;
  23634. for (var i = 0; i < 9; i++) {
  23635. coefficients[i].fromArray(array, offset + i * 3);
  23636. }
  23637. return this;
  23638. };
  23639. _proto.toArray = function toArray(array, offset) {
  23640. if (array === void 0) {
  23641. array = [];
  23642. }
  23643. if (offset === void 0) {
  23644. offset = 0;
  23645. }
  23646. var coefficients = this.coefficients;
  23647. for (var i = 0; i < 9; i++) {
  23648. coefficients[i].toArray(array, offset + i * 3);
  23649. }
  23650. return array;
  23651. } // evaluate the basis functions
  23652. // shBasis is an Array[ 9 ]
  23653. ;
  23654. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  23655. // normal is assumed to be unit length
  23656. var x = normal.x,
  23657. y = normal.y,
  23658. z = normal.z; // band 0
  23659. shBasis[0] = 0.282095; // band 1
  23660. shBasis[1] = 0.488603 * y;
  23661. shBasis[2] = 0.488603 * z;
  23662. shBasis[3] = 0.488603 * x; // band 2
  23663. shBasis[4] = 1.092548 * x * y;
  23664. shBasis[5] = 1.092548 * y * z;
  23665. shBasis[6] = 0.315392 * (3 * z * z - 1);
  23666. shBasis[7] = 1.092548 * x * z;
  23667. shBasis[8] = 0.546274 * (x * x - y * y);
  23668. };
  23669. return SphericalHarmonics3;
  23670. }();
  23671. function LightProbe(sh, intensity) {
  23672. Light.call(this, undefined, intensity);
  23673. this.type = 'LightProbe';
  23674. this.sh = sh !== undefined ? sh : new SphericalHarmonics3();
  23675. }
  23676. LightProbe.prototype = Object.assign(Object.create(Light.prototype), {
  23677. constructor: LightProbe,
  23678. isLightProbe: true,
  23679. copy: function copy(source) {
  23680. Light.prototype.copy.call(this, source);
  23681. this.sh.copy(source.sh);
  23682. return this;
  23683. },
  23684. fromJSON: function fromJSON(json) {
  23685. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  23686. this.sh.fromArray(json.sh);
  23687. return this;
  23688. },
  23689. toJSON: function toJSON(meta) {
  23690. var data = Light.prototype.toJSON.call(this, meta);
  23691. data.object.sh = this.sh.toArray();
  23692. return data;
  23693. }
  23694. });
  23695. function MaterialLoader(manager) {
  23696. Loader.call(this, manager);
  23697. this.textures = {};
  23698. }
  23699. MaterialLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  23700. constructor: MaterialLoader,
  23701. load: function load(url, onLoad, onProgress, onError) {
  23702. var scope = this;
  23703. var loader = new FileLoader(scope.manager);
  23704. loader.setPath(scope.path);
  23705. loader.setRequestHeader(scope.requestHeader);
  23706. loader.setWithCredentials(scope.withCredentials);
  23707. loader.load(url, function (text) {
  23708. try {
  23709. onLoad(scope.parse(JSON.parse(text)));
  23710. } catch (e) {
  23711. if (onError) {
  23712. onError(e);
  23713. } else {
  23714. console.error(e);
  23715. }
  23716. scope.manager.itemError(url);
  23717. }
  23718. }, onProgress, onError);
  23719. },
  23720. parse: function parse(json) {
  23721. var textures = this.textures;
  23722. function getTexture(name) {
  23723. if (textures[name] === undefined) {
  23724. console.warn('THREE.MaterialLoader: Undefined texture', name);
  23725. }
  23726. return textures[name];
  23727. }
  23728. var material = new Materials[json.type]();
  23729. if (json.uuid !== undefined) material.uuid = json.uuid;
  23730. if (json.name !== undefined) material.name = json.name;
  23731. if (json.color !== undefined && material.color !== undefined) material.color.setHex(json.color);
  23732. if (json.roughness !== undefined) material.roughness = json.roughness;
  23733. if (json.metalness !== undefined) material.metalness = json.metalness;
  23734. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  23735. if (json.emissive !== undefined && material.emissive !== undefined) material.emissive.setHex(json.emissive);
  23736. if (json.specular !== undefined && material.specular !== undefined) material.specular.setHex(json.specular);
  23737. if (json.shininess !== undefined) material.shininess = json.shininess;
  23738. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  23739. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  23740. if (json.fog !== undefined) material.fog = json.fog;
  23741. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  23742. if (json.blending !== undefined) material.blending = json.blending;
  23743. if (json.combine !== undefined) material.combine = json.combine;
  23744. if (json.side !== undefined) material.side = json.side;
  23745. if (json.opacity !== undefined) material.opacity = json.opacity;
  23746. if (json.transparent !== undefined) material.transparent = json.transparent;
  23747. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  23748. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  23749. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  23750. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  23751. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  23752. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  23753. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  23754. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  23755. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  23756. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  23757. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  23758. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  23759. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  23760. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  23761. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  23762. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  23763. if (json.rotation !== undefined) material.rotation = json.rotation;
  23764. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  23765. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  23766. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  23767. if (json.scale !== undefined) material.scale = json.scale;
  23768. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  23769. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  23770. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  23771. if (json.skinning !== undefined) material.skinning = json.skinning;
  23772. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  23773. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  23774. if (json.dithering !== undefined) material.dithering = json.dithering;
  23775. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  23776. if (json.visible !== undefined) material.visible = json.visible;
  23777. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  23778. if (json.userData !== undefined) material.userData = json.userData;
  23779. if (json.vertexColors !== undefined) {
  23780. if (typeof json.vertexColors === 'number') {
  23781. material.vertexColors = json.vertexColors > 0 ? true : false;
  23782. } else {
  23783. material.vertexColors = json.vertexColors;
  23784. }
  23785. } // Shader Material
  23786. if (json.uniforms !== undefined) {
  23787. for (var name in json.uniforms) {
  23788. var uniform = json.uniforms[name];
  23789. material.uniforms[name] = {};
  23790. switch (uniform.type) {
  23791. case 't':
  23792. material.uniforms[name].value = getTexture(uniform.value);
  23793. break;
  23794. case 'c':
  23795. material.uniforms[name].value = new Color().setHex(uniform.value);
  23796. break;
  23797. case 'v2':
  23798. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  23799. break;
  23800. case 'v3':
  23801. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  23802. break;
  23803. case 'v4':
  23804. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  23805. break;
  23806. case 'm3':
  23807. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  23808. break;
  23809. case 'm4':
  23810. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  23811. break;
  23812. default:
  23813. material.uniforms[name].value = uniform.value;
  23814. }
  23815. }
  23816. }
  23817. if (json.defines !== undefined) material.defines = json.defines;
  23818. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  23819. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  23820. if (json.extensions !== undefined) {
  23821. for (var key in json.extensions) {
  23822. material.extensions[key] = json.extensions[key];
  23823. }
  23824. } // Deprecated
  23825. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  23826. // for PointsMaterial
  23827. if (json.size !== undefined) material.size = json.size;
  23828. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  23829. if (json.map !== undefined) material.map = getTexture(json.map);
  23830. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  23831. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  23832. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  23833. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  23834. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  23835. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  23836. if (json.normalScale !== undefined) {
  23837. var normalScale = json.normalScale;
  23838. if (Array.isArray(normalScale) === false) {
  23839. // Blender exporter used to export a scalar. See #7459
  23840. normalScale = [normalScale, normalScale];
  23841. }
  23842. material.normalScale = new Vector2().fromArray(normalScale);
  23843. }
  23844. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  23845. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  23846. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  23847. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  23848. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  23849. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  23850. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  23851. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  23852. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  23853. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  23854. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  23855. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  23856. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  23857. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  23858. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  23859. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  23860. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  23861. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  23862. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  23863. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  23864. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  23865. if (json.transmission !== undefined) material.transmission = json.transmission;
  23866. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  23867. return material;
  23868. },
  23869. setTextures: function setTextures(value) {
  23870. this.textures = value;
  23871. return this;
  23872. }
  23873. });
  23874. var LoaderUtils = {
  23875. decodeText: function decodeText(array) {
  23876. if (typeof TextDecoder !== 'undefined') {
  23877. return new TextDecoder().decode(array);
  23878. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  23879. // throws a "maximum call stack size exceeded" error for large arrays.
  23880. var s = '';
  23881. for (var i = 0, il = array.length; i < il; i++) {
  23882. // Implicitly assumes little-endian.
  23883. s += String.fromCharCode(array[i]);
  23884. }
  23885. try {
  23886. // merges multi-byte utf-8 characters.
  23887. return decodeURIComponent(escape(s));
  23888. } catch (e) {
  23889. // see #16358
  23890. return s;
  23891. }
  23892. },
  23893. extractUrlBase: function extractUrlBase(url) {
  23894. var index = url.lastIndexOf('/');
  23895. if (index === -1) return './';
  23896. return url.substr(0, index + 1);
  23897. }
  23898. };
  23899. function InstancedBufferGeometry() {
  23900. BufferGeometry.call(this);
  23901. this.type = 'InstancedBufferGeometry';
  23902. this.instanceCount = Infinity;
  23903. }
  23904. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  23905. constructor: InstancedBufferGeometry,
  23906. isInstancedBufferGeometry: true,
  23907. copy: function copy(source) {
  23908. BufferGeometry.prototype.copy.call(this, source);
  23909. this.instanceCount = source.instanceCount;
  23910. return this;
  23911. },
  23912. clone: function clone() {
  23913. return new this.constructor().copy(this);
  23914. },
  23915. toJSON: function toJSON() {
  23916. var data = BufferGeometry.prototype.toJSON.call(this);
  23917. data.instanceCount = this.instanceCount;
  23918. data.isInstancedBufferGeometry = true;
  23919. return data;
  23920. }
  23921. });
  23922. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  23923. if (typeof normalized === 'number') {
  23924. meshPerAttribute = normalized;
  23925. normalized = false;
  23926. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  23927. }
  23928. BufferAttribute.call(this, array, itemSize, normalized);
  23929. this.meshPerAttribute = meshPerAttribute || 1;
  23930. }
  23931. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  23932. constructor: InstancedBufferAttribute,
  23933. isInstancedBufferAttribute: true,
  23934. copy: function copy(source) {
  23935. BufferAttribute.prototype.copy.call(this, source);
  23936. this.meshPerAttribute = source.meshPerAttribute;
  23937. return this;
  23938. },
  23939. toJSON: function toJSON() {
  23940. var data = BufferAttribute.prototype.toJSON.call(this);
  23941. data.meshPerAttribute = this.meshPerAttribute;
  23942. data.isInstancedBufferAttribute = true;
  23943. return data;
  23944. }
  23945. });
  23946. function BufferGeometryLoader(manager) {
  23947. Loader.call(this, manager);
  23948. }
  23949. BufferGeometryLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  23950. constructor: BufferGeometryLoader,
  23951. load: function load(url, onLoad, onProgress, onError) {
  23952. var scope = this;
  23953. var loader = new FileLoader(scope.manager);
  23954. loader.setPath(scope.path);
  23955. loader.setRequestHeader(scope.requestHeader);
  23956. loader.setWithCredentials(scope.withCredentials);
  23957. loader.load(url, function (text) {
  23958. try {
  23959. onLoad(scope.parse(JSON.parse(text)));
  23960. } catch (e) {
  23961. if (onError) {
  23962. onError(e);
  23963. } else {
  23964. console.error(e);
  23965. }
  23966. scope.manager.itemError(url);
  23967. }
  23968. }, onProgress, onError);
  23969. },
  23970. parse: function parse(json) {
  23971. var interleavedBufferMap = {};
  23972. var arrayBufferMap = {};
  23973. function getInterleavedBuffer(json, uuid) {
  23974. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  23975. var interleavedBuffers = json.interleavedBuffers;
  23976. var interleavedBuffer = interleavedBuffers[uuid];
  23977. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  23978. var array = getTypedArray(interleavedBuffer.type, buffer);
  23979. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  23980. ib.uuid = interleavedBuffer.uuid;
  23981. interleavedBufferMap[uuid] = ib;
  23982. return ib;
  23983. }
  23984. function getArrayBuffer(json, uuid) {
  23985. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  23986. var arrayBuffers = json.arrayBuffers;
  23987. var arrayBuffer = arrayBuffers[uuid];
  23988. var ab = new Uint32Array(arrayBuffer).buffer;
  23989. arrayBufferMap[uuid] = ab;
  23990. return ab;
  23991. }
  23992. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  23993. var index = json.data.index;
  23994. if (index !== undefined) {
  23995. var typedArray = getTypedArray(index.type, index.array);
  23996. geometry.setIndex(new BufferAttribute(typedArray, 1));
  23997. }
  23998. var attributes = json.data.attributes;
  23999. for (var key in attributes) {
  24000. var attribute = attributes[key];
  24001. var bufferAttribute = void 0;
  24002. if (attribute.isInterleavedBufferAttribute) {
  24003. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  24004. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  24005. } else {
  24006. var _typedArray = getTypedArray(attribute.type, attribute.array);
  24007. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24008. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  24009. }
  24010. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  24011. geometry.setAttribute(key, bufferAttribute);
  24012. }
  24013. var morphAttributes = json.data.morphAttributes;
  24014. if (morphAttributes) {
  24015. for (var _key in morphAttributes) {
  24016. var attributeArray = morphAttributes[_key];
  24017. var array = [];
  24018. for (var i = 0, il = attributeArray.length; i < il; i++) {
  24019. var _attribute = attributeArray[i];
  24020. var _bufferAttribute = void 0;
  24021. if (_attribute.isInterleavedBufferAttribute) {
  24022. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  24023. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  24024. } else {
  24025. var _typedArray2 = getTypedArray(_attribute.type, _attribute.array);
  24026. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  24027. }
  24028. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  24029. array.push(_bufferAttribute);
  24030. }
  24031. geometry.morphAttributes[_key] = array;
  24032. }
  24033. }
  24034. var morphTargetsRelative = json.data.morphTargetsRelative;
  24035. if (morphTargetsRelative) {
  24036. geometry.morphTargetsRelative = true;
  24037. }
  24038. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24039. if (groups !== undefined) {
  24040. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  24041. var group = groups[_i];
  24042. geometry.addGroup(group.start, group.count, group.materialIndex);
  24043. }
  24044. }
  24045. var boundingSphere = json.data.boundingSphere;
  24046. if (boundingSphere !== undefined) {
  24047. var center = new Vector3();
  24048. if (boundingSphere.center !== undefined) {
  24049. center.fromArray(boundingSphere.center);
  24050. }
  24051. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  24052. }
  24053. if (json.name) geometry.name = json.name;
  24054. if (json.userData) geometry.userData = json.userData;
  24055. return geometry;
  24056. }
  24057. });
  24058. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  24059. _inheritsLoose(ObjectLoader, _Loader);
  24060. function ObjectLoader(manager) {
  24061. return _Loader.call(this, manager) || this;
  24062. }
  24063. var _proto = ObjectLoader.prototype;
  24064. _proto.load = function load(url, onLoad, onProgress, onError) {
  24065. var scope = this;
  24066. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  24067. this.resourcePath = this.resourcePath || path;
  24068. var loader = new FileLoader(this.manager);
  24069. loader.setPath(this.path);
  24070. loader.setRequestHeader(this.requestHeader);
  24071. loader.setWithCredentials(this.withCredentials);
  24072. loader.load(url, function (text) {
  24073. var json = null;
  24074. try {
  24075. json = JSON.parse(text);
  24076. } catch (error) {
  24077. if (onError !== undefined) onError(error);
  24078. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  24079. return;
  24080. }
  24081. var metadata = json.metadata;
  24082. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  24083. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  24084. return;
  24085. }
  24086. scope.parse(json, onLoad);
  24087. }, onProgress, onError);
  24088. };
  24089. _proto.parse = function parse(json, onLoad) {
  24090. var animations = this.parseAnimations(json.animations);
  24091. var shapes = this.parseShapes(json.shapes);
  24092. var geometries = this.parseGeometries(json.geometries, shapes);
  24093. var images = this.parseImages(json.images, function () {
  24094. if (onLoad !== undefined) onLoad(object);
  24095. });
  24096. var textures = this.parseTextures(json.textures, images);
  24097. var materials = this.parseMaterials(json.materials, textures);
  24098. var object = this.parseObject(json.object, geometries, materials, animations);
  24099. var skeletons = this.parseSkeletons(json.skeletons, object);
  24100. this.bindSkeletons(object, skeletons); //
  24101. if (onLoad !== undefined) {
  24102. var hasImages = false;
  24103. for (var uuid in images) {
  24104. if (images[uuid] instanceof HTMLImageElement) {
  24105. hasImages = true;
  24106. break;
  24107. }
  24108. }
  24109. if (hasImages === false) onLoad(object);
  24110. }
  24111. return object;
  24112. };
  24113. _proto.parseShapes = function parseShapes(json) {
  24114. var shapes = {};
  24115. if (json !== undefined) {
  24116. for (var i = 0, l = json.length; i < l; i++) {
  24117. var shape = new Shape().fromJSON(json[i]);
  24118. shapes[shape.uuid] = shape;
  24119. }
  24120. }
  24121. return shapes;
  24122. };
  24123. _proto.parseSkeletons = function parseSkeletons(json, object) {
  24124. var skeletons = {};
  24125. var bones = {}; // generate bone lookup table
  24126. object.traverse(function (child) {
  24127. if (child.isBone) bones[child.uuid] = child;
  24128. }); // create skeletons
  24129. if (json !== undefined) {
  24130. for (var i = 0, l = json.length; i < l; i++) {
  24131. var skeleton = new Skeleton().fromJSON(json[i], bones);
  24132. skeletons[skeleton.uuid] = skeleton;
  24133. }
  24134. }
  24135. return skeletons;
  24136. };
  24137. _proto.parseGeometries = function parseGeometries(json, shapes) {
  24138. var geometries = {};
  24139. var geometryShapes;
  24140. if (json !== undefined) {
  24141. var bufferGeometryLoader = new BufferGeometryLoader();
  24142. for (var i = 0, l = json.length; i < l; i++) {
  24143. var geometry = void 0;
  24144. var data = json[i];
  24145. switch (data.type) {
  24146. case 'PlaneGeometry':
  24147. case 'PlaneBufferGeometry':
  24148. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  24149. break;
  24150. case 'BoxGeometry':
  24151. case 'BoxBufferGeometry':
  24152. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  24153. break;
  24154. case 'CircleGeometry':
  24155. case 'CircleBufferGeometry':
  24156. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  24157. break;
  24158. case 'CylinderGeometry':
  24159. case 'CylinderBufferGeometry':
  24160. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24161. break;
  24162. case 'ConeGeometry':
  24163. case 'ConeBufferGeometry':
  24164. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24165. break;
  24166. case 'SphereGeometry':
  24167. case 'SphereBufferGeometry':
  24168. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  24169. break;
  24170. case 'DodecahedronGeometry':
  24171. case 'DodecahedronBufferGeometry':
  24172. case 'IcosahedronGeometry':
  24173. case 'IcosahedronBufferGeometry':
  24174. case 'OctahedronGeometry':
  24175. case 'OctahedronBufferGeometry':
  24176. case 'TetrahedronGeometry':
  24177. case 'TetrahedronBufferGeometry':
  24178. geometry = new Geometries[data.type](data.radius, data.detail);
  24179. break;
  24180. case 'RingGeometry':
  24181. case 'RingBufferGeometry':
  24182. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  24183. break;
  24184. case 'TorusGeometry':
  24185. case 'TorusBufferGeometry':
  24186. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  24187. break;
  24188. case 'TorusKnotGeometry':
  24189. case 'TorusKnotBufferGeometry':
  24190. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  24191. break;
  24192. case 'TubeGeometry':
  24193. case 'TubeBufferGeometry':
  24194. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24195. // User defined curves or instances of CurvePath will not be deserialized.
  24196. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  24197. break;
  24198. case 'LatheGeometry':
  24199. case 'LatheBufferGeometry':
  24200. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  24201. break;
  24202. case 'PolyhedronGeometry':
  24203. case 'PolyhedronBufferGeometry':
  24204. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  24205. break;
  24206. case 'ShapeGeometry':
  24207. case 'ShapeBufferGeometry':
  24208. geometryShapes = [];
  24209. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  24210. var shape = shapes[data.shapes[j]];
  24211. geometryShapes.push(shape);
  24212. }
  24213. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  24214. break;
  24215. case 'ExtrudeGeometry':
  24216. case 'ExtrudeBufferGeometry':
  24217. geometryShapes = [];
  24218. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  24219. var _shape = shapes[data.shapes[_j]];
  24220. geometryShapes.push(_shape);
  24221. }
  24222. var extrudePath = data.options.extrudePath;
  24223. if (extrudePath !== undefined) {
  24224. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  24225. }
  24226. geometry = new Geometries[data.type](geometryShapes, data.options);
  24227. break;
  24228. case 'BufferGeometry':
  24229. case 'InstancedBufferGeometry':
  24230. geometry = bufferGeometryLoader.parse(data);
  24231. break;
  24232. case 'Geometry':
  24233. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  24234. break;
  24235. default:
  24236. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  24237. continue;
  24238. }
  24239. geometry.uuid = data.uuid;
  24240. if (data.name !== undefined) geometry.name = data.name;
  24241. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  24242. geometries[data.uuid] = geometry;
  24243. }
  24244. }
  24245. return geometries;
  24246. };
  24247. _proto.parseMaterials = function parseMaterials(json, textures) {
  24248. var cache = {}; // MultiMaterial
  24249. var materials = {};
  24250. if (json !== undefined) {
  24251. var loader = new MaterialLoader();
  24252. loader.setTextures(textures);
  24253. for (var i = 0, l = json.length; i < l; i++) {
  24254. var data = json[i];
  24255. if (data.type === 'MultiMaterial') {
  24256. // Deprecated
  24257. var array = [];
  24258. for (var j = 0; j < data.materials.length; j++) {
  24259. var material = data.materials[j];
  24260. if (cache[material.uuid] === undefined) {
  24261. cache[material.uuid] = loader.parse(material);
  24262. }
  24263. array.push(cache[material.uuid]);
  24264. }
  24265. materials[data.uuid] = array;
  24266. } else {
  24267. if (cache[data.uuid] === undefined) {
  24268. cache[data.uuid] = loader.parse(data);
  24269. }
  24270. materials[data.uuid] = cache[data.uuid];
  24271. }
  24272. }
  24273. }
  24274. return materials;
  24275. };
  24276. _proto.parseAnimations = function parseAnimations(json) {
  24277. var animations = {};
  24278. if (json !== undefined) {
  24279. for (var i = 0; i < json.length; i++) {
  24280. var data = json[i];
  24281. var clip = AnimationClip.parse(data);
  24282. animations[clip.uuid] = clip;
  24283. }
  24284. }
  24285. return animations;
  24286. };
  24287. _proto.parseImages = function parseImages(json, onLoad) {
  24288. var scope = this;
  24289. var images = {};
  24290. var loader;
  24291. function loadImage(url) {
  24292. scope.manager.itemStart(url);
  24293. return loader.load(url, function () {
  24294. scope.manager.itemEnd(url);
  24295. }, undefined, function () {
  24296. scope.manager.itemError(url);
  24297. scope.manager.itemEnd(url);
  24298. });
  24299. }
  24300. function deserializeImage(image) {
  24301. if (typeof image === 'string') {
  24302. var url = image;
  24303. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(url) ? url : scope.resourcePath + url;
  24304. return loadImage(path);
  24305. } else {
  24306. if (image.data) {
  24307. return {
  24308. data: getTypedArray(image.type, image.data),
  24309. width: image.width,
  24310. height: image.height
  24311. };
  24312. } else {
  24313. return null;
  24314. }
  24315. }
  24316. }
  24317. if (json !== undefined && json.length > 0) {
  24318. var manager = new LoadingManager(onLoad);
  24319. loader = new ImageLoader(manager);
  24320. loader.setCrossOrigin(this.crossOrigin);
  24321. for (var i = 0, il = json.length; i < il; i++) {
  24322. var image = json[i];
  24323. var url = image.url;
  24324. if (Array.isArray(url)) {
  24325. // load array of images e.g CubeTexture
  24326. images[image.uuid] = [];
  24327. for (var j = 0, jl = url.length; j < jl; j++) {
  24328. var currentUrl = url[j];
  24329. var deserializedImage = deserializeImage(currentUrl);
  24330. if (deserializedImage !== null) {
  24331. if (deserializedImage instanceof HTMLImageElement) {
  24332. images[image.uuid].push(deserializedImage);
  24333. } else {
  24334. // special case: handle array of data textures for cube textures
  24335. images[image.uuid].push(new DataTexture(deserializedImage.data, deserializedImage.width, deserializedImage.height));
  24336. }
  24337. }
  24338. }
  24339. } else {
  24340. // load single image
  24341. var _deserializedImage = deserializeImage(image.url);
  24342. if (_deserializedImage !== null) {
  24343. images[image.uuid] = _deserializedImage;
  24344. }
  24345. }
  24346. }
  24347. }
  24348. return images;
  24349. };
  24350. _proto.parseTextures = function parseTextures(json, images) {
  24351. function parseConstant(value, type) {
  24352. if (typeof value === 'number') return value;
  24353. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  24354. return type[value];
  24355. }
  24356. var textures = {};
  24357. if (json !== undefined) {
  24358. for (var i = 0, l = json.length; i < l; i++) {
  24359. var data = json[i];
  24360. if (data.image === undefined) {
  24361. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  24362. }
  24363. if (images[data.image] === undefined) {
  24364. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  24365. }
  24366. var texture = void 0;
  24367. var image = images[data.image];
  24368. if (Array.isArray(image)) {
  24369. texture = new CubeTexture(image);
  24370. if (image.length === 6) texture.needsUpdate = true;
  24371. } else {
  24372. if (image && image.data) {
  24373. texture = new DataTexture(image.data, image.width, image.height);
  24374. } else {
  24375. texture = new Texture(image);
  24376. }
  24377. if (image) texture.needsUpdate = true; // textures can have undefined image data
  24378. }
  24379. texture.uuid = data.uuid;
  24380. if (data.name !== undefined) texture.name = data.name;
  24381. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  24382. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  24383. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  24384. if (data.center !== undefined) texture.center.fromArray(data.center);
  24385. if (data.rotation !== undefined) texture.rotation = data.rotation;
  24386. if (data.wrap !== undefined) {
  24387. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  24388. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  24389. }
  24390. if (data.format !== undefined) texture.format = data.format;
  24391. if (data.type !== undefined) texture.type = data.type;
  24392. if (data.encoding !== undefined) texture.encoding = data.encoding;
  24393. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  24394. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  24395. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  24396. if (data.flipY !== undefined) texture.flipY = data.flipY;
  24397. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  24398. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  24399. textures[data.uuid] = texture;
  24400. }
  24401. }
  24402. return textures;
  24403. };
  24404. _proto.parseObject = function parseObject(data, geometries, materials, animations) {
  24405. var object;
  24406. function getGeometry(name) {
  24407. if (geometries[name] === undefined) {
  24408. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  24409. }
  24410. return geometries[name];
  24411. }
  24412. function getMaterial(name) {
  24413. if (name === undefined) return undefined;
  24414. if (Array.isArray(name)) {
  24415. var array = [];
  24416. for (var i = 0, l = name.length; i < l; i++) {
  24417. var uuid = name[i];
  24418. if (materials[uuid] === undefined) {
  24419. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  24420. }
  24421. array.push(materials[uuid]);
  24422. }
  24423. return array;
  24424. }
  24425. if (materials[name] === undefined) {
  24426. console.warn('THREE.ObjectLoader: Undefined material', name);
  24427. }
  24428. return materials[name];
  24429. }
  24430. var geometry, material;
  24431. switch (data.type) {
  24432. case 'Scene':
  24433. object = new Scene();
  24434. if (data.background !== undefined) {
  24435. if (Number.isInteger(data.background)) {
  24436. object.background = new Color(data.background);
  24437. }
  24438. }
  24439. if (data.fog !== undefined) {
  24440. if (data.fog.type === 'Fog') {
  24441. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  24442. } else if (data.fog.type === 'FogExp2') {
  24443. object.fog = new FogExp2(data.fog.color, data.fog.density);
  24444. }
  24445. }
  24446. break;
  24447. case 'PerspectiveCamera':
  24448. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  24449. if (data.focus !== undefined) object.focus = data.focus;
  24450. if (data.zoom !== undefined) object.zoom = data.zoom;
  24451. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  24452. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  24453. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24454. break;
  24455. case 'OrthographicCamera':
  24456. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  24457. if (data.zoom !== undefined) object.zoom = data.zoom;
  24458. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24459. break;
  24460. case 'AmbientLight':
  24461. object = new AmbientLight(data.color, data.intensity);
  24462. break;
  24463. case 'DirectionalLight':
  24464. object = new DirectionalLight(data.color, data.intensity);
  24465. break;
  24466. case 'PointLight':
  24467. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  24468. break;
  24469. case 'RectAreaLight':
  24470. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  24471. break;
  24472. case 'SpotLight':
  24473. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  24474. break;
  24475. case 'HemisphereLight':
  24476. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  24477. break;
  24478. case 'LightProbe':
  24479. object = new LightProbe().fromJSON(data);
  24480. break;
  24481. case 'SkinnedMesh':
  24482. geometry = getGeometry(data.geometry);
  24483. material = getMaterial(data.material);
  24484. object = new SkinnedMesh(geometry, material);
  24485. if (data.bindMode !== undefined) object.bindMode = data.bindMode;
  24486. if (data.bindMatrix !== undefined) object.bindMatrix.fromArray(data.bindMatrix);
  24487. if (data.skeleton !== undefined) object.skeleton = data.skeleton;
  24488. break;
  24489. case 'Mesh':
  24490. geometry = getGeometry(data.geometry);
  24491. material = getMaterial(data.material);
  24492. object = new Mesh(geometry, material);
  24493. break;
  24494. case 'InstancedMesh':
  24495. geometry = getGeometry(data.geometry);
  24496. material = getMaterial(data.material);
  24497. var count = data.count;
  24498. var instanceMatrix = data.instanceMatrix;
  24499. object = new InstancedMesh(geometry, material, count);
  24500. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  24501. break;
  24502. case 'LOD':
  24503. object = new LOD();
  24504. break;
  24505. case 'Line':
  24506. object = new Line(getGeometry(data.geometry), getMaterial(data.material));
  24507. break;
  24508. case 'LineLoop':
  24509. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  24510. break;
  24511. case 'LineSegments':
  24512. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  24513. break;
  24514. case 'PointCloud':
  24515. case 'Points':
  24516. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  24517. break;
  24518. case 'Sprite':
  24519. object = new Sprite(getMaterial(data.material));
  24520. break;
  24521. case 'Group':
  24522. object = new Group();
  24523. break;
  24524. case 'Bone':
  24525. object = new Bone();
  24526. break;
  24527. default:
  24528. object = new Object3D();
  24529. }
  24530. object.uuid = data.uuid;
  24531. if (data.name !== undefined) object.name = data.name;
  24532. if (data.matrix !== undefined) {
  24533. object.matrix.fromArray(data.matrix);
  24534. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24535. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  24536. } else {
  24537. if (data.position !== undefined) object.position.fromArray(data.position);
  24538. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  24539. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  24540. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  24541. }
  24542. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  24543. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  24544. if (data.shadow) {
  24545. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  24546. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  24547. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  24548. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  24549. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  24550. }
  24551. if (data.visible !== undefined) object.visible = data.visible;
  24552. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  24553. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  24554. if (data.userData !== undefined) object.userData = data.userData;
  24555. if (data.layers !== undefined) object.layers.mask = data.layers;
  24556. if (data.children !== undefined) {
  24557. var children = data.children;
  24558. for (var i = 0; i < children.length; i++) {
  24559. object.add(this.parseObject(children[i], geometries, materials, animations));
  24560. }
  24561. }
  24562. if (data.animations !== undefined) {
  24563. var objectAnimations = data.animations;
  24564. for (var _i = 0; _i < objectAnimations.length; _i++) {
  24565. var uuid = objectAnimations[_i];
  24566. object.animations.push(animations[uuid]);
  24567. }
  24568. }
  24569. if (data.type === 'LOD') {
  24570. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  24571. var levels = data.levels;
  24572. for (var l = 0; l < levels.length; l++) {
  24573. var level = levels[l];
  24574. var child = object.getObjectByProperty('uuid', level.object);
  24575. if (child !== undefined) {
  24576. object.addLevel(child, level.distance);
  24577. }
  24578. }
  24579. }
  24580. return object;
  24581. };
  24582. _proto.bindSkeletons = function bindSkeletons(object, skeletons) {
  24583. if (Object.keys(skeletons).length === 0) return;
  24584. object.traverse(function (child) {
  24585. if (child.isSkinnedMesh === true && child.skeleton !== undefined) {
  24586. var skeleton = skeletons[child.skeleton];
  24587. if (skeleton === undefined) {
  24588. console.warn('THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton);
  24589. } else {
  24590. child.bind(skeleton, child.bindMatrix);
  24591. }
  24592. }
  24593. });
  24594. }
  24595. /* DEPRECATED */
  24596. ;
  24597. _proto.setTexturePath = function setTexturePath(value) {
  24598. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  24599. return this.setResourcePath(value);
  24600. };
  24601. return ObjectLoader;
  24602. }(Loader);
  24603. var TEXTURE_MAPPING = {
  24604. UVMapping: UVMapping,
  24605. CubeReflectionMapping: CubeReflectionMapping,
  24606. CubeRefractionMapping: CubeRefractionMapping,
  24607. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  24608. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  24609. CubeUVReflectionMapping: CubeUVReflectionMapping,
  24610. CubeUVRefractionMapping: CubeUVRefractionMapping
  24611. };
  24612. var TEXTURE_WRAPPING = {
  24613. RepeatWrapping: RepeatWrapping,
  24614. ClampToEdgeWrapping: ClampToEdgeWrapping,
  24615. MirroredRepeatWrapping: MirroredRepeatWrapping
  24616. };
  24617. var TEXTURE_FILTER = {
  24618. NearestFilter: NearestFilter,
  24619. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  24620. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  24621. LinearFilter: LinearFilter,
  24622. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  24623. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  24624. };
  24625. function ImageBitmapLoader(manager) {
  24626. if (typeof createImageBitmap === 'undefined') {
  24627. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  24628. }
  24629. if (typeof fetch === 'undefined') {
  24630. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  24631. }
  24632. Loader.call(this, manager);
  24633. this.options = {
  24634. premultiplyAlpha: 'none'
  24635. };
  24636. }
  24637. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24638. constructor: ImageBitmapLoader,
  24639. isImageBitmapLoader: true,
  24640. setOptions: function setOptions(options) {
  24641. this.options = options;
  24642. return this;
  24643. },
  24644. load: function load(url, onLoad, onProgress, onError) {
  24645. if (url === undefined) url = '';
  24646. if (this.path !== undefined) url = this.path + url;
  24647. url = this.manager.resolveURL(url);
  24648. var scope = this;
  24649. var cached = Cache.get(url);
  24650. if (cached !== undefined) {
  24651. scope.manager.itemStart(url);
  24652. setTimeout(function () {
  24653. if (onLoad) onLoad(cached);
  24654. scope.manager.itemEnd(url);
  24655. }, 0);
  24656. return cached;
  24657. }
  24658. var fetchOptions = {};
  24659. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  24660. fetch(url, fetchOptions).then(function (res) {
  24661. return res.blob();
  24662. }).then(function (blob) {
  24663. return createImageBitmap(blob, scope.options);
  24664. }).then(function (imageBitmap) {
  24665. Cache.add(url, imageBitmap);
  24666. if (onLoad) onLoad(imageBitmap);
  24667. scope.manager.itemEnd(url);
  24668. }).catch(function (e) {
  24669. if (onError) onError(e);
  24670. scope.manager.itemError(url);
  24671. scope.manager.itemEnd(url);
  24672. });
  24673. scope.manager.itemStart(url);
  24674. }
  24675. });
  24676. function ShapePath() {
  24677. this.type = 'ShapePath';
  24678. this.color = new Color();
  24679. this.subPaths = [];
  24680. this.currentPath = null;
  24681. }
  24682. Object.assign(ShapePath.prototype, {
  24683. moveTo: function moveTo(x, y) {
  24684. this.currentPath = new Path();
  24685. this.subPaths.push(this.currentPath);
  24686. this.currentPath.moveTo(x, y);
  24687. return this;
  24688. },
  24689. lineTo: function lineTo(x, y) {
  24690. this.currentPath.lineTo(x, y);
  24691. return this;
  24692. },
  24693. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  24694. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  24695. return this;
  24696. },
  24697. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  24698. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  24699. return this;
  24700. },
  24701. splineThru: function splineThru(pts) {
  24702. this.currentPath.splineThru(pts);
  24703. return this;
  24704. },
  24705. toShapes: function toShapes(isCCW, noHoles) {
  24706. function toShapesNoHoles(inSubpaths) {
  24707. var shapes = [];
  24708. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  24709. var _tmpPath = inSubpaths[i];
  24710. var _tmpShape = new Shape();
  24711. _tmpShape.curves = _tmpPath.curves;
  24712. shapes.push(_tmpShape);
  24713. }
  24714. return shapes;
  24715. }
  24716. function isPointInsidePolygon(inPt, inPolygon) {
  24717. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  24718. // toggling of inside/outside at every single! intersection point of an edge
  24719. // with the horizontal line through inPt, left of inPt
  24720. // not counting lowerY endpoints of edges and whole edges on that line
  24721. var inside = false;
  24722. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  24723. var edgeLowPt = inPolygon[p];
  24724. var edgeHighPt = inPolygon[q];
  24725. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  24726. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  24727. if (Math.abs(edgeDy) > Number.EPSILON) {
  24728. // not parallel
  24729. if (edgeDy < 0) {
  24730. edgeLowPt = inPolygon[q];
  24731. edgeDx = -edgeDx;
  24732. edgeHighPt = inPolygon[p];
  24733. edgeDy = -edgeDy;
  24734. }
  24735. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  24736. if (inPt.y === edgeLowPt.y) {
  24737. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  24738. // continue; // no intersection or edgeLowPt => doesn't count !!!
  24739. } else {
  24740. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  24741. if (perpEdge === 0) return true; // inPt is on contour ?
  24742. if (perpEdge < 0) continue;
  24743. inside = !inside; // true intersection left of inPt
  24744. }
  24745. } else {
  24746. // parallel or collinear
  24747. if (inPt.y !== edgeLowPt.y) continue; // parallel
  24748. // edge lies on the same horizontal line as inPt
  24749. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  24750. // continue;
  24751. }
  24752. }
  24753. return inside;
  24754. }
  24755. var isClockWise = ShapeUtils.isClockWise;
  24756. var subPaths = this.subPaths;
  24757. if (subPaths.length === 0) return [];
  24758. if (noHoles === true) return toShapesNoHoles(subPaths);
  24759. var solid, tmpPath, tmpShape;
  24760. var shapes = [];
  24761. if (subPaths.length === 1) {
  24762. tmpPath = subPaths[0];
  24763. tmpShape = new Shape();
  24764. tmpShape.curves = tmpPath.curves;
  24765. shapes.push(tmpShape);
  24766. return shapes;
  24767. }
  24768. var holesFirst = !isClockWise(subPaths[0].getPoints());
  24769. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  24770. var betterShapeHoles = [];
  24771. var newShapes = [];
  24772. var newShapeHoles = [];
  24773. var mainIdx = 0;
  24774. var tmpPoints;
  24775. newShapes[mainIdx] = undefined;
  24776. newShapeHoles[mainIdx] = [];
  24777. for (var i = 0, l = subPaths.length; i < l; i++) {
  24778. tmpPath = subPaths[i];
  24779. tmpPoints = tmpPath.getPoints();
  24780. solid = isClockWise(tmpPoints);
  24781. solid = isCCW ? !solid : solid;
  24782. if (solid) {
  24783. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  24784. newShapes[mainIdx] = {
  24785. s: new Shape(),
  24786. p: tmpPoints
  24787. };
  24788. newShapes[mainIdx].s.curves = tmpPath.curves;
  24789. if (holesFirst) mainIdx++;
  24790. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  24791. } else {
  24792. newShapeHoles[mainIdx].push({
  24793. h: tmpPath,
  24794. p: tmpPoints[0]
  24795. }); //console.log('ccw', i);
  24796. }
  24797. } // only Holes? -> probably all Shapes with wrong orientation
  24798. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  24799. if (newShapes.length > 1) {
  24800. var ambiguous = false;
  24801. var toChange = [];
  24802. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  24803. betterShapeHoles[sIdx] = [];
  24804. }
  24805. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  24806. var sho = newShapeHoles[_sIdx];
  24807. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  24808. var ho = sho[hIdx];
  24809. var hole_unassigned = true;
  24810. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  24811. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  24812. if (_sIdx !== s2Idx) toChange.push({
  24813. froms: _sIdx,
  24814. tos: s2Idx,
  24815. hole: hIdx
  24816. });
  24817. if (hole_unassigned) {
  24818. hole_unassigned = false;
  24819. betterShapeHoles[s2Idx].push(ho);
  24820. } else {
  24821. ambiguous = true;
  24822. }
  24823. }
  24824. }
  24825. if (hole_unassigned) {
  24826. betterShapeHoles[_sIdx].push(ho);
  24827. }
  24828. }
  24829. } // console.log("ambiguous: ", ambiguous);
  24830. if (toChange.length > 0) {
  24831. // console.log("to change: ", toChange);
  24832. if (!ambiguous) newShapeHoles = betterShapeHoles;
  24833. }
  24834. }
  24835. var tmpHoles;
  24836. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  24837. tmpShape = newShapes[_i].s;
  24838. shapes.push(tmpShape);
  24839. tmpHoles = newShapeHoles[_i];
  24840. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  24841. tmpShape.holes.push(tmpHoles[j].h);
  24842. }
  24843. } //console.log("shape", shapes);
  24844. return shapes;
  24845. }
  24846. });
  24847. var Font = /*#__PURE__*/function () {
  24848. function Font(data) {
  24849. Object.defineProperty(this, 'isFont', {
  24850. value: true
  24851. });
  24852. this.type = 'Font';
  24853. this.data = data;
  24854. }
  24855. var _proto = Font.prototype;
  24856. _proto.generateShapes = function generateShapes(text, size) {
  24857. if (size === void 0) {
  24858. size = 100;
  24859. }
  24860. var shapes = [];
  24861. var paths = createPaths(text, size, this.data);
  24862. for (var p = 0, pl = paths.length; p < pl; p++) {
  24863. Array.prototype.push.apply(shapes, paths[p].toShapes());
  24864. }
  24865. return shapes;
  24866. };
  24867. return Font;
  24868. }();
  24869. function createPaths(text, size, data) {
  24870. var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
  24871. var scale = size / data.resolution;
  24872. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  24873. var paths = [];
  24874. var offsetX = 0,
  24875. offsetY = 0;
  24876. for (var i = 0; i < chars.length; i++) {
  24877. var char = chars[i];
  24878. if (char === '\n') {
  24879. offsetX = 0;
  24880. offsetY -= line_height;
  24881. } else {
  24882. var ret = createPath(char, scale, offsetX, offsetY, data);
  24883. offsetX += ret.offsetX;
  24884. paths.push(ret.path);
  24885. }
  24886. }
  24887. return paths;
  24888. }
  24889. function createPath(char, scale, offsetX, offsetY, data) {
  24890. var glyph = data.glyphs[char] || data.glyphs['?'];
  24891. if (!glyph) {
  24892. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  24893. return;
  24894. }
  24895. var path = new ShapePath();
  24896. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  24897. if (glyph.o) {
  24898. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  24899. for (var i = 0, l = outline.length; i < l;) {
  24900. var action = outline[i++];
  24901. switch (action) {
  24902. case 'm':
  24903. // moveTo
  24904. x = outline[i++] * scale + offsetX;
  24905. y = outline[i++] * scale + offsetY;
  24906. path.moveTo(x, y);
  24907. break;
  24908. case 'l':
  24909. // lineTo
  24910. x = outline[i++] * scale + offsetX;
  24911. y = outline[i++] * scale + offsetY;
  24912. path.lineTo(x, y);
  24913. break;
  24914. case 'q':
  24915. // quadraticCurveTo
  24916. cpx = outline[i++] * scale + offsetX;
  24917. cpy = outline[i++] * scale + offsetY;
  24918. cpx1 = outline[i++] * scale + offsetX;
  24919. cpy1 = outline[i++] * scale + offsetY;
  24920. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  24921. break;
  24922. case 'b':
  24923. // bezierCurveTo
  24924. cpx = outline[i++] * scale + offsetX;
  24925. cpy = outline[i++] * scale + offsetY;
  24926. cpx1 = outline[i++] * scale + offsetX;
  24927. cpy1 = outline[i++] * scale + offsetY;
  24928. cpx2 = outline[i++] * scale + offsetX;
  24929. cpy2 = outline[i++] * scale + offsetY;
  24930. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  24931. break;
  24932. }
  24933. }
  24934. }
  24935. return {
  24936. offsetX: glyph.ha * scale,
  24937. path: path
  24938. };
  24939. }
  24940. function FontLoader(manager) {
  24941. Loader.call(this, manager);
  24942. }
  24943. FontLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24944. constructor: FontLoader,
  24945. load: function load(url, onLoad, onProgress, onError) {
  24946. var scope = this;
  24947. var loader = new FileLoader(this.manager);
  24948. loader.setPath(this.path);
  24949. loader.setRequestHeader(this.requestHeader);
  24950. loader.setWithCredentials(scope.withCredentials);
  24951. loader.load(url, function (text) {
  24952. var json;
  24953. try {
  24954. json = JSON.parse(text);
  24955. } catch (e) {
  24956. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  24957. json = JSON.parse(text.substring(65, text.length - 2));
  24958. }
  24959. var font = scope.parse(json);
  24960. if (onLoad) onLoad(font);
  24961. }, onProgress, onError);
  24962. },
  24963. parse: function parse(json) {
  24964. return new Font(json);
  24965. }
  24966. });
  24967. var _context;
  24968. var AudioContext = {
  24969. getContext: function getContext() {
  24970. if (_context === undefined) {
  24971. _context = new (window.AudioContext || window.webkitAudioContext)();
  24972. }
  24973. return _context;
  24974. },
  24975. setContext: function setContext(value) {
  24976. _context = value;
  24977. }
  24978. };
  24979. function AudioLoader(manager) {
  24980. Loader.call(this, manager);
  24981. }
  24982. AudioLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24983. constructor: AudioLoader,
  24984. load: function load(url, onLoad, onProgress, onError) {
  24985. var scope = this;
  24986. var loader = new FileLoader(scope.manager);
  24987. loader.setResponseType('arraybuffer');
  24988. loader.setPath(scope.path);
  24989. loader.setRequestHeader(scope.requestHeader);
  24990. loader.setWithCredentials(scope.withCredentials);
  24991. loader.load(url, function (buffer) {
  24992. try {
  24993. // Create a copy of the buffer. The `decodeAudioData` method
  24994. // detaches the buffer when complete, preventing reuse.
  24995. var bufferCopy = buffer.slice(0);
  24996. var context = AudioContext.getContext();
  24997. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  24998. onLoad(audioBuffer);
  24999. });
  25000. } catch (e) {
  25001. if (onError) {
  25002. onError(e);
  25003. } else {
  25004. console.error(e);
  25005. }
  25006. scope.manager.itemError(url);
  25007. }
  25008. }, onProgress, onError);
  25009. }
  25010. });
  25011. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  25012. LightProbe.call(this, undefined, intensity);
  25013. var color1 = new Color().set(skyColor);
  25014. var color2 = new Color().set(groundColor);
  25015. var sky = new Vector3(color1.r, color1.g, color1.b);
  25016. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25017. var c0 = Math.sqrt(Math.PI);
  25018. var c1 = c0 * Math.sqrt(0.75);
  25019. this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  25020. this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  25021. }
  25022. HemisphereLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25023. constructor: HemisphereLightProbe,
  25024. isHemisphereLightProbe: true,
  25025. copy: function copy(source) {
  25026. // modifying colors not currently supported
  25027. LightProbe.prototype.copy.call(this, source);
  25028. return this;
  25029. },
  25030. toJSON: function toJSON(meta) {
  25031. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25032. return data;
  25033. }
  25034. });
  25035. function AmbientLightProbe(color, intensity) {
  25036. LightProbe.call(this, undefined, intensity);
  25037. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25038. this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  25039. }
  25040. AmbientLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25041. constructor: AmbientLightProbe,
  25042. isAmbientLightProbe: true,
  25043. copy: function copy(source) {
  25044. // modifying color not currently supported
  25045. LightProbe.prototype.copy.call(this, source);
  25046. return this;
  25047. },
  25048. toJSON: function toJSON(meta) {
  25049. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25050. return data;
  25051. }
  25052. });
  25053. var _eyeRight = new Matrix4();
  25054. var _eyeLeft = new Matrix4();
  25055. function StereoCamera() {
  25056. this.type = 'StereoCamera';
  25057. this.aspect = 1;
  25058. this.eyeSep = 0.064;
  25059. this.cameraL = new PerspectiveCamera();
  25060. this.cameraL.layers.enable(1);
  25061. this.cameraL.matrixAutoUpdate = false;
  25062. this.cameraR = new PerspectiveCamera();
  25063. this.cameraR.layers.enable(2);
  25064. this.cameraR.matrixAutoUpdate = false;
  25065. this._cache = {
  25066. focus: null,
  25067. fov: null,
  25068. aspect: null,
  25069. near: null,
  25070. far: null,
  25071. zoom: null,
  25072. eyeSep: null
  25073. };
  25074. }
  25075. Object.assign(StereoCamera.prototype, {
  25076. update: function update(camera) {
  25077. var cache = this._cache;
  25078. 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;
  25079. if (needsUpdate) {
  25080. cache.focus = camera.focus;
  25081. cache.fov = camera.fov;
  25082. cache.aspect = camera.aspect * this.aspect;
  25083. cache.near = camera.near;
  25084. cache.far = camera.far;
  25085. cache.zoom = camera.zoom;
  25086. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  25087. // http://paulbourke.net/stereographics/stereorender/
  25088. var projectionMatrix = camera.projectionMatrix.clone();
  25089. var eyeSepHalf = cache.eyeSep / 2;
  25090. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25091. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  25092. var xmin, xmax; // translate xOffset
  25093. _eyeLeft.elements[12] = -eyeSepHalf;
  25094. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  25095. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  25096. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25097. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25098. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25099. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  25100. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  25101. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25102. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25103. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25104. this.cameraR.projectionMatrix.copy(projectionMatrix);
  25105. }
  25106. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  25107. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  25108. }
  25109. });
  25110. var Clock = /*#__PURE__*/function () {
  25111. function Clock(autoStart) {
  25112. this.autoStart = autoStart !== undefined ? autoStart : true;
  25113. this.startTime = 0;
  25114. this.oldTime = 0;
  25115. this.elapsedTime = 0;
  25116. this.running = false;
  25117. }
  25118. var _proto = Clock.prototype;
  25119. _proto.start = function start() {
  25120. this.startTime = now();
  25121. this.oldTime = this.startTime;
  25122. this.elapsedTime = 0;
  25123. this.running = true;
  25124. };
  25125. _proto.stop = function stop() {
  25126. this.getElapsedTime();
  25127. this.running = false;
  25128. this.autoStart = false;
  25129. };
  25130. _proto.getElapsedTime = function getElapsedTime() {
  25131. this.getDelta();
  25132. return this.elapsedTime;
  25133. };
  25134. _proto.getDelta = function getDelta() {
  25135. var diff = 0;
  25136. if (this.autoStart && !this.running) {
  25137. this.start();
  25138. return 0;
  25139. }
  25140. if (this.running) {
  25141. var newTime = now();
  25142. diff = (newTime - this.oldTime) / 1000;
  25143. this.oldTime = newTime;
  25144. this.elapsedTime += diff;
  25145. }
  25146. return diff;
  25147. };
  25148. return Clock;
  25149. }();
  25150. function now() {
  25151. return (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  25152. }
  25153. var _position$2 = /*@__PURE__*/new Vector3();
  25154. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  25155. var _scale$1 = /*@__PURE__*/new Vector3();
  25156. var _orientation = /*@__PURE__*/new Vector3();
  25157. var AudioListener = /*#__PURE__*/function (_Object3D) {
  25158. _inheritsLoose(AudioListener, _Object3D);
  25159. function AudioListener() {
  25160. var _this;
  25161. _this = _Object3D.call(this) || this;
  25162. _this.type = 'AudioListener';
  25163. _this.context = AudioContext.getContext();
  25164. _this.gain = _this.context.createGain();
  25165. _this.gain.connect(_this.context.destination);
  25166. _this.filter = null;
  25167. _this.timeDelta = 0; // private
  25168. _this._clock = new Clock();
  25169. return _this;
  25170. }
  25171. var _proto = AudioListener.prototype;
  25172. _proto.getInput = function getInput() {
  25173. return this.gain;
  25174. };
  25175. _proto.removeFilter = function removeFilter() {
  25176. if (this.filter !== null) {
  25177. this.gain.disconnect(this.filter);
  25178. this.filter.disconnect(this.context.destination);
  25179. this.gain.connect(this.context.destination);
  25180. this.filter = null;
  25181. }
  25182. return this;
  25183. };
  25184. _proto.getFilter = function getFilter() {
  25185. return this.filter;
  25186. };
  25187. _proto.setFilter = function setFilter(value) {
  25188. if (this.filter !== null) {
  25189. this.gain.disconnect(this.filter);
  25190. this.filter.disconnect(this.context.destination);
  25191. } else {
  25192. this.gain.disconnect(this.context.destination);
  25193. }
  25194. this.filter = value;
  25195. this.gain.connect(this.filter);
  25196. this.filter.connect(this.context.destination);
  25197. return this;
  25198. };
  25199. _proto.getMasterVolume = function getMasterVolume() {
  25200. return this.gain.gain.value;
  25201. };
  25202. _proto.setMasterVolume = function setMasterVolume(value) {
  25203. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25204. return this;
  25205. };
  25206. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25207. _Object3D.prototype.updateMatrixWorld.call(this, force);
  25208. var listener = this.context.listener;
  25209. var up = this.up;
  25210. this.timeDelta = this._clock.getDelta();
  25211. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  25212. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  25213. if (listener.positionX) {
  25214. // code path for Chrome (see #14393)
  25215. var endTime = this.context.currentTime + this.timeDelta;
  25216. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  25217. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  25218. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  25219. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  25220. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  25221. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  25222. listener.upX.linearRampToValueAtTime(up.x, endTime);
  25223. listener.upY.linearRampToValueAtTime(up.y, endTime);
  25224. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  25225. } else {
  25226. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  25227. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  25228. }
  25229. };
  25230. return AudioListener;
  25231. }(Object3D);
  25232. var Audio = /*#__PURE__*/function (_Object3D) {
  25233. _inheritsLoose(Audio, _Object3D);
  25234. function Audio(listener) {
  25235. var _this;
  25236. _this = _Object3D.call(this) || this;
  25237. _this.type = 'Audio';
  25238. _this.listener = listener;
  25239. _this.context = listener.context;
  25240. _this.gain = _this.context.createGain();
  25241. _this.gain.connect(listener.getInput());
  25242. _this.autoplay = false;
  25243. _this.buffer = null;
  25244. _this.detune = 0;
  25245. _this.loop = false;
  25246. _this.loopStart = 0;
  25247. _this.loopEnd = 0;
  25248. _this.offset = 0;
  25249. _this.duration = undefined;
  25250. _this.playbackRate = 1;
  25251. _this.isPlaying = false;
  25252. _this.hasPlaybackControl = true;
  25253. _this.source = null;
  25254. _this.sourceType = 'empty';
  25255. _this._startedAt = 0;
  25256. _this._progress = 0;
  25257. _this._connected = false;
  25258. _this.filters = [];
  25259. return _this;
  25260. }
  25261. var _proto = Audio.prototype;
  25262. _proto.getOutput = function getOutput() {
  25263. return this.gain;
  25264. };
  25265. _proto.setNodeSource = function setNodeSource(audioNode) {
  25266. this.hasPlaybackControl = false;
  25267. this.sourceType = 'audioNode';
  25268. this.source = audioNode;
  25269. this.connect();
  25270. return this;
  25271. };
  25272. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  25273. this.hasPlaybackControl = false;
  25274. this.sourceType = 'mediaNode';
  25275. this.source = this.context.createMediaElementSource(mediaElement);
  25276. this.connect();
  25277. return this;
  25278. };
  25279. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  25280. this.hasPlaybackControl = false;
  25281. this.sourceType = 'mediaStreamNode';
  25282. this.source = this.context.createMediaStreamSource(mediaStream);
  25283. this.connect();
  25284. return this;
  25285. };
  25286. _proto.setBuffer = function setBuffer(audioBuffer) {
  25287. this.buffer = audioBuffer;
  25288. this.sourceType = 'buffer';
  25289. if (this.autoplay) this.play();
  25290. return this;
  25291. };
  25292. _proto.play = function play(delay) {
  25293. if (delay === void 0) {
  25294. delay = 0;
  25295. }
  25296. if (this.isPlaying === true) {
  25297. console.warn('THREE.Audio: Audio is already playing.');
  25298. return;
  25299. }
  25300. if (this.hasPlaybackControl === false) {
  25301. console.warn('THREE.Audio: this Audio has no playback control.');
  25302. return;
  25303. }
  25304. this._startedAt = this.context.currentTime + delay;
  25305. var source = this.context.createBufferSource();
  25306. source.buffer = this.buffer;
  25307. source.loop = this.loop;
  25308. source.loopStart = this.loopStart;
  25309. source.loopEnd = this.loopEnd;
  25310. source.onended = this.onEnded.bind(this);
  25311. source.start(this._startedAt, this._progress + this.offset, this.duration);
  25312. this.isPlaying = true;
  25313. this.source = source;
  25314. this.setDetune(this.detune);
  25315. this.setPlaybackRate(this.playbackRate);
  25316. return this.connect();
  25317. };
  25318. _proto.pause = function pause() {
  25319. if (this.hasPlaybackControl === false) {
  25320. console.warn('THREE.Audio: this Audio has no playback control.');
  25321. return;
  25322. }
  25323. if (this.isPlaying === true) {
  25324. // update current progress
  25325. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  25326. if (this.loop === true) {
  25327. // ensure _progress does not exceed duration with looped audios
  25328. this._progress = this._progress % (this.duration || this.buffer.duration);
  25329. }
  25330. this.source.stop();
  25331. this.source.onended = null;
  25332. this.isPlaying = false;
  25333. }
  25334. return this;
  25335. };
  25336. _proto.stop = function stop() {
  25337. if (this.hasPlaybackControl === false) {
  25338. console.warn('THREE.Audio: this Audio has no playback control.');
  25339. return;
  25340. }
  25341. this._progress = 0;
  25342. this.source.stop();
  25343. this.source.onended = null;
  25344. this.isPlaying = false;
  25345. return this;
  25346. };
  25347. _proto.connect = function connect() {
  25348. if (this.filters.length > 0) {
  25349. this.source.connect(this.filters[0]);
  25350. for (var i = 1, l = this.filters.length; i < l; i++) {
  25351. this.filters[i - 1].connect(this.filters[i]);
  25352. }
  25353. this.filters[this.filters.length - 1].connect(this.getOutput());
  25354. } else {
  25355. this.source.connect(this.getOutput());
  25356. }
  25357. this._connected = true;
  25358. return this;
  25359. };
  25360. _proto.disconnect = function disconnect() {
  25361. if (this.filters.length > 0) {
  25362. this.source.disconnect(this.filters[0]);
  25363. for (var i = 1, l = this.filters.length; i < l; i++) {
  25364. this.filters[i - 1].disconnect(this.filters[i]);
  25365. }
  25366. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  25367. } else {
  25368. this.source.disconnect(this.getOutput());
  25369. }
  25370. this._connected = false;
  25371. return this;
  25372. };
  25373. _proto.getFilters = function getFilters() {
  25374. return this.filters;
  25375. };
  25376. _proto.setFilters = function setFilters(value) {
  25377. if (!value) value = [];
  25378. if (this._connected === true) {
  25379. this.disconnect();
  25380. this.filters = value.slice();
  25381. this.connect();
  25382. } else {
  25383. this.filters = value.slice();
  25384. }
  25385. return this;
  25386. };
  25387. _proto.setDetune = function setDetune(value) {
  25388. this.detune = value;
  25389. if (this.source.detune === undefined) return; // only set detune when available
  25390. if (this.isPlaying === true) {
  25391. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  25392. }
  25393. return this;
  25394. };
  25395. _proto.getDetune = function getDetune() {
  25396. return this.detune;
  25397. };
  25398. _proto.getFilter = function getFilter() {
  25399. return this.getFilters()[0];
  25400. };
  25401. _proto.setFilter = function setFilter(filter) {
  25402. return this.setFilters(filter ? [filter] : []);
  25403. };
  25404. _proto.setPlaybackRate = function setPlaybackRate(value) {
  25405. if (this.hasPlaybackControl === false) {
  25406. console.warn('THREE.Audio: this Audio has no playback control.');
  25407. return;
  25408. }
  25409. this.playbackRate = value;
  25410. if (this.isPlaying === true) {
  25411. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  25412. }
  25413. return this;
  25414. };
  25415. _proto.getPlaybackRate = function getPlaybackRate() {
  25416. return this.playbackRate;
  25417. };
  25418. _proto.onEnded = function onEnded() {
  25419. this.isPlaying = false;
  25420. };
  25421. _proto.getLoop = function getLoop() {
  25422. if (this.hasPlaybackControl === false) {
  25423. console.warn('THREE.Audio: this Audio has no playback control.');
  25424. return false;
  25425. }
  25426. return this.loop;
  25427. };
  25428. _proto.setLoop = function setLoop(value) {
  25429. if (this.hasPlaybackControl === false) {
  25430. console.warn('THREE.Audio: this Audio has no playback control.');
  25431. return;
  25432. }
  25433. this.loop = value;
  25434. if (this.isPlaying === true) {
  25435. this.source.loop = this.loop;
  25436. }
  25437. return this;
  25438. };
  25439. _proto.setLoopStart = function setLoopStart(value) {
  25440. this.loopStart = value;
  25441. return this;
  25442. };
  25443. _proto.setLoopEnd = function setLoopEnd(value) {
  25444. this.loopEnd = value;
  25445. return this;
  25446. };
  25447. _proto.getVolume = function getVolume() {
  25448. return this.gain.gain.value;
  25449. };
  25450. _proto.setVolume = function setVolume(value) {
  25451. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25452. return this;
  25453. };
  25454. return Audio;
  25455. }(Object3D);
  25456. var _position$3 = /*@__PURE__*/new Vector3();
  25457. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  25458. var _scale$2 = /*@__PURE__*/new Vector3();
  25459. var _orientation$1 = /*@__PURE__*/new Vector3();
  25460. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  25461. _inheritsLoose(PositionalAudio, _Audio);
  25462. function PositionalAudio(listener) {
  25463. var _this;
  25464. _this = _Audio.call(this, listener) || this;
  25465. _this.panner = _this.context.createPanner();
  25466. _this.panner.panningModel = 'HRTF';
  25467. _this.panner.connect(_this.gain);
  25468. return _this;
  25469. }
  25470. var _proto = PositionalAudio.prototype;
  25471. _proto.getOutput = function getOutput() {
  25472. return this.panner;
  25473. };
  25474. _proto.getRefDistance = function getRefDistance() {
  25475. return this.panner.refDistance;
  25476. };
  25477. _proto.setRefDistance = function setRefDistance(value) {
  25478. this.panner.refDistance = value;
  25479. return this;
  25480. };
  25481. _proto.getRolloffFactor = function getRolloffFactor() {
  25482. return this.panner.rolloffFactor;
  25483. };
  25484. _proto.setRolloffFactor = function setRolloffFactor(value) {
  25485. this.panner.rolloffFactor = value;
  25486. return this;
  25487. };
  25488. _proto.getDistanceModel = function getDistanceModel() {
  25489. return this.panner.distanceModel;
  25490. };
  25491. _proto.setDistanceModel = function setDistanceModel(value) {
  25492. this.panner.distanceModel = value;
  25493. return this;
  25494. };
  25495. _proto.getMaxDistance = function getMaxDistance() {
  25496. return this.panner.maxDistance;
  25497. };
  25498. _proto.setMaxDistance = function setMaxDistance(value) {
  25499. this.panner.maxDistance = value;
  25500. return this;
  25501. };
  25502. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  25503. this.panner.coneInnerAngle = coneInnerAngle;
  25504. this.panner.coneOuterAngle = coneOuterAngle;
  25505. this.panner.coneOuterGain = coneOuterGain;
  25506. return this;
  25507. };
  25508. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25509. _Audio.prototype.updateMatrixWorld.call(this, force);
  25510. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  25511. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  25512. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  25513. var panner = this.panner;
  25514. if (panner.positionX) {
  25515. // code path for Chrome and Firefox (see #14393)
  25516. var endTime = this.context.currentTime + this.listener.timeDelta;
  25517. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  25518. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  25519. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  25520. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  25521. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  25522. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  25523. } else {
  25524. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  25525. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  25526. }
  25527. };
  25528. return PositionalAudio;
  25529. }(Audio);
  25530. var AudioAnalyser = /*#__PURE__*/function () {
  25531. function AudioAnalyser(audio, fftSize) {
  25532. if (fftSize === void 0) {
  25533. fftSize = 2048;
  25534. }
  25535. this.analyser = audio.context.createAnalyser();
  25536. this.analyser.fftSize = fftSize;
  25537. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  25538. audio.getOutput().connect(this.analyser);
  25539. }
  25540. var _proto = AudioAnalyser.prototype;
  25541. _proto.getFrequencyData = function getFrequencyData() {
  25542. this.analyser.getByteFrequencyData(this.data);
  25543. return this.data;
  25544. };
  25545. _proto.getAverageFrequency = function getAverageFrequency() {
  25546. var value = 0;
  25547. var data = this.getFrequencyData();
  25548. for (var i = 0; i < data.length; i++) {
  25549. value += data[i];
  25550. }
  25551. return value / data.length;
  25552. };
  25553. return AudioAnalyser;
  25554. }();
  25555. function PropertyMixer(binding, typeName, valueSize) {
  25556. this.binding = binding;
  25557. this.valueSize = valueSize;
  25558. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  25559. //
  25560. // interpolators can use .buffer as their .result
  25561. // the data then goes to 'incoming'
  25562. //
  25563. // 'accu0' and 'accu1' are used frame-interleaved for
  25564. // the cumulative result and are compared to detect
  25565. // changes
  25566. //
  25567. // 'orig' stores the original state of the property
  25568. //
  25569. // 'add' is used for additive cumulative results
  25570. //
  25571. // 'work' is optional and is only present for quaternion types. It is used
  25572. // to store intermediate quaternion multiplication results
  25573. switch (typeName) {
  25574. case 'quaternion':
  25575. mixFunction = this._slerp;
  25576. mixFunctionAdditive = this._slerpAdditive;
  25577. setIdentity = this._setAdditiveIdentityQuaternion;
  25578. this.buffer = new Float64Array(valueSize * 6);
  25579. this._workIndex = 5;
  25580. break;
  25581. case 'string':
  25582. case 'bool':
  25583. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  25584. // additive is not relevant for non-numeric types
  25585. mixFunctionAdditive = this._select;
  25586. setIdentity = this._setAdditiveIdentityOther;
  25587. this.buffer = new Array(valueSize * 5);
  25588. break;
  25589. default:
  25590. mixFunction = this._lerp;
  25591. mixFunctionAdditive = this._lerpAdditive;
  25592. setIdentity = this._setAdditiveIdentityNumeric;
  25593. this.buffer = new Float64Array(valueSize * 5);
  25594. }
  25595. this._mixBufferRegion = mixFunction;
  25596. this._mixBufferRegionAdditive = mixFunctionAdditive;
  25597. this._setIdentity = setIdentity;
  25598. this._origIndex = 3;
  25599. this._addIndex = 4;
  25600. this.cumulativeWeight = 0;
  25601. this.cumulativeWeightAdditive = 0;
  25602. this.useCount = 0;
  25603. this.referenceCount = 0;
  25604. }
  25605. Object.assign(PropertyMixer.prototype, {
  25606. // accumulate data in the 'incoming' region into 'accu<i>'
  25607. accumulate: function accumulate(accuIndex, weight) {
  25608. // note: happily accumulating nothing when weight = 0, the caller knows
  25609. // the weight and shouldn't have made the call in the first place
  25610. var buffer = this.buffer,
  25611. stride = this.valueSize,
  25612. offset = accuIndex * stride + stride;
  25613. var currentWeight = this.cumulativeWeight;
  25614. if (currentWeight === 0) {
  25615. // accuN := incoming * weight
  25616. for (var i = 0; i !== stride; ++i) {
  25617. buffer[offset + i] = buffer[i];
  25618. }
  25619. currentWeight = weight;
  25620. } else {
  25621. // accuN := accuN + incoming * weight
  25622. currentWeight += weight;
  25623. var mix = weight / currentWeight;
  25624. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  25625. }
  25626. this.cumulativeWeight = currentWeight;
  25627. },
  25628. // accumulate data in the 'incoming' region into 'add'
  25629. accumulateAdditive: function accumulateAdditive(weight) {
  25630. var buffer = this.buffer,
  25631. stride = this.valueSize,
  25632. offset = stride * this._addIndex;
  25633. if (this.cumulativeWeightAdditive === 0) {
  25634. // add = identity
  25635. this._setIdentity();
  25636. } // add := add + incoming * weight
  25637. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  25638. this.cumulativeWeightAdditive += weight;
  25639. },
  25640. // apply the state of 'accu<i>' to the binding when accus differ
  25641. apply: function apply(accuIndex) {
  25642. var stride = this.valueSize,
  25643. buffer = this.buffer,
  25644. offset = accuIndex * stride + stride,
  25645. weight = this.cumulativeWeight,
  25646. weightAdditive = this.cumulativeWeightAdditive,
  25647. binding = this.binding;
  25648. this.cumulativeWeight = 0;
  25649. this.cumulativeWeightAdditive = 0;
  25650. if (weight < 1) {
  25651. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25652. var originalValueOffset = stride * this._origIndex;
  25653. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  25654. }
  25655. if (weightAdditive > 0) {
  25656. // accuN := accuN + additive accuN
  25657. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  25658. }
  25659. for (var i = stride, e = stride + stride; i !== e; ++i) {
  25660. if (buffer[i] !== buffer[i + stride]) {
  25661. // value has changed -> update scene graph
  25662. binding.setValue(buffer, offset);
  25663. break;
  25664. }
  25665. }
  25666. },
  25667. // remember the state of the bound property and copy it to both accus
  25668. saveOriginalState: function saveOriginalState() {
  25669. var binding = this.binding;
  25670. var buffer = this.buffer,
  25671. stride = this.valueSize,
  25672. originalValueOffset = stride * this._origIndex;
  25673. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  25674. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  25675. buffer[i] = buffer[originalValueOffset + i % stride];
  25676. } // Add to identity for additive
  25677. this._setIdentity();
  25678. this.cumulativeWeight = 0;
  25679. this.cumulativeWeightAdditive = 0;
  25680. },
  25681. // apply the state previously taken via 'saveOriginalState' to the binding
  25682. restoreOriginalState: function restoreOriginalState() {
  25683. var originalValueOffset = this.valueSize * 3;
  25684. this.binding.setValue(this.buffer, originalValueOffset);
  25685. },
  25686. _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
  25687. var startIndex = this._addIndex * this.valueSize;
  25688. var endIndex = startIndex + this.valueSize;
  25689. for (var i = startIndex; i < endIndex; i++) {
  25690. this.buffer[i] = 0;
  25691. }
  25692. },
  25693. _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
  25694. this._setAdditiveIdentityNumeric();
  25695. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  25696. },
  25697. _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
  25698. var startIndex = this._origIndex * this.valueSize;
  25699. var targetIndex = this._addIndex * this.valueSize;
  25700. for (var i = 0; i < this.valueSize; i++) {
  25701. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  25702. }
  25703. },
  25704. // mix functions
  25705. _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
  25706. if (t >= 0.5) {
  25707. for (var i = 0; i !== stride; ++i) {
  25708. buffer[dstOffset + i] = buffer[srcOffset + i];
  25709. }
  25710. }
  25711. },
  25712. _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
  25713. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  25714. },
  25715. _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25716. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  25717. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  25718. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  25719. },
  25720. _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  25721. var s = 1 - t;
  25722. for (var i = 0; i !== stride; ++i) {
  25723. var j = dstOffset + i;
  25724. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  25725. }
  25726. },
  25727. _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25728. for (var i = 0; i !== stride; ++i) {
  25729. var j = dstOffset + i;
  25730. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  25731. }
  25732. }
  25733. });
  25734. // Characters [].:/ are reserved for track binding syntax.
  25735. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  25736. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  25737. // only latin characters, and the unicode \p{L} is not yet supported. So
  25738. // instead, we exclude reserved characters and match everything else.
  25739. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  25740. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  25741. // be matched to parse the rest of the track name.
  25742. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  25743. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  25744. // characters. Accessor may contain any character except closing bracket.
  25745. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  25746. // contain any non-bracket characters.
  25747. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  25748. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  25749. var _supportedObjectNames = ['material', 'materials', 'bones'];
  25750. function Composite(targetGroup, path, optionalParsedPath) {
  25751. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  25752. this._targetGroup = targetGroup;
  25753. this._bindings = targetGroup.subscribe_(path, parsedPath);
  25754. }
  25755. Object.assign(Composite.prototype, {
  25756. getValue: function getValue(array, offset) {
  25757. this.bind(); // bind all binding
  25758. var firstValidIndex = this._targetGroup.nCachedObjects_,
  25759. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  25760. if (binding !== undefined) binding.getValue(array, offset);
  25761. },
  25762. setValue: function setValue(array, offset) {
  25763. var bindings = this._bindings;
  25764. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25765. bindings[i].setValue(array, offset);
  25766. }
  25767. },
  25768. bind: function bind() {
  25769. var bindings = this._bindings;
  25770. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25771. bindings[i].bind();
  25772. }
  25773. },
  25774. unbind: function unbind() {
  25775. var bindings = this._bindings;
  25776. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25777. bindings[i].unbind();
  25778. }
  25779. }
  25780. });
  25781. function PropertyBinding(rootNode, path, parsedPath) {
  25782. this.path = path;
  25783. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  25784. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  25785. this.rootNode = rootNode;
  25786. }
  25787. Object.assign(PropertyBinding, {
  25788. Composite: Composite,
  25789. create: function create(root, path, parsedPath) {
  25790. if (!(root && root.isAnimationObjectGroup)) {
  25791. return new PropertyBinding(root, path, parsedPath);
  25792. } else {
  25793. return new PropertyBinding.Composite(root, path, parsedPath);
  25794. }
  25795. },
  25796. /**
  25797. * Replaces spaces with underscores and removes unsupported characters from
  25798. * node names, to ensure compatibility with parseTrackName().
  25799. *
  25800. * @param {string} name Node name to be sanitized.
  25801. * @return {string}
  25802. */
  25803. sanitizeNodeName: function sanitizeNodeName(name) {
  25804. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  25805. },
  25806. parseTrackName: function parseTrackName(trackName) {
  25807. var matches = _trackRe.exec(trackName);
  25808. if (!matches) {
  25809. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  25810. }
  25811. var results = {
  25812. // directoryName: matches[ 1 ], // (tschw) currently unused
  25813. nodeName: matches[2],
  25814. objectName: matches[3],
  25815. objectIndex: matches[4],
  25816. propertyName: matches[5],
  25817. // required
  25818. propertyIndex: matches[6]
  25819. };
  25820. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  25821. if (lastDot !== undefined && lastDot !== -1) {
  25822. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  25823. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  25824. // 'bar' could be the objectName, or part of a nodeName (which can
  25825. // include '.' characters).
  25826. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  25827. results.nodeName = results.nodeName.substring(0, lastDot);
  25828. results.objectName = objectName;
  25829. }
  25830. }
  25831. if (results.propertyName === null || results.propertyName.length === 0) {
  25832. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  25833. }
  25834. return results;
  25835. },
  25836. findNode: function findNode(root, nodeName) {
  25837. if (!nodeName || nodeName === '' || nodeName === '.' || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  25838. return root;
  25839. } // search into skeleton bones.
  25840. if (root.skeleton) {
  25841. var bone = root.skeleton.getBoneByName(nodeName);
  25842. if (bone !== undefined) {
  25843. return bone;
  25844. }
  25845. } // search into node subtree.
  25846. if (root.children) {
  25847. var searchNodeSubtree = function searchNodeSubtree(children) {
  25848. for (var i = 0; i < children.length; i++) {
  25849. var childNode = children[i];
  25850. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  25851. return childNode;
  25852. }
  25853. var result = searchNodeSubtree(childNode.children);
  25854. if (result) return result;
  25855. }
  25856. return null;
  25857. };
  25858. var subTreeNode = searchNodeSubtree(root.children);
  25859. if (subTreeNode) {
  25860. return subTreeNode;
  25861. }
  25862. }
  25863. return null;
  25864. }
  25865. });
  25866. Object.assign(PropertyBinding.prototype, {
  25867. // prototype, continued
  25868. // these are used to "bind" a nonexistent property
  25869. _getValue_unavailable: function _getValue_unavailable() {},
  25870. _setValue_unavailable: function _setValue_unavailable() {},
  25871. BindingType: {
  25872. Direct: 0,
  25873. EntireArray: 1,
  25874. ArrayElement: 2,
  25875. HasFromToArray: 3
  25876. },
  25877. Versioning: {
  25878. None: 0,
  25879. NeedsUpdate: 1,
  25880. MatrixWorldNeedsUpdate: 2
  25881. },
  25882. GetterByBindingType: [function getValue_direct(buffer, offset) {
  25883. buffer[offset] = this.node[this.propertyName];
  25884. }, function getValue_array(buffer, offset) {
  25885. var source = this.resolvedProperty;
  25886. for (var i = 0, n = source.length; i !== n; ++i) {
  25887. buffer[offset++] = source[i];
  25888. }
  25889. }, function getValue_arrayElement(buffer, offset) {
  25890. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  25891. }, function getValue_toArray(buffer, offset) {
  25892. this.resolvedProperty.toArray(buffer, offset);
  25893. }],
  25894. SetterByBindingTypeAndVersioning: [[// Direct
  25895. function setValue_direct(buffer, offset) {
  25896. this.targetObject[this.propertyName] = buffer[offset];
  25897. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  25898. this.targetObject[this.propertyName] = buffer[offset];
  25899. this.targetObject.needsUpdate = true;
  25900. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  25901. this.targetObject[this.propertyName] = buffer[offset];
  25902. this.targetObject.matrixWorldNeedsUpdate = true;
  25903. }], [// EntireArray
  25904. function setValue_array(buffer, offset) {
  25905. var dest = this.resolvedProperty;
  25906. for (var i = 0, n = dest.length; i !== n; ++i) {
  25907. dest[i] = buffer[offset++];
  25908. }
  25909. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  25910. var dest = this.resolvedProperty;
  25911. for (var i = 0, n = dest.length; i !== n; ++i) {
  25912. dest[i] = buffer[offset++];
  25913. }
  25914. this.targetObject.needsUpdate = true;
  25915. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  25916. var dest = this.resolvedProperty;
  25917. for (var i = 0, n = dest.length; i !== n; ++i) {
  25918. dest[i] = buffer[offset++];
  25919. }
  25920. this.targetObject.matrixWorldNeedsUpdate = true;
  25921. }], [// ArrayElement
  25922. function setValue_arrayElement(buffer, offset) {
  25923. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25924. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  25925. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25926. this.targetObject.needsUpdate = true;
  25927. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  25928. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25929. this.targetObject.matrixWorldNeedsUpdate = true;
  25930. }], [// HasToFromArray
  25931. function setValue_fromArray(buffer, offset) {
  25932. this.resolvedProperty.fromArray(buffer, offset);
  25933. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  25934. this.resolvedProperty.fromArray(buffer, offset);
  25935. this.targetObject.needsUpdate = true;
  25936. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  25937. this.resolvedProperty.fromArray(buffer, offset);
  25938. this.targetObject.matrixWorldNeedsUpdate = true;
  25939. }]],
  25940. getValue: function getValue_unbound(targetArray, offset) {
  25941. this.bind();
  25942. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  25943. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  25944. // prototype version of these methods with one that represents
  25945. // the bound state. When the property is not found, the methods
  25946. // become no-ops.
  25947. },
  25948. setValue: function getValue_unbound(sourceArray, offset) {
  25949. this.bind();
  25950. this.setValue(sourceArray, offset);
  25951. },
  25952. // create getter / setter pair for a property in the scene graph
  25953. bind: function bind() {
  25954. var targetObject = this.node;
  25955. var parsedPath = this.parsedPath;
  25956. var objectName = parsedPath.objectName;
  25957. var propertyName = parsedPath.propertyName;
  25958. var propertyIndex = parsedPath.propertyIndex;
  25959. if (!targetObject) {
  25960. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  25961. this.node = targetObject;
  25962. } // set fail state so we can just 'return' on error
  25963. this.getValue = this._getValue_unavailable;
  25964. this.setValue = this._setValue_unavailable; // ensure there is a value node
  25965. if (!targetObject) {
  25966. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  25967. return;
  25968. }
  25969. if (objectName) {
  25970. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  25971. switch (objectName) {
  25972. case 'materials':
  25973. if (!targetObject.material) {
  25974. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  25975. return;
  25976. }
  25977. if (!targetObject.material.materials) {
  25978. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  25979. return;
  25980. }
  25981. targetObject = targetObject.material.materials;
  25982. break;
  25983. case 'bones':
  25984. if (!targetObject.skeleton) {
  25985. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  25986. return;
  25987. } // potential future optimization: skip this if propertyIndex is already an integer
  25988. // and convert the integer string to a true integer.
  25989. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  25990. for (var i = 0; i < targetObject.length; i++) {
  25991. if (targetObject[i].name === objectIndex) {
  25992. objectIndex = i;
  25993. break;
  25994. }
  25995. }
  25996. break;
  25997. default:
  25998. if (targetObject[objectName] === undefined) {
  25999. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  26000. return;
  26001. }
  26002. targetObject = targetObject[objectName];
  26003. }
  26004. if (objectIndex !== undefined) {
  26005. if (targetObject[objectIndex] === undefined) {
  26006. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  26007. return;
  26008. }
  26009. targetObject = targetObject[objectIndex];
  26010. }
  26011. } // resolve property
  26012. var nodeProperty = targetObject[propertyName];
  26013. if (nodeProperty === undefined) {
  26014. var nodeName = parsedPath.nodeName;
  26015. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  26016. return;
  26017. } // determine versioning scheme
  26018. var versioning = this.Versioning.None;
  26019. this.targetObject = targetObject;
  26020. if (targetObject.needsUpdate !== undefined) {
  26021. // material
  26022. versioning = this.Versioning.NeedsUpdate;
  26023. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  26024. // node transform
  26025. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26026. } // determine how the property gets bound
  26027. var bindingType = this.BindingType.Direct;
  26028. if (propertyIndex !== undefined) {
  26029. // access a sub element of the property array (only primitives are supported right now)
  26030. if (propertyName === 'morphTargetInfluences') {
  26031. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26032. // support resolving morphTarget names into indices.
  26033. if (!targetObject.geometry) {
  26034. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  26035. return;
  26036. }
  26037. if (targetObject.geometry.isBufferGeometry) {
  26038. if (!targetObject.geometry.morphAttributes) {
  26039. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  26040. return;
  26041. }
  26042. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  26043. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  26044. }
  26045. } else {
  26046. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  26047. return;
  26048. }
  26049. }
  26050. bindingType = this.BindingType.ArrayElement;
  26051. this.resolvedProperty = nodeProperty;
  26052. this.propertyIndex = propertyIndex;
  26053. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  26054. // must use copy for Object3D.Euler/Quaternion
  26055. bindingType = this.BindingType.HasFromToArray;
  26056. this.resolvedProperty = nodeProperty;
  26057. } else if (Array.isArray(nodeProperty)) {
  26058. bindingType = this.BindingType.EntireArray;
  26059. this.resolvedProperty = nodeProperty;
  26060. } else {
  26061. this.propertyName = propertyName;
  26062. } // select getter / setter
  26063. this.getValue = this.GetterByBindingType[bindingType];
  26064. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  26065. },
  26066. unbind: function unbind() {
  26067. this.node = null; // back to the prototype version of getValue / setValue
  26068. // note: avoiding to mutate the shape of 'this' via 'delete'
  26069. this.getValue = this._getValue_unbound;
  26070. this.setValue = this._setValue_unbound;
  26071. }
  26072. }); // DECLARE ALIAS AFTER assign prototype
  26073. Object.assign(PropertyBinding.prototype, {
  26074. // initial state of these methods that calls 'bind'
  26075. _getValue_unbound: PropertyBinding.prototype.getValue,
  26076. _setValue_unbound: PropertyBinding.prototype.setValue
  26077. });
  26078. /**
  26079. *
  26080. * A group of objects that receives a shared animation state.
  26081. *
  26082. * Usage:
  26083. *
  26084. * - Add objects you would otherwise pass as 'root' to the
  26085. * constructor or the .clipAction method of AnimationMixer.
  26086. *
  26087. * - Instead pass this object as 'root'.
  26088. *
  26089. * - You can also add and remove objects later when the mixer
  26090. * is running.
  26091. *
  26092. * Note:
  26093. *
  26094. * Objects of this class appear as one object to the mixer,
  26095. * so cache control of the individual objects must be done
  26096. * on the group.
  26097. *
  26098. * Limitation:
  26099. *
  26100. * - The animated properties must be compatible among the
  26101. * all objects in the group.
  26102. *
  26103. * - A single property can either be controlled through a
  26104. * target group or directly, but not both.
  26105. */
  26106. function AnimationObjectGroup() {
  26107. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  26108. this._objects = Array.prototype.slice.call(arguments);
  26109. this.nCachedObjects_ = 0; // threshold
  26110. // note: read by PropertyBinding.Composite
  26111. var indices = {};
  26112. this._indicesByUUID = indices; // for bookkeeping
  26113. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26114. indices[arguments[i].uuid] = i;
  26115. }
  26116. this._paths = []; // inside: string
  26117. this._parsedPaths = []; // inside: { we don't care, here }
  26118. this._bindings = []; // inside: Array< PropertyBinding >
  26119. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26120. var scope = this;
  26121. this.stats = {
  26122. objects: {
  26123. get total() {
  26124. return scope._objects.length;
  26125. },
  26126. get inUse() {
  26127. return this.total - scope.nCachedObjects_;
  26128. }
  26129. },
  26130. get bindingsPerObject() {
  26131. return scope._bindings.length;
  26132. }
  26133. };
  26134. }
  26135. Object.assign(AnimationObjectGroup.prototype, {
  26136. isAnimationObjectGroup: true,
  26137. add: function add() {
  26138. var objects = this._objects,
  26139. indicesByUUID = this._indicesByUUID,
  26140. paths = this._paths,
  26141. parsedPaths = this._parsedPaths,
  26142. bindings = this._bindings,
  26143. nBindings = bindings.length;
  26144. var knownObject = undefined,
  26145. nObjects = objects.length,
  26146. nCachedObjects = this.nCachedObjects_;
  26147. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26148. var object = arguments[i],
  26149. uuid = object.uuid;
  26150. var index = indicesByUUID[uuid];
  26151. if (index === undefined) {
  26152. // unknown object -> add it to the ACTIVE region
  26153. index = nObjects++;
  26154. indicesByUUID[uuid] = index;
  26155. objects.push(object); // accounting is done, now do the same for all bindings
  26156. for (var j = 0, m = nBindings; j !== m; ++j) {
  26157. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  26158. }
  26159. } else if (index < nCachedObjects) {
  26160. knownObject = objects[index]; // move existing object to the ACTIVE region
  26161. var firstActiveIndex = --nCachedObjects,
  26162. lastCachedObject = objects[firstActiveIndex];
  26163. indicesByUUID[lastCachedObject.uuid] = index;
  26164. objects[index] = lastCachedObject;
  26165. indicesByUUID[uuid] = firstActiveIndex;
  26166. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  26167. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  26168. var bindingsForPath = bindings[_j],
  26169. lastCached = bindingsForPath[firstActiveIndex];
  26170. var binding = bindingsForPath[index];
  26171. bindingsForPath[index] = lastCached;
  26172. if (binding === undefined) {
  26173. // since we do not bother to create new bindings
  26174. // for objects that are cached, the binding may
  26175. // or may not exist
  26176. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  26177. }
  26178. bindingsForPath[firstActiveIndex] = binding;
  26179. }
  26180. } else if (objects[index] !== knownObject) {
  26181. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  26182. } // else the object is already where we want it to be
  26183. } // for arguments
  26184. this.nCachedObjects_ = nCachedObjects;
  26185. },
  26186. remove: function remove() {
  26187. var objects = this._objects,
  26188. indicesByUUID = this._indicesByUUID,
  26189. bindings = this._bindings,
  26190. nBindings = bindings.length;
  26191. var nCachedObjects = this.nCachedObjects_;
  26192. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26193. var object = arguments[i],
  26194. uuid = object.uuid,
  26195. index = indicesByUUID[uuid];
  26196. if (index !== undefined && index >= nCachedObjects) {
  26197. // move existing object into the CACHED region
  26198. var lastCachedIndex = nCachedObjects++,
  26199. firstActiveObject = objects[lastCachedIndex];
  26200. indicesByUUID[firstActiveObject.uuid] = index;
  26201. objects[index] = firstActiveObject;
  26202. indicesByUUID[uuid] = lastCachedIndex;
  26203. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  26204. for (var j = 0, m = nBindings; j !== m; ++j) {
  26205. var bindingsForPath = bindings[j],
  26206. firstActive = bindingsForPath[lastCachedIndex],
  26207. binding = bindingsForPath[index];
  26208. bindingsForPath[index] = firstActive;
  26209. bindingsForPath[lastCachedIndex] = binding;
  26210. }
  26211. }
  26212. } // for arguments
  26213. this.nCachedObjects_ = nCachedObjects;
  26214. },
  26215. // remove & forget
  26216. uncache: function uncache() {
  26217. var objects = this._objects,
  26218. indicesByUUID = this._indicesByUUID,
  26219. bindings = this._bindings,
  26220. nBindings = bindings.length;
  26221. var nCachedObjects = this.nCachedObjects_,
  26222. nObjects = objects.length;
  26223. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26224. var object = arguments[i],
  26225. uuid = object.uuid,
  26226. index = indicesByUUID[uuid];
  26227. if (index !== undefined) {
  26228. delete indicesByUUID[uuid];
  26229. if (index < nCachedObjects) {
  26230. // object is cached, shrink the CACHED region
  26231. var firstActiveIndex = --nCachedObjects,
  26232. lastCachedObject = objects[firstActiveIndex],
  26233. lastIndex = --nObjects,
  26234. lastObject = objects[lastIndex]; // last cached object takes this object's place
  26235. indicesByUUID[lastCachedObject.uuid] = index;
  26236. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  26237. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  26238. objects[firstActiveIndex] = lastObject;
  26239. objects.pop(); // accounting is done, now do the same for all bindings
  26240. for (var j = 0, m = nBindings; j !== m; ++j) {
  26241. var bindingsForPath = bindings[j],
  26242. lastCached = bindingsForPath[firstActiveIndex],
  26243. last = bindingsForPath[lastIndex];
  26244. bindingsForPath[index] = lastCached;
  26245. bindingsForPath[firstActiveIndex] = last;
  26246. bindingsForPath.pop();
  26247. }
  26248. } else {
  26249. // object is active, just swap with the last and pop
  26250. var _lastIndex = --nObjects,
  26251. _lastObject = objects[_lastIndex];
  26252. if (_lastIndex > 0) {
  26253. indicesByUUID[_lastObject.uuid] = index;
  26254. }
  26255. objects[index] = _lastObject;
  26256. objects.pop(); // accounting is done, now do the same for all bindings
  26257. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  26258. var _bindingsForPath = bindings[_j2];
  26259. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  26260. _bindingsForPath.pop();
  26261. }
  26262. } // cached or active
  26263. } // if object is known
  26264. } // for arguments
  26265. this.nCachedObjects_ = nCachedObjects;
  26266. },
  26267. // Internal interface used by befriended PropertyBinding.Composite:
  26268. subscribe_: function subscribe_(path, parsedPath) {
  26269. // returns an array of bindings for the given path that is changed
  26270. // according to the contained objects in the group
  26271. var indicesByPath = this._bindingsIndicesByPath;
  26272. var index = indicesByPath[path];
  26273. var bindings = this._bindings;
  26274. if (index !== undefined) return bindings[index];
  26275. var paths = this._paths,
  26276. parsedPaths = this._parsedPaths,
  26277. objects = this._objects,
  26278. nObjects = objects.length,
  26279. nCachedObjects = this.nCachedObjects_,
  26280. bindingsForPath = new Array(nObjects);
  26281. index = bindings.length;
  26282. indicesByPath[path] = index;
  26283. paths.push(path);
  26284. parsedPaths.push(parsedPath);
  26285. bindings.push(bindingsForPath);
  26286. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  26287. var object = objects[i];
  26288. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  26289. }
  26290. return bindingsForPath;
  26291. },
  26292. unsubscribe_: function unsubscribe_(path) {
  26293. // tells the group to forget about a property path and no longer
  26294. // update the array previously obtained with 'subscribe_'
  26295. var indicesByPath = this._bindingsIndicesByPath,
  26296. index = indicesByPath[path];
  26297. if (index !== undefined) {
  26298. var paths = this._paths,
  26299. parsedPaths = this._parsedPaths,
  26300. bindings = this._bindings,
  26301. lastBindingsIndex = bindings.length - 1,
  26302. lastBindings = bindings[lastBindingsIndex],
  26303. lastBindingsPath = path[lastBindingsIndex];
  26304. indicesByPath[lastBindingsPath] = index;
  26305. bindings[index] = lastBindings;
  26306. bindings.pop();
  26307. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  26308. parsedPaths.pop();
  26309. paths[index] = paths[lastBindingsIndex];
  26310. paths.pop();
  26311. }
  26312. }
  26313. });
  26314. var AnimationAction = /*#__PURE__*/function () {
  26315. function AnimationAction(mixer, clip, localRoot, blendMode) {
  26316. if (localRoot === void 0) {
  26317. localRoot = null;
  26318. }
  26319. if (blendMode === void 0) {
  26320. blendMode = clip.blendMode;
  26321. }
  26322. this._mixer = mixer;
  26323. this._clip = clip;
  26324. this._localRoot = localRoot;
  26325. this.blendMode = blendMode;
  26326. var tracks = clip.tracks,
  26327. nTracks = tracks.length,
  26328. interpolants = new Array(nTracks);
  26329. var interpolantSettings = {
  26330. endingStart: ZeroCurvatureEnding,
  26331. endingEnd: ZeroCurvatureEnding
  26332. };
  26333. for (var i = 0; i !== nTracks; ++i) {
  26334. var interpolant = tracks[i].createInterpolant(null);
  26335. interpolants[i] = interpolant;
  26336. interpolant.settings = interpolantSettings;
  26337. }
  26338. this._interpolantSettings = interpolantSettings;
  26339. this._interpolants = interpolants; // bound by the mixer
  26340. // inside: PropertyMixer (managed by the mixer)
  26341. this._propertyBindings = new Array(nTracks);
  26342. this._cacheIndex = null; // for the memory manager
  26343. this._byClipCacheIndex = null; // for the memory manager
  26344. this._timeScaleInterpolant = null;
  26345. this._weightInterpolant = null;
  26346. this.loop = LoopRepeat;
  26347. this._loopCount = -1; // global mixer time when the action is to be started
  26348. // it's set back to 'null' upon start of the action
  26349. this._startTime = null; // scaled local time of the action
  26350. // gets clamped or wrapped to 0..clip.duration according to loop
  26351. this.time = 0;
  26352. this.timeScale = 1;
  26353. this._effectiveTimeScale = 1;
  26354. this.weight = 1;
  26355. this._effectiveWeight = 1;
  26356. this.repetitions = Infinity; // no. of repetitions when looping
  26357. this.paused = false; // true -> zero effective time scale
  26358. this.enabled = true; // false -> zero effective weight
  26359. this.clampWhenFinished = false; // keep feeding the last frame?
  26360. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  26361. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  26362. } // State & Scheduling
  26363. var _proto = AnimationAction.prototype;
  26364. _proto.play = function play() {
  26365. this._mixer._activateAction(this);
  26366. return this;
  26367. };
  26368. _proto.stop = function stop() {
  26369. this._mixer._deactivateAction(this);
  26370. return this.reset();
  26371. };
  26372. _proto.reset = function reset() {
  26373. this.paused = false;
  26374. this.enabled = true;
  26375. this.time = 0; // restart clip
  26376. this._loopCount = -1; // forget previous loops
  26377. this._startTime = null; // forget scheduling
  26378. return this.stopFading().stopWarping();
  26379. };
  26380. _proto.isRunning = function isRunning() {
  26381. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  26382. } // return true when play has been called
  26383. ;
  26384. _proto.isScheduled = function isScheduled() {
  26385. return this._mixer._isActiveAction(this);
  26386. };
  26387. _proto.startAt = function startAt(time) {
  26388. this._startTime = time;
  26389. return this;
  26390. };
  26391. _proto.setLoop = function setLoop(mode, repetitions) {
  26392. this.loop = mode;
  26393. this.repetitions = repetitions;
  26394. return this;
  26395. } // Weight
  26396. // set the weight stopping any scheduled fading
  26397. // although .enabled = false yields an effective weight of zero, this
  26398. // method does *not* change .enabled, because it would be confusing
  26399. ;
  26400. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  26401. this.weight = weight; // note: same logic as when updated at runtime
  26402. this._effectiveWeight = this.enabled ? weight : 0;
  26403. return this.stopFading();
  26404. } // return the weight considering fading and .enabled
  26405. ;
  26406. _proto.getEffectiveWeight = function getEffectiveWeight() {
  26407. return this._effectiveWeight;
  26408. };
  26409. _proto.fadeIn = function fadeIn(duration) {
  26410. return this._scheduleFading(duration, 0, 1);
  26411. };
  26412. _proto.fadeOut = function fadeOut(duration) {
  26413. return this._scheduleFading(duration, 1, 0);
  26414. };
  26415. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  26416. fadeOutAction.fadeOut(duration);
  26417. this.fadeIn(duration);
  26418. if (warp) {
  26419. var fadeInDuration = this._clip.duration,
  26420. fadeOutDuration = fadeOutAction._clip.duration,
  26421. startEndRatio = fadeOutDuration / fadeInDuration,
  26422. endStartRatio = fadeInDuration / fadeOutDuration;
  26423. fadeOutAction.warp(1.0, startEndRatio, duration);
  26424. this.warp(endStartRatio, 1.0, duration);
  26425. }
  26426. return this;
  26427. };
  26428. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  26429. return fadeInAction.crossFadeFrom(this, duration, warp);
  26430. };
  26431. _proto.stopFading = function stopFading() {
  26432. var weightInterpolant = this._weightInterpolant;
  26433. if (weightInterpolant !== null) {
  26434. this._weightInterpolant = null;
  26435. this._mixer._takeBackControlInterpolant(weightInterpolant);
  26436. }
  26437. return this;
  26438. } // Time Scale Control
  26439. // set the time scale stopping any scheduled warping
  26440. // although .paused = true yields an effective time scale of zero, this
  26441. // method does *not* change .paused, because it would be confusing
  26442. ;
  26443. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  26444. this.timeScale = timeScale;
  26445. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26446. return this.stopWarping();
  26447. } // return the time scale considering warping and .paused
  26448. ;
  26449. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  26450. return this._effectiveTimeScale;
  26451. };
  26452. _proto.setDuration = function setDuration(duration) {
  26453. this.timeScale = this._clip.duration / duration;
  26454. return this.stopWarping();
  26455. };
  26456. _proto.syncWith = function syncWith(action) {
  26457. this.time = action.time;
  26458. this.timeScale = action.timeScale;
  26459. return this.stopWarping();
  26460. };
  26461. _proto.halt = function halt(duration) {
  26462. return this.warp(this._effectiveTimeScale, 0, duration);
  26463. };
  26464. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  26465. var mixer = this._mixer,
  26466. now = mixer.time,
  26467. timeScale = this.timeScale;
  26468. var interpolant = this._timeScaleInterpolant;
  26469. if (interpolant === null) {
  26470. interpolant = mixer._lendControlInterpolant();
  26471. this._timeScaleInterpolant = interpolant;
  26472. }
  26473. var times = interpolant.parameterPositions,
  26474. values = interpolant.sampleValues;
  26475. times[0] = now;
  26476. times[1] = now + duration;
  26477. values[0] = startTimeScale / timeScale;
  26478. values[1] = endTimeScale / timeScale;
  26479. return this;
  26480. };
  26481. _proto.stopWarping = function stopWarping() {
  26482. var timeScaleInterpolant = this._timeScaleInterpolant;
  26483. if (timeScaleInterpolant !== null) {
  26484. this._timeScaleInterpolant = null;
  26485. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  26486. }
  26487. return this;
  26488. } // Object Accessors
  26489. ;
  26490. _proto.getMixer = function getMixer() {
  26491. return this._mixer;
  26492. };
  26493. _proto.getClip = function getClip() {
  26494. return this._clip;
  26495. };
  26496. _proto.getRoot = function getRoot() {
  26497. return this._localRoot || this._mixer._root;
  26498. } // Interna
  26499. ;
  26500. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  26501. // called by the mixer
  26502. if (!this.enabled) {
  26503. // call ._updateWeight() to update ._effectiveWeight
  26504. this._updateWeight(time);
  26505. return;
  26506. }
  26507. var startTime = this._startTime;
  26508. if (startTime !== null) {
  26509. // check for scheduled start of action
  26510. var timeRunning = (time - startTime) * timeDirection;
  26511. if (timeRunning < 0 || timeDirection === 0) {
  26512. return; // yet to come / don't decide when delta = 0
  26513. } // start
  26514. this._startTime = null; // unschedule
  26515. deltaTime = timeDirection * timeRunning;
  26516. } // apply time scale and advance time
  26517. deltaTime *= this._updateTimeScale(time);
  26518. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  26519. // an effective weight of 0
  26520. var weight = this._updateWeight(time);
  26521. if (weight > 0) {
  26522. var _interpolants = this._interpolants;
  26523. var propertyMixers = this._propertyBindings;
  26524. switch (this.blendMode) {
  26525. case AdditiveAnimationBlendMode:
  26526. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  26527. _interpolants[j].evaluate(clipTime);
  26528. propertyMixers[j].accumulateAdditive(weight);
  26529. }
  26530. break;
  26531. case NormalAnimationBlendMode:
  26532. default:
  26533. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  26534. _interpolants[_j].evaluate(clipTime);
  26535. propertyMixers[_j].accumulate(accuIndex, weight);
  26536. }
  26537. }
  26538. }
  26539. };
  26540. _proto._updateWeight = function _updateWeight(time) {
  26541. var weight = 0;
  26542. if (this.enabled) {
  26543. weight = this.weight;
  26544. var interpolant = this._weightInterpolant;
  26545. if (interpolant !== null) {
  26546. var interpolantValue = interpolant.evaluate(time)[0];
  26547. weight *= interpolantValue;
  26548. if (time > interpolant.parameterPositions[1]) {
  26549. this.stopFading();
  26550. if (interpolantValue === 0) {
  26551. // faded out, disable
  26552. this.enabled = false;
  26553. }
  26554. }
  26555. }
  26556. }
  26557. this._effectiveWeight = weight;
  26558. return weight;
  26559. };
  26560. _proto._updateTimeScale = function _updateTimeScale(time) {
  26561. var timeScale = 0;
  26562. if (!this.paused) {
  26563. timeScale = this.timeScale;
  26564. var interpolant = this._timeScaleInterpolant;
  26565. if (interpolant !== null) {
  26566. var interpolantValue = interpolant.evaluate(time)[0];
  26567. timeScale *= interpolantValue;
  26568. if (time > interpolant.parameterPositions[1]) {
  26569. this.stopWarping();
  26570. if (timeScale === 0) {
  26571. // motion has halted, pause
  26572. this.paused = true;
  26573. } else {
  26574. // warp done - apply final time scale
  26575. this.timeScale = timeScale;
  26576. }
  26577. }
  26578. }
  26579. }
  26580. this._effectiveTimeScale = timeScale;
  26581. return timeScale;
  26582. };
  26583. _proto._updateTime = function _updateTime(deltaTime) {
  26584. var duration = this._clip.duration;
  26585. var loop = this.loop;
  26586. var time = this.time + deltaTime;
  26587. var loopCount = this._loopCount;
  26588. var pingPong = loop === LoopPingPong;
  26589. if (deltaTime === 0) {
  26590. if (loopCount === -1) return time;
  26591. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  26592. }
  26593. if (loop === LoopOnce) {
  26594. if (loopCount === -1) {
  26595. // just started
  26596. this._loopCount = 0;
  26597. this._setEndings(true, true, false);
  26598. }
  26599. handle_stop: {
  26600. if (time >= duration) {
  26601. time = duration;
  26602. } else if (time < 0) {
  26603. time = 0;
  26604. } else {
  26605. this.time = time;
  26606. break handle_stop;
  26607. }
  26608. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26609. this.time = time;
  26610. this._mixer.dispatchEvent({
  26611. type: 'finished',
  26612. action: this,
  26613. direction: deltaTime < 0 ? -1 : 1
  26614. });
  26615. }
  26616. } else {
  26617. // repetitive Repeat or PingPong
  26618. if (loopCount === -1) {
  26619. // just started
  26620. if (deltaTime >= 0) {
  26621. loopCount = 0;
  26622. this._setEndings(true, this.repetitions === 0, pingPong);
  26623. } else {
  26624. // when looping in reverse direction, the initial
  26625. // transition through zero counts as a repetition,
  26626. // so leave loopCount at -1
  26627. this._setEndings(this.repetitions === 0, true, pingPong);
  26628. }
  26629. }
  26630. if (time >= duration || time < 0) {
  26631. // wrap around
  26632. var loopDelta = Math.floor(time / duration); // signed
  26633. time -= duration * loopDelta;
  26634. loopCount += Math.abs(loopDelta);
  26635. var pending = this.repetitions - loopCount;
  26636. if (pending <= 0) {
  26637. // have to stop (switch state, clamp time, fire event)
  26638. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26639. time = deltaTime > 0 ? duration : 0;
  26640. this.time = time;
  26641. this._mixer.dispatchEvent({
  26642. type: 'finished',
  26643. action: this,
  26644. direction: deltaTime > 0 ? 1 : -1
  26645. });
  26646. } else {
  26647. // keep running
  26648. if (pending === 1) {
  26649. // entering the last round
  26650. var atStart = deltaTime < 0;
  26651. this._setEndings(atStart, !atStart, pingPong);
  26652. } else {
  26653. this._setEndings(false, false, pingPong);
  26654. }
  26655. this._loopCount = loopCount;
  26656. this.time = time;
  26657. this._mixer.dispatchEvent({
  26658. type: 'loop',
  26659. action: this,
  26660. loopDelta: loopDelta
  26661. });
  26662. }
  26663. } else {
  26664. this.time = time;
  26665. }
  26666. if (pingPong && (loopCount & 1) === 1) {
  26667. // invert time for the "pong round"
  26668. return duration - time;
  26669. }
  26670. }
  26671. return time;
  26672. };
  26673. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  26674. var settings = this._interpolantSettings;
  26675. if (pingPong) {
  26676. settings.endingStart = ZeroSlopeEnding;
  26677. settings.endingEnd = ZeroSlopeEnding;
  26678. } else {
  26679. // assuming for LoopOnce atStart == atEnd == true
  26680. if (atStart) {
  26681. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26682. } else {
  26683. settings.endingStart = WrapAroundEnding;
  26684. }
  26685. if (atEnd) {
  26686. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26687. } else {
  26688. settings.endingEnd = WrapAroundEnding;
  26689. }
  26690. }
  26691. };
  26692. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  26693. var mixer = this._mixer,
  26694. now = mixer.time;
  26695. var interpolant = this._weightInterpolant;
  26696. if (interpolant === null) {
  26697. interpolant = mixer._lendControlInterpolant();
  26698. this._weightInterpolant = interpolant;
  26699. }
  26700. var times = interpolant.parameterPositions,
  26701. values = interpolant.sampleValues;
  26702. times[0] = now;
  26703. values[0] = weightNow;
  26704. times[1] = now + duration;
  26705. values[1] = weightThen;
  26706. return this;
  26707. };
  26708. return AnimationAction;
  26709. }();
  26710. function AnimationMixer(root) {
  26711. this._root = root;
  26712. this._initMemoryManager();
  26713. this._accuIndex = 0;
  26714. this.time = 0;
  26715. this.timeScale = 1.0;
  26716. }
  26717. AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  26718. constructor: AnimationMixer,
  26719. _bindAction: function _bindAction(action, prototypeAction) {
  26720. var root = action._localRoot || this._root,
  26721. tracks = action._clip.tracks,
  26722. nTracks = tracks.length,
  26723. bindings = action._propertyBindings,
  26724. interpolants = action._interpolants,
  26725. rootUuid = root.uuid,
  26726. bindingsByRoot = this._bindingsByRootAndName;
  26727. var bindingsByName = bindingsByRoot[rootUuid];
  26728. if (bindingsByName === undefined) {
  26729. bindingsByName = {};
  26730. bindingsByRoot[rootUuid] = bindingsByName;
  26731. }
  26732. for (var i = 0; i !== nTracks; ++i) {
  26733. var track = tracks[i],
  26734. trackName = track.name;
  26735. var binding = bindingsByName[trackName];
  26736. if (binding !== undefined) {
  26737. bindings[i] = binding;
  26738. } else {
  26739. binding = bindings[i];
  26740. if (binding !== undefined) {
  26741. // existing binding, make sure the cache knows
  26742. if (binding._cacheIndex === null) {
  26743. ++binding.referenceCount;
  26744. this._addInactiveBinding(binding, rootUuid, trackName);
  26745. }
  26746. continue;
  26747. }
  26748. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  26749. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  26750. ++binding.referenceCount;
  26751. this._addInactiveBinding(binding, rootUuid, trackName);
  26752. bindings[i] = binding;
  26753. }
  26754. interpolants[i].resultBuffer = binding.buffer;
  26755. }
  26756. },
  26757. _activateAction: function _activateAction(action) {
  26758. if (!this._isActiveAction(action)) {
  26759. if (action._cacheIndex === null) {
  26760. // this action has been forgotten by the cache, but the user
  26761. // appears to be still using it -> rebind
  26762. var rootUuid = (action._localRoot || this._root).uuid,
  26763. clipUuid = action._clip.uuid,
  26764. actionsForClip = this._actionsByClip[clipUuid];
  26765. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  26766. this._addInactiveAction(action, clipUuid, rootUuid);
  26767. }
  26768. var bindings = action._propertyBindings; // increment reference counts / sort out state
  26769. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26770. var binding = bindings[i];
  26771. if (binding.useCount++ === 0) {
  26772. this._lendBinding(binding);
  26773. binding.saveOriginalState();
  26774. }
  26775. }
  26776. this._lendAction(action);
  26777. }
  26778. },
  26779. _deactivateAction: function _deactivateAction(action) {
  26780. if (this._isActiveAction(action)) {
  26781. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  26782. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26783. var binding = bindings[i];
  26784. if (--binding.useCount === 0) {
  26785. binding.restoreOriginalState();
  26786. this._takeBackBinding(binding);
  26787. }
  26788. }
  26789. this._takeBackAction(action);
  26790. }
  26791. },
  26792. // Memory manager
  26793. _initMemoryManager: function _initMemoryManager() {
  26794. this._actions = []; // 'nActiveActions' followed by inactive ones
  26795. this._nActiveActions = 0;
  26796. this._actionsByClip = {}; // inside:
  26797. // {
  26798. // knownActions: Array< AnimationAction > - used as prototypes
  26799. // actionByRoot: AnimationAction - lookup
  26800. // }
  26801. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  26802. this._nActiveBindings = 0;
  26803. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  26804. this._controlInterpolants = []; // same game as above
  26805. this._nActiveControlInterpolants = 0;
  26806. var scope = this;
  26807. this.stats = {
  26808. actions: {
  26809. get total() {
  26810. return scope._actions.length;
  26811. },
  26812. get inUse() {
  26813. return scope._nActiveActions;
  26814. }
  26815. },
  26816. bindings: {
  26817. get total() {
  26818. return scope._bindings.length;
  26819. },
  26820. get inUse() {
  26821. return scope._nActiveBindings;
  26822. }
  26823. },
  26824. controlInterpolants: {
  26825. get total() {
  26826. return scope._controlInterpolants.length;
  26827. },
  26828. get inUse() {
  26829. return scope._nActiveControlInterpolants;
  26830. }
  26831. }
  26832. };
  26833. },
  26834. // Memory management for AnimationAction objects
  26835. _isActiveAction: function _isActiveAction(action) {
  26836. var index = action._cacheIndex;
  26837. return index !== null && index < this._nActiveActions;
  26838. },
  26839. _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
  26840. var actions = this._actions,
  26841. actionsByClip = this._actionsByClip;
  26842. var actionsForClip = actionsByClip[clipUuid];
  26843. if (actionsForClip === undefined) {
  26844. actionsForClip = {
  26845. knownActions: [action],
  26846. actionByRoot: {}
  26847. };
  26848. action._byClipCacheIndex = 0;
  26849. actionsByClip[clipUuid] = actionsForClip;
  26850. } else {
  26851. var knownActions = actionsForClip.knownActions;
  26852. action._byClipCacheIndex = knownActions.length;
  26853. knownActions.push(action);
  26854. }
  26855. action._cacheIndex = actions.length;
  26856. actions.push(action);
  26857. actionsForClip.actionByRoot[rootUuid] = action;
  26858. },
  26859. _removeInactiveAction: function _removeInactiveAction(action) {
  26860. var actions = this._actions,
  26861. lastInactiveAction = actions[actions.length - 1],
  26862. cacheIndex = action._cacheIndex;
  26863. lastInactiveAction._cacheIndex = cacheIndex;
  26864. actions[cacheIndex] = lastInactiveAction;
  26865. actions.pop();
  26866. action._cacheIndex = null;
  26867. var clipUuid = action._clip.uuid,
  26868. actionsByClip = this._actionsByClip,
  26869. actionsForClip = actionsByClip[clipUuid],
  26870. knownActionsForClip = actionsForClip.knownActions,
  26871. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  26872. byClipCacheIndex = action._byClipCacheIndex;
  26873. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  26874. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  26875. knownActionsForClip.pop();
  26876. action._byClipCacheIndex = null;
  26877. var actionByRoot = actionsForClip.actionByRoot,
  26878. rootUuid = (action._localRoot || this._root).uuid;
  26879. delete actionByRoot[rootUuid];
  26880. if (knownActionsForClip.length === 0) {
  26881. delete actionsByClip[clipUuid];
  26882. }
  26883. this._removeInactiveBindingsForAction(action);
  26884. },
  26885. _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
  26886. var bindings = action._propertyBindings;
  26887. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26888. var binding = bindings[i];
  26889. if (--binding.referenceCount === 0) {
  26890. this._removeInactiveBinding(binding);
  26891. }
  26892. }
  26893. },
  26894. _lendAction: function _lendAction(action) {
  26895. // [ active actions | inactive actions ]
  26896. // [ active actions >| inactive actions ]
  26897. // s a
  26898. // <-swap->
  26899. // a s
  26900. var actions = this._actions,
  26901. prevIndex = action._cacheIndex,
  26902. lastActiveIndex = this._nActiveActions++,
  26903. firstInactiveAction = actions[lastActiveIndex];
  26904. action._cacheIndex = lastActiveIndex;
  26905. actions[lastActiveIndex] = action;
  26906. firstInactiveAction._cacheIndex = prevIndex;
  26907. actions[prevIndex] = firstInactiveAction;
  26908. },
  26909. _takeBackAction: function _takeBackAction(action) {
  26910. // [ active actions | inactive actions ]
  26911. // [ active actions |< inactive actions ]
  26912. // a s
  26913. // <-swap->
  26914. // s a
  26915. var actions = this._actions,
  26916. prevIndex = action._cacheIndex,
  26917. firstInactiveIndex = --this._nActiveActions,
  26918. lastActiveAction = actions[firstInactiveIndex];
  26919. action._cacheIndex = firstInactiveIndex;
  26920. actions[firstInactiveIndex] = action;
  26921. lastActiveAction._cacheIndex = prevIndex;
  26922. actions[prevIndex] = lastActiveAction;
  26923. },
  26924. // Memory management for PropertyMixer objects
  26925. _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
  26926. var bindingsByRoot = this._bindingsByRootAndName,
  26927. bindings = this._bindings;
  26928. var bindingByName = bindingsByRoot[rootUuid];
  26929. if (bindingByName === undefined) {
  26930. bindingByName = {};
  26931. bindingsByRoot[rootUuid] = bindingByName;
  26932. }
  26933. bindingByName[trackName] = binding;
  26934. binding._cacheIndex = bindings.length;
  26935. bindings.push(binding);
  26936. },
  26937. _removeInactiveBinding: function _removeInactiveBinding(binding) {
  26938. var bindings = this._bindings,
  26939. propBinding = binding.binding,
  26940. rootUuid = propBinding.rootNode.uuid,
  26941. trackName = propBinding.path,
  26942. bindingsByRoot = this._bindingsByRootAndName,
  26943. bindingByName = bindingsByRoot[rootUuid],
  26944. lastInactiveBinding = bindings[bindings.length - 1],
  26945. cacheIndex = binding._cacheIndex;
  26946. lastInactiveBinding._cacheIndex = cacheIndex;
  26947. bindings[cacheIndex] = lastInactiveBinding;
  26948. bindings.pop();
  26949. delete bindingByName[trackName];
  26950. if (Object.keys(bindingByName).length === 0) {
  26951. delete bindingsByRoot[rootUuid];
  26952. }
  26953. },
  26954. _lendBinding: function _lendBinding(binding) {
  26955. var bindings = this._bindings,
  26956. prevIndex = binding._cacheIndex,
  26957. lastActiveIndex = this._nActiveBindings++,
  26958. firstInactiveBinding = bindings[lastActiveIndex];
  26959. binding._cacheIndex = lastActiveIndex;
  26960. bindings[lastActiveIndex] = binding;
  26961. firstInactiveBinding._cacheIndex = prevIndex;
  26962. bindings[prevIndex] = firstInactiveBinding;
  26963. },
  26964. _takeBackBinding: function _takeBackBinding(binding) {
  26965. var bindings = this._bindings,
  26966. prevIndex = binding._cacheIndex,
  26967. firstInactiveIndex = --this._nActiveBindings,
  26968. lastActiveBinding = bindings[firstInactiveIndex];
  26969. binding._cacheIndex = firstInactiveIndex;
  26970. bindings[firstInactiveIndex] = binding;
  26971. lastActiveBinding._cacheIndex = prevIndex;
  26972. bindings[prevIndex] = lastActiveBinding;
  26973. },
  26974. // Memory management of Interpolants for weight and time scale
  26975. _lendControlInterpolant: function _lendControlInterpolant() {
  26976. var interpolants = this._controlInterpolants,
  26977. lastActiveIndex = this._nActiveControlInterpolants++;
  26978. var interpolant = interpolants[lastActiveIndex];
  26979. if (interpolant === undefined) {
  26980. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  26981. interpolant.__cacheIndex = lastActiveIndex;
  26982. interpolants[lastActiveIndex] = interpolant;
  26983. }
  26984. return interpolant;
  26985. },
  26986. _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
  26987. var interpolants = this._controlInterpolants,
  26988. prevIndex = interpolant.__cacheIndex,
  26989. firstInactiveIndex = --this._nActiveControlInterpolants,
  26990. lastActiveInterpolant = interpolants[firstInactiveIndex];
  26991. interpolant.__cacheIndex = firstInactiveIndex;
  26992. interpolants[firstInactiveIndex] = interpolant;
  26993. lastActiveInterpolant.__cacheIndex = prevIndex;
  26994. interpolants[prevIndex] = lastActiveInterpolant;
  26995. },
  26996. _controlInterpolantsResultBuffer: new Float32Array(1),
  26997. // return an action for a clip optionally using a custom root target
  26998. // object (this method allocates a lot of dynamic memory in case a
  26999. // previously unknown clip/root combination is specified)
  27000. clipAction: function clipAction(clip, optionalRoot, blendMode) {
  27001. var root = optionalRoot || this._root,
  27002. rootUuid = root.uuid;
  27003. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  27004. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  27005. var actionsForClip = this._actionsByClip[clipUuid];
  27006. var prototypeAction = null;
  27007. if (blendMode === undefined) {
  27008. if (clipObject !== null) {
  27009. blendMode = clipObject.blendMode;
  27010. } else {
  27011. blendMode = NormalAnimationBlendMode;
  27012. }
  27013. }
  27014. if (actionsForClip !== undefined) {
  27015. var existingAction = actionsForClip.actionByRoot[rootUuid];
  27016. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  27017. return existingAction;
  27018. } // we know the clip, so we don't have to parse all
  27019. // the bindings again but can just copy
  27020. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  27021. if (clipObject === null) clipObject = prototypeAction._clip;
  27022. } // clip must be known when specified via string
  27023. if (clipObject === null) return null; // allocate all resources required to run it
  27024. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  27025. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  27026. this._addInactiveAction(newAction, clipUuid, rootUuid);
  27027. return newAction;
  27028. },
  27029. // get an existing action
  27030. existingAction: function existingAction(clip, optionalRoot) {
  27031. var root = optionalRoot || this._root,
  27032. rootUuid = root.uuid,
  27033. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  27034. clipUuid = clipObject ? clipObject.uuid : clip,
  27035. actionsForClip = this._actionsByClip[clipUuid];
  27036. if (actionsForClip !== undefined) {
  27037. return actionsForClip.actionByRoot[rootUuid] || null;
  27038. }
  27039. return null;
  27040. },
  27041. // deactivates all previously scheduled actions
  27042. stopAllAction: function stopAllAction() {
  27043. var actions = this._actions,
  27044. nActions = this._nActiveActions;
  27045. for (var i = nActions - 1; i >= 0; --i) {
  27046. actions[i].stop();
  27047. }
  27048. return this;
  27049. },
  27050. // advance the time and update apply the animation
  27051. update: function update(deltaTime) {
  27052. deltaTime *= this.timeScale;
  27053. var actions = this._actions,
  27054. nActions = this._nActiveActions,
  27055. time = this.time += deltaTime,
  27056. timeDirection = Math.sign(deltaTime),
  27057. accuIndex = this._accuIndex ^= 1; // run active actions
  27058. for (var i = 0; i !== nActions; ++i) {
  27059. var action = actions[i];
  27060. action._update(time, deltaTime, timeDirection, accuIndex);
  27061. } // update scene graph
  27062. var bindings = this._bindings,
  27063. nBindings = this._nActiveBindings;
  27064. for (var _i = 0; _i !== nBindings; ++_i) {
  27065. bindings[_i].apply(accuIndex);
  27066. }
  27067. return this;
  27068. },
  27069. // Allows you to seek to a specific time in an animation.
  27070. setTime: function setTime(timeInSeconds) {
  27071. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27072. for (var i = 0; i < this._actions.length; i++) {
  27073. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27074. }
  27075. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  27076. },
  27077. // return this mixer's root target object
  27078. getRoot: function getRoot() {
  27079. return this._root;
  27080. },
  27081. // free all resources specific to a particular clip
  27082. uncacheClip: function uncacheClip(clip) {
  27083. var actions = this._actions,
  27084. clipUuid = clip.uuid,
  27085. actionsByClip = this._actionsByClip,
  27086. actionsForClip = actionsByClip[clipUuid];
  27087. if (actionsForClip !== undefined) {
  27088. // note: just calling _removeInactiveAction would mess up the
  27089. // iteration state and also require updating the state we can
  27090. // just throw away
  27091. var actionsToRemove = actionsForClip.knownActions;
  27092. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  27093. var action = actionsToRemove[i];
  27094. this._deactivateAction(action);
  27095. var cacheIndex = action._cacheIndex,
  27096. lastInactiveAction = actions[actions.length - 1];
  27097. action._cacheIndex = null;
  27098. action._byClipCacheIndex = null;
  27099. lastInactiveAction._cacheIndex = cacheIndex;
  27100. actions[cacheIndex] = lastInactiveAction;
  27101. actions.pop();
  27102. this._removeInactiveBindingsForAction(action);
  27103. }
  27104. delete actionsByClip[clipUuid];
  27105. }
  27106. },
  27107. // free all resources specific to a particular root target object
  27108. uncacheRoot: function uncacheRoot(root) {
  27109. var rootUuid = root.uuid,
  27110. actionsByClip = this._actionsByClip;
  27111. for (var clipUuid in actionsByClip) {
  27112. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  27113. action = actionByRoot[rootUuid];
  27114. if (action !== undefined) {
  27115. this._deactivateAction(action);
  27116. this._removeInactiveAction(action);
  27117. }
  27118. }
  27119. var bindingsByRoot = this._bindingsByRootAndName,
  27120. bindingByName = bindingsByRoot[rootUuid];
  27121. if (bindingByName !== undefined) {
  27122. for (var trackName in bindingByName) {
  27123. var binding = bindingByName[trackName];
  27124. binding.restoreOriginalState();
  27125. this._removeInactiveBinding(binding);
  27126. }
  27127. }
  27128. },
  27129. // remove a targeted clip from the cache
  27130. uncacheAction: function uncacheAction(clip, optionalRoot) {
  27131. var action = this.existingAction(clip, optionalRoot);
  27132. if (action !== null) {
  27133. this._deactivateAction(action);
  27134. this._removeInactiveAction(action);
  27135. }
  27136. }
  27137. });
  27138. var Uniform = /*#__PURE__*/function () {
  27139. function Uniform(value) {
  27140. if (typeof value === 'string') {
  27141. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  27142. value = arguments[1];
  27143. }
  27144. this.value = value;
  27145. }
  27146. var _proto = Uniform.prototype;
  27147. _proto.clone = function clone() {
  27148. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  27149. };
  27150. return Uniform;
  27151. }();
  27152. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27153. InterleavedBuffer.call(this, array, stride);
  27154. this.meshPerAttribute = meshPerAttribute || 1;
  27155. }
  27156. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27157. constructor: InstancedInterleavedBuffer,
  27158. isInstancedInterleavedBuffer: true,
  27159. copy: function copy(source) {
  27160. InterleavedBuffer.prototype.copy.call(this, source);
  27161. this.meshPerAttribute = source.meshPerAttribute;
  27162. return this;
  27163. },
  27164. clone: function clone(data) {
  27165. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27166. ib.meshPerAttribute = this.meshPerAttribute;
  27167. return ib;
  27168. },
  27169. toJSON: function toJSON(data) {
  27170. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27171. json.isInstancedInterleavedBuffer = true;
  27172. json.meshPerAttribute = this.meshPerAttribute;
  27173. return json;
  27174. }
  27175. });
  27176. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27177. this.buffer = buffer;
  27178. this.type = type;
  27179. this.itemSize = itemSize;
  27180. this.elementSize = elementSize;
  27181. this.count = count;
  27182. this.version = 0;
  27183. }
  27184. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27185. set: function set(value) {
  27186. if (value === true) this.version++;
  27187. }
  27188. });
  27189. Object.assign(GLBufferAttribute.prototype, {
  27190. isGLBufferAttribute: true,
  27191. setBuffer: function setBuffer(buffer) {
  27192. this.buffer = buffer;
  27193. return this;
  27194. },
  27195. setType: function setType(type, elementSize) {
  27196. this.type = type;
  27197. this.elementSize = elementSize;
  27198. return this;
  27199. },
  27200. setItemSize: function setItemSize(itemSize) {
  27201. this.itemSize = itemSize;
  27202. return this;
  27203. },
  27204. setCount: function setCount(count) {
  27205. this.count = count;
  27206. return this;
  27207. }
  27208. });
  27209. function Raycaster(origin, direction, near, far) {
  27210. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27211. this.near = near || 0;
  27212. this.far = far || Infinity;
  27213. this.camera = null;
  27214. this.layers = new Layers();
  27215. this.params = {
  27216. Mesh: {},
  27217. Line: {
  27218. threshold: 1
  27219. },
  27220. LOD: {},
  27221. Points: {
  27222. threshold: 1
  27223. },
  27224. Sprite: {}
  27225. };
  27226. Object.defineProperties(this.params, {
  27227. PointCloud: {
  27228. get: function get() {
  27229. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27230. return this.Points;
  27231. }
  27232. }
  27233. });
  27234. }
  27235. function ascSort(a, b) {
  27236. return a.distance - b.distance;
  27237. }
  27238. function _intersectObject(object, raycaster, intersects, recursive) {
  27239. if (object.layers.test(raycaster.layers)) {
  27240. object.raycast(raycaster, intersects);
  27241. }
  27242. if (recursive === true) {
  27243. var children = object.children;
  27244. for (var i = 0, l = children.length; i < l; i++) {
  27245. _intersectObject(children[i], raycaster, intersects, true);
  27246. }
  27247. }
  27248. }
  27249. Object.assign(Raycaster.prototype, {
  27250. set: function set(origin, direction) {
  27251. // direction is assumed to be normalized (for accurate distance calculations)
  27252. this.ray.set(origin, direction);
  27253. },
  27254. setFromCamera: function setFromCamera(coords, camera) {
  27255. if (camera && camera.isPerspectiveCamera) {
  27256. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27257. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27258. this.camera = camera;
  27259. } else if (camera && camera.isOrthographicCamera) {
  27260. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27261. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27262. this.camera = camera;
  27263. } else {
  27264. console.error('THREE.Raycaster: Unsupported camera type: ' + camera.type);
  27265. }
  27266. },
  27267. intersectObject: function intersectObject(object, recursive, optionalTarget) {
  27268. var intersects = optionalTarget || [];
  27269. _intersectObject(object, this, intersects, recursive);
  27270. intersects.sort(ascSort);
  27271. return intersects;
  27272. },
  27273. intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
  27274. var intersects = optionalTarget || [];
  27275. if (Array.isArray(objects) === false) {
  27276. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  27277. return intersects;
  27278. }
  27279. for (var i = 0, l = objects.length; i < l; i++) {
  27280. _intersectObject(objects[i], this, intersects, recursive);
  27281. }
  27282. intersects.sort(ascSort);
  27283. return intersects;
  27284. }
  27285. });
  27286. /**
  27287. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27288. *
  27289. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27290. * The azimuthal angle (theta) is measured from the positive z-axis.
  27291. */
  27292. var Spherical = /*#__PURE__*/function () {
  27293. function Spherical(radius, phi, theta) {
  27294. if (radius === void 0) {
  27295. radius = 1;
  27296. }
  27297. if (phi === void 0) {
  27298. phi = 0;
  27299. }
  27300. if (theta === void 0) {
  27301. theta = 0;
  27302. }
  27303. this.radius = radius;
  27304. this.phi = phi; // polar angle
  27305. this.theta = theta; // azimuthal angle
  27306. return this;
  27307. }
  27308. var _proto = Spherical.prototype;
  27309. _proto.set = function set(radius, phi, theta) {
  27310. this.radius = radius;
  27311. this.phi = phi;
  27312. this.theta = theta;
  27313. return this;
  27314. };
  27315. _proto.clone = function clone() {
  27316. return new this.constructor().copy(this);
  27317. };
  27318. _proto.copy = function copy(other) {
  27319. this.radius = other.radius;
  27320. this.phi = other.phi;
  27321. this.theta = other.theta;
  27322. return this;
  27323. } // restrict phi to be betwee EPS and PI-EPS
  27324. ;
  27325. _proto.makeSafe = function makeSafe() {
  27326. var EPS = 0.000001;
  27327. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  27328. return this;
  27329. };
  27330. _proto.setFromVector3 = function setFromVector3(v) {
  27331. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27332. };
  27333. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27334. this.radius = Math.sqrt(x * x + y * y + z * z);
  27335. if (this.radius === 0) {
  27336. this.theta = 0;
  27337. this.phi = 0;
  27338. } else {
  27339. this.theta = Math.atan2(x, z);
  27340. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  27341. }
  27342. return this;
  27343. };
  27344. return Spherical;
  27345. }();
  27346. /**
  27347. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27348. */
  27349. var Cylindrical = /*#__PURE__*/function () {
  27350. function Cylindrical(radius, theta, y) {
  27351. this.radius = radius !== undefined ? radius : 1.0; // distance from the origin to a point in the x-z plane
  27352. this.theta = theta !== undefined ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27353. this.y = y !== undefined ? y : 0; // height above the x-z plane
  27354. return this;
  27355. }
  27356. var _proto = Cylindrical.prototype;
  27357. _proto.set = function set(radius, theta, y) {
  27358. this.radius = radius;
  27359. this.theta = theta;
  27360. this.y = y;
  27361. return this;
  27362. };
  27363. _proto.clone = function clone() {
  27364. return new this.constructor().copy(this);
  27365. };
  27366. _proto.copy = function copy(other) {
  27367. this.radius = other.radius;
  27368. this.theta = other.theta;
  27369. this.y = other.y;
  27370. return this;
  27371. };
  27372. _proto.setFromVector3 = function setFromVector3(v) {
  27373. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27374. };
  27375. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27376. this.radius = Math.sqrt(x * x + z * z);
  27377. this.theta = Math.atan2(x, z);
  27378. this.y = y;
  27379. return this;
  27380. };
  27381. return Cylindrical;
  27382. }();
  27383. var _vector$8 = /*@__PURE__*/new Vector2();
  27384. var Box2 = /*#__PURE__*/function () {
  27385. function Box2(min, max) {
  27386. Object.defineProperty(this, 'isBox2', {
  27387. value: true
  27388. });
  27389. this.min = min !== undefined ? min : new Vector2(+Infinity, +Infinity);
  27390. this.max = max !== undefined ? max : new Vector2(-Infinity, -Infinity);
  27391. }
  27392. var _proto = Box2.prototype;
  27393. _proto.set = function set(min, max) {
  27394. this.min.copy(min);
  27395. this.max.copy(max);
  27396. return this;
  27397. };
  27398. _proto.setFromPoints = function setFromPoints(points) {
  27399. this.makeEmpty();
  27400. for (var i = 0, il = points.length; i < il; i++) {
  27401. this.expandByPoint(points[i]);
  27402. }
  27403. return this;
  27404. };
  27405. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  27406. var halfSize = _vector$8.copy(size).multiplyScalar(0.5);
  27407. this.min.copy(center).sub(halfSize);
  27408. this.max.copy(center).add(halfSize);
  27409. return this;
  27410. };
  27411. _proto.clone = function clone() {
  27412. return new this.constructor().copy(this);
  27413. };
  27414. _proto.copy = function copy(box) {
  27415. this.min.copy(box.min);
  27416. this.max.copy(box.max);
  27417. return this;
  27418. };
  27419. _proto.makeEmpty = function makeEmpty() {
  27420. this.min.x = this.min.y = +Infinity;
  27421. this.max.x = this.max.y = -Infinity;
  27422. return this;
  27423. };
  27424. _proto.isEmpty = function isEmpty() {
  27425. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27426. return this.max.x < this.min.x || this.max.y < this.min.y;
  27427. };
  27428. _proto.getCenter = function getCenter(target) {
  27429. if (target === undefined) {
  27430. console.warn('THREE.Box2: .getCenter() target is now required');
  27431. target = new Vector2();
  27432. }
  27433. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  27434. };
  27435. _proto.getSize = function getSize(target) {
  27436. if (target === undefined) {
  27437. console.warn('THREE.Box2: .getSize() target is now required');
  27438. target = new Vector2();
  27439. }
  27440. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  27441. };
  27442. _proto.expandByPoint = function expandByPoint(point) {
  27443. this.min.min(point);
  27444. this.max.max(point);
  27445. return this;
  27446. };
  27447. _proto.expandByVector = function expandByVector(vector) {
  27448. this.min.sub(vector);
  27449. this.max.add(vector);
  27450. return this;
  27451. };
  27452. _proto.expandByScalar = function expandByScalar(scalar) {
  27453. this.min.addScalar(-scalar);
  27454. this.max.addScalar(scalar);
  27455. return this;
  27456. };
  27457. _proto.containsPoint = function containsPoint(point) {
  27458. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  27459. };
  27460. _proto.containsBox = function containsBox(box) {
  27461. 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;
  27462. };
  27463. _proto.getParameter = function getParameter(point, target) {
  27464. // This can potentially have a divide by zero if the box
  27465. // has a size dimension of 0.
  27466. if (target === undefined) {
  27467. console.warn('THREE.Box2: .getParameter() target is now required');
  27468. target = new Vector2();
  27469. }
  27470. 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));
  27471. };
  27472. _proto.intersectsBox = function intersectsBox(box) {
  27473. // using 4 splitting planes to rule out intersections
  27474. 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;
  27475. };
  27476. _proto.clampPoint = function clampPoint(point, target) {
  27477. if (target === undefined) {
  27478. console.warn('THREE.Box2: .clampPoint() target is now required');
  27479. target = new Vector2();
  27480. }
  27481. return target.copy(point).clamp(this.min, this.max);
  27482. };
  27483. _proto.distanceToPoint = function distanceToPoint(point) {
  27484. var clampedPoint = _vector$8.copy(point).clamp(this.min, this.max);
  27485. return clampedPoint.sub(point).length();
  27486. };
  27487. _proto.intersect = function intersect(box) {
  27488. this.min.max(box.min);
  27489. this.max.min(box.max);
  27490. return this;
  27491. };
  27492. _proto.union = function union(box) {
  27493. this.min.min(box.min);
  27494. this.max.max(box.max);
  27495. return this;
  27496. };
  27497. _proto.translate = function translate(offset) {
  27498. this.min.add(offset);
  27499. this.max.add(offset);
  27500. return this;
  27501. };
  27502. _proto.equals = function equals(box) {
  27503. return box.min.equals(this.min) && box.max.equals(this.max);
  27504. };
  27505. return Box2;
  27506. }();
  27507. var _startP = /*@__PURE__*/new Vector3();
  27508. var _startEnd = /*@__PURE__*/new Vector3();
  27509. var Line3 = /*#__PURE__*/function () {
  27510. function Line3(start, end) {
  27511. this.start = start !== undefined ? start : new Vector3();
  27512. this.end = end !== undefined ? end : new Vector3();
  27513. }
  27514. var _proto = Line3.prototype;
  27515. _proto.set = function set(start, end) {
  27516. this.start.copy(start);
  27517. this.end.copy(end);
  27518. return this;
  27519. };
  27520. _proto.clone = function clone() {
  27521. return new this.constructor().copy(this);
  27522. };
  27523. _proto.copy = function copy(line) {
  27524. this.start.copy(line.start);
  27525. this.end.copy(line.end);
  27526. return this;
  27527. };
  27528. _proto.getCenter = function getCenter(target) {
  27529. if (target === undefined) {
  27530. console.warn('THREE.Line3: .getCenter() target is now required');
  27531. target = new Vector3();
  27532. }
  27533. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  27534. };
  27535. _proto.delta = function delta(target) {
  27536. if (target === undefined) {
  27537. console.warn('THREE.Line3: .delta() target is now required');
  27538. target = new Vector3();
  27539. }
  27540. return target.subVectors(this.end, this.start);
  27541. };
  27542. _proto.distanceSq = function distanceSq() {
  27543. return this.start.distanceToSquared(this.end);
  27544. };
  27545. _proto.distance = function distance() {
  27546. return this.start.distanceTo(this.end);
  27547. };
  27548. _proto.at = function at(t, target) {
  27549. if (target === undefined) {
  27550. console.warn('THREE.Line3: .at() target is now required');
  27551. target = new Vector3();
  27552. }
  27553. return this.delta(target).multiplyScalar(t).add(this.start);
  27554. };
  27555. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  27556. _startP.subVectors(point, this.start);
  27557. _startEnd.subVectors(this.end, this.start);
  27558. var startEnd2 = _startEnd.dot(_startEnd);
  27559. var startEnd_startP = _startEnd.dot(_startP);
  27560. var t = startEnd_startP / startEnd2;
  27561. if (clampToLine) {
  27562. t = MathUtils.clamp(t, 0, 1);
  27563. }
  27564. return t;
  27565. };
  27566. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  27567. var t = this.closestPointToPointParameter(point, clampToLine);
  27568. if (target === undefined) {
  27569. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  27570. target = new Vector3();
  27571. }
  27572. return this.delta(target).multiplyScalar(t).add(this.start);
  27573. };
  27574. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  27575. this.start.applyMatrix4(matrix);
  27576. this.end.applyMatrix4(matrix);
  27577. return this;
  27578. };
  27579. _proto.equals = function equals(line) {
  27580. return line.start.equals(this.start) && line.end.equals(this.end);
  27581. };
  27582. return Line3;
  27583. }();
  27584. function ImmediateRenderObject(material) {
  27585. Object3D.call(this);
  27586. this.material = material;
  27587. this.render = function ()
  27588. /* renderCallback */
  27589. {};
  27590. this.hasPositions = false;
  27591. this.hasNormals = false;
  27592. this.hasColors = false;
  27593. this.hasUvs = false;
  27594. this.positionArray = null;
  27595. this.normalArray = null;
  27596. this.colorArray = null;
  27597. this.uvArray = null;
  27598. this.count = 0;
  27599. }
  27600. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  27601. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27602. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27603. var _vector$9 = /*@__PURE__*/new Vector3();
  27604. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  27605. _inheritsLoose(SpotLightHelper, _Object3D);
  27606. function SpotLightHelper(light, color) {
  27607. var _this;
  27608. _this = _Object3D.call(this) || this;
  27609. _this.light = light;
  27610. _this.light.updateMatrixWorld();
  27611. _this.matrix = light.matrixWorld;
  27612. _this.matrixAutoUpdate = false;
  27613. _this.color = color;
  27614. var geometry = new BufferGeometry();
  27615. 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];
  27616. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  27617. var p1 = i / l * Math.PI * 2;
  27618. var p2 = j / l * Math.PI * 2;
  27619. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  27620. }
  27621. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  27622. var material = new LineBasicMaterial({
  27623. fog: false,
  27624. toneMapped: false
  27625. });
  27626. _this.cone = new LineSegments(geometry, material);
  27627. _this.add(_this.cone);
  27628. _this.update();
  27629. return _this;
  27630. }
  27631. var _proto = SpotLightHelper.prototype;
  27632. _proto.dispose = function dispose() {
  27633. this.cone.geometry.dispose();
  27634. this.cone.material.dispose();
  27635. };
  27636. _proto.update = function update() {
  27637. this.light.updateMatrixWorld();
  27638. var coneLength = this.light.distance ? this.light.distance : 1000;
  27639. var coneWidth = coneLength * Math.tan(this.light.angle);
  27640. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  27641. _vector$9.setFromMatrixPosition(this.light.target.matrixWorld);
  27642. this.cone.lookAt(_vector$9);
  27643. if (this.color !== undefined) {
  27644. this.cone.material.color.set(this.color);
  27645. } else {
  27646. this.cone.material.color.copy(this.light.color);
  27647. }
  27648. };
  27649. return SpotLightHelper;
  27650. }(Object3D);
  27651. var _vector$a = /*@__PURE__*/new Vector3();
  27652. var _boneMatrix = /*@__PURE__*/new Matrix4();
  27653. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  27654. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  27655. _inheritsLoose(SkeletonHelper, _LineSegments);
  27656. function SkeletonHelper(object) {
  27657. var _this;
  27658. var bones = getBoneList(object);
  27659. var geometry = new BufferGeometry();
  27660. var vertices = [];
  27661. var colors = [];
  27662. var color1 = new Color(0, 0, 1);
  27663. var color2 = new Color(0, 1, 0);
  27664. for (var i = 0; i < bones.length; i++) {
  27665. var bone = bones[i];
  27666. if (bone.parent && bone.parent.isBone) {
  27667. vertices.push(0, 0, 0);
  27668. vertices.push(0, 0, 0);
  27669. colors.push(color1.r, color1.g, color1.b);
  27670. colors.push(color2.r, color2.g, color2.b);
  27671. }
  27672. }
  27673. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27674. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27675. var material = new LineBasicMaterial({
  27676. vertexColors: true,
  27677. depthTest: false,
  27678. depthWrite: false,
  27679. toneMapped: false,
  27680. transparent: true
  27681. });
  27682. _this = _LineSegments.call(this, geometry, material) || this;
  27683. _this.type = 'SkeletonHelper';
  27684. _this.isSkeletonHelper = true;
  27685. _this.root = object;
  27686. _this.bones = bones;
  27687. _this.matrix = object.matrixWorld;
  27688. _this.matrixAutoUpdate = false;
  27689. return _this;
  27690. }
  27691. var _proto = SkeletonHelper.prototype;
  27692. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  27693. var bones = this.bones;
  27694. var geometry = this.geometry;
  27695. var position = geometry.getAttribute('position');
  27696. _matrixWorldInv.copy(this.root.matrixWorld).invert();
  27697. for (var i = 0, j = 0; i < bones.length; i++) {
  27698. var bone = bones[i];
  27699. if (bone.parent && bone.parent.isBone) {
  27700. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  27701. _vector$a.setFromMatrixPosition(_boneMatrix);
  27702. position.setXYZ(j, _vector$a.x, _vector$a.y, _vector$a.z);
  27703. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  27704. _vector$a.setFromMatrixPosition(_boneMatrix);
  27705. position.setXYZ(j + 1, _vector$a.x, _vector$a.y, _vector$a.z);
  27706. j += 2;
  27707. }
  27708. }
  27709. geometry.getAttribute('position').needsUpdate = true;
  27710. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  27711. };
  27712. return SkeletonHelper;
  27713. }(LineSegments);
  27714. function getBoneList(object) {
  27715. var boneList = [];
  27716. if (object && object.isBone) {
  27717. boneList.push(object);
  27718. }
  27719. for (var i = 0; i < object.children.length; i++) {
  27720. boneList.push.apply(boneList, getBoneList(object.children[i]));
  27721. }
  27722. return boneList;
  27723. }
  27724. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  27725. _inheritsLoose(PointLightHelper, _Mesh);
  27726. function PointLightHelper(light, sphereSize, color) {
  27727. var _this;
  27728. var geometry = new SphereGeometry(sphereSize, 4, 2);
  27729. var material = new MeshBasicMaterial({
  27730. wireframe: true,
  27731. fog: false,
  27732. toneMapped: false
  27733. });
  27734. _this = _Mesh.call(this, geometry, material) || this;
  27735. _this.light = light;
  27736. _this.light.updateMatrixWorld();
  27737. _this.color = color;
  27738. _this.type = 'PointLightHelper';
  27739. _this.matrix = _this.light.matrixWorld;
  27740. _this.matrixAutoUpdate = false;
  27741. _this.update();
  27742. /*
  27743. // TODO: delete this comment?
  27744. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27745. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27746. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27747. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27748. const d = light.distance;
  27749. if ( d === 0.0 ) {
  27750. this.lightDistance.visible = false;
  27751. } else {
  27752. this.lightDistance.scale.set( d, d, d );
  27753. }
  27754. this.add( this.lightDistance );
  27755. */
  27756. return _this;
  27757. }
  27758. var _proto = PointLightHelper.prototype;
  27759. _proto.dispose = function dispose() {
  27760. this.geometry.dispose();
  27761. this.material.dispose();
  27762. };
  27763. _proto.update = function update() {
  27764. if (this.color !== undefined) {
  27765. this.material.color.set(this.color);
  27766. } else {
  27767. this.material.color.copy(this.light.color);
  27768. }
  27769. /*
  27770. const d = this.light.distance;
  27771. if ( d === 0.0 ) {
  27772. this.lightDistance.visible = false;
  27773. } else {
  27774. this.lightDistance.visible = true;
  27775. this.lightDistance.scale.set( d, d, d );
  27776. }
  27777. */
  27778. };
  27779. return PointLightHelper;
  27780. }(Mesh);
  27781. var _vector$b = /*@__PURE__*/new Vector3();
  27782. var _color1 = /*@__PURE__*/new Color();
  27783. var _color2 = /*@__PURE__*/new Color();
  27784. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  27785. _inheritsLoose(HemisphereLightHelper, _Object3D);
  27786. function HemisphereLightHelper(light, size, color) {
  27787. var _this;
  27788. _this = _Object3D.call(this) || this;
  27789. _this.light = light;
  27790. _this.light.updateMatrixWorld();
  27791. _this.matrix = light.matrixWorld;
  27792. _this.matrixAutoUpdate = false;
  27793. _this.color = color;
  27794. var geometry = new OctahedronGeometry(size);
  27795. geometry.rotateY(Math.PI * 0.5);
  27796. _this.material = new MeshBasicMaterial({
  27797. wireframe: true,
  27798. fog: false,
  27799. toneMapped: false
  27800. });
  27801. if (_this.color === undefined) _this.material.vertexColors = true;
  27802. var position = geometry.getAttribute('position');
  27803. var colors = new Float32Array(position.count * 3);
  27804. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  27805. _this.add(new Mesh(geometry, _this.material));
  27806. _this.update();
  27807. return _this;
  27808. }
  27809. var _proto = HemisphereLightHelper.prototype;
  27810. _proto.dispose = function dispose() {
  27811. this.children[0].geometry.dispose();
  27812. this.children[0].material.dispose();
  27813. };
  27814. _proto.update = function update() {
  27815. var mesh = this.children[0];
  27816. if (this.color !== undefined) {
  27817. this.material.color.set(this.color);
  27818. } else {
  27819. var colors = mesh.geometry.getAttribute('color');
  27820. _color1.copy(this.light.color);
  27821. _color2.copy(this.light.groundColor);
  27822. for (var i = 0, l = colors.count; i < l; i++) {
  27823. var color = i < l / 2 ? _color1 : _color2;
  27824. colors.setXYZ(i, color.r, color.g, color.b);
  27825. }
  27826. colors.needsUpdate = true;
  27827. }
  27828. mesh.lookAt(_vector$b.setFromMatrixPosition(this.light.matrixWorld).negate());
  27829. };
  27830. return HemisphereLightHelper;
  27831. }(Object3D);
  27832. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  27833. _inheritsLoose(GridHelper, _LineSegments);
  27834. function GridHelper(size, divisions, color1, color2) {
  27835. var _this;
  27836. if (size === void 0) {
  27837. size = 10;
  27838. }
  27839. if (divisions === void 0) {
  27840. divisions = 10;
  27841. }
  27842. if (color1 === void 0) {
  27843. color1 = 0x444444;
  27844. }
  27845. if (color2 === void 0) {
  27846. color2 = 0x888888;
  27847. }
  27848. color1 = new Color(color1);
  27849. color2 = new Color(color2);
  27850. var center = divisions / 2;
  27851. var step = size / divisions;
  27852. var halfSize = size / 2;
  27853. var vertices = [],
  27854. colors = [];
  27855. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  27856. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  27857. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  27858. var color = i === center ? color1 : color2;
  27859. color.toArray(colors, j);
  27860. j += 3;
  27861. color.toArray(colors, j);
  27862. j += 3;
  27863. color.toArray(colors, j);
  27864. j += 3;
  27865. color.toArray(colors, j);
  27866. j += 3;
  27867. }
  27868. var geometry = new BufferGeometry();
  27869. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27870. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27871. var material = new LineBasicMaterial({
  27872. vertexColors: true,
  27873. toneMapped: false
  27874. });
  27875. _this = _LineSegments.call(this, geometry, material) || this;
  27876. _this.type = 'GridHelper';
  27877. return _this;
  27878. }
  27879. return GridHelper;
  27880. }(LineSegments);
  27881. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  27882. _inheritsLoose(PolarGridHelper, _LineSegments);
  27883. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  27884. var _this;
  27885. if (radius === void 0) {
  27886. radius = 10;
  27887. }
  27888. if (radials === void 0) {
  27889. radials = 16;
  27890. }
  27891. if (circles === void 0) {
  27892. circles = 8;
  27893. }
  27894. if (divisions === void 0) {
  27895. divisions = 64;
  27896. }
  27897. if (color1 === void 0) {
  27898. color1 = 0x444444;
  27899. }
  27900. if (color2 === void 0) {
  27901. color2 = 0x888888;
  27902. }
  27903. color1 = new Color(color1);
  27904. color2 = new Color(color2);
  27905. var vertices = [];
  27906. var colors = []; // create the radials
  27907. for (var i = 0; i <= radials; i++) {
  27908. var v = i / radials * (Math.PI * 2);
  27909. var x = Math.sin(v) * radius;
  27910. var z = Math.cos(v) * radius;
  27911. vertices.push(0, 0, 0);
  27912. vertices.push(x, 0, z);
  27913. var color = i & 1 ? color1 : color2;
  27914. colors.push(color.r, color.g, color.b);
  27915. colors.push(color.r, color.g, color.b);
  27916. } // create the circles
  27917. for (var _i = 0; _i <= circles; _i++) {
  27918. var _color = _i & 1 ? color1 : color2;
  27919. var r = radius - radius / circles * _i;
  27920. for (var j = 0; j < divisions; j++) {
  27921. // first vertex
  27922. var _v = j / divisions * (Math.PI * 2);
  27923. var _x = Math.sin(_v) * r;
  27924. var _z = Math.cos(_v) * r;
  27925. vertices.push(_x, 0, _z);
  27926. colors.push(_color.r, _color.g, _color.b); // second vertex
  27927. _v = (j + 1) / divisions * (Math.PI * 2);
  27928. _x = Math.sin(_v) * r;
  27929. _z = Math.cos(_v) * r;
  27930. vertices.push(_x, 0, _z);
  27931. colors.push(_color.r, _color.g, _color.b);
  27932. }
  27933. }
  27934. var geometry = new BufferGeometry();
  27935. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27936. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27937. var material = new LineBasicMaterial({
  27938. vertexColors: true,
  27939. toneMapped: false
  27940. });
  27941. _this = _LineSegments.call(this, geometry, material) || this;
  27942. _this.type = 'PolarGridHelper';
  27943. return _this;
  27944. }
  27945. return PolarGridHelper;
  27946. }(LineSegments);
  27947. var _v1$6 = /*@__PURE__*/new Vector3();
  27948. var _v2$3 = /*@__PURE__*/new Vector3();
  27949. var _v3$1 = /*@__PURE__*/new Vector3();
  27950. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  27951. _inheritsLoose(DirectionalLightHelper, _Object3D);
  27952. function DirectionalLightHelper(light, size, color) {
  27953. var _this;
  27954. _this = _Object3D.call(this) || this;
  27955. _this.light = light;
  27956. _this.light.updateMatrixWorld();
  27957. _this.matrix = light.matrixWorld;
  27958. _this.matrixAutoUpdate = false;
  27959. _this.color = color;
  27960. if (size === undefined) size = 1;
  27961. var geometry = new BufferGeometry();
  27962. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  27963. var material = new LineBasicMaterial({
  27964. fog: false,
  27965. toneMapped: false
  27966. });
  27967. _this.lightPlane = new Line(geometry, material);
  27968. _this.add(_this.lightPlane);
  27969. geometry = new BufferGeometry();
  27970. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  27971. _this.targetLine = new Line(geometry, material);
  27972. _this.add(_this.targetLine);
  27973. _this.update();
  27974. return _this;
  27975. }
  27976. var _proto = DirectionalLightHelper.prototype;
  27977. _proto.dispose = function dispose() {
  27978. this.lightPlane.geometry.dispose();
  27979. this.lightPlane.material.dispose();
  27980. this.targetLine.geometry.dispose();
  27981. this.targetLine.material.dispose();
  27982. };
  27983. _proto.update = function update() {
  27984. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  27985. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  27986. _v3$1.subVectors(_v2$3, _v1$6);
  27987. this.lightPlane.lookAt(_v2$3);
  27988. if (this.color !== undefined) {
  27989. this.lightPlane.material.color.set(this.color);
  27990. this.targetLine.material.color.set(this.color);
  27991. } else {
  27992. this.lightPlane.material.color.copy(this.light.color);
  27993. this.targetLine.material.color.copy(this.light.color);
  27994. }
  27995. this.targetLine.lookAt(_v2$3);
  27996. this.targetLine.scale.z = _v3$1.length();
  27997. };
  27998. return DirectionalLightHelper;
  27999. }(Object3D);
  28000. var _vector$c = /*@__PURE__*/new Vector3();
  28001. var _camera = /*@__PURE__*/new Camera();
  28002. /**
  28003. * - shows frustum, line of sight and up of the camera
  28004. * - suitable for fast updates
  28005. * - based on frustum visualization in lightgl.js shadowmap example
  28006. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28007. */
  28008. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  28009. _inheritsLoose(CameraHelper, _LineSegments);
  28010. function CameraHelper(camera) {
  28011. var _this;
  28012. var geometry = new BufferGeometry();
  28013. var material = new LineBasicMaterial({
  28014. color: 0xffffff,
  28015. vertexColors: true,
  28016. toneMapped: false
  28017. });
  28018. var vertices = [];
  28019. var colors = [];
  28020. var pointMap = {}; // colors
  28021. var colorFrustum = new Color(0xffaa00);
  28022. var colorCone = new Color(0xff0000);
  28023. var colorUp = new Color(0x00aaff);
  28024. var colorTarget = new Color(0xffffff);
  28025. var colorCross = new Color(0x333333); // near
  28026. addLine('n1', 'n2', colorFrustum);
  28027. addLine('n2', 'n4', colorFrustum);
  28028. addLine('n4', 'n3', colorFrustum);
  28029. addLine('n3', 'n1', colorFrustum); // far
  28030. addLine('f1', 'f2', colorFrustum);
  28031. addLine('f2', 'f4', colorFrustum);
  28032. addLine('f4', 'f3', colorFrustum);
  28033. addLine('f3', 'f1', colorFrustum); // sides
  28034. addLine('n1', 'f1', colorFrustum);
  28035. addLine('n2', 'f2', colorFrustum);
  28036. addLine('n3', 'f3', colorFrustum);
  28037. addLine('n4', 'f4', colorFrustum); // cone
  28038. addLine('p', 'n1', colorCone);
  28039. addLine('p', 'n2', colorCone);
  28040. addLine('p', 'n3', colorCone);
  28041. addLine('p', 'n4', colorCone); // up
  28042. addLine('u1', 'u2', colorUp);
  28043. addLine('u2', 'u3', colorUp);
  28044. addLine('u3', 'u1', colorUp); // target
  28045. addLine('c', 't', colorTarget);
  28046. addLine('p', 'c', colorCross); // cross
  28047. addLine('cn1', 'cn2', colorCross);
  28048. addLine('cn3', 'cn4', colorCross);
  28049. addLine('cf1', 'cf2', colorCross);
  28050. addLine('cf3', 'cf4', colorCross);
  28051. function addLine(a, b, color) {
  28052. addPoint(a, color);
  28053. addPoint(b, color);
  28054. }
  28055. function addPoint(id, color) {
  28056. vertices.push(0, 0, 0);
  28057. colors.push(color.r, color.g, color.b);
  28058. if (pointMap[id] === undefined) {
  28059. pointMap[id] = [];
  28060. }
  28061. pointMap[id].push(vertices.length / 3 - 1);
  28062. }
  28063. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28064. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28065. _this = _LineSegments.call(this, geometry, material) || this;
  28066. _this.type = 'CameraHelper';
  28067. _this.camera = camera;
  28068. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  28069. _this.matrix = camera.matrixWorld;
  28070. _this.matrixAutoUpdate = false;
  28071. _this.pointMap = pointMap;
  28072. _this.update();
  28073. return _this;
  28074. }
  28075. var _proto = CameraHelper.prototype;
  28076. _proto.update = function update() {
  28077. var geometry = this.geometry;
  28078. var pointMap = this.pointMap;
  28079. var w = 1,
  28080. h = 1; // we need just camera projection matrix inverse
  28081. // world matrix must be identity
  28082. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  28083. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  28084. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  28085. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  28086. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  28087. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  28088. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  28089. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  28090. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  28091. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  28092. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  28093. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  28094. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  28095. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  28096. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  28097. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  28098. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  28099. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  28100. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  28101. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  28102. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  28103. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  28104. geometry.getAttribute('position').needsUpdate = true;
  28105. };
  28106. return CameraHelper;
  28107. }(LineSegments);
  28108. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  28109. _vector$c.set(x, y, z).unproject(camera);
  28110. var points = pointMap[point];
  28111. if (points !== undefined) {
  28112. var position = geometry.getAttribute('position');
  28113. for (var i = 0, l = points.length; i < l; i++) {
  28114. position.setXYZ(points[i], _vector$c.x, _vector$c.y, _vector$c.z);
  28115. }
  28116. }
  28117. }
  28118. var _box$3 = /*@__PURE__*/new Box3();
  28119. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  28120. _inheritsLoose(BoxHelper, _LineSegments);
  28121. function BoxHelper(object, color) {
  28122. var _this;
  28123. if (color === void 0) {
  28124. color = 0xffff00;
  28125. }
  28126. 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]);
  28127. var positions = new Float32Array(8 * 3);
  28128. var geometry = new BufferGeometry();
  28129. geometry.setIndex(new BufferAttribute(indices, 1));
  28130. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28131. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28132. color: color,
  28133. toneMapped: false
  28134. })) || this;
  28135. _this.object = object;
  28136. _this.type = 'BoxHelper';
  28137. _this.matrixAutoUpdate = false;
  28138. _this.update();
  28139. return _this;
  28140. }
  28141. var _proto = BoxHelper.prototype;
  28142. _proto.update = function update(object) {
  28143. if (object !== undefined) {
  28144. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28145. }
  28146. if (this.object !== undefined) {
  28147. _box$3.setFromObject(this.object);
  28148. }
  28149. if (_box$3.isEmpty()) return;
  28150. var min = _box$3.min;
  28151. var max = _box$3.max;
  28152. /*
  28153. 5____4
  28154. 1/___0/|
  28155. | 6__|_7
  28156. 2/___3/
  28157. 0: max.x, max.y, max.z
  28158. 1: min.x, max.y, max.z
  28159. 2: min.x, min.y, max.z
  28160. 3: max.x, min.y, max.z
  28161. 4: max.x, max.y, min.z
  28162. 5: min.x, max.y, min.z
  28163. 6: min.x, min.y, min.z
  28164. 7: max.x, min.y, min.z
  28165. */
  28166. var position = this.geometry.attributes.position;
  28167. var array = position.array;
  28168. array[0] = max.x;
  28169. array[1] = max.y;
  28170. array[2] = max.z;
  28171. array[3] = min.x;
  28172. array[4] = max.y;
  28173. array[5] = max.z;
  28174. array[6] = min.x;
  28175. array[7] = min.y;
  28176. array[8] = max.z;
  28177. array[9] = max.x;
  28178. array[10] = min.y;
  28179. array[11] = max.z;
  28180. array[12] = max.x;
  28181. array[13] = max.y;
  28182. array[14] = min.z;
  28183. array[15] = min.x;
  28184. array[16] = max.y;
  28185. array[17] = min.z;
  28186. array[18] = min.x;
  28187. array[19] = min.y;
  28188. array[20] = min.z;
  28189. array[21] = max.x;
  28190. array[22] = min.y;
  28191. array[23] = min.z;
  28192. position.needsUpdate = true;
  28193. this.geometry.computeBoundingSphere();
  28194. };
  28195. _proto.setFromObject = function setFromObject(object) {
  28196. this.object = object;
  28197. this.update();
  28198. return this;
  28199. };
  28200. _proto.copy = function copy(source) {
  28201. LineSegments.prototype.copy.call(this, source);
  28202. this.object = source.object;
  28203. return this;
  28204. };
  28205. return BoxHelper;
  28206. }(LineSegments);
  28207. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28208. _inheritsLoose(Box3Helper, _LineSegments);
  28209. function Box3Helper(box, color) {
  28210. var _this;
  28211. if (color === void 0) {
  28212. color = 0xffff00;
  28213. }
  28214. 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]);
  28215. 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];
  28216. var geometry = new BufferGeometry();
  28217. geometry.setIndex(new BufferAttribute(indices, 1));
  28218. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28219. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28220. color: color,
  28221. toneMapped: false
  28222. })) || this;
  28223. _this.box = box;
  28224. _this.type = 'Box3Helper';
  28225. _this.geometry.computeBoundingSphere();
  28226. return _this;
  28227. }
  28228. var _proto = Box3Helper.prototype;
  28229. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28230. var box = this.box;
  28231. if (box.isEmpty()) return;
  28232. box.getCenter(this.position);
  28233. box.getSize(this.scale);
  28234. this.scale.multiplyScalar(0.5);
  28235. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28236. };
  28237. return Box3Helper;
  28238. }(LineSegments);
  28239. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28240. _inheritsLoose(PlaneHelper, _Line);
  28241. function PlaneHelper(plane, size, hex) {
  28242. var _this;
  28243. if (size === void 0) {
  28244. size = 1;
  28245. }
  28246. if (hex === void 0) {
  28247. hex = 0xffff00;
  28248. }
  28249. var color = hex;
  28250. 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];
  28251. var geometry = new BufferGeometry();
  28252. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28253. geometry.computeBoundingSphere();
  28254. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28255. color: color,
  28256. toneMapped: false
  28257. })) || this;
  28258. _this.type = 'PlaneHelper';
  28259. _this.plane = plane;
  28260. _this.size = size;
  28261. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28262. var geometry2 = new BufferGeometry();
  28263. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28264. geometry2.computeBoundingSphere();
  28265. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28266. color: color,
  28267. opacity: 0.2,
  28268. transparent: true,
  28269. depthWrite: false,
  28270. toneMapped: false
  28271. })));
  28272. return _this;
  28273. }
  28274. var _proto = PlaneHelper.prototype;
  28275. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28276. var scale = -this.plane.constant;
  28277. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28278. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28279. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28280. this.lookAt(this.plane.normal);
  28281. _Line.prototype.updateMatrixWorld.call(this, force);
  28282. };
  28283. return PlaneHelper;
  28284. }(Line);
  28285. var _axis = /*@__PURE__*/new Vector3();
  28286. var _lineGeometry, _coneGeometry;
  28287. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28288. _inheritsLoose(ArrowHelper, _Object3D);
  28289. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28290. var _this;
  28291. _this = _Object3D.call(this) || this; // dir is assumed to be normalized
  28292. _this.type = 'ArrowHelper';
  28293. if (dir === undefined) dir = new Vector3(0, 0, 1);
  28294. if (origin === undefined) origin = new Vector3(0, 0, 0);
  28295. if (length === undefined) length = 1;
  28296. if (color === undefined) color = 0xffff00;
  28297. if (headLength === undefined) headLength = 0.2 * length;
  28298. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28299. if (_lineGeometry === undefined) {
  28300. _lineGeometry = new BufferGeometry();
  28301. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28302. _coneGeometry = new CylinderGeometry(0, 0.5, 1, 5, 1);
  28303. _coneGeometry.translate(0, -0.5, 0);
  28304. }
  28305. _this.position.copy(origin);
  28306. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28307. color: color,
  28308. toneMapped: false
  28309. }));
  28310. _this.line.matrixAutoUpdate = false;
  28311. _this.add(_this.line);
  28312. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  28313. color: color,
  28314. toneMapped: false
  28315. }));
  28316. _this.cone.matrixAutoUpdate = false;
  28317. _this.add(_this.cone);
  28318. _this.setDirection(dir);
  28319. _this.setLength(length, headLength, headWidth);
  28320. return _this;
  28321. }
  28322. var _proto = ArrowHelper.prototype;
  28323. _proto.setDirection = function setDirection(dir) {
  28324. // dir is assumed to be normalized
  28325. if (dir.y > 0.99999) {
  28326. this.quaternion.set(0, 0, 0, 1);
  28327. } else if (dir.y < -0.99999) {
  28328. this.quaternion.set(1, 0, 0, 0);
  28329. } else {
  28330. _axis.set(dir.z, 0, -dir.x).normalize();
  28331. var radians = Math.acos(dir.y);
  28332. this.quaternion.setFromAxisAngle(_axis, radians);
  28333. }
  28334. };
  28335. _proto.setLength = function setLength(length, headLength, headWidth) {
  28336. if (headLength === undefined) headLength = 0.2 * length;
  28337. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28338. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  28339. this.line.updateMatrix();
  28340. this.cone.scale.set(headWidth, headLength, headWidth);
  28341. this.cone.position.y = length;
  28342. this.cone.updateMatrix();
  28343. };
  28344. _proto.setColor = function setColor(color) {
  28345. this.line.material.color.set(color);
  28346. this.cone.material.color.set(color);
  28347. };
  28348. _proto.copy = function copy(source) {
  28349. _Object3D.prototype.copy.call(this, source, false);
  28350. this.line.copy(source.line);
  28351. this.cone.copy(source.cone);
  28352. return this;
  28353. };
  28354. return ArrowHelper;
  28355. }(Object3D);
  28356. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  28357. _inheritsLoose(AxesHelper, _LineSegments);
  28358. function AxesHelper(size) {
  28359. var _this;
  28360. if (size === void 0) {
  28361. size = 1;
  28362. }
  28363. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  28364. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  28365. var geometry = new BufferGeometry();
  28366. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28367. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28368. var material = new LineBasicMaterial({
  28369. vertexColors: true,
  28370. toneMapped: false
  28371. });
  28372. _this = _LineSegments.call(this, geometry, material) || this;
  28373. _this.type = 'AxesHelper';
  28374. return _this;
  28375. }
  28376. return AxesHelper;
  28377. }(LineSegments);
  28378. var _floatView = new Float32Array(1);
  28379. var _int32View = new Int32Array(_floatView.buffer);
  28380. var DataUtils = {
  28381. // Converts float32 to float16 (stored as uint16 value).
  28382. toHalfFloat: function toHalfFloat(val) {
  28383. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  28384. /* This method is faster than the OpenEXR implementation (very often
  28385. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  28386. * by James Tursa?s half-precision code. */
  28387. _floatView[0] = val;
  28388. var x = _int32View[0];
  28389. var bits = x >> 16 & 0x8000;
  28390. /* Get the sign */
  28391. var m = x >> 12 & 0x07ff;
  28392. /* Keep one extra bit for rounding */
  28393. var e = x >> 23 & 0xff;
  28394. /* Using int is faster here */
  28395. /* If zero, or denormal, or exponent underflows too much for a denormal
  28396. * half, return signed zero. */
  28397. if (e < 103) return bits;
  28398. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  28399. if (e > 142) {
  28400. bits |= 0x7c00;
  28401. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  28402. * not Inf, so make sure we set one mantissa bit too. */
  28403. bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;
  28404. return bits;
  28405. }
  28406. /* If exponent underflows but not too much, return a denormal */
  28407. if (e < 113) {
  28408. m |= 0x0800;
  28409. /* Extra rounding may overflow and set mantissa to 0 and exponent
  28410. * to 1, which is OK. */
  28411. bits |= (m >> 114 - e) + (m >> 113 - e & 1);
  28412. return bits;
  28413. }
  28414. bits |= e - 112 << 10 | m >> 1;
  28415. /* Extra rounding. An overflow will set mantissa to 0 and increment
  28416. * the exponent, which is OK. */
  28417. bits += m & 1;
  28418. return bits;
  28419. }
  28420. };
  28421. var _ENCODINGS;
  28422. var LOD_MIN = 4;
  28423. var LOD_MAX = 8;
  28424. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  28425. // chosen to approximate a Trowbridge-Reitz distribution function times the
  28426. // geometric shadowing function. These sigma values squared must match the
  28427. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  28428. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  28429. 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
  28430. // samples and exit early, but not recompile the shader.
  28431. var MAX_SAMPLES = 20;
  28432. 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);
  28433. var backgroundMaterial = new MeshBasicMaterial({
  28434. side: BackSide,
  28435. depthWrite: false,
  28436. depthTest: false
  28437. });
  28438. var backgroundBox = new Mesh(new BoxGeometry(), backgroundMaterial);
  28439. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  28440. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  28441. _lodPlanes = _createPlanes2._lodPlanes,
  28442. _sizeLods = _createPlanes2._sizeLods,
  28443. _sigmas = _createPlanes2._sigmas;
  28444. var _clearColor = /*@__PURE__*/new Color();
  28445. var _oldTarget = null; // Golden Ratio
  28446. var PHI = (1 + Math.sqrt(5)) / 2;
  28447. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  28448. // same axis), used as axis directions evenly spread on a sphere.
  28449. 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)];
  28450. /**
  28451. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28452. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28453. * blur to be quickly accessed based on material roughness. It is packed into a
  28454. * special CubeUV format that allows us to perform custom interpolation so that
  28455. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  28456. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  28457. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  28458. * higher roughness levels. In this way we maintain resolution to smoothly
  28459. * interpolate diffuse lighting while limiting sampling computation.
  28460. */
  28461. function convertLinearToRGBE(color) {
  28462. var maxComponent = Math.max(color.r, color.g, color.b);
  28463. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  28464. color.multiplyScalar(Math.pow(2.0, -fExp));
  28465. var alpha = (fExp + 128.0) / 255.0;
  28466. return alpha;
  28467. }
  28468. var PMREMGenerator = /*#__PURE__*/function () {
  28469. function PMREMGenerator(renderer) {
  28470. this._renderer = renderer;
  28471. this._pingPongRenderTarget = null;
  28472. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  28473. this._equirectShader = null;
  28474. this._cubemapShader = null;
  28475. this._compileMaterial(this._blurMaterial);
  28476. }
  28477. /**
  28478. * Generates a PMREM from a supplied Scene, which can be faster than using an
  28479. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  28480. * in radians to be applied to the scene before PMREM generation. Optional near
  28481. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  28482. * is placed at the origin).
  28483. */
  28484. var _proto = PMREMGenerator.prototype;
  28485. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  28486. if (sigma === void 0) {
  28487. sigma = 0;
  28488. }
  28489. if (near === void 0) {
  28490. near = 0.1;
  28491. }
  28492. if (far === void 0) {
  28493. far = 100;
  28494. }
  28495. _oldTarget = this._renderer.getRenderTarget();
  28496. var cubeUVRenderTarget = this._allocateTargets();
  28497. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  28498. if (sigma > 0) {
  28499. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  28500. }
  28501. this._applyPMREM(cubeUVRenderTarget);
  28502. this._cleanup(cubeUVRenderTarget);
  28503. return cubeUVRenderTarget;
  28504. }
  28505. /**
  28506. * Generates a PMREM from an equirectangular texture, which can be either LDR
  28507. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  28508. * as this matches best with the 256 x 256 cubemap output.
  28509. */
  28510. ;
  28511. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  28512. return this._fromTexture(equirectangular);
  28513. }
  28514. /**
  28515. * Generates a PMREM from an cubemap texture, which can be either LDR
  28516. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  28517. * as this matches best with the 256 x 256 cubemap output.
  28518. */
  28519. ;
  28520. _proto.fromCubemap = function fromCubemap(cubemap) {
  28521. return this._fromTexture(cubemap);
  28522. }
  28523. /**
  28524. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  28525. * your texture's network fetch for increased concurrency.
  28526. */
  28527. ;
  28528. _proto.compileCubemapShader = function compileCubemapShader() {
  28529. if (this._cubemapShader === null) {
  28530. this._cubemapShader = _getCubemapShader();
  28531. this._compileMaterial(this._cubemapShader);
  28532. }
  28533. }
  28534. /**
  28535. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  28536. * your texture's network fetch for increased concurrency.
  28537. */
  28538. ;
  28539. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  28540. if (this._equirectShader === null) {
  28541. this._equirectShader = _getEquirectShader();
  28542. this._compileMaterial(this._equirectShader);
  28543. }
  28544. }
  28545. /**
  28546. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  28547. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  28548. * one of them will cause any others to also become unusable.
  28549. */
  28550. ;
  28551. _proto.dispose = function dispose() {
  28552. this._blurMaterial.dispose();
  28553. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  28554. if (this._equirectShader !== null) this._equirectShader.dispose();
  28555. for (var i = 0; i < _lodPlanes.length; i++) {
  28556. _lodPlanes[i].dispose();
  28557. }
  28558. } // private interface
  28559. ;
  28560. _proto._cleanup = function _cleanup(outputTarget) {
  28561. this._pingPongRenderTarget.dispose();
  28562. this._renderer.setRenderTarget(_oldTarget);
  28563. outputTarget.scissorTest = false;
  28564. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  28565. };
  28566. _proto._fromTexture = function _fromTexture(texture) {
  28567. _oldTarget = this._renderer.getRenderTarget();
  28568. var cubeUVRenderTarget = this._allocateTargets(texture);
  28569. this._textureToCubeUV(texture, cubeUVRenderTarget);
  28570. this._applyPMREM(cubeUVRenderTarget);
  28571. this._cleanup(cubeUVRenderTarget);
  28572. return cubeUVRenderTarget;
  28573. };
  28574. _proto._allocateTargets = function _allocateTargets(texture) {
  28575. // warning: null texture is valid
  28576. var params = {
  28577. magFilter: NearestFilter,
  28578. minFilter: NearestFilter,
  28579. generateMipmaps: false,
  28580. type: UnsignedByteType,
  28581. format: RGBEFormat,
  28582. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  28583. depthBuffer: false
  28584. };
  28585. var cubeUVRenderTarget = _createRenderTarget(params);
  28586. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  28587. this._pingPongRenderTarget = _createRenderTarget(params);
  28588. return cubeUVRenderTarget;
  28589. };
  28590. _proto._compileMaterial = function _compileMaterial(material) {
  28591. var tmpMesh = new Mesh(_lodPlanes[0], material);
  28592. this._renderer.compile(tmpMesh, _flatCamera);
  28593. };
  28594. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  28595. var fov = 90;
  28596. var aspect = 1;
  28597. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  28598. var upSign = [1, -1, 1, 1, 1, 1];
  28599. var forwardSign = [1, 1, 1, -1, -1, -1];
  28600. var renderer = this._renderer;
  28601. var originalAutoClear = renderer.autoClear;
  28602. var outputEncoding = renderer.outputEncoding;
  28603. var toneMapping = renderer.toneMapping;
  28604. renderer.getClearColor(_clearColor);
  28605. renderer.toneMapping = NoToneMapping;
  28606. renderer.outputEncoding = LinearEncoding;
  28607. renderer.autoClear = false;
  28608. var useSolidColor = false;
  28609. var background = scene.background;
  28610. if (background) {
  28611. if (background.isColor) {
  28612. backgroundMaterial.color.copy(background).convertSRGBToLinear();
  28613. scene.background = null;
  28614. var alpha = convertLinearToRGBE(backgroundMaterial.color);
  28615. backgroundMaterial.opacity = alpha;
  28616. useSolidColor = true;
  28617. }
  28618. } else {
  28619. backgroundMaterial.color.copy(_clearColor).convertSRGBToLinear();
  28620. var _alpha = convertLinearToRGBE(backgroundMaterial.color);
  28621. backgroundMaterial.opacity = _alpha;
  28622. useSolidColor = true;
  28623. }
  28624. for (var i = 0; i < 6; i++) {
  28625. var col = i % 3;
  28626. if (col == 0) {
  28627. cubeCamera.up.set(0, upSign[i], 0);
  28628. cubeCamera.lookAt(forwardSign[i], 0, 0);
  28629. } else if (col == 1) {
  28630. cubeCamera.up.set(0, 0, upSign[i]);
  28631. cubeCamera.lookAt(0, forwardSign[i], 0);
  28632. } else {
  28633. cubeCamera.up.set(0, upSign[i], 0);
  28634. cubeCamera.lookAt(0, 0, forwardSign[i]);
  28635. }
  28636. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  28637. renderer.setRenderTarget(cubeUVRenderTarget);
  28638. if (useSolidColor) {
  28639. renderer.render(backgroundBox, cubeCamera);
  28640. }
  28641. renderer.render(scene, cubeCamera);
  28642. }
  28643. renderer.toneMapping = toneMapping;
  28644. renderer.outputEncoding = outputEncoding;
  28645. renderer.autoClear = originalAutoClear;
  28646. };
  28647. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  28648. var renderer = this._renderer;
  28649. if (texture.isCubeTexture) {
  28650. if (this._cubemapShader == null) {
  28651. this._cubemapShader = _getCubemapShader();
  28652. }
  28653. } else {
  28654. if (this._equirectShader == null) {
  28655. this._equirectShader = _getEquirectShader();
  28656. }
  28657. }
  28658. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  28659. var mesh = new Mesh(_lodPlanes[0], material);
  28660. var uniforms = material.uniforms;
  28661. uniforms['envMap'].value = texture;
  28662. if (!texture.isCubeTexture) {
  28663. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  28664. }
  28665. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  28666. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  28667. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  28668. renderer.setRenderTarget(cubeUVRenderTarget);
  28669. renderer.render(mesh, _flatCamera);
  28670. };
  28671. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  28672. var renderer = this._renderer;
  28673. var autoClear = renderer.autoClear;
  28674. renderer.autoClear = false;
  28675. for (var i = 1; i < TOTAL_LODS; i++) {
  28676. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  28677. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  28678. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  28679. }
  28680. renderer.autoClear = autoClear;
  28681. }
  28682. /**
  28683. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  28684. * vertically and horizontally, but this breaks down on a cube. Here we apply
  28685. * the blur latitudinally (around the poles), and then longitudinally (towards
  28686. * the poles) to approximate the orthogonally-separable blur. It is least
  28687. * accurate at the poles, but still does a decent job.
  28688. */
  28689. ;
  28690. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  28691. var pingPongRenderTarget = this._pingPongRenderTarget;
  28692. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  28693. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  28694. };
  28695. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  28696. var renderer = this._renderer;
  28697. var blurMaterial = this._blurMaterial;
  28698. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  28699. console.error('blur direction must be either latitudinal or longitudinal!');
  28700. } // Number of standard deviations at which to cut off the discrete approximation.
  28701. var STANDARD_DEVIATIONS = 3;
  28702. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  28703. var blurUniforms = blurMaterial.uniforms;
  28704. var pixels = _sizeLods[lodIn] - 1;
  28705. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  28706. var sigmaPixels = sigmaRadians / radiansPerPixel;
  28707. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  28708. if (samples > MAX_SAMPLES) {
  28709. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  28710. }
  28711. var weights = [];
  28712. var sum = 0;
  28713. for (var i = 0; i < MAX_SAMPLES; ++i) {
  28714. var _x = i / sigmaPixels;
  28715. var weight = Math.exp(-_x * _x / 2);
  28716. weights.push(weight);
  28717. if (i == 0) {
  28718. sum += weight;
  28719. } else if (i < samples) {
  28720. sum += 2 * weight;
  28721. }
  28722. }
  28723. for (var _i = 0; _i < weights.length; _i++) {
  28724. weights[_i] = weights[_i] / sum;
  28725. }
  28726. blurUniforms['envMap'].value = targetIn.texture;
  28727. blurUniforms['samples'].value = samples;
  28728. blurUniforms['weights'].value = weights;
  28729. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  28730. if (poleAxis) {
  28731. blurUniforms['poleAxis'].value = poleAxis;
  28732. }
  28733. blurUniforms['dTheta'].value = radiansPerPixel;
  28734. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  28735. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28736. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28737. var outputSize = _sizeLods[lodOut];
  28738. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  28739. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  28740. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  28741. renderer.setRenderTarget(targetOut);
  28742. renderer.render(blurMesh, _flatCamera);
  28743. };
  28744. return PMREMGenerator;
  28745. }();
  28746. function _isLDR(texture) {
  28747. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  28748. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  28749. }
  28750. function _createPlanes() {
  28751. var _lodPlanes = [];
  28752. var _sizeLods = [];
  28753. var _sigmas = [];
  28754. var lod = LOD_MAX;
  28755. for (var i = 0; i < TOTAL_LODS; i++) {
  28756. var sizeLod = Math.pow(2, lod);
  28757. _sizeLods.push(sizeLod);
  28758. var sigma = 1.0 / sizeLod;
  28759. if (i > LOD_MAX - LOD_MIN) {
  28760. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  28761. } else if (i == 0) {
  28762. sigma = 0;
  28763. }
  28764. _sigmas.push(sigma);
  28765. var texelSize = 1.0 / (sizeLod - 1);
  28766. var min = -texelSize / 2;
  28767. var max = 1 + texelSize / 2;
  28768. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  28769. var cubeFaces = 6;
  28770. var vertices = 6;
  28771. var positionSize = 3;
  28772. var uvSize = 2;
  28773. var faceIndexSize = 1;
  28774. var position = new Float32Array(positionSize * vertices * cubeFaces);
  28775. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  28776. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  28777. for (var face = 0; face < cubeFaces; face++) {
  28778. var x = face % 3 * 2 / 3 - 1;
  28779. var y = face > 2 ? 0 : -1;
  28780. 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];
  28781. position.set(coordinates, positionSize * vertices * face);
  28782. uv.set(uv1, uvSize * vertices * face);
  28783. var fill = [face, face, face, face, face, face];
  28784. faceIndex.set(fill, faceIndexSize * vertices * face);
  28785. }
  28786. var planes = new BufferGeometry();
  28787. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  28788. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  28789. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  28790. _lodPlanes.push(planes);
  28791. if (lod > LOD_MIN) {
  28792. lod--;
  28793. }
  28794. }
  28795. return {
  28796. _lodPlanes: _lodPlanes,
  28797. _sizeLods: _sizeLods,
  28798. _sigmas: _sigmas
  28799. };
  28800. }
  28801. function _createRenderTarget(params) {
  28802. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  28803. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  28804. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  28805. cubeUVRenderTarget.scissorTest = true;
  28806. return cubeUVRenderTarget;
  28807. }
  28808. function _setViewport(target, x, y, width, height) {
  28809. target.viewport.set(x, y, width, height);
  28810. target.scissor.set(x, y, width, height);
  28811. }
  28812. function _getBlurShader(maxSamples) {
  28813. var weights = new Float32Array(maxSamples);
  28814. var poleAxis = new Vector3(0, 1, 0);
  28815. var shaderMaterial = new RawShaderMaterial({
  28816. name: 'SphericalGaussianBlur',
  28817. defines: {
  28818. 'n': maxSamples
  28819. },
  28820. uniforms: {
  28821. 'envMap': {
  28822. value: null
  28823. },
  28824. 'samples': {
  28825. value: 1
  28826. },
  28827. 'weights': {
  28828. value: weights
  28829. },
  28830. 'latitudinal': {
  28831. value: false
  28832. },
  28833. 'dTheta': {
  28834. value: 0
  28835. },
  28836. 'mipInt': {
  28837. value: 0
  28838. },
  28839. 'poleAxis': {
  28840. value: poleAxis
  28841. },
  28842. 'inputEncoding': {
  28843. value: ENCODINGS[LinearEncoding]
  28844. },
  28845. 'outputEncoding': {
  28846. value: ENCODINGS[LinearEncoding]
  28847. }
  28848. },
  28849. vertexShader: _getCommonVertexShader(),
  28850. fragmentShader:
  28851. /* glsl */
  28852. "\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",
  28853. blending: NoBlending,
  28854. depthTest: false,
  28855. depthWrite: false
  28856. });
  28857. return shaderMaterial;
  28858. }
  28859. function _getEquirectShader() {
  28860. var texelSize = new Vector2(1, 1);
  28861. var shaderMaterial = new RawShaderMaterial({
  28862. name: 'EquirectangularToCubeUV',
  28863. uniforms: {
  28864. 'envMap': {
  28865. value: null
  28866. },
  28867. 'texelSize': {
  28868. value: texelSize
  28869. },
  28870. 'inputEncoding': {
  28871. value: ENCODINGS[LinearEncoding]
  28872. },
  28873. 'outputEncoding': {
  28874. value: ENCODINGS[LinearEncoding]
  28875. }
  28876. },
  28877. vertexShader: _getCommonVertexShader(),
  28878. fragmentShader:
  28879. /* glsl */
  28880. "\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",
  28881. blending: NoBlending,
  28882. depthTest: false,
  28883. depthWrite: false
  28884. });
  28885. return shaderMaterial;
  28886. }
  28887. function _getCubemapShader() {
  28888. var shaderMaterial = new RawShaderMaterial({
  28889. name: 'CubemapToCubeUV',
  28890. uniforms: {
  28891. 'envMap': {
  28892. value: null
  28893. },
  28894. 'inputEncoding': {
  28895. value: ENCODINGS[LinearEncoding]
  28896. },
  28897. 'outputEncoding': {
  28898. value: ENCODINGS[LinearEncoding]
  28899. }
  28900. },
  28901. vertexShader: _getCommonVertexShader(),
  28902. fragmentShader:
  28903. /* glsl */
  28904. "\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",
  28905. blending: NoBlending,
  28906. depthTest: false,
  28907. depthWrite: false
  28908. });
  28909. return shaderMaterial;
  28910. }
  28911. function _getCommonVertexShader() {
  28912. return (
  28913. /* glsl */
  28914. "\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"
  28915. );
  28916. }
  28917. function _getEncodings() {
  28918. return (
  28919. /* glsl */
  28920. "\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"
  28921. );
  28922. }
  28923. function Face4(a, b, c, d, normal, color, materialIndex) {
  28924. console.warn('THREE.Face4 has been removed. A THREE.Face3 will be created instead.');
  28925. return new Face3(a, b, c, normal, color, materialIndex);
  28926. }
  28927. var LineStrip = 0;
  28928. var LinePieces = 1;
  28929. var NoColors = 0;
  28930. var FaceColors = 1;
  28931. var VertexColors = 2;
  28932. function MeshFaceMaterial(materials) {
  28933. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  28934. return materials;
  28935. }
  28936. function MultiMaterial(materials) {
  28937. if (materials === void 0) {
  28938. materials = [];
  28939. }
  28940. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  28941. materials.isMultiMaterial = true;
  28942. materials.materials = materials;
  28943. materials.clone = function () {
  28944. return materials.slice();
  28945. };
  28946. return materials;
  28947. }
  28948. function PointCloud(geometry, material) {
  28949. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  28950. return new Points(geometry, material);
  28951. }
  28952. function Particle(material) {
  28953. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  28954. return new Sprite(material);
  28955. }
  28956. function ParticleSystem(geometry, material) {
  28957. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  28958. return new Points(geometry, material);
  28959. }
  28960. function PointCloudMaterial(parameters) {
  28961. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  28962. return new PointsMaterial(parameters);
  28963. }
  28964. function ParticleBasicMaterial(parameters) {
  28965. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  28966. return new PointsMaterial(parameters);
  28967. }
  28968. function ParticleSystemMaterial(parameters) {
  28969. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  28970. return new PointsMaterial(parameters);
  28971. }
  28972. function Vertex(x, y, z) {
  28973. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  28974. return new Vector3(x, y, z);
  28975. } //
  28976. function DynamicBufferAttribute(array, itemSize) {
  28977. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  28978. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  28979. }
  28980. function Int8Attribute(array, itemSize) {
  28981. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  28982. return new Int8BufferAttribute(array, itemSize);
  28983. }
  28984. function Uint8Attribute(array, itemSize) {
  28985. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  28986. return new Uint8BufferAttribute(array, itemSize);
  28987. }
  28988. function Uint8ClampedAttribute(array, itemSize) {
  28989. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  28990. return new Uint8ClampedBufferAttribute(array, itemSize);
  28991. }
  28992. function Int16Attribute(array, itemSize) {
  28993. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  28994. return new Int16BufferAttribute(array, itemSize);
  28995. }
  28996. function Uint16Attribute(array, itemSize) {
  28997. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  28998. return new Uint16BufferAttribute(array, itemSize);
  28999. }
  29000. function Int32Attribute(array, itemSize) {
  29001. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  29002. return new Int32BufferAttribute(array, itemSize);
  29003. }
  29004. function Uint32Attribute(array, itemSize) {
  29005. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  29006. return new Uint32BufferAttribute(array, itemSize);
  29007. }
  29008. function Float32Attribute(array, itemSize) {
  29009. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  29010. return new Float32BufferAttribute(array, itemSize);
  29011. }
  29012. function Float64Attribute(array, itemSize) {
  29013. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  29014. return new Float64BufferAttribute(array, itemSize);
  29015. } //
  29016. Curve.create = function (construct, getPoint) {
  29017. console.log('THREE.Curve.create() has been deprecated');
  29018. construct.prototype = Object.create(Curve.prototype);
  29019. construct.prototype.constructor = construct;
  29020. construct.prototype.getPoint = getPoint;
  29021. return construct;
  29022. }; //
  29023. Object.assign(Path.prototype, {
  29024. fromPoints: function fromPoints(points) {
  29025. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  29026. return this.setFromPoints(points);
  29027. }
  29028. }); //
  29029. function ClosedSplineCurve3(points) {
  29030. console.warn('THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29031. CatmullRomCurve3.call(this, points);
  29032. this.type = 'catmullrom';
  29033. this.closed = true;
  29034. }
  29035. ClosedSplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29036. function SplineCurve3(points) {
  29037. console.warn('THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29038. CatmullRomCurve3.call(this, points);
  29039. this.type = 'catmullrom';
  29040. }
  29041. SplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29042. function Spline(points) {
  29043. console.warn('THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.');
  29044. CatmullRomCurve3.call(this, points);
  29045. this.type = 'catmullrom';
  29046. }
  29047. Spline.prototype = Object.create(CatmullRomCurve3.prototype);
  29048. Object.assign(Spline.prototype, {
  29049. initFromArray: function initFromArray()
  29050. /* a */
  29051. {
  29052. console.error('THREE.Spline: .initFromArray() has been removed.');
  29053. },
  29054. getControlPointsArray: function getControlPointsArray()
  29055. /* optionalTarget */
  29056. {
  29057. console.error('THREE.Spline: .getControlPointsArray() has been removed.');
  29058. },
  29059. reparametrizeByArcLength: function reparametrizeByArcLength()
  29060. /* samplingCoef */
  29061. {
  29062. console.error('THREE.Spline: .reparametrizeByArcLength() has been removed.');
  29063. }
  29064. }); //
  29065. function AxisHelper(size) {
  29066. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  29067. return new AxesHelper(size);
  29068. }
  29069. function BoundingBoxHelper(object, color) {
  29070. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  29071. return new BoxHelper(object, color);
  29072. }
  29073. function EdgesHelper(object, hex) {
  29074. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  29075. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  29076. color: hex !== undefined ? hex : 0xffffff
  29077. }));
  29078. }
  29079. GridHelper.prototype.setColors = function () {
  29080. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  29081. };
  29082. SkeletonHelper.prototype.update = function () {
  29083. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  29084. };
  29085. function WireframeHelper(object, hex) {
  29086. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  29087. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  29088. color: hex !== undefined ? hex : 0xffffff
  29089. }));
  29090. } //
  29091. Object.assign(Loader.prototype, {
  29092. extractUrlBase: function extractUrlBase(url) {
  29093. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  29094. return LoaderUtils.extractUrlBase(url);
  29095. }
  29096. });
  29097. Loader.Handlers = {
  29098. add: function add()
  29099. /* regex, loader */
  29100. {
  29101. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  29102. },
  29103. get: function get()
  29104. /* file */
  29105. {
  29106. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  29107. }
  29108. };
  29109. function XHRLoader(manager) {
  29110. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  29111. return new FileLoader(manager);
  29112. }
  29113. function BinaryTextureLoader(manager) {
  29114. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  29115. return new DataTextureLoader(manager);
  29116. } //
  29117. Object.assign(Box2.prototype, {
  29118. center: function center(optionalTarget) {
  29119. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  29120. return this.getCenter(optionalTarget);
  29121. },
  29122. empty: function empty() {
  29123. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  29124. return this.isEmpty();
  29125. },
  29126. isIntersectionBox: function isIntersectionBox(box) {
  29127. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  29128. return this.intersectsBox(box);
  29129. },
  29130. size: function size(optionalTarget) {
  29131. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  29132. return this.getSize(optionalTarget);
  29133. }
  29134. });
  29135. Object.assign(Box3.prototype, {
  29136. center: function center(optionalTarget) {
  29137. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  29138. return this.getCenter(optionalTarget);
  29139. },
  29140. empty: function empty() {
  29141. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  29142. return this.isEmpty();
  29143. },
  29144. isIntersectionBox: function isIntersectionBox(box) {
  29145. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  29146. return this.intersectsBox(box);
  29147. },
  29148. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29149. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29150. return this.intersectsSphere(sphere);
  29151. },
  29152. size: function size(optionalTarget) {
  29153. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  29154. return this.getSize(optionalTarget);
  29155. }
  29156. });
  29157. Object.assign(Sphere.prototype, {
  29158. empty: function empty() {
  29159. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  29160. return this.isEmpty();
  29161. }
  29162. });
  29163. Frustum.prototype.setFromMatrix = function (m) {
  29164. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  29165. return this.setFromProjectionMatrix(m);
  29166. };
  29167. Line3.prototype.center = function (optionalTarget) {
  29168. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  29169. return this.getCenter(optionalTarget);
  29170. };
  29171. Object.assign(MathUtils, {
  29172. random16: function random16() {
  29173. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  29174. return Math.random();
  29175. },
  29176. nearestPowerOfTwo: function nearestPowerOfTwo(value) {
  29177. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  29178. return MathUtils.floorPowerOfTwo(value);
  29179. },
  29180. nextPowerOfTwo: function nextPowerOfTwo(value) {
  29181. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29182. return MathUtils.ceilPowerOfTwo(value);
  29183. }
  29184. });
  29185. Object.assign(Matrix3.prototype, {
  29186. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29187. console.warn('THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29188. return this.toArray(array, offset);
  29189. },
  29190. multiplyVector3: function multiplyVector3(vector) {
  29191. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29192. return vector.applyMatrix3(this);
  29193. },
  29194. multiplyVector3Array: function multiplyVector3Array()
  29195. /* a */
  29196. {
  29197. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29198. },
  29199. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29200. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29201. return attribute.applyMatrix3(this);
  29202. },
  29203. applyToVector3Array: function applyToVector3Array()
  29204. /* array, offset, length */
  29205. {
  29206. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29207. },
  29208. getInverse: function getInverse(matrix) {
  29209. console.warn('THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29210. return this.copy(matrix).invert();
  29211. }
  29212. });
  29213. Object.assign(Matrix4.prototype, {
  29214. extractPosition: function extractPosition(m) {
  29215. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29216. return this.copyPosition(m);
  29217. },
  29218. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29219. console.warn('THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29220. return this.toArray(array, offset);
  29221. },
  29222. getPosition: function getPosition() {
  29223. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29224. return new Vector3().setFromMatrixColumn(this, 3);
  29225. },
  29226. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  29227. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29228. return this.makeRotationFromQuaternion(q);
  29229. },
  29230. multiplyToArray: function multiplyToArray() {
  29231. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29232. },
  29233. multiplyVector3: function multiplyVector3(vector) {
  29234. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29235. return vector.applyMatrix4(this);
  29236. },
  29237. multiplyVector4: function multiplyVector4(vector) {
  29238. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29239. return vector.applyMatrix4(this);
  29240. },
  29241. multiplyVector3Array: function multiplyVector3Array()
  29242. /* a */
  29243. {
  29244. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29245. },
  29246. rotateAxis: function rotateAxis(v) {
  29247. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29248. v.transformDirection(this);
  29249. },
  29250. crossVector: function crossVector(vector) {
  29251. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29252. return vector.applyMatrix4(this);
  29253. },
  29254. translate: function translate() {
  29255. console.error('THREE.Matrix4: .translate() has been removed.');
  29256. },
  29257. rotateX: function rotateX() {
  29258. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29259. },
  29260. rotateY: function rotateY() {
  29261. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29262. },
  29263. rotateZ: function rotateZ() {
  29264. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29265. },
  29266. rotateByAxis: function rotateByAxis() {
  29267. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29268. },
  29269. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29270. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29271. return attribute.applyMatrix4(this);
  29272. },
  29273. applyToVector3Array: function applyToVector3Array()
  29274. /* array, offset, length */
  29275. {
  29276. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29277. },
  29278. makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
  29279. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29280. return this.makePerspective(left, right, top, bottom, near, far);
  29281. },
  29282. getInverse: function getInverse(matrix) {
  29283. console.warn('THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29284. return this.copy(matrix).invert();
  29285. }
  29286. });
  29287. Plane.prototype.isIntersectionLine = function (line) {
  29288. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29289. return this.intersectsLine(line);
  29290. };
  29291. Object.assign(Quaternion.prototype, {
  29292. multiplyVector3: function multiplyVector3(vector) {
  29293. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29294. return vector.applyQuaternion(this);
  29295. },
  29296. inverse: function inverse() {
  29297. console.warn('THREE.Quaternion: .inverse() has been renamed to invert().');
  29298. return this.invert();
  29299. }
  29300. });
  29301. Object.assign(Ray.prototype, {
  29302. isIntersectionBox: function isIntersectionBox(box) {
  29303. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29304. return this.intersectsBox(box);
  29305. },
  29306. isIntersectionPlane: function isIntersectionPlane(plane) {
  29307. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29308. return this.intersectsPlane(plane);
  29309. },
  29310. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29311. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29312. return this.intersectsSphere(sphere);
  29313. }
  29314. });
  29315. Object.assign(Triangle.prototype, {
  29316. area: function area() {
  29317. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  29318. return this.getArea();
  29319. },
  29320. barycoordFromPoint: function barycoordFromPoint(point, target) {
  29321. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29322. return this.getBarycoord(point, target);
  29323. },
  29324. midpoint: function midpoint(target) {
  29325. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  29326. return this.getMidpoint(target);
  29327. },
  29328. normal: function normal(target) {
  29329. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29330. return this.getNormal(target);
  29331. },
  29332. plane: function plane(target) {
  29333. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  29334. return this.getPlane(target);
  29335. }
  29336. });
  29337. Object.assign(Triangle, {
  29338. barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
  29339. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29340. return Triangle.getBarycoord(point, a, b, c, target);
  29341. },
  29342. normal: function normal(a, b, c, target) {
  29343. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29344. return Triangle.getNormal(a, b, c, target);
  29345. }
  29346. });
  29347. Object.assign(Shape.prototype, {
  29348. extractAllPoints: function extractAllPoints(divisions) {
  29349. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  29350. return this.extractPoints(divisions);
  29351. },
  29352. extrude: function extrude(options) {
  29353. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  29354. return new ExtrudeGeometry(this, options);
  29355. },
  29356. makeGeometry: function makeGeometry(options) {
  29357. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  29358. return new ShapeGeometry(this, options);
  29359. }
  29360. });
  29361. Object.assign(Vector2.prototype, {
  29362. fromAttribute: function fromAttribute(attribute, index, offset) {
  29363. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29364. return this.fromBufferAttribute(attribute, index, offset);
  29365. },
  29366. distanceToManhattan: function distanceToManhattan(v) {
  29367. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29368. return this.manhattanDistanceTo(v);
  29369. },
  29370. lengthManhattan: function lengthManhattan() {
  29371. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  29372. return this.manhattanLength();
  29373. }
  29374. });
  29375. Object.assign(Vector3.prototype, {
  29376. setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
  29377. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  29378. },
  29379. setEulerFromQuaternion: function setEulerFromQuaternion() {
  29380. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  29381. },
  29382. getPositionFromMatrix: function getPositionFromMatrix(m) {
  29383. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  29384. return this.setFromMatrixPosition(m);
  29385. },
  29386. getScaleFromMatrix: function getScaleFromMatrix(m) {
  29387. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  29388. return this.setFromMatrixScale(m);
  29389. },
  29390. getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
  29391. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  29392. return this.setFromMatrixColumn(matrix, index);
  29393. },
  29394. applyProjection: function applyProjection(m) {
  29395. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  29396. return this.applyMatrix4(m);
  29397. },
  29398. fromAttribute: function fromAttribute(attribute, index, offset) {
  29399. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29400. return this.fromBufferAttribute(attribute, index, offset);
  29401. },
  29402. distanceToManhattan: function distanceToManhattan(v) {
  29403. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29404. return this.manhattanDistanceTo(v);
  29405. },
  29406. lengthManhattan: function lengthManhattan() {
  29407. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  29408. return this.manhattanLength();
  29409. }
  29410. });
  29411. Object.assign(Vector4.prototype, {
  29412. fromAttribute: function fromAttribute(attribute, index, offset) {
  29413. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29414. return this.fromBufferAttribute(attribute, index, offset);
  29415. },
  29416. lengthManhattan: function lengthManhattan() {
  29417. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  29418. return this.manhattanLength();
  29419. }
  29420. }); //
  29421. Object.assign(Object3D.prototype, {
  29422. getChildByName: function getChildByName(name) {
  29423. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  29424. return this.getObjectByName(name);
  29425. },
  29426. renderDepth: function renderDepth() {
  29427. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  29428. },
  29429. translate: function translate(distance, axis) {
  29430. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  29431. return this.translateOnAxis(axis, distance);
  29432. },
  29433. getWorldRotation: function getWorldRotation() {
  29434. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  29435. },
  29436. applyMatrix: function applyMatrix(matrix) {
  29437. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  29438. return this.applyMatrix4(matrix);
  29439. }
  29440. });
  29441. Object.defineProperties(Object3D.prototype, {
  29442. eulerOrder: {
  29443. get: function get() {
  29444. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29445. return this.rotation.order;
  29446. },
  29447. set: function set(value) {
  29448. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29449. this.rotation.order = value;
  29450. }
  29451. },
  29452. useQuaternion: {
  29453. get: function get() {
  29454. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29455. },
  29456. set: function set() {
  29457. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29458. }
  29459. }
  29460. });
  29461. Object.assign(Mesh.prototype, {
  29462. setDrawMode: function setDrawMode() {
  29463. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29464. }
  29465. });
  29466. Object.defineProperties(Mesh.prototype, {
  29467. drawMode: {
  29468. get: function get() {
  29469. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  29470. return TrianglesDrawMode;
  29471. },
  29472. set: function set() {
  29473. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29474. }
  29475. }
  29476. });
  29477. Object.defineProperties(LOD.prototype, {
  29478. objects: {
  29479. get: function get() {
  29480. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  29481. return this.levels;
  29482. }
  29483. }
  29484. });
  29485. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  29486. get: function get() {
  29487. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29488. },
  29489. set: function set() {
  29490. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29491. }
  29492. });
  29493. SkinnedMesh.prototype.initBones = function () {
  29494. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  29495. };
  29496. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  29497. get: function get() {
  29498. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29499. return this.arcLengthDivisions;
  29500. },
  29501. set: function set(value) {
  29502. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29503. this.arcLengthDivisions = value;
  29504. }
  29505. }); //
  29506. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  29507. console.warn('THREE.PerspectiveCamera.setLens is deprecated. ' + 'Use .setFocalLength and .filmGauge for a photographic setup.');
  29508. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  29509. this.setFocalLength(focalLength);
  29510. }; //
  29511. Object.defineProperties(Light.prototype, {
  29512. onlyShadow: {
  29513. set: function set() {
  29514. console.warn('THREE.Light: .onlyShadow has been removed.');
  29515. }
  29516. },
  29517. shadowCameraFov: {
  29518. set: function set(value) {
  29519. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  29520. this.shadow.camera.fov = value;
  29521. }
  29522. },
  29523. shadowCameraLeft: {
  29524. set: function set(value) {
  29525. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  29526. this.shadow.camera.left = value;
  29527. }
  29528. },
  29529. shadowCameraRight: {
  29530. set: function set(value) {
  29531. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  29532. this.shadow.camera.right = value;
  29533. }
  29534. },
  29535. shadowCameraTop: {
  29536. set: function set(value) {
  29537. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  29538. this.shadow.camera.top = value;
  29539. }
  29540. },
  29541. shadowCameraBottom: {
  29542. set: function set(value) {
  29543. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  29544. this.shadow.camera.bottom = value;
  29545. }
  29546. },
  29547. shadowCameraNear: {
  29548. set: function set(value) {
  29549. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  29550. this.shadow.camera.near = value;
  29551. }
  29552. },
  29553. shadowCameraFar: {
  29554. set: function set(value) {
  29555. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  29556. this.shadow.camera.far = value;
  29557. }
  29558. },
  29559. shadowCameraVisible: {
  29560. set: function set() {
  29561. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  29562. }
  29563. },
  29564. shadowBias: {
  29565. set: function set(value) {
  29566. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  29567. this.shadow.bias = value;
  29568. }
  29569. },
  29570. shadowDarkness: {
  29571. set: function set() {
  29572. console.warn('THREE.Light: .shadowDarkness has been removed.');
  29573. }
  29574. },
  29575. shadowMapWidth: {
  29576. set: function set(value) {
  29577. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  29578. this.shadow.mapSize.width = value;
  29579. }
  29580. },
  29581. shadowMapHeight: {
  29582. set: function set(value) {
  29583. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  29584. this.shadow.mapSize.height = value;
  29585. }
  29586. }
  29587. }); //
  29588. Object.defineProperties(BufferAttribute.prototype, {
  29589. length: {
  29590. get: function get() {
  29591. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  29592. return this.array.length;
  29593. }
  29594. },
  29595. dynamic: {
  29596. get: function get() {
  29597. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29598. return this.usage === DynamicDrawUsage;
  29599. },
  29600. set: function set()
  29601. /* value */
  29602. {
  29603. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29604. this.setUsage(DynamicDrawUsage);
  29605. }
  29606. }
  29607. });
  29608. Object.assign(BufferAttribute.prototype, {
  29609. setDynamic: function setDynamic(value) {
  29610. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29611. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29612. return this;
  29613. },
  29614. copyIndicesArray: function copyIndicesArray()
  29615. /* indices */
  29616. {
  29617. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  29618. },
  29619. setArray: function setArray()
  29620. /* array */
  29621. {
  29622. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29623. }
  29624. });
  29625. Object.assign(BufferGeometry.prototype, {
  29626. addIndex: function addIndex(index) {
  29627. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  29628. this.setIndex(index);
  29629. },
  29630. addAttribute: function addAttribute(name, attribute) {
  29631. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  29632. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  29633. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  29634. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  29635. }
  29636. if (name === 'index') {
  29637. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  29638. this.setIndex(attribute);
  29639. return this;
  29640. }
  29641. return this.setAttribute(name, attribute);
  29642. },
  29643. addDrawCall: function addDrawCall(start, count, indexOffset) {
  29644. if (indexOffset !== undefined) {
  29645. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  29646. }
  29647. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  29648. this.addGroup(start, count);
  29649. },
  29650. clearDrawCalls: function clearDrawCalls() {
  29651. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  29652. this.clearGroups();
  29653. },
  29654. computeOffsets: function computeOffsets() {
  29655. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  29656. },
  29657. removeAttribute: function removeAttribute(name) {
  29658. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  29659. return this.deleteAttribute(name);
  29660. },
  29661. applyMatrix: function applyMatrix(matrix) {
  29662. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29663. return this.applyMatrix4(matrix);
  29664. }
  29665. });
  29666. Object.defineProperties(BufferGeometry.prototype, {
  29667. drawcalls: {
  29668. get: function get() {
  29669. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  29670. return this.groups;
  29671. }
  29672. },
  29673. offsets: {
  29674. get: function get() {
  29675. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  29676. return this.groups;
  29677. }
  29678. }
  29679. });
  29680. Object.defineProperties(InstancedBufferGeometry.prototype, {
  29681. maxInstancedCount: {
  29682. get: function get() {
  29683. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29684. return this.instanceCount;
  29685. },
  29686. set: function set(value) {
  29687. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29688. this.instanceCount = value;
  29689. }
  29690. }
  29691. });
  29692. Object.defineProperties(Raycaster.prototype, {
  29693. linePrecision: {
  29694. get: function get() {
  29695. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29696. return this.params.Line.threshold;
  29697. },
  29698. set: function set(value) {
  29699. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29700. this.params.Line.threshold = value;
  29701. }
  29702. }
  29703. });
  29704. Object.defineProperties(InterleavedBuffer.prototype, {
  29705. dynamic: {
  29706. get: function get() {
  29707. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29708. return this.usage === DynamicDrawUsage;
  29709. },
  29710. set: function set(value) {
  29711. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29712. this.setUsage(value);
  29713. }
  29714. }
  29715. });
  29716. Object.assign(InterleavedBuffer.prototype, {
  29717. setDynamic: function setDynamic(value) {
  29718. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29719. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29720. return this;
  29721. },
  29722. setArray: function setArray()
  29723. /* array */
  29724. {
  29725. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29726. }
  29727. }); //
  29728. Object.assign(ExtrudeGeometry.prototype, {
  29729. getArrays: function getArrays() {
  29730. console.error('THREE.ExtrudeGeometry: .getArrays() has been removed.');
  29731. },
  29732. addShapeList: function addShapeList() {
  29733. console.error('THREE.ExtrudeGeometry: .addShapeList() has been removed.');
  29734. },
  29735. addShape: function addShape() {
  29736. console.error('THREE.ExtrudeGeometry: .addShape() has been removed.');
  29737. }
  29738. }); //
  29739. Object.assign(Scene.prototype, {
  29740. dispose: function dispose() {
  29741. console.error('THREE.Scene: .dispose() has been removed.');
  29742. }
  29743. }); //
  29744. Object.defineProperties(Uniform.prototype, {
  29745. dynamic: {
  29746. set: function set() {
  29747. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  29748. }
  29749. },
  29750. onUpdate: {
  29751. value: function value() {
  29752. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  29753. return this;
  29754. }
  29755. }
  29756. }); //
  29757. Object.defineProperties(Material.prototype, {
  29758. wrapAround: {
  29759. get: function get() {
  29760. console.warn('THREE.Material: .wrapAround has been removed.');
  29761. },
  29762. set: function set() {
  29763. console.warn('THREE.Material: .wrapAround has been removed.');
  29764. }
  29765. },
  29766. overdraw: {
  29767. get: function get() {
  29768. console.warn('THREE.Material: .overdraw has been removed.');
  29769. },
  29770. set: function set() {
  29771. console.warn('THREE.Material: .overdraw has been removed.');
  29772. }
  29773. },
  29774. wrapRGB: {
  29775. get: function get() {
  29776. console.warn('THREE.Material: .wrapRGB has been removed.');
  29777. return new Color();
  29778. }
  29779. },
  29780. shading: {
  29781. get: function get() {
  29782. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29783. },
  29784. set: function set(value) {
  29785. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29786. this.flatShading = value === FlatShading;
  29787. }
  29788. },
  29789. stencilMask: {
  29790. get: function get() {
  29791. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29792. return this.stencilFuncMask;
  29793. },
  29794. set: function set(value) {
  29795. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29796. this.stencilFuncMask = value;
  29797. }
  29798. }
  29799. });
  29800. Object.defineProperties(MeshPhongMaterial.prototype, {
  29801. metal: {
  29802. get: function get() {
  29803. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  29804. return false;
  29805. },
  29806. set: function set() {
  29807. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  29808. }
  29809. }
  29810. });
  29811. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  29812. transparency: {
  29813. get: function get() {
  29814. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29815. return this.transmission;
  29816. },
  29817. set: function set(value) {
  29818. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29819. this.transmission = value;
  29820. }
  29821. }
  29822. });
  29823. Object.defineProperties(ShaderMaterial.prototype, {
  29824. derivatives: {
  29825. get: function get() {
  29826. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29827. return this.extensions.derivatives;
  29828. },
  29829. set: function set(value) {
  29830. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29831. this.extensions.derivatives = value;
  29832. }
  29833. }
  29834. }); //
  29835. Object.assign(WebGLRenderer.prototype, {
  29836. clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
  29837. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  29838. this.setRenderTarget(renderTarget);
  29839. this.clear(color, depth, stencil);
  29840. },
  29841. animate: function animate(callback) {
  29842. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  29843. this.setAnimationLoop(callback);
  29844. },
  29845. getCurrentRenderTarget: function getCurrentRenderTarget() {
  29846. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  29847. return this.getRenderTarget();
  29848. },
  29849. getMaxAnisotropy: function getMaxAnisotropy() {
  29850. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  29851. return this.capabilities.getMaxAnisotropy();
  29852. },
  29853. getPrecision: function getPrecision() {
  29854. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  29855. return this.capabilities.precision;
  29856. },
  29857. resetGLState: function resetGLState() {
  29858. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  29859. return this.state.reset();
  29860. },
  29861. supportsFloatTextures: function supportsFloatTextures() {
  29862. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  29863. return this.extensions.get('OES_texture_float');
  29864. },
  29865. supportsHalfFloatTextures: function supportsHalfFloatTextures() {
  29866. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  29867. return this.extensions.get('OES_texture_half_float');
  29868. },
  29869. supportsStandardDerivatives: function supportsStandardDerivatives() {
  29870. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  29871. return this.extensions.get('OES_standard_derivatives');
  29872. },
  29873. supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
  29874. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  29875. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  29876. },
  29877. supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
  29878. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  29879. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  29880. },
  29881. supportsBlendMinMax: function supportsBlendMinMax() {
  29882. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  29883. return this.extensions.get('EXT_blend_minmax');
  29884. },
  29885. supportsVertexTextures: function supportsVertexTextures() {
  29886. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  29887. return this.capabilities.vertexTextures;
  29888. },
  29889. supportsInstancedArrays: function supportsInstancedArrays() {
  29890. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  29891. return this.extensions.get('ANGLE_instanced_arrays');
  29892. },
  29893. enableScissorTest: function enableScissorTest(boolean) {
  29894. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  29895. this.setScissorTest(boolean);
  29896. },
  29897. initMaterial: function initMaterial() {
  29898. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  29899. },
  29900. addPrePlugin: function addPrePlugin() {
  29901. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  29902. },
  29903. addPostPlugin: function addPostPlugin() {
  29904. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  29905. },
  29906. updateShadowMap: function updateShadowMap() {
  29907. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  29908. },
  29909. setFaceCulling: function setFaceCulling() {
  29910. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  29911. },
  29912. allocTextureUnit: function allocTextureUnit() {
  29913. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  29914. },
  29915. setTexture: function setTexture() {
  29916. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  29917. },
  29918. setTexture2D: function setTexture2D() {
  29919. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  29920. },
  29921. setTextureCube: function setTextureCube() {
  29922. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  29923. },
  29924. getActiveMipMapLevel: function getActiveMipMapLevel() {
  29925. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  29926. return this.getActiveMipmapLevel();
  29927. }
  29928. });
  29929. Object.defineProperties(WebGLRenderer.prototype, {
  29930. shadowMapEnabled: {
  29931. get: function get() {
  29932. return this.shadowMap.enabled;
  29933. },
  29934. set: function set(value) {
  29935. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  29936. this.shadowMap.enabled = value;
  29937. }
  29938. },
  29939. shadowMapType: {
  29940. get: function get() {
  29941. return this.shadowMap.type;
  29942. },
  29943. set: function set(value) {
  29944. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  29945. this.shadowMap.type = value;
  29946. }
  29947. },
  29948. shadowMapCullFace: {
  29949. get: function get() {
  29950. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  29951. return undefined;
  29952. },
  29953. set: function set()
  29954. /* value */
  29955. {
  29956. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  29957. }
  29958. },
  29959. context: {
  29960. get: function get() {
  29961. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  29962. return this.getContext();
  29963. }
  29964. },
  29965. vr: {
  29966. get: function get() {
  29967. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  29968. return this.xr;
  29969. }
  29970. },
  29971. gammaInput: {
  29972. get: function get() {
  29973. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  29974. return false;
  29975. },
  29976. set: function set() {
  29977. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  29978. }
  29979. },
  29980. gammaOutput: {
  29981. get: function get() {
  29982. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  29983. return false;
  29984. },
  29985. set: function set(value) {
  29986. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  29987. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  29988. }
  29989. },
  29990. toneMappingWhitePoint: {
  29991. get: function get() {
  29992. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  29993. return 1.0;
  29994. },
  29995. set: function set() {
  29996. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  29997. }
  29998. }
  29999. });
  30000. Object.defineProperties(WebGLShadowMap.prototype, {
  30001. cullFace: {
  30002. get: function get() {
  30003. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30004. return undefined;
  30005. },
  30006. set: function set()
  30007. /* cullFace */
  30008. {
  30009. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30010. }
  30011. },
  30012. renderReverseSided: {
  30013. get: function get() {
  30014. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30015. return undefined;
  30016. },
  30017. set: function set() {
  30018. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30019. }
  30020. },
  30021. renderSingleSided: {
  30022. get: function get() {
  30023. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30024. return undefined;
  30025. },
  30026. set: function set() {
  30027. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30028. }
  30029. }
  30030. });
  30031. function WebGLRenderTargetCube(width, height, options) {
  30032. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  30033. return new WebGLCubeRenderTarget(width, options);
  30034. } //
  30035. Object.defineProperties(WebGLRenderTarget.prototype, {
  30036. wrapS: {
  30037. get: function get() {
  30038. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30039. return this.texture.wrapS;
  30040. },
  30041. set: function set(value) {
  30042. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30043. this.texture.wrapS = value;
  30044. }
  30045. },
  30046. wrapT: {
  30047. get: function get() {
  30048. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30049. return this.texture.wrapT;
  30050. },
  30051. set: function set(value) {
  30052. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30053. this.texture.wrapT = value;
  30054. }
  30055. },
  30056. magFilter: {
  30057. get: function get() {
  30058. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30059. return this.texture.magFilter;
  30060. },
  30061. set: function set(value) {
  30062. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30063. this.texture.magFilter = value;
  30064. }
  30065. },
  30066. minFilter: {
  30067. get: function get() {
  30068. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30069. return this.texture.minFilter;
  30070. },
  30071. set: function set(value) {
  30072. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30073. this.texture.minFilter = value;
  30074. }
  30075. },
  30076. anisotropy: {
  30077. get: function get() {
  30078. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30079. return this.texture.anisotropy;
  30080. },
  30081. set: function set(value) {
  30082. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30083. this.texture.anisotropy = value;
  30084. }
  30085. },
  30086. offset: {
  30087. get: function get() {
  30088. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30089. return this.texture.offset;
  30090. },
  30091. set: function set(value) {
  30092. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30093. this.texture.offset = value;
  30094. }
  30095. },
  30096. repeat: {
  30097. get: function get() {
  30098. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30099. return this.texture.repeat;
  30100. },
  30101. set: function set(value) {
  30102. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30103. this.texture.repeat = value;
  30104. }
  30105. },
  30106. format: {
  30107. get: function get() {
  30108. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30109. return this.texture.format;
  30110. },
  30111. set: function set(value) {
  30112. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30113. this.texture.format = value;
  30114. }
  30115. },
  30116. type: {
  30117. get: function get() {
  30118. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30119. return this.texture.type;
  30120. },
  30121. set: function set(value) {
  30122. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30123. this.texture.type = value;
  30124. }
  30125. },
  30126. generateMipmaps: {
  30127. get: function get() {
  30128. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30129. return this.texture.generateMipmaps;
  30130. },
  30131. set: function set(value) {
  30132. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30133. this.texture.generateMipmaps = value;
  30134. }
  30135. }
  30136. }); //
  30137. Object.defineProperties(Audio.prototype, {
  30138. load: {
  30139. value: function value(file) {
  30140. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  30141. var scope = this;
  30142. var audioLoader = new AudioLoader();
  30143. audioLoader.load(file, function (buffer) {
  30144. scope.setBuffer(buffer);
  30145. });
  30146. return this;
  30147. }
  30148. },
  30149. startTime: {
  30150. set: function set() {
  30151. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  30152. }
  30153. }
  30154. });
  30155. AudioAnalyser.prototype.getData = function () {
  30156. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  30157. return this.getFrequencyData();
  30158. }; //
  30159. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  30160. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  30161. return this.update(renderer, scene);
  30162. };
  30163. CubeCamera.prototype.clear = function (renderer, color, depth, stencil) {
  30164. console.warn('THREE.CubeCamera: .clear() is now .renderTarget.clear().');
  30165. return this.renderTarget.clear(renderer, color, depth, stencil);
  30166. }; //
  30167. var GeometryUtils = {
  30168. merge: function merge(geometry1, geometry2, materialIndexOffset) {
  30169. console.warn('THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.');
  30170. var matrix;
  30171. if (geometry2.isMesh) {
  30172. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  30173. matrix = geometry2.matrix;
  30174. geometry2 = geometry2.geometry;
  30175. }
  30176. geometry1.merge(geometry2, matrix, materialIndexOffset);
  30177. },
  30178. center: function center(geometry) {
  30179. console.warn('THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.');
  30180. return geometry.center();
  30181. }
  30182. };
  30183. ImageUtils.crossOrigin = undefined;
  30184. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30185. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30186. var loader = new TextureLoader();
  30187. loader.setCrossOrigin(this.crossOrigin);
  30188. var texture = loader.load(url, onLoad, undefined, onError);
  30189. if (mapping) texture.mapping = mapping;
  30190. return texture;
  30191. };
  30192. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30193. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30194. var loader = new CubeTextureLoader();
  30195. loader.setCrossOrigin(this.crossOrigin);
  30196. var texture = loader.load(urls, onLoad, undefined, onError);
  30197. if (mapping) texture.mapping = mapping;
  30198. return texture;
  30199. };
  30200. ImageUtils.loadCompressedTexture = function () {
  30201. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30202. };
  30203. ImageUtils.loadCompressedTextureCube = function () {
  30204. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30205. }; //
  30206. function CanvasRenderer() {
  30207. console.error('THREE.CanvasRenderer has been removed');
  30208. } //
  30209. function JSONLoader() {
  30210. console.error('THREE.JSONLoader has been removed.');
  30211. } //
  30212. var SceneUtils = {
  30213. createMultiMaterialObject: function createMultiMaterialObject()
  30214. /* geometry, materials */
  30215. {
  30216. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30217. },
  30218. detach: function detach()
  30219. /* child, parent, scene */
  30220. {
  30221. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30222. },
  30223. attach: function attach()
  30224. /* child, scene, parent */
  30225. {
  30226. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30227. }
  30228. }; //
  30229. function LensFlare() {
  30230. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30231. }
  30232. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30233. /* eslint-disable no-undef */
  30234. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30235. detail: {
  30236. revision: REVISION
  30237. }
  30238. }));
  30239. /* eslint-enable no-undef */
  30240. }
  30241. if (typeof window !== 'undefined') {
  30242. if (window.__THREE__) {
  30243. console.warn('WARNING: Multiple instances of Three.js being imported.');
  30244. } else {
  30245. window.__THREE__ = REVISION;
  30246. }
  30247. }
  30248. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30249. exports.AddEquation = AddEquation;
  30250. exports.AddOperation = AddOperation;
  30251. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30252. exports.AdditiveBlending = AdditiveBlending;
  30253. exports.AlphaFormat = AlphaFormat;
  30254. exports.AlwaysDepth = AlwaysDepth;
  30255. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30256. exports.AmbientLight = AmbientLight;
  30257. exports.AmbientLightProbe = AmbientLightProbe;
  30258. exports.AnimationClip = AnimationClip;
  30259. exports.AnimationLoader = AnimationLoader;
  30260. exports.AnimationMixer = AnimationMixer;
  30261. exports.AnimationObjectGroup = AnimationObjectGroup;
  30262. exports.AnimationUtils = AnimationUtils;
  30263. exports.ArcCurve = ArcCurve;
  30264. exports.ArrayCamera = ArrayCamera;
  30265. exports.ArrowHelper = ArrowHelper;
  30266. exports.Audio = Audio;
  30267. exports.AudioAnalyser = AudioAnalyser;
  30268. exports.AudioContext = AudioContext;
  30269. exports.AudioListener = AudioListener;
  30270. exports.AudioLoader = AudioLoader;
  30271. exports.AxesHelper = AxesHelper;
  30272. exports.AxisHelper = AxisHelper;
  30273. exports.BackSide = BackSide;
  30274. exports.BasicDepthPacking = BasicDepthPacking;
  30275. exports.BasicShadowMap = BasicShadowMap;
  30276. exports.BinaryTextureLoader = BinaryTextureLoader;
  30277. exports.Bone = Bone;
  30278. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30279. exports.BoundingBoxHelper = BoundingBoxHelper;
  30280. exports.Box2 = Box2;
  30281. exports.Box3 = Box3;
  30282. exports.Box3Helper = Box3Helper;
  30283. exports.BoxBufferGeometry = BoxGeometry;
  30284. exports.BoxGeometry = BoxGeometry;
  30285. exports.BoxHelper = BoxHelper;
  30286. exports.BufferAttribute = BufferAttribute;
  30287. exports.BufferGeometry = BufferGeometry;
  30288. exports.BufferGeometryLoader = BufferGeometryLoader;
  30289. exports.ByteType = ByteType;
  30290. exports.Cache = Cache;
  30291. exports.Camera = Camera;
  30292. exports.CameraHelper = CameraHelper;
  30293. exports.CanvasRenderer = CanvasRenderer;
  30294. exports.CanvasTexture = CanvasTexture;
  30295. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30296. exports.CineonToneMapping = CineonToneMapping;
  30297. exports.CircleBufferGeometry = CircleGeometry;
  30298. exports.CircleGeometry = CircleGeometry;
  30299. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30300. exports.Clock = Clock;
  30301. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  30302. exports.Color = Color;
  30303. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30304. exports.CompressedTexture = CompressedTexture;
  30305. exports.CompressedTextureLoader = CompressedTextureLoader;
  30306. exports.ConeBufferGeometry = ConeGeometry;
  30307. exports.ConeGeometry = ConeGeometry;
  30308. exports.CubeCamera = CubeCamera;
  30309. exports.CubeReflectionMapping = CubeReflectionMapping;
  30310. exports.CubeRefractionMapping = CubeRefractionMapping;
  30311. exports.CubeTexture = CubeTexture;
  30312. exports.CubeTextureLoader = CubeTextureLoader;
  30313. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  30314. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  30315. exports.CubicBezierCurve = CubicBezierCurve;
  30316. exports.CubicBezierCurve3 = CubicBezierCurve3;
  30317. exports.CubicInterpolant = CubicInterpolant;
  30318. exports.CullFaceBack = CullFaceBack;
  30319. exports.CullFaceFront = CullFaceFront;
  30320. exports.CullFaceFrontBack = CullFaceFrontBack;
  30321. exports.CullFaceNone = CullFaceNone;
  30322. exports.Curve = Curve;
  30323. exports.CurvePath = CurvePath;
  30324. exports.CustomBlending = CustomBlending;
  30325. exports.CustomToneMapping = CustomToneMapping;
  30326. exports.CylinderBufferGeometry = CylinderGeometry;
  30327. exports.CylinderGeometry = CylinderGeometry;
  30328. exports.Cylindrical = Cylindrical;
  30329. exports.DataTexture = DataTexture;
  30330. exports.DataTexture2DArray = DataTexture2DArray;
  30331. exports.DataTexture3D = DataTexture3D;
  30332. exports.DataTextureLoader = DataTextureLoader;
  30333. exports.DataUtils = DataUtils;
  30334. exports.DecrementStencilOp = DecrementStencilOp;
  30335. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  30336. exports.DefaultLoadingManager = DefaultLoadingManager;
  30337. exports.DepthFormat = DepthFormat;
  30338. exports.DepthStencilFormat = DepthStencilFormat;
  30339. exports.DepthTexture = DepthTexture;
  30340. exports.DirectionalLight = DirectionalLight;
  30341. exports.DirectionalLightHelper = DirectionalLightHelper;
  30342. exports.DiscreteInterpolant = DiscreteInterpolant;
  30343. exports.DodecahedronBufferGeometry = DodecahedronGeometry;
  30344. exports.DodecahedronGeometry = DodecahedronGeometry;
  30345. exports.DoubleSide = DoubleSide;
  30346. exports.DstAlphaFactor = DstAlphaFactor;
  30347. exports.DstColorFactor = DstColorFactor;
  30348. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  30349. exports.DynamicCopyUsage = DynamicCopyUsage;
  30350. exports.DynamicDrawUsage = DynamicDrawUsage;
  30351. exports.DynamicReadUsage = DynamicReadUsage;
  30352. exports.EdgesGeometry = EdgesGeometry;
  30353. exports.EdgesHelper = EdgesHelper;
  30354. exports.EllipseCurve = EllipseCurve;
  30355. exports.EqualDepth = EqualDepth;
  30356. exports.EqualStencilFunc = EqualStencilFunc;
  30357. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  30358. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  30359. exports.Euler = Euler;
  30360. exports.EventDispatcher = EventDispatcher;
  30361. exports.ExtrudeBufferGeometry = ExtrudeGeometry;
  30362. exports.ExtrudeGeometry = ExtrudeGeometry;
  30363. exports.Face3 = Face3;
  30364. exports.Face4 = Face4;
  30365. exports.FaceColors = FaceColors;
  30366. exports.FileLoader = FileLoader;
  30367. exports.FlatShading = FlatShading;
  30368. exports.Float16BufferAttribute = Float16BufferAttribute;
  30369. exports.Float32Attribute = Float32Attribute;
  30370. exports.Float32BufferAttribute = Float32BufferAttribute;
  30371. exports.Float64Attribute = Float64Attribute;
  30372. exports.Float64BufferAttribute = Float64BufferAttribute;
  30373. exports.FloatType = FloatType;
  30374. exports.Fog = Fog;
  30375. exports.FogExp2 = FogExp2;
  30376. exports.Font = Font;
  30377. exports.FontLoader = FontLoader;
  30378. exports.FrontSide = FrontSide;
  30379. exports.Frustum = Frustum;
  30380. exports.GLBufferAttribute = GLBufferAttribute;
  30381. exports.GLSL1 = GLSL1;
  30382. exports.GLSL3 = GLSL3;
  30383. exports.GammaEncoding = GammaEncoding;
  30384. exports.GeometryUtils = GeometryUtils;
  30385. exports.GreaterDepth = GreaterDepth;
  30386. exports.GreaterEqualDepth = GreaterEqualDepth;
  30387. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  30388. exports.GreaterStencilFunc = GreaterStencilFunc;
  30389. exports.GridHelper = GridHelper;
  30390. exports.Group = Group;
  30391. exports.HalfFloatType = HalfFloatType;
  30392. exports.HemisphereLight = HemisphereLight;
  30393. exports.HemisphereLightHelper = HemisphereLightHelper;
  30394. exports.HemisphereLightProbe = HemisphereLightProbe;
  30395. exports.IcosahedronBufferGeometry = IcosahedronGeometry;
  30396. exports.IcosahedronGeometry = IcosahedronGeometry;
  30397. exports.ImageBitmapLoader = ImageBitmapLoader;
  30398. exports.ImageLoader = ImageLoader;
  30399. exports.ImageUtils = ImageUtils;
  30400. exports.ImmediateRenderObject = ImmediateRenderObject;
  30401. exports.IncrementStencilOp = IncrementStencilOp;
  30402. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  30403. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  30404. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  30405. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  30406. exports.InstancedMesh = InstancedMesh;
  30407. exports.Int16Attribute = Int16Attribute;
  30408. exports.Int16BufferAttribute = Int16BufferAttribute;
  30409. exports.Int32Attribute = Int32Attribute;
  30410. exports.Int32BufferAttribute = Int32BufferAttribute;
  30411. exports.Int8Attribute = Int8Attribute;
  30412. exports.Int8BufferAttribute = Int8BufferAttribute;
  30413. exports.IntType = IntType;
  30414. exports.InterleavedBuffer = InterleavedBuffer;
  30415. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  30416. exports.Interpolant = Interpolant;
  30417. exports.InterpolateDiscrete = InterpolateDiscrete;
  30418. exports.InterpolateLinear = InterpolateLinear;
  30419. exports.InterpolateSmooth = InterpolateSmooth;
  30420. exports.InvertStencilOp = InvertStencilOp;
  30421. exports.JSONLoader = JSONLoader;
  30422. exports.KeepStencilOp = KeepStencilOp;
  30423. exports.KeyframeTrack = KeyframeTrack;
  30424. exports.LOD = LOD;
  30425. exports.LatheBufferGeometry = LatheGeometry;
  30426. exports.LatheGeometry = LatheGeometry;
  30427. exports.Layers = Layers;
  30428. exports.LensFlare = LensFlare;
  30429. exports.LessDepth = LessDepth;
  30430. exports.LessEqualDepth = LessEqualDepth;
  30431. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  30432. exports.LessStencilFunc = LessStencilFunc;
  30433. exports.Light = Light;
  30434. exports.LightProbe = LightProbe;
  30435. exports.Line = Line;
  30436. exports.Line3 = Line3;
  30437. exports.LineBasicMaterial = LineBasicMaterial;
  30438. exports.LineCurve = LineCurve;
  30439. exports.LineCurve3 = LineCurve3;
  30440. exports.LineDashedMaterial = LineDashedMaterial;
  30441. exports.LineLoop = LineLoop;
  30442. exports.LinePieces = LinePieces;
  30443. exports.LineSegments = LineSegments;
  30444. exports.LineStrip = LineStrip;
  30445. exports.LinearEncoding = LinearEncoding;
  30446. exports.LinearFilter = LinearFilter;
  30447. exports.LinearInterpolant = LinearInterpolant;
  30448. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  30449. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  30450. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  30451. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  30452. exports.LinearToneMapping = LinearToneMapping;
  30453. exports.Loader = Loader;
  30454. exports.LoaderUtils = LoaderUtils;
  30455. exports.LoadingManager = LoadingManager;
  30456. exports.LogLuvEncoding = LogLuvEncoding;
  30457. exports.LoopOnce = LoopOnce;
  30458. exports.LoopPingPong = LoopPingPong;
  30459. exports.LoopRepeat = LoopRepeat;
  30460. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  30461. exports.LuminanceFormat = LuminanceFormat;
  30462. exports.MOUSE = MOUSE;
  30463. exports.Material = Material;
  30464. exports.MaterialLoader = MaterialLoader;
  30465. exports.Math = MathUtils;
  30466. exports.MathUtils = MathUtils;
  30467. exports.Matrix3 = Matrix3;
  30468. exports.Matrix4 = Matrix4;
  30469. exports.MaxEquation = MaxEquation;
  30470. exports.Mesh = Mesh;
  30471. exports.MeshBasicMaterial = MeshBasicMaterial;
  30472. exports.MeshDepthMaterial = MeshDepthMaterial;
  30473. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  30474. exports.MeshFaceMaterial = MeshFaceMaterial;
  30475. exports.MeshLambertMaterial = MeshLambertMaterial;
  30476. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  30477. exports.MeshNormalMaterial = MeshNormalMaterial;
  30478. exports.MeshPhongMaterial = MeshPhongMaterial;
  30479. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  30480. exports.MeshStandardMaterial = MeshStandardMaterial;
  30481. exports.MeshToonMaterial = MeshToonMaterial;
  30482. exports.MinEquation = MinEquation;
  30483. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  30484. exports.MixOperation = MixOperation;
  30485. exports.MultiMaterial = MultiMaterial;
  30486. exports.MultiplyBlending = MultiplyBlending;
  30487. exports.MultiplyOperation = MultiplyOperation;
  30488. exports.NearestFilter = NearestFilter;
  30489. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  30490. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  30491. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  30492. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  30493. exports.NeverDepth = NeverDepth;
  30494. exports.NeverStencilFunc = NeverStencilFunc;
  30495. exports.NoBlending = NoBlending;
  30496. exports.NoColors = NoColors;
  30497. exports.NoToneMapping = NoToneMapping;
  30498. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  30499. exports.NormalBlending = NormalBlending;
  30500. exports.NotEqualDepth = NotEqualDepth;
  30501. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  30502. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  30503. exports.Object3D = Object3D;
  30504. exports.ObjectLoader = ObjectLoader;
  30505. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  30506. exports.OctahedronBufferGeometry = OctahedronGeometry;
  30507. exports.OctahedronGeometry = OctahedronGeometry;
  30508. exports.OneFactor = OneFactor;
  30509. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  30510. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  30511. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  30512. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  30513. exports.OrthographicCamera = OrthographicCamera;
  30514. exports.PCFShadowMap = PCFShadowMap;
  30515. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  30516. exports.PMREMGenerator = PMREMGenerator;
  30517. exports.ParametricBufferGeometry = ParametricGeometry;
  30518. exports.ParametricGeometry = ParametricGeometry;
  30519. exports.Particle = Particle;
  30520. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  30521. exports.ParticleSystem = ParticleSystem;
  30522. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  30523. exports.Path = Path;
  30524. exports.PerspectiveCamera = PerspectiveCamera;
  30525. exports.Plane = Plane;
  30526. exports.PlaneBufferGeometry = PlaneGeometry;
  30527. exports.PlaneGeometry = PlaneGeometry;
  30528. exports.PlaneHelper = PlaneHelper;
  30529. exports.PointCloud = PointCloud;
  30530. exports.PointCloudMaterial = PointCloudMaterial;
  30531. exports.PointLight = PointLight;
  30532. exports.PointLightHelper = PointLightHelper;
  30533. exports.Points = Points;
  30534. exports.PointsMaterial = PointsMaterial;
  30535. exports.PolarGridHelper = PolarGridHelper;
  30536. exports.PolyhedronBufferGeometry = PolyhedronGeometry;
  30537. exports.PolyhedronGeometry = PolyhedronGeometry;
  30538. exports.PositionalAudio = PositionalAudio;
  30539. exports.PropertyBinding = PropertyBinding;
  30540. exports.PropertyMixer = PropertyMixer;
  30541. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  30542. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  30543. exports.Quaternion = Quaternion;
  30544. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  30545. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  30546. exports.REVISION = REVISION;
  30547. exports.RGBADepthPacking = RGBADepthPacking;
  30548. exports.RGBAFormat = RGBAFormat;
  30549. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  30550. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  30551. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  30552. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  30553. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  30554. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  30555. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  30556. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  30557. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  30558. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  30559. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  30560. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  30561. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  30562. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  30563. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  30564. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  30565. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  30566. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  30567. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  30568. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  30569. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  30570. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  30571. exports.RGBDEncoding = RGBDEncoding;
  30572. exports.RGBEEncoding = RGBEEncoding;
  30573. exports.RGBEFormat = RGBEFormat;
  30574. exports.RGBFormat = RGBFormat;
  30575. exports.RGBIntegerFormat = RGBIntegerFormat;
  30576. exports.RGBM16Encoding = RGBM16Encoding;
  30577. exports.RGBM7Encoding = RGBM7Encoding;
  30578. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  30579. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  30580. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  30581. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  30582. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  30583. exports.RGFormat = RGFormat;
  30584. exports.RGIntegerFormat = RGIntegerFormat;
  30585. exports.RawShaderMaterial = RawShaderMaterial;
  30586. exports.Ray = Ray;
  30587. exports.Raycaster = Raycaster;
  30588. exports.RectAreaLight = RectAreaLight;
  30589. exports.RedFormat = RedFormat;
  30590. exports.RedIntegerFormat = RedIntegerFormat;
  30591. exports.ReinhardToneMapping = ReinhardToneMapping;
  30592. exports.RepeatWrapping = RepeatWrapping;
  30593. exports.ReplaceStencilOp = ReplaceStencilOp;
  30594. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  30595. exports.RingBufferGeometry = RingGeometry;
  30596. exports.RingGeometry = RingGeometry;
  30597. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  30598. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  30599. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  30600. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  30601. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  30602. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  30603. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  30604. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  30605. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  30606. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  30607. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  30608. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  30609. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  30610. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  30611. exports.Scene = Scene;
  30612. exports.SceneUtils = SceneUtils;
  30613. exports.ShaderChunk = ShaderChunk;
  30614. exports.ShaderLib = ShaderLib;
  30615. exports.ShaderMaterial = ShaderMaterial;
  30616. exports.ShadowMaterial = ShadowMaterial;
  30617. exports.Shape = Shape;
  30618. exports.ShapeBufferGeometry = ShapeGeometry;
  30619. exports.ShapeGeometry = ShapeGeometry;
  30620. exports.ShapePath = ShapePath;
  30621. exports.ShapeUtils = ShapeUtils;
  30622. exports.ShortType = ShortType;
  30623. exports.Skeleton = Skeleton;
  30624. exports.SkeletonHelper = SkeletonHelper;
  30625. exports.SkinnedMesh = SkinnedMesh;
  30626. exports.SmoothShading = SmoothShading;
  30627. exports.Sphere = Sphere;
  30628. exports.SphereBufferGeometry = SphereGeometry;
  30629. exports.SphereGeometry = SphereGeometry;
  30630. exports.Spherical = Spherical;
  30631. exports.SphericalHarmonics3 = SphericalHarmonics3;
  30632. exports.Spline = Spline;
  30633. exports.SplineCurve = SplineCurve;
  30634. exports.SplineCurve3 = SplineCurve3;
  30635. exports.SpotLight = SpotLight;
  30636. exports.SpotLightHelper = SpotLightHelper;
  30637. exports.Sprite = Sprite;
  30638. exports.SpriteMaterial = SpriteMaterial;
  30639. exports.SrcAlphaFactor = SrcAlphaFactor;
  30640. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  30641. exports.SrcColorFactor = SrcColorFactor;
  30642. exports.StaticCopyUsage = StaticCopyUsage;
  30643. exports.StaticDrawUsage = StaticDrawUsage;
  30644. exports.StaticReadUsage = StaticReadUsage;
  30645. exports.StereoCamera = StereoCamera;
  30646. exports.StreamCopyUsage = StreamCopyUsage;
  30647. exports.StreamDrawUsage = StreamDrawUsage;
  30648. exports.StreamReadUsage = StreamReadUsage;
  30649. exports.StringKeyframeTrack = StringKeyframeTrack;
  30650. exports.SubtractEquation = SubtractEquation;
  30651. exports.SubtractiveBlending = SubtractiveBlending;
  30652. exports.TOUCH = TOUCH;
  30653. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  30654. exports.TetrahedronBufferGeometry = TetrahedronGeometry;
  30655. exports.TetrahedronGeometry = TetrahedronGeometry;
  30656. exports.TextBufferGeometry = TextGeometry;
  30657. exports.TextGeometry = TextGeometry;
  30658. exports.Texture = Texture;
  30659. exports.TextureLoader = TextureLoader;
  30660. exports.TorusBufferGeometry = TorusGeometry;
  30661. exports.TorusGeometry = TorusGeometry;
  30662. exports.TorusKnotBufferGeometry = TorusKnotGeometry;
  30663. exports.TorusKnotGeometry = TorusKnotGeometry;
  30664. exports.Triangle = Triangle;
  30665. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  30666. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  30667. exports.TrianglesDrawMode = TrianglesDrawMode;
  30668. exports.TubeBufferGeometry = TubeGeometry;
  30669. exports.TubeGeometry = TubeGeometry;
  30670. exports.UVMapping = UVMapping;
  30671. exports.Uint16Attribute = Uint16Attribute;
  30672. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  30673. exports.Uint32Attribute = Uint32Attribute;
  30674. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  30675. exports.Uint8Attribute = Uint8Attribute;
  30676. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  30677. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  30678. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  30679. exports.Uniform = Uniform;
  30680. exports.UniformsLib = UniformsLib;
  30681. exports.UniformsUtils = UniformsUtils;
  30682. exports.UnsignedByteType = UnsignedByteType;
  30683. exports.UnsignedInt248Type = UnsignedInt248Type;
  30684. exports.UnsignedIntType = UnsignedIntType;
  30685. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  30686. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  30687. exports.UnsignedShort565Type = UnsignedShort565Type;
  30688. exports.UnsignedShortType = UnsignedShortType;
  30689. exports.VSMShadowMap = VSMShadowMap;
  30690. exports.Vector2 = Vector2;
  30691. exports.Vector3 = Vector3;
  30692. exports.Vector4 = Vector4;
  30693. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  30694. exports.Vertex = Vertex;
  30695. exports.VertexColors = VertexColors;
  30696. exports.VideoTexture = VideoTexture;
  30697. exports.WebGL1Renderer = WebGL1Renderer;
  30698. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  30699. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  30700. exports.WebGLRenderTarget = WebGLRenderTarget;
  30701. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  30702. exports.WebGLRenderer = WebGLRenderer;
  30703. exports.WebGLUtils = WebGLUtils;
  30704. exports.WireframeGeometry = WireframeGeometry;
  30705. exports.WireframeHelper = WireframeHelper;
  30706. exports.WrapAroundEnding = WrapAroundEnding;
  30707. exports.XHRLoader = XHRLoader;
  30708. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  30709. exports.ZeroFactor = ZeroFactor;
  30710. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  30711. exports.ZeroStencilOp = ZeroStencilOp;
  30712. exports.sRGBEncoding = sRGBEncoding;
  30713. Object.defineProperty(exports, '__esModule', { value: true });
  30714. })));