three.js 1.2 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567
  1. // threejs.org/license
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.THREE = {}));
  6. }(this, (function (exports) { 'use strict';
  7. // Polyfills
  8. if (Number.EPSILON === undefined) {
  9. Number.EPSILON = Math.pow(2, -52);
  10. }
  11. if (Number.isInteger === undefined) {
  12. // Missing in IE
  13. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  14. Number.isInteger = function (value) {
  15. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  16. };
  17. } //
  18. if (Math.sign === undefined) {
  19. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  20. Math.sign = function (x) {
  21. return x < 0 ? -1 : x > 0 ? 1 : +x;
  22. };
  23. }
  24. if ('name' in Function.prototype === false) {
  25. // Missing in IE
  26. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  27. Object.defineProperty(Function.prototype, 'name', {
  28. get: function get() {
  29. return this.toString().match(/^\s*function\s*([^\(\s]*)/)[1];
  30. }
  31. });
  32. }
  33. if (Object.assign === undefined) {
  34. // Missing in IE
  35. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  36. Object.assign = function (target) {
  37. if (target === undefined || target === null) {
  38. throw new TypeError('Cannot convert undefined or null to object');
  39. }
  40. var output = Object(target);
  41. for (var index = 1; index < arguments.length; index++) {
  42. var source = arguments[index];
  43. if (source !== undefined && source !== null) {
  44. for (var nextKey in source) {
  45. if (Object.prototype.hasOwnProperty.call(source, nextKey)) {
  46. output[nextKey] = source[nextKey];
  47. }
  48. }
  49. }
  50. }
  51. return output;
  52. };
  53. }
  54. /**
  55. * Copyright (c) 2014-present, Facebook, Inc.
  56. *
  57. * This source code is licensed under the MIT license found in the
  58. * LICENSE file in the root directory of this source tree.
  59. */
  60. var runtime = function (exports) {
  61. var Op = Object.prototype;
  62. var hasOwn = Op.hasOwnProperty;
  63. var undefined$1; // More compressible than void 0.
  64. var $Symbol = typeof Symbol === "function" ? Symbol : {};
  65. var iteratorSymbol = $Symbol.iterator || "@@iterator";
  66. var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
  67. var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  68. function define(obj, key, value) {
  69. Object.defineProperty(obj, key, {
  70. value: value,
  71. enumerable: true,
  72. configurable: true,
  73. writable: true
  74. });
  75. return obj[key];
  76. }
  77. try {
  78. // IE 8 has a broken Object.defineProperty that only works on DOM objects.
  79. define({}, "");
  80. } catch (err) {
  81. define = function define(obj, key, value) {
  82. return obj[key] = value;
  83. };
  84. }
  85. function wrap(innerFn, outerFn, self, tryLocsList) {
  86. // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
  87. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
  88. var generator = Object.create(protoGenerator.prototype);
  89. var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
  90. // .throw, and .return methods.
  91. generator._invoke = makeInvokeMethod(innerFn, self, context);
  92. return generator;
  93. }
  94. exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
  95. // record like context.tryEntries[i].completion. This interface could
  96. // have been (and was previously) designed to take a closure to be
  97. // invoked without arguments, but in all the cases we care about we
  98. // already have an existing method we want to call, so there's no need
  99. // to create a new function object. We can even get away with assuming
  100. // the method takes exactly one argument, since that happens to be true
  101. // in every case, so we don't have to touch the arguments object. The
  102. // only additional allocation required is the completion record, which
  103. // has a stable shape and so hopefully should be cheap to allocate.
  104. function tryCatch(fn, obj, arg) {
  105. try {
  106. return {
  107. type: "normal",
  108. arg: fn.call(obj, arg)
  109. };
  110. } catch (err) {
  111. return {
  112. type: "throw",
  113. arg: err
  114. };
  115. }
  116. }
  117. var GenStateSuspendedStart = "suspendedStart";
  118. var GenStateSuspendedYield = "suspendedYield";
  119. var GenStateExecuting = "executing";
  120. var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
  121. // breaking out of the dispatch switch statement.
  122. var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
  123. // .constructor.prototype properties for functions that return Generator
  124. // objects. For full spec compliance, you may wish to configure your
  125. // minifier not to mangle the names of these two functions.
  126. function Generator() {}
  127. function GeneratorFunction() {}
  128. function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
  129. // don't natively support it.
  130. var IteratorPrototype = {};
  131. IteratorPrototype[iteratorSymbol] = function () {
  132. return this;
  133. };
  134. var getProto = Object.getPrototypeOf;
  135. var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  136. if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
  137. // This environment has a native %IteratorPrototype%; use it instead
  138. // of the polyfill.
  139. IteratorPrototype = NativeIteratorPrototype;
  140. }
  141. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  142. GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
  143. GeneratorFunctionPrototype.constructor = GeneratorFunction;
  144. GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
  145. // Iterator interface in terms of a single ._invoke method.
  146. function defineIteratorMethods(prototype) {
  147. ["next", "throw", "return"].forEach(function (method) {
  148. define(prototype, method, function (arg) {
  149. return this._invoke(method, arg);
  150. });
  151. });
  152. }
  153. exports.isGeneratorFunction = function (genFun) {
  154. var ctor = typeof genFun === "function" && genFun.constructor;
  155. return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
  156. // do is to check its .name property.
  157. (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
  158. };
  159. exports.mark = function (genFun) {
  160. if (Object.setPrototypeOf) {
  161. Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
  162. } else {
  163. genFun.__proto__ = GeneratorFunctionPrototype;
  164. define(genFun, toStringTagSymbol, "GeneratorFunction");
  165. }
  166. genFun.prototype = Object.create(Gp);
  167. return genFun;
  168. }; // Within the body of any async function, `await x` is transformed to
  169. // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
  170. // `hasOwn.call(value, "__await")` to determine if the yielded value is
  171. // meant to be awaited.
  172. exports.awrap = function (arg) {
  173. return {
  174. __await: arg
  175. };
  176. };
  177. function AsyncIterator(generator, PromiseImpl) {
  178. function invoke(method, arg, resolve, reject) {
  179. var record = tryCatch(generator[method], generator, arg);
  180. if (record.type === "throw") {
  181. reject(record.arg);
  182. } else {
  183. var result = record.arg;
  184. var value = result.value;
  185. if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
  186. return PromiseImpl.resolve(value.__await).then(function (value) {
  187. invoke("next", value, resolve, reject);
  188. }, function (err) {
  189. invoke("throw", err, resolve, reject);
  190. });
  191. }
  192. return PromiseImpl.resolve(value).then(function (unwrapped) {
  193. // When a yielded Promise is resolved, its final value becomes
  194. // the .value of the Promise<{value,done}> result for the
  195. // current iteration.
  196. result.value = unwrapped;
  197. resolve(result);
  198. }, function (error) {
  199. // If a rejected Promise was yielded, throw the rejection back
  200. // into the async generator function so it can be handled there.
  201. return invoke("throw", error, resolve, reject);
  202. });
  203. }
  204. }
  205. var previousPromise;
  206. function enqueue(method, arg) {
  207. function callInvokeWithMethodAndArg() {
  208. return new PromiseImpl(function (resolve, reject) {
  209. invoke(method, arg, resolve, reject);
  210. });
  211. }
  212. return previousPromise = // If enqueue has been called before, then we want to wait until
  213. // all previous Promises have been resolved before calling invoke,
  214. // so that results are always delivered in the correct order. If
  215. // enqueue has not been called before, then it is important to
  216. // call invoke immediately, without waiting on a callback to fire,
  217. // so that the async generator function has the opportunity to do
  218. // any necessary setup in a predictable way. This predictability
  219. // is why the Promise constructor synchronously invokes its
  220. // executor callback, and why async functions synchronously
  221. // execute code before the first await. Since we implement simple
  222. // async functions in terms of async generators, it is especially
  223. // important to get this right, even though it requires care.
  224. previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
  225. // invocations of the iterator.
  226. callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  227. } // Define the unified helper method that is used to implement .next,
  228. // .throw, and .return (see defineIteratorMethods).
  229. this._invoke = enqueue;
  230. }
  231. defineIteratorMethods(AsyncIterator.prototype);
  232. AsyncIterator.prototype[asyncIteratorSymbol] = function () {
  233. return this;
  234. };
  235. exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
  236. // AsyncIterator objects; they just return a Promise for the value of
  237. // the final result produced by the iterator.
  238. exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  239. if (PromiseImpl === void 0) PromiseImpl = Promise;
  240. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  241. return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
  242. : iter.next().then(function (result) {
  243. return result.done ? result.value : iter.next();
  244. });
  245. };
  246. function makeInvokeMethod(innerFn, self, context) {
  247. var state = GenStateSuspendedStart;
  248. return function invoke(method, arg) {
  249. if (state === GenStateExecuting) {
  250. throw new Error("Generator is already running");
  251. }
  252. if (state === GenStateCompleted) {
  253. if (method === "throw") {
  254. throw arg;
  255. } // Be forgiving, per 25.3.3.3.3 of the spec:
  256. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
  257. return doneResult();
  258. }
  259. context.method = method;
  260. context.arg = arg;
  261. while (true) {
  262. var delegate = context.delegate;
  263. if (delegate) {
  264. var delegateResult = maybeInvokeDelegate(delegate, context);
  265. if (delegateResult) {
  266. if (delegateResult === ContinueSentinel) continue;
  267. return delegateResult;
  268. }
  269. }
  270. if (context.method === "next") {
  271. // Setting context._sent for legacy support of Babel's
  272. // function.sent implementation.
  273. context.sent = context._sent = context.arg;
  274. } else if (context.method === "throw") {
  275. if (state === GenStateSuspendedStart) {
  276. state = GenStateCompleted;
  277. throw context.arg;
  278. }
  279. context.dispatchException(context.arg);
  280. } else if (context.method === "return") {
  281. context.abrupt("return", context.arg);
  282. }
  283. state = GenStateExecuting;
  284. var record = tryCatch(innerFn, self, context);
  285. if (record.type === "normal") {
  286. // If an exception is thrown from innerFn, we leave state ===
  287. // GenStateExecuting and loop back for another invocation.
  288. state = context.done ? GenStateCompleted : GenStateSuspendedYield;
  289. if (record.arg === ContinueSentinel) {
  290. continue;
  291. }
  292. return {
  293. value: record.arg,
  294. done: context.done
  295. };
  296. } else if (record.type === "throw") {
  297. state = GenStateCompleted; // Dispatch the exception by looping back around to the
  298. // context.dispatchException(context.arg) call above.
  299. context.method = "throw";
  300. context.arg = record.arg;
  301. }
  302. }
  303. };
  304. } // Call delegate.iterator[context.method](context.arg) and handle the
  305. // result, either by returning a { value, done } result from the
  306. // delegate iterator, or by modifying context.method and context.arg,
  307. // setting context.delegate to null, and returning the ContinueSentinel.
  308. function maybeInvokeDelegate(delegate, context) {
  309. var method = delegate.iterator[context.method];
  310. if (method === undefined$1) {
  311. // A .throw or .return when the delegate iterator has no .throw
  312. // method always terminates the yield* loop.
  313. context.delegate = null;
  314. if (context.method === "throw") {
  315. // Note: ["return"] must be used for ES3 parsing compatibility.
  316. if (delegate.iterator["return"]) {
  317. // If the delegate iterator has a return method, give it a
  318. // chance to clean up.
  319. context.method = "return";
  320. context.arg = undefined$1;
  321. maybeInvokeDelegate(delegate, context);
  322. if (context.method === "throw") {
  323. // If maybeInvokeDelegate(context) changed context.method from
  324. // "return" to "throw", let that override the TypeError below.
  325. return ContinueSentinel;
  326. }
  327. }
  328. context.method = "throw";
  329. context.arg = new TypeError("The iterator does not provide a 'throw' method");
  330. }
  331. return ContinueSentinel;
  332. }
  333. var record = tryCatch(method, delegate.iterator, context.arg);
  334. if (record.type === "throw") {
  335. context.method = "throw";
  336. context.arg = record.arg;
  337. context.delegate = null;
  338. return ContinueSentinel;
  339. }
  340. var info = record.arg;
  341. if (!info) {
  342. context.method = "throw";
  343. context.arg = new TypeError("iterator result is not an object");
  344. context.delegate = null;
  345. return ContinueSentinel;
  346. }
  347. if (info.done) {
  348. // Assign the result of the finished delegate to the temporary
  349. // variable specified by delegate.resultName (see delegateYield).
  350. context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
  351. context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
  352. // exception, let the outer generator proceed normally. If
  353. // context.method was "next", forget context.arg since it has been
  354. // "consumed" by the delegate iterator. If context.method was
  355. // "return", allow the original .return call to continue in the
  356. // outer generator.
  357. if (context.method !== "return") {
  358. context.method = "next";
  359. context.arg = undefined$1;
  360. }
  361. } else {
  362. // Re-yield the result returned by the delegate method.
  363. return info;
  364. } // The delegate iterator is finished, so forget it and continue with
  365. // the outer generator.
  366. context.delegate = null;
  367. return ContinueSentinel;
  368. } // Define Generator.prototype.{next,throw,return} in terms of the
  369. // unified ._invoke helper method.
  370. defineIteratorMethods(Gp);
  371. define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
  372. // @@iterator function is called on it. Some browsers' implementations of the
  373. // iterator prototype chain incorrectly implement this, causing the Generator
  374. // object to not be returned from this call. This ensures that doesn't happen.
  375. // See https://github.com/facebook/regenerator/issues/274 for more details.
  376. Gp[iteratorSymbol] = function () {
  377. return this;
  378. };
  379. Gp.toString = function () {
  380. return "[object Generator]";
  381. };
  382. function pushTryEntry(locs) {
  383. var entry = {
  384. tryLoc: locs[0]
  385. };
  386. if (1 in locs) {
  387. entry.catchLoc = locs[1];
  388. }
  389. if (2 in locs) {
  390. entry.finallyLoc = locs[2];
  391. entry.afterLoc = locs[3];
  392. }
  393. this.tryEntries.push(entry);
  394. }
  395. function resetTryEntry(entry) {
  396. var record = entry.completion || {};
  397. record.type = "normal";
  398. delete record.arg;
  399. entry.completion = record;
  400. }
  401. function Context(tryLocsList) {
  402. // The root entry object (effectively a try statement without a catch
  403. // or a finally block) gives us a place to store values thrown from
  404. // locations where there is no enclosing try statement.
  405. this.tryEntries = [{
  406. tryLoc: "root"
  407. }];
  408. tryLocsList.forEach(pushTryEntry, this);
  409. this.reset(true);
  410. }
  411. exports.keys = function (object) {
  412. var keys = [];
  413. for (var key in object) {
  414. keys.push(key);
  415. }
  416. keys.reverse(); // Rather than returning an object with a next method, we keep
  417. // things simple and return the next function itself.
  418. return function next() {
  419. while (keys.length) {
  420. var key = keys.pop();
  421. if (key in object) {
  422. next.value = key;
  423. next.done = false;
  424. return next;
  425. }
  426. } // To avoid creating an additional object, we just hang the .value
  427. // and .done properties off the next function object itself. This
  428. // also ensures that the minifier will not anonymize the function.
  429. next.done = true;
  430. return next;
  431. };
  432. };
  433. function values(iterable) {
  434. if (iterable) {
  435. var iteratorMethod = iterable[iteratorSymbol];
  436. if (iteratorMethod) {
  437. return iteratorMethod.call(iterable);
  438. }
  439. if (typeof iterable.next === "function") {
  440. return iterable;
  441. }
  442. if (!isNaN(iterable.length)) {
  443. var i = -1,
  444. next = function next() {
  445. while (++i < iterable.length) {
  446. if (hasOwn.call(iterable, i)) {
  447. next.value = iterable[i];
  448. next.done = false;
  449. return next;
  450. }
  451. }
  452. next.value = undefined$1;
  453. next.done = true;
  454. return next;
  455. };
  456. return next.next = next;
  457. }
  458. } // Return an iterator with no values.
  459. return {
  460. next: doneResult
  461. };
  462. }
  463. exports.values = values;
  464. function doneResult() {
  465. return {
  466. value: undefined$1,
  467. done: true
  468. };
  469. }
  470. Context.prototype = {
  471. constructor: Context,
  472. reset: function reset(skipTempReset) {
  473. this.prev = 0;
  474. this.next = 0; // Resetting context._sent for legacy support of Babel's
  475. // function.sent implementation.
  476. this.sent = this._sent = undefined$1;
  477. this.done = false;
  478. this.delegate = null;
  479. this.method = "next";
  480. this.arg = undefined$1;
  481. this.tryEntries.forEach(resetTryEntry);
  482. if (!skipTempReset) {
  483. for (var name in this) {
  484. // Not sure about the optimal order of these conditions:
  485. if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
  486. this[name] = undefined$1;
  487. }
  488. }
  489. }
  490. },
  491. stop: function stop() {
  492. this.done = true;
  493. var rootEntry = this.tryEntries[0];
  494. var rootRecord = rootEntry.completion;
  495. if (rootRecord.type === "throw") {
  496. throw rootRecord.arg;
  497. }
  498. return this.rval;
  499. },
  500. dispatchException: function dispatchException(exception) {
  501. if (this.done) {
  502. throw exception;
  503. }
  504. var context = this;
  505. function handle(loc, caught) {
  506. record.type = "throw";
  507. record.arg = exception;
  508. context.next = loc;
  509. if (caught) {
  510. // If the dispatched exception was caught by a catch block,
  511. // then let that catch block handle the exception normally.
  512. context.method = "next";
  513. context.arg = undefined$1;
  514. }
  515. return !!caught;
  516. }
  517. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  518. var entry = this.tryEntries[i];
  519. var record = entry.completion;
  520. if (entry.tryLoc === "root") {
  521. // Exception thrown outside of any try block that could handle
  522. // it, so set the completion value of the entire function to
  523. // throw the exception.
  524. return handle("end");
  525. }
  526. if (entry.tryLoc <= this.prev) {
  527. var hasCatch = hasOwn.call(entry, "catchLoc");
  528. var hasFinally = hasOwn.call(entry, "finallyLoc");
  529. if (hasCatch && hasFinally) {
  530. if (this.prev < entry.catchLoc) {
  531. return handle(entry.catchLoc, true);
  532. } else if (this.prev < entry.finallyLoc) {
  533. return handle(entry.finallyLoc);
  534. }
  535. } else if (hasCatch) {
  536. if (this.prev < entry.catchLoc) {
  537. return handle(entry.catchLoc, true);
  538. }
  539. } else if (hasFinally) {
  540. if (this.prev < entry.finallyLoc) {
  541. return handle(entry.finallyLoc);
  542. }
  543. } else {
  544. throw new Error("try statement without catch or finally");
  545. }
  546. }
  547. }
  548. },
  549. abrupt: function abrupt(type, arg) {
  550. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  551. var entry = this.tryEntries[i];
  552. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  553. var finallyEntry = entry;
  554. break;
  555. }
  556. }
  557. if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
  558. // Ignore the finally entry if control is not jumping to a
  559. // location outside the try/catch block.
  560. finallyEntry = null;
  561. }
  562. var record = finallyEntry ? finallyEntry.completion : {};
  563. record.type = type;
  564. record.arg = arg;
  565. if (finallyEntry) {
  566. this.method = "next";
  567. this.next = finallyEntry.finallyLoc;
  568. return ContinueSentinel;
  569. }
  570. return this.complete(record);
  571. },
  572. complete: function complete(record, afterLoc) {
  573. if (record.type === "throw") {
  574. throw record.arg;
  575. }
  576. if (record.type === "break" || record.type === "continue") {
  577. this.next = record.arg;
  578. } else if (record.type === "return") {
  579. this.rval = this.arg = record.arg;
  580. this.method = "return";
  581. this.next = "end";
  582. } else if (record.type === "normal" && afterLoc) {
  583. this.next = afterLoc;
  584. }
  585. return ContinueSentinel;
  586. },
  587. finish: function finish(finallyLoc) {
  588. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  589. var entry = this.tryEntries[i];
  590. if (entry.finallyLoc === finallyLoc) {
  591. this.complete(entry.completion, entry.afterLoc);
  592. resetTryEntry(entry);
  593. return ContinueSentinel;
  594. }
  595. }
  596. },
  597. "catch": function _catch(tryLoc) {
  598. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  599. var entry = this.tryEntries[i];
  600. if (entry.tryLoc === tryLoc) {
  601. var record = entry.completion;
  602. if (record.type === "throw") {
  603. var thrown = record.arg;
  604. resetTryEntry(entry);
  605. }
  606. return thrown;
  607. }
  608. } // The context.catch method must only be called with a location
  609. // argument that corresponds to a known catch block.
  610. throw new Error("illegal catch attempt");
  611. },
  612. delegateYield: function delegateYield(iterable, resultName, nextLoc) {
  613. this.delegate = {
  614. iterator: values(iterable),
  615. resultName: resultName,
  616. nextLoc: nextLoc
  617. };
  618. if (this.method === "next") {
  619. // Deliberately forget the last sent value so that we don't
  620. // accidentally pass it on to the delegate.
  621. this.arg = undefined$1;
  622. }
  623. return ContinueSentinel;
  624. }
  625. }; // Regardless of whether this script is executing as a CommonJS module
  626. // or not, return the runtime object so that we can declare the variable
  627. // regeneratorRuntime in the outer scope, which allows this module to be
  628. // injected easily by `bin/regenerator --include-runtime script.js`.
  629. return exports;
  630. }( // If this script is executing as a CommonJS module, use module.exports
  631. // as the regeneratorRuntime namespace. Otherwise create a new empty
  632. // object. Either way, the resulting object will be used to initialize
  633. // the regeneratorRuntime variable at the top of this file.
  634. typeof module === "object" ? module.exports : {});
  635. try {
  636. regeneratorRuntime = runtime;
  637. } catch (accidentalStrictMode) {
  638. // This module should not be running in strict mode, so the above
  639. // assignment should always work unless something is misconfigured. Just
  640. // in case runtime.js accidentally runs in strict mode, we can escape
  641. // strict mode using a global Function call. This could conceivably fail
  642. // if a Content Security Policy forbids using Function, but in that case
  643. // the proper solution is to fix the accidental strict mode problem. If
  644. // you've misconfigured your bundler to force strict mode and applied a
  645. // CSP to forbid Function, and you're not willing to fix either of those
  646. // problems, please detail your unique predicament in a GitHub issue.
  647. Function("r", "regeneratorRuntime = r")(runtime);
  648. }
  649. var REVISION = '126dev';
  650. var MOUSE = {
  651. LEFT: 0,
  652. MIDDLE: 1,
  653. RIGHT: 2,
  654. ROTATE: 0,
  655. DOLLY: 1,
  656. PAN: 2
  657. };
  658. var TOUCH = {
  659. ROTATE: 0,
  660. PAN: 1,
  661. DOLLY_PAN: 2,
  662. DOLLY_ROTATE: 3
  663. };
  664. var CullFaceNone = 0;
  665. var CullFaceBack = 1;
  666. var CullFaceFront = 2;
  667. var CullFaceFrontBack = 3;
  668. var BasicShadowMap = 0;
  669. var PCFShadowMap = 1;
  670. var PCFSoftShadowMap = 2;
  671. var VSMShadowMap = 3;
  672. var FrontSide = 0;
  673. var BackSide = 1;
  674. var DoubleSide = 2;
  675. var FlatShading = 1;
  676. var SmoothShading = 2;
  677. var NoBlending = 0;
  678. var NormalBlending = 1;
  679. var AdditiveBlending = 2;
  680. var SubtractiveBlending = 3;
  681. var MultiplyBlending = 4;
  682. var CustomBlending = 5;
  683. var AddEquation = 100;
  684. var SubtractEquation = 101;
  685. var ReverseSubtractEquation = 102;
  686. var MinEquation = 103;
  687. var MaxEquation = 104;
  688. var ZeroFactor = 200;
  689. var OneFactor = 201;
  690. var SrcColorFactor = 202;
  691. var OneMinusSrcColorFactor = 203;
  692. var SrcAlphaFactor = 204;
  693. var OneMinusSrcAlphaFactor = 205;
  694. var DstAlphaFactor = 206;
  695. var OneMinusDstAlphaFactor = 207;
  696. var DstColorFactor = 208;
  697. var OneMinusDstColorFactor = 209;
  698. var SrcAlphaSaturateFactor = 210;
  699. var NeverDepth = 0;
  700. var AlwaysDepth = 1;
  701. var LessDepth = 2;
  702. var LessEqualDepth = 3;
  703. var EqualDepth = 4;
  704. var GreaterEqualDepth = 5;
  705. var GreaterDepth = 6;
  706. var NotEqualDepth = 7;
  707. var MultiplyOperation = 0;
  708. var MixOperation = 1;
  709. var AddOperation = 2;
  710. var NoToneMapping = 0;
  711. var LinearToneMapping = 1;
  712. var ReinhardToneMapping = 2;
  713. var CineonToneMapping = 3;
  714. var ACESFilmicToneMapping = 4;
  715. var CustomToneMapping = 5;
  716. var UVMapping = 300;
  717. var CubeReflectionMapping = 301;
  718. var CubeRefractionMapping = 302;
  719. var EquirectangularReflectionMapping = 303;
  720. var EquirectangularRefractionMapping = 304;
  721. var CubeUVReflectionMapping = 306;
  722. var CubeUVRefractionMapping = 307;
  723. var RepeatWrapping = 1000;
  724. var ClampToEdgeWrapping = 1001;
  725. var MirroredRepeatWrapping = 1002;
  726. var NearestFilter = 1003;
  727. var NearestMipmapNearestFilter = 1004;
  728. var NearestMipMapNearestFilter = 1004;
  729. var NearestMipmapLinearFilter = 1005;
  730. var NearestMipMapLinearFilter = 1005;
  731. var LinearFilter = 1006;
  732. var LinearMipmapNearestFilter = 1007;
  733. var LinearMipMapNearestFilter = 1007;
  734. var LinearMipmapLinearFilter = 1008;
  735. var LinearMipMapLinearFilter = 1008;
  736. var UnsignedByteType = 1009;
  737. var ByteType = 1010;
  738. var ShortType = 1011;
  739. var UnsignedShortType = 1012;
  740. var IntType = 1013;
  741. var UnsignedIntType = 1014;
  742. var FloatType = 1015;
  743. var HalfFloatType = 1016;
  744. var UnsignedShort4444Type = 1017;
  745. var UnsignedShort5551Type = 1018;
  746. var UnsignedShort565Type = 1019;
  747. var UnsignedInt248Type = 1020;
  748. var AlphaFormat = 1021;
  749. var RGBFormat = 1022;
  750. var RGBAFormat = 1023;
  751. var LuminanceFormat = 1024;
  752. var LuminanceAlphaFormat = 1025;
  753. var RGBEFormat = RGBAFormat;
  754. var DepthFormat = 1026;
  755. var DepthStencilFormat = 1027;
  756. var RedFormat = 1028;
  757. var RedIntegerFormat = 1029;
  758. var RGFormat = 1030;
  759. var RGIntegerFormat = 1031;
  760. var RGBIntegerFormat = 1032;
  761. var RGBAIntegerFormat = 1033;
  762. var RGB_S3TC_DXT1_Format = 33776;
  763. var RGBA_S3TC_DXT1_Format = 33777;
  764. var RGBA_S3TC_DXT3_Format = 33778;
  765. var RGBA_S3TC_DXT5_Format = 33779;
  766. var RGB_PVRTC_4BPPV1_Format = 35840;
  767. var RGB_PVRTC_2BPPV1_Format = 35841;
  768. var RGBA_PVRTC_4BPPV1_Format = 35842;
  769. var RGBA_PVRTC_2BPPV1_Format = 35843;
  770. var RGB_ETC1_Format = 36196;
  771. var RGB_ETC2_Format = 37492;
  772. var RGBA_ETC2_EAC_Format = 37496;
  773. var RGBA_ASTC_4x4_Format = 37808;
  774. var RGBA_ASTC_5x4_Format = 37809;
  775. var RGBA_ASTC_5x5_Format = 37810;
  776. var RGBA_ASTC_6x5_Format = 37811;
  777. var RGBA_ASTC_6x6_Format = 37812;
  778. var RGBA_ASTC_8x5_Format = 37813;
  779. var RGBA_ASTC_8x6_Format = 37814;
  780. var RGBA_ASTC_8x8_Format = 37815;
  781. var RGBA_ASTC_10x5_Format = 37816;
  782. var RGBA_ASTC_10x6_Format = 37817;
  783. var RGBA_ASTC_10x8_Format = 37818;
  784. var RGBA_ASTC_10x10_Format = 37819;
  785. var RGBA_ASTC_12x10_Format = 37820;
  786. var RGBA_ASTC_12x12_Format = 37821;
  787. var RGBA_BPTC_Format = 36492;
  788. var SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  789. var SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  790. var SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  791. var SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  792. var SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  793. var SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  794. var SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  795. var SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  796. var SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  797. var SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  798. var SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  799. var SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  800. var SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  801. var SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  802. var LoopOnce = 2200;
  803. var LoopRepeat = 2201;
  804. var LoopPingPong = 2202;
  805. var InterpolateDiscrete = 2300;
  806. var InterpolateLinear = 2301;
  807. var InterpolateSmooth = 2302;
  808. var ZeroCurvatureEnding = 2400;
  809. var ZeroSlopeEnding = 2401;
  810. var WrapAroundEnding = 2402;
  811. var NormalAnimationBlendMode = 2500;
  812. var AdditiveAnimationBlendMode = 2501;
  813. var TrianglesDrawMode = 0;
  814. var TriangleStripDrawMode = 1;
  815. var TriangleFanDrawMode = 2;
  816. var LinearEncoding = 3000;
  817. var sRGBEncoding = 3001;
  818. var GammaEncoding = 3007;
  819. var RGBEEncoding = 3002;
  820. var LogLuvEncoding = 3003;
  821. var RGBM7Encoding = 3004;
  822. var RGBM16Encoding = 3005;
  823. var RGBDEncoding = 3006;
  824. var BasicDepthPacking = 3200;
  825. var RGBADepthPacking = 3201;
  826. var TangentSpaceNormalMap = 0;
  827. var ObjectSpaceNormalMap = 1;
  828. var ZeroStencilOp = 0;
  829. var KeepStencilOp = 7680;
  830. var ReplaceStencilOp = 7681;
  831. var IncrementStencilOp = 7682;
  832. var DecrementStencilOp = 7683;
  833. var IncrementWrapStencilOp = 34055;
  834. var DecrementWrapStencilOp = 34056;
  835. var InvertStencilOp = 5386;
  836. var NeverStencilFunc = 512;
  837. var LessStencilFunc = 513;
  838. var EqualStencilFunc = 514;
  839. var LessEqualStencilFunc = 515;
  840. var GreaterStencilFunc = 516;
  841. var NotEqualStencilFunc = 517;
  842. var GreaterEqualStencilFunc = 518;
  843. var AlwaysStencilFunc = 519;
  844. var StaticDrawUsage = 35044;
  845. var DynamicDrawUsage = 35048;
  846. var StreamDrawUsage = 35040;
  847. var StaticReadUsage = 35045;
  848. var DynamicReadUsage = 35049;
  849. var StreamReadUsage = 35041;
  850. var StaticCopyUsage = 35046;
  851. var DynamicCopyUsage = 35050;
  852. var StreamCopyUsage = 35042;
  853. var GLSL1 = '100';
  854. var GLSL3 = '300 es';
  855. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  856. try {
  857. var info = gen[key](arg);
  858. var value = info.value;
  859. } catch (error) {
  860. reject(error);
  861. return;
  862. }
  863. if (info.done) {
  864. resolve(value);
  865. } else {
  866. Promise.resolve(value).then(_next, _throw);
  867. }
  868. }
  869. function _asyncToGenerator(fn) {
  870. return function () {
  871. var self = this,
  872. args = arguments;
  873. return new Promise(function (resolve, reject) {
  874. var gen = fn.apply(self, args);
  875. function _next(value) {
  876. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
  877. }
  878. function _throw(err) {
  879. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
  880. }
  881. _next(undefined);
  882. });
  883. };
  884. }
  885. function _defineProperties(target, props) {
  886. for (var i = 0; i < props.length; i++) {
  887. var descriptor = props[i];
  888. descriptor.enumerable = descriptor.enumerable || false;
  889. descriptor.configurable = true;
  890. if ("value" in descriptor) descriptor.writable = true;
  891. Object.defineProperty(target, descriptor.key, descriptor);
  892. }
  893. }
  894. function _createClass(Constructor, protoProps, staticProps) {
  895. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  896. if (staticProps) _defineProperties(Constructor, staticProps);
  897. return Constructor;
  898. }
  899. function _inheritsLoose(subClass, superClass) {
  900. subClass.prototype = Object.create(superClass.prototype);
  901. subClass.prototype.constructor = subClass;
  902. subClass.__proto__ = superClass;
  903. }
  904. function _assertThisInitialized(self) {
  905. if (self === void 0) {
  906. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  907. }
  908. return self;
  909. }
  910. function _unsupportedIterableToArray(o, minLen) {
  911. if (!o) return;
  912. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  913. var n = Object.prototype.toString.call(o).slice(8, -1);
  914. if (n === "Object" && o.constructor) n = o.constructor.name;
  915. if (n === "Map" || n === "Set") return Array.from(o);
  916. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  917. }
  918. function _arrayLikeToArray(arr, len) {
  919. if (len == null || len > arr.length) len = arr.length;
  920. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  921. return arr2;
  922. }
  923. function _createForOfIteratorHelperLoose(o, allowArrayLike) {
  924. var it;
  925. if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
  926. if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  927. if (it) o = it;
  928. var i = 0;
  929. return function () {
  930. if (i >= o.length) return {
  931. done: true
  932. };
  933. return {
  934. done: false,
  935. value: o[i++]
  936. };
  937. };
  938. }
  939. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  940. }
  941. it = o[Symbol.iterator]();
  942. return it.next.bind(it);
  943. }
  944. /**
  945. * https://github.com/mrdoob/eventdispatcher.js/
  946. */
  947. function EventDispatcher() {}
  948. Object.assign(EventDispatcher.prototype, {
  949. addEventListener: function addEventListener(type, listener) {
  950. if (this._listeners === undefined) this._listeners = {};
  951. var listeners = this._listeners;
  952. if (listeners[type] === undefined) {
  953. listeners[type] = [];
  954. }
  955. if (listeners[type].indexOf(listener) === -1) {
  956. listeners[type].push(listener);
  957. }
  958. },
  959. hasEventListener: function hasEventListener(type, listener) {
  960. if (this._listeners === undefined) return false;
  961. var listeners = this._listeners;
  962. return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
  963. },
  964. removeEventListener: function removeEventListener(type, listener) {
  965. if (this._listeners === undefined) return;
  966. var listeners = this._listeners;
  967. var listenerArray = listeners[type];
  968. if (listenerArray !== undefined) {
  969. var index = listenerArray.indexOf(listener);
  970. if (index !== -1) {
  971. listenerArray.splice(index, 1);
  972. }
  973. }
  974. },
  975. dispatchEvent: function dispatchEvent(event) {
  976. if (this._listeners === undefined) return;
  977. var listeners = this._listeners;
  978. var listenerArray = listeners[event.type];
  979. if (listenerArray !== undefined) {
  980. event.target = this; // Make a copy, in case listeners are removed while iterating.
  981. var array = listenerArray.slice(0);
  982. for (var i = 0, l = array.length; i < l; i++) {
  983. array[i].call(this, event);
  984. }
  985. }
  986. }
  987. });
  988. var _lut = [];
  989. for (var i = 0; i < 256; i++) {
  990. _lut[i] = (i < 16 ? '0' : '') + i.toString(16);
  991. }
  992. var _seed = 1234567;
  993. var MathUtils = {
  994. DEG2RAD: Math.PI / 180,
  995. RAD2DEG: 180 / Math.PI,
  996. generateUUID: function generateUUID() {
  997. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  998. var d0 = Math.random() * 0xffffffff | 0;
  999. var d1 = Math.random() * 0xffffffff | 0;
  1000. var d2 = Math.random() * 0xffffffff | 0;
  1001. var d3 = Math.random() * 0xffffffff | 0;
  1002. var uuid = _lut[d0 & 0xff] + _lut[d0 >> 8 & 0xff] + _lut[d0 >> 16 & 0xff] + _lut[d0 >> 24 & 0xff] + '-' + _lut[d1 & 0xff] + _lut[d1 >> 8 & 0xff] + '-' + _lut[d1 >> 16 & 0x0f | 0x40] + _lut[d1 >> 24 & 0xff] + '-' + _lut[d2 & 0x3f | 0x80] + _lut[d2 >> 8 & 0xff] + '-' + _lut[d2 >> 16 & 0xff] + _lut[d2 >> 24 & 0xff] + _lut[d3 & 0xff] + _lut[d3 >> 8 & 0xff] + _lut[d3 >> 16 & 0xff] + _lut[d3 >> 24 & 0xff]; // .toUpperCase() here flattens concatenated strings to save heap memory space.
  1003. return uuid.toUpperCase();
  1004. },
  1005. clamp: function clamp(value, min, max) {
  1006. return Math.max(min, Math.min(max, value));
  1007. },
  1008. // compute euclidian modulo of m % n
  1009. // https://en.wikipedia.org/wiki/Modulo_operation
  1010. euclideanModulo: function euclideanModulo(n, m) {
  1011. return (n % m + m) % m;
  1012. },
  1013. // Linear mapping from range <a1, a2> to range <b1, b2>
  1014. mapLinear: function mapLinear(x, a1, a2, b1, b2) {
  1015. return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
  1016. },
  1017. // https://en.wikipedia.org/wiki/Linear_interpolation
  1018. lerp: function lerp(x, y, t) {
  1019. return (1 - t) * x + t * y;
  1020. },
  1021. // http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/
  1022. damp: function damp(x, y, lambda, dt) {
  1023. return MathUtils.lerp(x, y, 1 - Math.exp(-lambda * dt));
  1024. },
  1025. // https://www.desmos.com/calculator/vcsjnyz7x4
  1026. pingpong: function pingpong(x, length) {
  1027. if (length === void 0) {
  1028. length = 1;
  1029. }
  1030. return length - Math.abs(MathUtils.euclideanModulo(x, length * 2) - length);
  1031. },
  1032. // http://en.wikipedia.org/wiki/Smoothstep
  1033. smoothstep: function smoothstep(x, min, max) {
  1034. if (x <= min) return 0;
  1035. if (x >= max) return 1;
  1036. x = (x - min) / (max - min);
  1037. return x * x * (3 - 2 * x);
  1038. },
  1039. smootherstep: function smootherstep(x, min, max) {
  1040. if (x <= min) return 0;
  1041. if (x >= max) return 1;
  1042. x = (x - min) / (max - min);
  1043. return x * x * x * (x * (x * 6 - 15) + 10);
  1044. },
  1045. // Random integer from <low, high> interval
  1046. randInt: function randInt(low, high) {
  1047. return low + Math.floor(Math.random() * (high - low + 1));
  1048. },
  1049. // Random float from <low, high> interval
  1050. randFloat: function randFloat(low, high) {
  1051. return low + Math.random() * (high - low);
  1052. },
  1053. // Random float from <-range/2, range/2> interval
  1054. randFloatSpread: function randFloatSpread(range) {
  1055. return range * (0.5 - Math.random());
  1056. },
  1057. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  1058. seededRandom: function seededRandom(s) {
  1059. if (s !== undefined) _seed = s % 2147483647; // Park-Miller algorithm
  1060. _seed = _seed * 16807 % 2147483647;
  1061. return (_seed - 1) / 2147483646;
  1062. },
  1063. degToRad: function degToRad(degrees) {
  1064. return degrees * MathUtils.DEG2RAD;
  1065. },
  1066. radToDeg: function radToDeg(radians) {
  1067. return radians * MathUtils.RAD2DEG;
  1068. },
  1069. isPowerOfTwo: function isPowerOfTwo(value) {
  1070. return (value & value - 1) === 0 && value !== 0;
  1071. },
  1072. ceilPowerOfTwo: function ceilPowerOfTwo(value) {
  1073. return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
  1074. },
  1075. floorPowerOfTwo: function floorPowerOfTwo(value) {
  1076. return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
  1077. },
  1078. setQuaternionFromProperEuler: function setQuaternionFromProperEuler(q, a, b, c, order) {
  1079. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  1080. // rotations are applied to the axes in the order specified by 'order'
  1081. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  1082. // angles are in radians
  1083. var cos = Math.cos;
  1084. var sin = Math.sin;
  1085. var c2 = cos(b / 2);
  1086. var s2 = sin(b / 2);
  1087. var c13 = cos((a + c) / 2);
  1088. var s13 = sin((a + c) / 2);
  1089. var c1_3 = cos((a - c) / 2);
  1090. var s1_3 = sin((a - c) / 2);
  1091. var c3_1 = cos((c - a) / 2);
  1092. var s3_1 = sin((c - a) / 2);
  1093. switch (order) {
  1094. case 'XYX':
  1095. q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
  1096. break;
  1097. case 'YZY':
  1098. q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
  1099. break;
  1100. case 'ZXZ':
  1101. q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
  1102. break;
  1103. case 'XZX':
  1104. q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
  1105. break;
  1106. case 'YXY':
  1107. q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
  1108. break;
  1109. case 'ZYZ':
  1110. q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
  1111. break;
  1112. default:
  1113. console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order);
  1114. }
  1115. }
  1116. };
  1117. var Vector2 = /*#__PURE__*/function () {
  1118. function Vector2(x, y) {
  1119. if (x === void 0) {
  1120. x = 0;
  1121. }
  1122. if (y === void 0) {
  1123. y = 0;
  1124. }
  1125. Object.defineProperty(this, 'isVector2', {
  1126. value: true
  1127. });
  1128. this.x = x;
  1129. this.y = y;
  1130. }
  1131. var _proto = Vector2.prototype;
  1132. _proto.set = function set(x, y) {
  1133. this.x = x;
  1134. this.y = y;
  1135. return this;
  1136. };
  1137. _proto.setScalar = function setScalar(scalar) {
  1138. this.x = scalar;
  1139. this.y = scalar;
  1140. return this;
  1141. };
  1142. _proto.setX = function setX(x) {
  1143. this.x = x;
  1144. return this;
  1145. };
  1146. _proto.setY = function setY(y) {
  1147. this.y = y;
  1148. return this;
  1149. };
  1150. _proto.setComponent = function setComponent(index, value) {
  1151. switch (index) {
  1152. case 0:
  1153. this.x = value;
  1154. break;
  1155. case 1:
  1156. this.y = value;
  1157. break;
  1158. default:
  1159. throw new Error('index is out of range: ' + index);
  1160. }
  1161. return this;
  1162. };
  1163. _proto.getComponent = function getComponent(index) {
  1164. switch (index) {
  1165. case 0:
  1166. return this.x;
  1167. case 1:
  1168. return this.y;
  1169. default:
  1170. throw new Error('index is out of range: ' + index);
  1171. }
  1172. };
  1173. _proto.clone = function clone() {
  1174. return new this.constructor(this.x, this.y);
  1175. };
  1176. _proto.copy = function copy(v) {
  1177. this.x = v.x;
  1178. this.y = v.y;
  1179. return this;
  1180. };
  1181. _proto.add = function add(v, w) {
  1182. if (w !== undefined) {
  1183. console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1184. return this.addVectors(v, w);
  1185. }
  1186. this.x += v.x;
  1187. this.y += v.y;
  1188. return this;
  1189. };
  1190. _proto.addScalar = function addScalar(s) {
  1191. this.x += s;
  1192. this.y += s;
  1193. return this;
  1194. };
  1195. _proto.addVectors = function addVectors(a, b) {
  1196. this.x = a.x + b.x;
  1197. this.y = a.y + b.y;
  1198. return this;
  1199. };
  1200. _proto.addScaledVector = function addScaledVector(v, s) {
  1201. this.x += v.x * s;
  1202. this.y += v.y * s;
  1203. return this;
  1204. };
  1205. _proto.sub = function sub(v, w) {
  1206. if (w !== undefined) {
  1207. console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  1208. return this.subVectors(v, w);
  1209. }
  1210. this.x -= v.x;
  1211. this.y -= v.y;
  1212. return this;
  1213. };
  1214. _proto.subScalar = function subScalar(s) {
  1215. this.x -= s;
  1216. this.y -= s;
  1217. return this;
  1218. };
  1219. _proto.subVectors = function subVectors(a, b) {
  1220. this.x = a.x - b.x;
  1221. this.y = a.y - b.y;
  1222. return this;
  1223. };
  1224. _proto.multiply = function multiply(v) {
  1225. this.x *= v.x;
  1226. this.y *= v.y;
  1227. return this;
  1228. };
  1229. _proto.multiplyScalar = function multiplyScalar(scalar) {
  1230. this.x *= scalar;
  1231. this.y *= scalar;
  1232. return this;
  1233. };
  1234. _proto.divide = function divide(v) {
  1235. this.x /= v.x;
  1236. this.y /= v.y;
  1237. return this;
  1238. };
  1239. _proto.divideScalar = function divideScalar(scalar) {
  1240. return this.multiplyScalar(1 / scalar);
  1241. };
  1242. _proto.applyMatrix3 = function applyMatrix3(m) {
  1243. var x = this.x,
  1244. y = this.y;
  1245. var e = m.elements;
  1246. this.x = e[0] * x + e[3] * y + e[6];
  1247. this.y = e[1] * x + e[4] * y + e[7];
  1248. return this;
  1249. };
  1250. _proto.min = function min(v) {
  1251. this.x = Math.min(this.x, v.x);
  1252. this.y = Math.min(this.y, v.y);
  1253. return this;
  1254. };
  1255. _proto.max = function max(v) {
  1256. this.x = Math.max(this.x, v.x);
  1257. this.y = Math.max(this.y, v.y);
  1258. return this;
  1259. };
  1260. _proto.clamp = function clamp(min, max) {
  1261. // assumes min < max, componentwise
  1262. this.x = Math.max(min.x, Math.min(max.x, this.x));
  1263. this.y = Math.max(min.y, Math.min(max.y, this.y));
  1264. return this;
  1265. };
  1266. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  1267. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  1268. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  1269. return this;
  1270. };
  1271. _proto.clampLength = function clampLength(min, max) {
  1272. var length = this.length();
  1273. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  1274. };
  1275. _proto.floor = function floor() {
  1276. this.x = Math.floor(this.x);
  1277. this.y = Math.floor(this.y);
  1278. return this;
  1279. };
  1280. _proto.ceil = function ceil() {
  1281. this.x = Math.ceil(this.x);
  1282. this.y = Math.ceil(this.y);
  1283. return this;
  1284. };
  1285. _proto.round = function round() {
  1286. this.x = Math.round(this.x);
  1287. this.y = Math.round(this.y);
  1288. return this;
  1289. };
  1290. _proto.roundToZero = function roundToZero() {
  1291. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  1292. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  1293. return this;
  1294. };
  1295. _proto.negate = function negate() {
  1296. this.x = -this.x;
  1297. this.y = -this.y;
  1298. return this;
  1299. };
  1300. _proto.dot = function dot(v) {
  1301. return this.x * v.x + this.y * v.y;
  1302. };
  1303. _proto.cross = function cross(v) {
  1304. return this.x * v.y - this.y * v.x;
  1305. };
  1306. _proto.lengthSq = function lengthSq() {
  1307. return this.x * this.x + this.y * this.y;
  1308. };
  1309. _proto.length = function length() {
  1310. return Math.sqrt(this.x * this.x + this.y * this.y);
  1311. };
  1312. _proto.manhattanLength = function manhattanLength() {
  1313. return Math.abs(this.x) + Math.abs(this.y);
  1314. };
  1315. _proto.normalize = function normalize() {
  1316. return this.divideScalar(this.length() || 1);
  1317. };
  1318. _proto.angle = function angle() {
  1319. // computes the angle in radians with respect to the positive x-axis
  1320. var angle = Math.atan2(-this.y, -this.x) + Math.PI;
  1321. return angle;
  1322. };
  1323. _proto.distanceTo = function distanceTo(v) {
  1324. return Math.sqrt(this.distanceToSquared(v));
  1325. };
  1326. _proto.distanceToSquared = function distanceToSquared(v) {
  1327. var dx = this.x - v.x,
  1328. dy = this.y - v.y;
  1329. return dx * dx + dy * dy;
  1330. };
  1331. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  1332. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
  1333. };
  1334. _proto.setLength = function setLength(length) {
  1335. return this.normalize().multiplyScalar(length);
  1336. };
  1337. _proto.lerp = function lerp(v, alpha) {
  1338. this.x += (v.x - this.x) * alpha;
  1339. this.y += (v.y - this.y) * alpha;
  1340. return this;
  1341. };
  1342. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  1343. this.x = v1.x + (v2.x - v1.x) * alpha;
  1344. this.y = v1.y + (v2.y - v1.y) * alpha;
  1345. return this;
  1346. };
  1347. _proto.equals = function equals(v) {
  1348. return v.x === this.x && v.y === this.y;
  1349. };
  1350. _proto.fromArray = function fromArray(array, offset) {
  1351. if (offset === void 0) {
  1352. offset = 0;
  1353. }
  1354. this.x = array[offset];
  1355. this.y = array[offset + 1];
  1356. return this;
  1357. };
  1358. _proto.toArray = function toArray(array, offset) {
  1359. if (array === void 0) {
  1360. array = [];
  1361. }
  1362. if (offset === void 0) {
  1363. offset = 0;
  1364. }
  1365. array[offset] = this.x;
  1366. array[offset + 1] = this.y;
  1367. return array;
  1368. };
  1369. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  1370. if (offset !== undefined) {
  1371. console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
  1372. }
  1373. this.x = attribute.getX(index);
  1374. this.y = attribute.getY(index);
  1375. return this;
  1376. };
  1377. _proto.rotateAround = function rotateAround(center, angle) {
  1378. var c = Math.cos(angle),
  1379. s = Math.sin(angle);
  1380. var x = this.x - center.x;
  1381. var y = this.y - center.y;
  1382. this.x = x * c - y * s + center.x;
  1383. this.y = x * s + y * c + center.y;
  1384. return this;
  1385. };
  1386. _proto.random = function random() {
  1387. this.x = Math.random();
  1388. this.y = Math.random();
  1389. return this;
  1390. };
  1391. _createClass(Vector2, [{
  1392. key: "width",
  1393. get: function get() {
  1394. return this.x;
  1395. },
  1396. set: function set(value) {
  1397. this.x = value;
  1398. }
  1399. }, {
  1400. key: "height",
  1401. get: function get() {
  1402. return this.y;
  1403. },
  1404. set: function set(value) {
  1405. this.y = value;
  1406. }
  1407. }]);
  1408. return Vector2;
  1409. }();
  1410. var Matrix3 = /*#__PURE__*/function () {
  1411. function Matrix3() {
  1412. Object.defineProperty(this, 'isMatrix3', {
  1413. value: true
  1414. });
  1415. this.elements = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  1416. if (arguments.length > 0) {
  1417. console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');
  1418. }
  1419. }
  1420. var _proto = Matrix3.prototype;
  1421. _proto.set = function set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
  1422. var te = this.elements;
  1423. te[0] = n11;
  1424. te[1] = n21;
  1425. te[2] = n31;
  1426. te[3] = n12;
  1427. te[4] = n22;
  1428. te[5] = n32;
  1429. te[6] = n13;
  1430. te[7] = n23;
  1431. te[8] = n33;
  1432. return this;
  1433. };
  1434. _proto.identity = function identity() {
  1435. this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
  1436. return this;
  1437. };
  1438. _proto.clone = function clone() {
  1439. return new this.constructor().fromArray(this.elements);
  1440. };
  1441. _proto.copy = function copy(m) {
  1442. var te = this.elements;
  1443. var me = m.elements;
  1444. te[0] = me[0];
  1445. te[1] = me[1];
  1446. te[2] = me[2];
  1447. te[3] = me[3];
  1448. te[4] = me[4];
  1449. te[5] = me[5];
  1450. te[6] = me[6];
  1451. te[7] = me[7];
  1452. te[8] = me[8];
  1453. return this;
  1454. };
  1455. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  1456. xAxis.setFromMatrix3Column(this, 0);
  1457. yAxis.setFromMatrix3Column(this, 1);
  1458. zAxis.setFromMatrix3Column(this, 2);
  1459. return this;
  1460. };
  1461. _proto.setFromMatrix4 = function setFromMatrix4(m) {
  1462. var me = m.elements;
  1463. this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
  1464. return this;
  1465. };
  1466. _proto.multiply = function multiply(m) {
  1467. return this.multiplyMatrices(this, m);
  1468. };
  1469. _proto.premultiply = function premultiply(m) {
  1470. return this.multiplyMatrices(m, this);
  1471. };
  1472. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  1473. var ae = a.elements;
  1474. var be = b.elements;
  1475. var te = this.elements;
  1476. var a11 = ae[0],
  1477. a12 = ae[3],
  1478. a13 = ae[6];
  1479. var a21 = ae[1],
  1480. a22 = ae[4],
  1481. a23 = ae[7];
  1482. var a31 = ae[2],
  1483. a32 = ae[5],
  1484. a33 = ae[8];
  1485. var b11 = be[0],
  1486. b12 = be[3],
  1487. b13 = be[6];
  1488. var b21 = be[1],
  1489. b22 = be[4],
  1490. b23 = be[7];
  1491. var b31 = be[2],
  1492. b32 = be[5],
  1493. b33 = be[8];
  1494. te[0] = a11 * b11 + a12 * b21 + a13 * b31;
  1495. te[3] = a11 * b12 + a12 * b22 + a13 * b32;
  1496. te[6] = a11 * b13 + a12 * b23 + a13 * b33;
  1497. te[1] = a21 * b11 + a22 * b21 + a23 * b31;
  1498. te[4] = a21 * b12 + a22 * b22 + a23 * b32;
  1499. te[7] = a21 * b13 + a22 * b23 + a23 * b33;
  1500. te[2] = a31 * b11 + a32 * b21 + a33 * b31;
  1501. te[5] = a31 * b12 + a32 * b22 + a33 * b32;
  1502. te[8] = a31 * b13 + a32 * b23 + a33 * b33;
  1503. return this;
  1504. };
  1505. _proto.multiplyScalar = function multiplyScalar(s) {
  1506. var te = this.elements;
  1507. te[0] *= s;
  1508. te[3] *= s;
  1509. te[6] *= s;
  1510. te[1] *= s;
  1511. te[4] *= s;
  1512. te[7] *= s;
  1513. te[2] *= s;
  1514. te[5] *= s;
  1515. te[8] *= s;
  1516. return this;
  1517. };
  1518. _proto.determinant = function determinant() {
  1519. var te = this.elements;
  1520. var a = te[0],
  1521. b = te[1],
  1522. c = te[2],
  1523. d = te[3],
  1524. e = te[4],
  1525. f = te[5],
  1526. g = te[6],
  1527. h = te[7],
  1528. i = te[8];
  1529. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  1530. };
  1531. _proto.invert = function invert() {
  1532. var te = this.elements,
  1533. n11 = te[0],
  1534. n21 = te[1],
  1535. n31 = te[2],
  1536. n12 = te[3],
  1537. n22 = te[4],
  1538. n32 = te[5],
  1539. n13 = te[6],
  1540. n23 = te[7],
  1541. n33 = te[8],
  1542. t11 = n33 * n22 - n32 * n23,
  1543. t12 = n32 * n13 - n33 * n12,
  1544. t13 = n23 * n12 - n22 * n13,
  1545. det = n11 * t11 + n21 * t12 + n31 * t13;
  1546. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
  1547. var detInv = 1 / det;
  1548. te[0] = t11 * detInv;
  1549. te[1] = (n31 * n23 - n33 * n21) * detInv;
  1550. te[2] = (n32 * n21 - n31 * n22) * detInv;
  1551. te[3] = t12 * detInv;
  1552. te[4] = (n33 * n11 - n31 * n13) * detInv;
  1553. te[5] = (n31 * n12 - n32 * n11) * detInv;
  1554. te[6] = t13 * detInv;
  1555. te[7] = (n21 * n13 - n23 * n11) * detInv;
  1556. te[8] = (n22 * n11 - n21 * n12) * detInv;
  1557. return this;
  1558. };
  1559. _proto.transpose = function transpose() {
  1560. var tmp;
  1561. var m = this.elements;
  1562. tmp = m[1];
  1563. m[1] = m[3];
  1564. m[3] = tmp;
  1565. tmp = m[2];
  1566. m[2] = m[6];
  1567. m[6] = tmp;
  1568. tmp = m[5];
  1569. m[5] = m[7];
  1570. m[7] = tmp;
  1571. return this;
  1572. };
  1573. _proto.getNormalMatrix = function getNormalMatrix(matrix4) {
  1574. return this.setFromMatrix4(matrix4).copy(this).invert().transpose();
  1575. };
  1576. _proto.transposeIntoArray = function transposeIntoArray(r) {
  1577. var m = this.elements;
  1578. r[0] = m[0];
  1579. r[1] = m[3];
  1580. r[2] = m[6];
  1581. r[3] = m[1];
  1582. r[4] = m[4];
  1583. r[5] = m[7];
  1584. r[6] = m[2];
  1585. r[7] = m[5];
  1586. r[8] = m[8];
  1587. return this;
  1588. };
  1589. _proto.setUvTransform = function setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
  1590. var c = Math.cos(rotation);
  1591. var s = Math.sin(rotation);
  1592. this.set(sx * c, sx * s, -sx * (c * cx + s * cy) + cx + tx, -sy * s, sy * c, -sy * (-s * cx + c * cy) + cy + ty, 0, 0, 1);
  1593. return this;
  1594. };
  1595. _proto.scale = function scale(sx, sy) {
  1596. var te = this.elements;
  1597. te[0] *= sx;
  1598. te[3] *= sx;
  1599. te[6] *= sx;
  1600. te[1] *= sy;
  1601. te[4] *= sy;
  1602. te[7] *= sy;
  1603. return this;
  1604. };
  1605. _proto.rotate = function rotate(theta) {
  1606. var c = Math.cos(theta);
  1607. var s = Math.sin(theta);
  1608. var te = this.elements;
  1609. var a11 = te[0],
  1610. a12 = te[3],
  1611. a13 = te[6];
  1612. var a21 = te[1],
  1613. a22 = te[4],
  1614. a23 = te[7];
  1615. te[0] = c * a11 + s * a21;
  1616. te[3] = c * a12 + s * a22;
  1617. te[6] = c * a13 + s * a23;
  1618. te[1] = -s * a11 + c * a21;
  1619. te[4] = -s * a12 + c * a22;
  1620. te[7] = -s * a13 + c * a23;
  1621. return this;
  1622. };
  1623. _proto.translate = function translate(tx, ty) {
  1624. var te = this.elements;
  1625. te[0] += tx * te[2];
  1626. te[3] += tx * te[5];
  1627. te[6] += tx * te[8];
  1628. te[1] += ty * te[2];
  1629. te[4] += ty * te[5];
  1630. te[7] += ty * te[8];
  1631. return this;
  1632. };
  1633. _proto.equals = function equals(matrix) {
  1634. var te = this.elements;
  1635. var me = matrix.elements;
  1636. for (var i = 0; i < 9; i++) {
  1637. if (te[i] !== me[i]) return false;
  1638. }
  1639. return true;
  1640. };
  1641. _proto.fromArray = function fromArray(array, offset) {
  1642. if (offset === void 0) {
  1643. offset = 0;
  1644. }
  1645. for (var i = 0; i < 9; i++) {
  1646. this.elements[i] = array[i + offset];
  1647. }
  1648. return this;
  1649. };
  1650. _proto.toArray = function toArray(array, offset) {
  1651. if (array === void 0) {
  1652. array = [];
  1653. }
  1654. if (offset === void 0) {
  1655. offset = 0;
  1656. }
  1657. var te = this.elements;
  1658. array[offset] = te[0];
  1659. array[offset + 1] = te[1];
  1660. array[offset + 2] = te[2];
  1661. array[offset + 3] = te[3];
  1662. array[offset + 4] = te[4];
  1663. array[offset + 5] = te[5];
  1664. array[offset + 6] = te[6];
  1665. array[offset + 7] = te[7];
  1666. array[offset + 8] = te[8];
  1667. return array;
  1668. };
  1669. return Matrix3;
  1670. }();
  1671. var _canvas;
  1672. var ImageUtils = {
  1673. getDataURL: function getDataURL(image) {
  1674. if (/^data:/i.test(image.src)) {
  1675. return image.src;
  1676. }
  1677. if (typeof HTMLCanvasElement == 'undefined') {
  1678. return image.src;
  1679. }
  1680. var canvas;
  1681. if (image instanceof HTMLCanvasElement) {
  1682. canvas = image;
  1683. } else {
  1684. if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  1685. _canvas.width = image.width;
  1686. _canvas.height = image.height;
  1687. var context = _canvas.getContext('2d');
  1688. if (image instanceof ImageData) {
  1689. context.putImageData(image, 0, 0);
  1690. } else {
  1691. context.drawImage(image, 0, 0, image.width, image.height);
  1692. }
  1693. canvas = _canvas;
  1694. }
  1695. if (canvas.width > 2048 || canvas.height > 2048) {
  1696. return canvas.toDataURL('image/jpeg', 0.6);
  1697. } else {
  1698. return canvas.toDataURL('image/png');
  1699. }
  1700. }
  1701. };
  1702. var textureId = 0;
  1703. function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  1704. if (image === void 0) {
  1705. image = Texture.DEFAULT_IMAGE;
  1706. }
  1707. if (mapping === void 0) {
  1708. mapping = Texture.DEFAULT_MAPPING;
  1709. }
  1710. if (wrapS === void 0) {
  1711. wrapS = ClampToEdgeWrapping;
  1712. }
  1713. if (wrapT === void 0) {
  1714. wrapT = ClampToEdgeWrapping;
  1715. }
  1716. if (magFilter === void 0) {
  1717. magFilter = LinearFilter;
  1718. }
  1719. if (minFilter === void 0) {
  1720. minFilter = LinearMipmapLinearFilter;
  1721. }
  1722. if (format === void 0) {
  1723. format = RGBAFormat;
  1724. }
  1725. if (type === void 0) {
  1726. type = UnsignedByteType;
  1727. }
  1728. if (anisotropy === void 0) {
  1729. anisotropy = 1;
  1730. }
  1731. if (encoding === void 0) {
  1732. encoding = LinearEncoding;
  1733. }
  1734. Object.defineProperty(this, 'id', {
  1735. value: textureId++
  1736. });
  1737. this.uuid = MathUtils.generateUUID();
  1738. this.name = '';
  1739. this.image = image;
  1740. this.mipmaps = [];
  1741. this.mapping = mapping;
  1742. this.wrapS = wrapS;
  1743. this.wrapT = wrapT;
  1744. this.magFilter = magFilter;
  1745. this.minFilter = minFilter;
  1746. this.anisotropy = anisotropy;
  1747. this.format = format;
  1748. this.internalFormat = null;
  1749. this.type = type;
  1750. this.offset = new Vector2(0, 0);
  1751. this.repeat = new Vector2(1, 1);
  1752. this.center = new Vector2(0, 0);
  1753. this.rotation = 0;
  1754. this.matrixAutoUpdate = true;
  1755. this.matrix = new Matrix3();
  1756. this.generateMipmaps = true;
  1757. this.premultiplyAlpha = false;
  1758. this.flipY = true;
  1759. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1760. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1761. //
  1762. // Also changing the encoding after already used by a Material will not automatically make the Material
  1763. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1764. this.encoding = encoding;
  1765. this.version = 0;
  1766. this.onUpdate = null;
  1767. }
  1768. Texture.DEFAULT_IMAGE = undefined;
  1769. Texture.DEFAULT_MAPPING = UVMapping;
  1770. Texture.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1771. constructor: Texture,
  1772. isTexture: true,
  1773. updateMatrix: function updateMatrix() {
  1774. this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  1775. },
  1776. clone: function clone() {
  1777. return new this.constructor().copy(this);
  1778. },
  1779. copy: function copy(source) {
  1780. this.name = source.name;
  1781. this.image = source.image;
  1782. this.mipmaps = source.mipmaps.slice(0);
  1783. this.mapping = source.mapping;
  1784. this.wrapS = source.wrapS;
  1785. this.wrapT = source.wrapT;
  1786. this.magFilter = source.magFilter;
  1787. this.minFilter = source.minFilter;
  1788. this.anisotropy = source.anisotropy;
  1789. this.format = source.format;
  1790. this.internalFormat = source.internalFormat;
  1791. this.type = source.type;
  1792. this.offset.copy(source.offset);
  1793. this.repeat.copy(source.repeat);
  1794. this.center.copy(source.center);
  1795. this.rotation = source.rotation;
  1796. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1797. this.matrix.copy(source.matrix);
  1798. this.generateMipmaps = source.generateMipmaps;
  1799. this.premultiplyAlpha = source.premultiplyAlpha;
  1800. this.flipY = source.flipY;
  1801. this.unpackAlignment = source.unpackAlignment;
  1802. this.encoding = source.encoding;
  1803. return this;
  1804. },
  1805. toJSON: function toJSON(meta) {
  1806. var isRootObject = meta === undefined || typeof meta === 'string';
  1807. if (!isRootObject && meta.textures[this.uuid] !== undefined) {
  1808. return meta.textures[this.uuid];
  1809. }
  1810. var output = {
  1811. metadata: {
  1812. version: 4.5,
  1813. type: 'Texture',
  1814. generator: 'Texture.toJSON'
  1815. },
  1816. uuid: this.uuid,
  1817. name: this.name,
  1818. mapping: this.mapping,
  1819. repeat: [this.repeat.x, this.repeat.y],
  1820. offset: [this.offset.x, this.offset.y],
  1821. center: [this.center.x, this.center.y],
  1822. rotation: this.rotation,
  1823. wrap: [this.wrapS, this.wrapT],
  1824. format: this.format,
  1825. type: this.type,
  1826. encoding: this.encoding,
  1827. minFilter: this.minFilter,
  1828. magFilter: this.magFilter,
  1829. anisotropy: this.anisotropy,
  1830. flipY: this.flipY,
  1831. premultiplyAlpha: this.premultiplyAlpha,
  1832. unpackAlignment: this.unpackAlignment
  1833. };
  1834. if (this.image !== undefined) {
  1835. // TODO: Move to THREE.Image
  1836. var image = this.image;
  1837. if (image.uuid === undefined) {
  1838. image.uuid = MathUtils.generateUUID(); // UGH
  1839. }
  1840. if (!isRootObject && meta.images[image.uuid] === undefined) {
  1841. var url;
  1842. if (Array.isArray(image)) {
  1843. // process array of images e.g. CubeTexture
  1844. url = [];
  1845. for (var i = 0, l = image.length; i < l; i++) {
  1846. // check cube texture with data textures
  1847. if (image[i].isDataTexture) {
  1848. url.push(serializeImage(image[i].image));
  1849. } else {
  1850. url.push(serializeImage(image[i]));
  1851. }
  1852. }
  1853. } else {
  1854. // process single image
  1855. url = serializeImage(image);
  1856. }
  1857. meta.images[image.uuid] = {
  1858. uuid: image.uuid,
  1859. url: url
  1860. };
  1861. }
  1862. output.image = image.uuid;
  1863. }
  1864. if (!isRootObject) {
  1865. meta.textures[this.uuid] = output;
  1866. }
  1867. return output;
  1868. },
  1869. dispose: function dispose() {
  1870. this.dispatchEvent({
  1871. type: 'dispose'
  1872. });
  1873. },
  1874. transformUv: function transformUv(uv) {
  1875. if (this.mapping !== UVMapping) return uv;
  1876. uv.applyMatrix3(this.matrix);
  1877. if (uv.x < 0 || uv.x > 1) {
  1878. switch (this.wrapS) {
  1879. case RepeatWrapping:
  1880. uv.x = uv.x - Math.floor(uv.x);
  1881. break;
  1882. case ClampToEdgeWrapping:
  1883. uv.x = uv.x < 0 ? 0 : 1;
  1884. break;
  1885. case MirroredRepeatWrapping:
  1886. if (Math.abs(Math.floor(uv.x) % 2) === 1) {
  1887. uv.x = Math.ceil(uv.x) - uv.x;
  1888. } else {
  1889. uv.x = uv.x - Math.floor(uv.x);
  1890. }
  1891. break;
  1892. }
  1893. }
  1894. if (uv.y < 0 || uv.y > 1) {
  1895. switch (this.wrapT) {
  1896. case RepeatWrapping:
  1897. uv.y = uv.y - Math.floor(uv.y);
  1898. break;
  1899. case ClampToEdgeWrapping:
  1900. uv.y = uv.y < 0 ? 0 : 1;
  1901. break;
  1902. case MirroredRepeatWrapping:
  1903. if (Math.abs(Math.floor(uv.y) % 2) === 1) {
  1904. uv.y = Math.ceil(uv.y) - uv.y;
  1905. } else {
  1906. uv.y = uv.y - Math.floor(uv.y);
  1907. }
  1908. break;
  1909. }
  1910. }
  1911. if (this.flipY) {
  1912. uv.y = 1 - uv.y;
  1913. }
  1914. return uv;
  1915. }
  1916. });
  1917. Object.defineProperty(Texture.prototype, 'needsUpdate', {
  1918. set: function set(value) {
  1919. if (value === true) this.version++;
  1920. }
  1921. });
  1922. function serializeImage(image) {
  1923. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  1924. // default images
  1925. return ImageUtils.getDataURL(image);
  1926. } else {
  1927. if (image.data) {
  1928. // images of DataTexture
  1929. return {
  1930. data: Array.prototype.slice.call(image.data),
  1931. width: image.width,
  1932. height: image.height,
  1933. type: image.data.constructor.name
  1934. };
  1935. } else {
  1936. console.warn('THREE.Texture: Unable to serialize Texture.');
  1937. return {};
  1938. }
  1939. }
  1940. }
  1941. var Vector4 = /*#__PURE__*/function () {
  1942. function Vector4(x, y, z, w) {
  1943. if (x === void 0) {
  1944. x = 0;
  1945. }
  1946. if (y === void 0) {
  1947. y = 0;
  1948. }
  1949. if (z === void 0) {
  1950. z = 0;
  1951. }
  1952. if (w === void 0) {
  1953. w = 1;
  1954. }
  1955. Object.defineProperty(this, 'isVector4', {
  1956. value: true
  1957. });
  1958. this.x = x;
  1959. this.y = y;
  1960. this.z = z;
  1961. this.w = w;
  1962. }
  1963. var _proto = Vector4.prototype;
  1964. _proto.set = function set(x, y, z, w) {
  1965. this.x = x;
  1966. this.y = y;
  1967. this.z = z;
  1968. this.w = w;
  1969. return this;
  1970. };
  1971. _proto.setScalar = function setScalar(scalar) {
  1972. this.x = scalar;
  1973. this.y = scalar;
  1974. this.z = scalar;
  1975. this.w = scalar;
  1976. return this;
  1977. };
  1978. _proto.setX = function setX(x) {
  1979. this.x = x;
  1980. return this;
  1981. };
  1982. _proto.setY = function setY(y) {
  1983. this.y = y;
  1984. return this;
  1985. };
  1986. _proto.setZ = function setZ(z) {
  1987. this.z = z;
  1988. return this;
  1989. };
  1990. _proto.setW = function setW(w) {
  1991. this.w = w;
  1992. return this;
  1993. };
  1994. _proto.setComponent = function setComponent(index, value) {
  1995. switch (index) {
  1996. case 0:
  1997. this.x = value;
  1998. break;
  1999. case 1:
  2000. this.y = value;
  2001. break;
  2002. case 2:
  2003. this.z = value;
  2004. break;
  2005. case 3:
  2006. this.w = value;
  2007. break;
  2008. default:
  2009. throw new Error('index is out of range: ' + index);
  2010. }
  2011. return this;
  2012. };
  2013. _proto.getComponent = function getComponent(index) {
  2014. switch (index) {
  2015. case 0:
  2016. return this.x;
  2017. case 1:
  2018. return this.y;
  2019. case 2:
  2020. return this.z;
  2021. case 3:
  2022. return this.w;
  2023. default:
  2024. throw new Error('index is out of range: ' + index);
  2025. }
  2026. };
  2027. _proto.clone = function clone() {
  2028. return new this.constructor(this.x, this.y, this.z, this.w);
  2029. };
  2030. _proto.copy = function copy(v) {
  2031. this.x = v.x;
  2032. this.y = v.y;
  2033. this.z = v.z;
  2034. this.w = v.w !== undefined ? v.w : 1;
  2035. return this;
  2036. };
  2037. _proto.add = function add(v, w) {
  2038. if (w !== undefined) {
  2039. console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2040. return this.addVectors(v, w);
  2041. }
  2042. this.x += v.x;
  2043. this.y += v.y;
  2044. this.z += v.z;
  2045. this.w += v.w;
  2046. return this;
  2047. };
  2048. _proto.addScalar = function addScalar(s) {
  2049. this.x += s;
  2050. this.y += s;
  2051. this.z += s;
  2052. this.w += s;
  2053. return this;
  2054. };
  2055. _proto.addVectors = function addVectors(a, b) {
  2056. this.x = a.x + b.x;
  2057. this.y = a.y + b.y;
  2058. this.z = a.z + b.z;
  2059. this.w = a.w + b.w;
  2060. return this;
  2061. };
  2062. _proto.addScaledVector = function addScaledVector(v, s) {
  2063. this.x += v.x * s;
  2064. this.y += v.y * s;
  2065. this.z += v.z * s;
  2066. this.w += v.w * s;
  2067. return this;
  2068. };
  2069. _proto.sub = function sub(v, w) {
  2070. if (w !== undefined) {
  2071. console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2072. return this.subVectors(v, w);
  2073. }
  2074. this.x -= v.x;
  2075. this.y -= v.y;
  2076. this.z -= v.z;
  2077. this.w -= v.w;
  2078. return this;
  2079. };
  2080. _proto.subScalar = function subScalar(s) {
  2081. this.x -= s;
  2082. this.y -= s;
  2083. this.z -= s;
  2084. this.w -= s;
  2085. return this;
  2086. };
  2087. _proto.subVectors = function subVectors(a, b) {
  2088. this.x = a.x - b.x;
  2089. this.y = a.y - b.y;
  2090. this.z = a.z - b.z;
  2091. this.w = a.w - b.w;
  2092. return this;
  2093. };
  2094. _proto.multiply = function multiply(v) {
  2095. this.x *= v.x;
  2096. this.y *= v.y;
  2097. this.z *= v.z;
  2098. this.w *= v.w;
  2099. return this;
  2100. };
  2101. _proto.multiplyScalar = function multiplyScalar(scalar) {
  2102. this.x *= scalar;
  2103. this.y *= scalar;
  2104. this.z *= scalar;
  2105. this.w *= scalar;
  2106. return this;
  2107. };
  2108. _proto.applyMatrix4 = function applyMatrix4(m) {
  2109. var x = this.x,
  2110. y = this.y,
  2111. z = this.z,
  2112. w = this.w;
  2113. var e = m.elements;
  2114. this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
  2115. this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
  2116. this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
  2117. this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
  2118. return this;
  2119. };
  2120. _proto.divideScalar = function divideScalar(scalar) {
  2121. return this.multiplyScalar(1 / scalar);
  2122. };
  2123. _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
  2124. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2125. // q is assumed to be normalized
  2126. this.w = 2 * Math.acos(q.w);
  2127. var s = Math.sqrt(1 - q.w * q.w);
  2128. if (s < 0.0001) {
  2129. this.x = 1;
  2130. this.y = 0;
  2131. this.z = 0;
  2132. } else {
  2133. this.x = q.x / s;
  2134. this.y = q.y / s;
  2135. this.z = q.z / s;
  2136. }
  2137. return this;
  2138. };
  2139. _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
  2140. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2141. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2142. var angle, x, y, z; // variables for result
  2143. var epsilon = 0.01,
  2144. // margin to allow for rounding errors
  2145. epsilon2 = 0.1,
  2146. // margin to distinguish between 0 and 180 degrees
  2147. te = m.elements,
  2148. m11 = te[0],
  2149. m12 = te[4],
  2150. m13 = te[8],
  2151. m21 = te[1],
  2152. m22 = te[5],
  2153. m23 = te[9],
  2154. m31 = te[2],
  2155. m32 = te[6],
  2156. m33 = te[10];
  2157. if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
  2158. // singularity found
  2159. // first check for identity matrix which must have +1 for all terms
  2160. // in leading diagonal and zero in other terms
  2161. if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
  2162. // this singularity is identity matrix so angle = 0
  2163. this.set(1, 0, 0, 0);
  2164. return this; // zero angle, arbitrary axis
  2165. } // otherwise this singularity is angle = 180
  2166. angle = Math.PI;
  2167. var xx = (m11 + 1) / 2;
  2168. var yy = (m22 + 1) / 2;
  2169. var zz = (m33 + 1) / 2;
  2170. var xy = (m12 + m21) / 4;
  2171. var xz = (m13 + m31) / 4;
  2172. var yz = (m23 + m32) / 4;
  2173. if (xx > yy && xx > zz) {
  2174. // m11 is the largest diagonal term
  2175. if (xx < epsilon) {
  2176. x = 0;
  2177. y = 0.707106781;
  2178. z = 0.707106781;
  2179. } else {
  2180. x = Math.sqrt(xx);
  2181. y = xy / x;
  2182. z = xz / x;
  2183. }
  2184. } else if (yy > zz) {
  2185. // m22 is the largest diagonal term
  2186. if (yy < epsilon) {
  2187. x = 0.707106781;
  2188. y = 0;
  2189. z = 0.707106781;
  2190. } else {
  2191. y = Math.sqrt(yy);
  2192. x = xy / y;
  2193. z = yz / y;
  2194. }
  2195. } else {
  2196. // m33 is the largest diagonal term so base result on this
  2197. if (zz < epsilon) {
  2198. x = 0.707106781;
  2199. y = 0.707106781;
  2200. z = 0;
  2201. } else {
  2202. z = Math.sqrt(zz);
  2203. x = xz / z;
  2204. y = yz / z;
  2205. }
  2206. }
  2207. this.set(x, y, z, angle);
  2208. return this; // return 180 deg rotation
  2209. } // as we have reached here there are no singularities so we can handle normally
  2210. var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
  2211. if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2212. // caught by singularity test above, but I've left it in just in case
  2213. this.x = (m32 - m23) / s;
  2214. this.y = (m13 - m31) / s;
  2215. this.z = (m21 - m12) / s;
  2216. this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
  2217. return this;
  2218. };
  2219. _proto.min = function min(v) {
  2220. this.x = Math.min(this.x, v.x);
  2221. this.y = Math.min(this.y, v.y);
  2222. this.z = Math.min(this.z, v.z);
  2223. this.w = Math.min(this.w, v.w);
  2224. return this;
  2225. };
  2226. _proto.max = function max(v) {
  2227. this.x = Math.max(this.x, v.x);
  2228. this.y = Math.max(this.y, v.y);
  2229. this.z = Math.max(this.z, v.z);
  2230. this.w = Math.max(this.w, v.w);
  2231. return this;
  2232. };
  2233. _proto.clamp = function clamp(min, max) {
  2234. // assumes min < max, componentwise
  2235. this.x = Math.max(min.x, Math.min(max.x, this.x));
  2236. this.y = Math.max(min.y, Math.min(max.y, this.y));
  2237. this.z = Math.max(min.z, Math.min(max.z, this.z));
  2238. this.w = Math.max(min.w, Math.min(max.w, this.w));
  2239. return this;
  2240. };
  2241. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  2242. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  2243. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  2244. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  2245. this.w = Math.max(minVal, Math.min(maxVal, this.w));
  2246. return this;
  2247. };
  2248. _proto.clampLength = function clampLength(min, max) {
  2249. var length = this.length();
  2250. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  2251. };
  2252. _proto.floor = function floor() {
  2253. this.x = Math.floor(this.x);
  2254. this.y = Math.floor(this.y);
  2255. this.z = Math.floor(this.z);
  2256. this.w = Math.floor(this.w);
  2257. return this;
  2258. };
  2259. _proto.ceil = function ceil() {
  2260. this.x = Math.ceil(this.x);
  2261. this.y = Math.ceil(this.y);
  2262. this.z = Math.ceil(this.z);
  2263. this.w = Math.ceil(this.w);
  2264. return this;
  2265. };
  2266. _proto.round = function round() {
  2267. this.x = Math.round(this.x);
  2268. this.y = Math.round(this.y);
  2269. this.z = Math.round(this.z);
  2270. this.w = Math.round(this.w);
  2271. return this;
  2272. };
  2273. _proto.roundToZero = function roundToZero() {
  2274. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  2275. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  2276. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  2277. this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
  2278. return this;
  2279. };
  2280. _proto.negate = function negate() {
  2281. this.x = -this.x;
  2282. this.y = -this.y;
  2283. this.z = -this.z;
  2284. this.w = -this.w;
  2285. return this;
  2286. };
  2287. _proto.dot = function dot(v) {
  2288. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2289. };
  2290. _proto.lengthSq = function lengthSq() {
  2291. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2292. };
  2293. _proto.length = function length() {
  2294. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  2295. };
  2296. _proto.manhattanLength = function manhattanLength() {
  2297. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  2298. };
  2299. _proto.normalize = function normalize() {
  2300. return this.divideScalar(this.length() || 1);
  2301. };
  2302. _proto.setLength = function setLength(length) {
  2303. return this.normalize().multiplyScalar(length);
  2304. };
  2305. _proto.lerp = function lerp(v, alpha) {
  2306. this.x += (v.x - this.x) * alpha;
  2307. this.y += (v.y - this.y) * alpha;
  2308. this.z += (v.z - this.z) * alpha;
  2309. this.w += (v.w - this.w) * alpha;
  2310. return this;
  2311. };
  2312. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  2313. this.x = v1.x + (v2.x - v1.x) * alpha;
  2314. this.y = v1.y + (v2.y - v1.y) * alpha;
  2315. this.z = v1.z + (v2.z - v1.z) * alpha;
  2316. this.w = v1.w + (v2.w - v1.w) * alpha;
  2317. return this;
  2318. };
  2319. _proto.equals = function equals(v) {
  2320. return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
  2321. };
  2322. _proto.fromArray = function fromArray(array, offset) {
  2323. if (offset === void 0) {
  2324. offset = 0;
  2325. }
  2326. this.x = array[offset];
  2327. this.y = array[offset + 1];
  2328. this.z = array[offset + 2];
  2329. this.w = array[offset + 3];
  2330. return this;
  2331. };
  2332. _proto.toArray = function toArray(array, offset) {
  2333. if (array === void 0) {
  2334. array = [];
  2335. }
  2336. if (offset === void 0) {
  2337. offset = 0;
  2338. }
  2339. array[offset] = this.x;
  2340. array[offset + 1] = this.y;
  2341. array[offset + 2] = this.z;
  2342. array[offset + 3] = this.w;
  2343. return array;
  2344. };
  2345. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  2346. if (offset !== undefined) {
  2347. console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
  2348. }
  2349. this.x = attribute.getX(index);
  2350. this.y = attribute.getY(index);
  2351. this.z = attribute.getZ(index);
  2352. this.w = attribute.getW(index);
  2353. return this;
  2354. };
  2355. _proto.random = function random() {
  2356. this.x = Math.random();
  2357. this.y = Math.random();
  2358. this.z = Math.random();
  2359. this.w = Math.random();
  2360. return this;
  2361. };
  2362. _createClass(Vector4, [{
  2363. key: "width",
  2364. get: function get() {
  2365. return this.z;
  2366. },
  2367. set: function set(value) {
  2368. this.z = value;
  2369. }
  2370. }, {
  2371. key: "height",
  2372. get: function get() {
  2373. return this.w;
  2374. },
  2375. set: function set(value) {
  2376. this.w = value;
  2377. }
  2378. }]);
  2379. return Vector4;
  2380. }();
  2381. /*
  2382. In options, we can specify:
  2383. * Texture parameters for an auto-generated target texture
  2384. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2385. */
  2386. var WebGLRenderTarget = /*#__PURE__*/function (_EventDispatcher) {
  2387. _inheritsLoose(WebGLRenderTarget, _EventDispatcher);
  2388. function WebGLRenderTarget(width, height, options) {
  2389. var _this;
  2390. _this = _EventDispatcher.call(this) || this;
  2391. Object.defineProperty(_assertThisInitialized(_this), 'isWebGLRenderTarget', {
  2392. value: true
  2393. });
  2394. _this.width = width;
  2395. _this.height = height;
  2396. _this.depth = 1;
  2397. _this.scissor = new Vector4(0, 0, width, height);
  2398. _this.scissorTest = false;
  2399. _this.viewport = new Vector4(0, 0, width, height);
  2400. options = options || {};
  2401. _this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  2402. _this.texture.image = {};
  2403. _this.texture.image.width = width;
  2404. _this.texture.image.height = height;
  2405. _this.texture.image.depth = 1;
  2406. _this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2407. _this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2408. _this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2409. _this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  2410. _this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2411. return _this;
  2412. }
  2413. var _proto = WebGLRenderTarget.prototype;
  2414. _proto.setTexture = function setTexture(texture) {
  2415. texture.image = {
  2416. width: this.width,
  2417. height: this.height,
  2418. depth: this.depth
  2419. };
  2420. this.texture = texture;
  2421. };
  2422. _proto.setSize = function setSize(width, height, depth) {
  2423. if (depth === void 0) {
  2424. depth = 1;
  2425. }
  2426. if (this.width !== width || this.height !== height || this.depth !== depth) {
  2427. this.width = width;
  2428. this.height = height;
  2429. this.depth = depth;
  2430. this.texture.image.width = width;
  2431. this.texture.image.height = height;
  2432. this.texture.image.depth = depth;
  2433. this.dispose();
  2434. }
  2435. this.viewport.set(0, 0, width, height);
  2436. this.scissor.set(0, 0, width, height);
  2437. };
  2438. _proto.clone = function clone() {
  2439. return new this.constructor().copy(this);
  2440. };
  2441. _proto.copy = function copy(source) {
  2442. this.width = source.width;
  2443. this.height = source.height;
  2444. this.depth = source.depth;
  2445. this.viewport.copy(source.viewport);
  2446. this.texture = source.texture.clone();
  2447. this.depthBuffer = source.depthBuffer;
  2448. this.stencilBuffer = source.stencilBuffer;
  2449. this.depthTexture = source.depthTexture;
  2450. return this;
  2451. };
  2452. _proto.dispose = function dispose() {
  2453. this.dispatchEvent({
  2454. type: 'dispose'
  2455. });
  2456. };
  2457. return WebGLRenderTarget;
  2458. }(EventDispatcher);
  2459. var WebGLMultisampleRenderTarget = /*#__PURE__*/function (_WebGLRenderTarget) {
  2460. _inheritsLoose(WebGLMultisampleRenderTarget, _WebGLRenderTarget);
  2461. function WebGLMultisampleRenderTarget(width, height, options) {
  2462. var _this;
  2463. _this = _WebGLRenderTarget.call(this, width, height, options) || this;
  2464. Object.defineProperty(_assertThisInitialized(_this), 'isWebGLMultisampleRenderTarget', {
  2465. value: true
  2466. });
  2467. _this.samples = 4;
  2468. return _this;
  2469. }
  2470. var _proto = WebGLMultisampleRenderTarget.prototype;
  2471. _proto.copy = function copy(source) {
  2472. _WebGLRenderTarget.prototype.copy.call(this, source);
  2473. this.samples = source.samples;
  2474. return this;
  2475. };
  2476. return WebGLMultisampleRenderTarget;
  2477. }(WebGLRenderTarget);
  2478. var Quaternion = /*#__PURE__*/function () {
  2479. function Quaternion(x, y, z, w) {
  2480. if (x === void 0) {
  2481. x = 0;
  2482. }
  2483. if (y === void 0) {
  2484. y = 0;
  2485. }
  2486. if (z === void 0) {
  2487. z = 0;
  2488. }
  2489. if (w === void 0) {
  2490. w = 1;
  2491. }
  2492. Object.defineProperty(this, 'isQuaternion', {
  2493. value: true
  2494. });
  2495. this._x = x;
  2496. this._y = y;
  2497. this._z = z;
  2498. this._w = w;
  2499. }
  2500. Quaternion.slerp = function slerp(qa, qb, qm, t) {
  2501. return qm.copy(qa).slerp(qb, t);
  2502. };
  2503. Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
  2504. // fuzz-free, array-based Quaternion SLERP operation
  2505. var x0 = src0[srcOffset0 + 0],
  2506. y0 = src0[srcOffset0 + 1],
  2507. z0 = src0[srcOffset0 + 2],
  2508. w0 = src0[srcOffset0 + 3];
  2509. var x1 = src1[srcOffset1 + 0],
  2510. y1 = src1[srcOffset1 + 1],
  2511. z1 = src1[srcOffset1 + 2],
  2512. w1 = src1[srcOffset1 + 3];
  2513. if (t === 0) {
  2514. dst[dstOffset + 0] = x0;
  2515. dst[dstOffset + 1] = y0;
  2516. dst[dstOffset + 2] = z0;
  2517. dst[dstOffset + 3] = w0;
  2518. return;
  2519. }
  2520. if (t === 1) {
  2521. dst[dstOffset + 0] = x1;
  2522. dst[dstOffset + 1] = y1;
  2523. dst[dstOffset + 2] = z1;
  2524. dst[dstOffset + 3] = w1;
  2525. return;
  2526. }
  2527. if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
  2528. var s = 1 - t;
  2529. var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  2530. dir = cos >= 0 ? 1 : -1,
  2531. sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
  2532. if (sqrSin > Number.EPSILON) {
  2533. var sin = Math.sqrt(sqrSin),
  2534. len = Math.atan2(sin, cos * dir);
  2535. s = Math.sin(s * len) / sin;
  2536. t = Math.sin(t * len) / sin;
  2537. }
  2538. var tDir = t * dir;
  2539. x0 = x0 * s + x1 * tDir;
  2540. y0 = y0 * s + y1 * tDir;
  2541. z0 = z0 * s + z1 * tDir;
  2542. w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
  2543. if (s === 1 - t) {
  2544. var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
  2545. x0 *= f;
  2546. y0 *= f;
  2547. z0 *= f;
  2548. w0 *= f;
  2549. }
  2550. }
  2551. dst[dstOffset] = x0;
  2552. dst[dstOffset + 1] = y0;
  2553. dst[dstOffset + 2] = z0;
  2554. dst[dstOffset + 3] = w0;
  2555. };
  2556. Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
  2557. var x0 = src0[srcOffset0];
  2558. var y0 = src0[srcOffset0 + 1];
  2559. var z0 = src0[srcOffset0 + 2];
  2560. var w0 = src0[srcOffset0 + 3];
  2561. var x1 = src1[srcOffset1];
  2562. var y1 = src1[srcOffset1 + 1];
  2563. var z1 = src1[srcOffset1 + 2];
  2564. var w1 = src1[srcOffset1 + 3];
  2565. dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  2566. dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  2567. dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  2568. dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  2569. return dst;
  2570. };
  2571. var _proto = Quaternion.prototype;
  2572. _proto.set = function set(x, y, z, w) {
  2573. this._x = x;
  2574. this._y = y;
  2575. this._z = z;
  2576. this._w = w;
  2577. this._onChangeCallback();
  2578. return this;
  2579. };
  2580. _proto.clone = function clone() {
  2581. return new this.constructor(this._x, this._y, this._z, this._w);
  2582. };
  2583. _proto.copy = function copy(quaternion) {
  2584. this._x = quaternion.x;
  2585. this._y = quaternion.y;
  2586. this._z = quaternion.z;
  2587. this._w = quaternion.w;
  2588. this._onChangeCallback();
  2589. return this;
  2590. };
  2591. _proto.setFromEuler = function setFromEuler(euler, update) {
  2592. if (!(euler && euler.isEuler)) {
  2593. throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
  2594. }
  2595. var x = euler._x,
  2596. y = euler._y,
  2597. z = euler._z,
  2598. order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
  2599. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  2600. // content/SpinCalc.m
  2601. var cos = Math.cos;
  2602. var sin = Math.sin;
  2603. var c1 = cos(x / 2);
  2604. var c2 = cos(y / 2);
  2605. var c3 = cos(z / 2);
  2606. var s1 = sin(x / 2);
  2607. var s2 = sin(y / 2);
  2608. var s3 = sin(z / 2);
  2609. switch (order) {
  2610. case 'XYZ':
  2611. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2612. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2613. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2614. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2615. break;
  2616. case 'YXZ':
  2617. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2618. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2619. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2620. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2621. break;
  2622. case 'ZXY':
  2623. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2624. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2625. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2626. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2627. break;
  2628. case 'ZYX':
  2629. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2630. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2631. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2632. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2633. break;
  2634. case 'YZX':
  2635. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2636. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2637. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2638. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2639. break;
  2640. case 'XZY':
  2641. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2642. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2643. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2644. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2645. break;
  2646. default:
  2647. console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
  2648. }
  2649. if (update !== false) this._onChangeCallback();
  2650. return this;
  2651. };
  2652. _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
  2653. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  2654. // assumes axis is normalized
  2655. var halfAngle = angle / 2,
  2656. s = Math.sin(halfAngle);
  2657. this._x = axis.x * s;
  2658. this._y = axis.y * s;
  2659. this._z = axis.z * s;
  2660. this._w = Math.cos(halfAngle);
  2661. this._onChangeCallback();
  2662. return this;
  2663. };
  2664. _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
  2665. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  2666. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2667. var te = m.elements,
  2668. m11 = te[0],
  2669. m12 = te[4],
  2670. m13 = te[8],
  2671. m21 = te[1],
  2672. m22 = te[5],
  2673. m23 = te[9],
  2674. m31 = te[2],
  2675. m32 = te[6],
  2676. m33 = te[10],
  2677. trace = m11 + m22 + m33;
  2678. if (trace > 0) {
  2679. var s = 0.5 / Math.sqrt(trace + 1.0);
  2680. this._w = 0.25 / s;
  2681. this._x = (m32 - m23) * s;
  2682. this._y = (m13 - m31) * s;
  2683. this._z = (m21 - m12) * s;
  2684. } else if (m11 > m22 && m11 > m33) {
  2685. var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  2686. this._w = (m32 - m23) / _s;
  2687. this._x = 0.25 * _s;
  2688. this._y = (m12 + m21) / _s;
  2689. this._z = (m13 + m31) / _s;
  2690. } else if (m22 > m33) {
  2691. var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  2692. this._w = (m13 - m31) / _s2;
  2693. this._x = (m12 + m21) / _s2;
  2694. this._y = 0.25 * _s2;
  2695. this._z = (m23 + m32) / _s2;
  2696. } else {
  2697. var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  2698. this._w = (m21 - m12) / _s3;
  2699. this._x = (m13 + m31) / _s3;
  2700. this._y = (m23 + m32) / _s3;
  2701. this._z = 0.25 * _s3;
  2702. }
  2703. this._onChangeCallback();
  2704. return this;
  2705. };
  2706. _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
  2707. // assumes direction vectors vFrom and vTo are normalized
  2708. var EPS = 0.000001;
  2709. var r = vFrom.dot(vTo) + 1;
  2710. if (r < EPS) {
  2711. r = 0;
  2712. if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
  2713. this._x = -vFrom.y;
  2714. this._y = vFrom.x;
  2715. this._z = 0;
  2716. this._w = r;
  2717. } else {
  2718. this._x = 0;
  2719. this._y = -vFrom.z;
  2720. this._z = vFrom.y;
  2721. this._w = r;
  2722. }
  2723. } else {
  2724. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  2725. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  2726. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  2727. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  2728. this._w = r;
  2729. }
  2730. return this.normalize();
  2731. };
  2732. _proto.angleTo = function angleTo(q) {
  2733. return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
  2734. };
  2735. _proto.rotateTowards = function rotateTowards(q, step) {
  2736. var angle = this.angleTo(q);
  2737. if (angle === 0) return this;
  2738. var t = Math.min(1, step / angle);
  2739. this.slerp(q, t);
  2740. return this;
  2741. };
  2742. _proto.identity = function identity() {
  2743. return this.set(0, 0, 0, 1);
  2744. };
  2745. _proto.invert = function invert() {
  2746. // quaternion is assumed to have unit length
  2747. return this.conjugate();
  2748. };
  2749. _proto.conjugate = function conjugate() {
  2750. this._x *= -1;
  2751. this._y *= -1;
  2752. this._z *= -1;
  2753. this._onChangeCallback();
  2754. return this;
  2755. };
  2756. _proto.dot = function dot(v) {
  2757. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  2758. };
  2759. _proto.lengthSq = function lengthSq() {
  2760. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  2761. };
  2762. _proto.length = function length() {
  2763. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  2764. };
  2765. _proto.normalize = function normalize() {
  2766. var l = this.length();
  2767. if (l === 0) {
  2768. this._x = 0;
  2769. this._y = 0;
  2770. this._z = 0;
  2771. this._w = 1;
  2772. } else {
  2773. l = 1 / l;
  2774. this._x = this._x * l;
  2775. this._y = this._y * l;
  2776. this._z = this._z * l;
  2777. this._w = this._w * l;
  2778. }
  2779. this._onChangeCallback();
  2780. return this;
  2781. };
  2782. _proto.multiply = function multiply(q, p) {
  2783. if (p !== undefined) {
  2784. console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
  2785. return this.multiplyQuaternions(q, p);
  2786. }
  2787. return this.multiplyQuaternions(this, q);
  2788. };
  2789. _proto.premultiply = function premultiply(q) {
  2790. return this.multiplyQuaternions(q, this);
  2791. };
  2792. _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
  2793. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2794. var qax = a._x,
  2795. qay = a._y,
  2796. qaz = a._z,
  2797. qaw = a._w;
  2798. var qbx = b._x,
  2799. qby = b._y,
  2800. qbz = b._z,
  2801. qbw = b._w;
  2802. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2803. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2804. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2805. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2806. this._onChangeCallback();
  2807. return this;
  2808. };
  2809. _proto.slerp = function slerp(qb, t) {
  2810. if (t === 0) return this;
  2811. if (t === 1) return this.copy(qb);
  2812. var x = this._x,
  2813. y = this._y,
  2814. z = this._z,
  2815. w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2816. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2817. if (cosHalfTheta < 0) {
  2818. this._w = -qb._w;
  2819. this._x = -qb._x;
  2820. this._y = -qb._y;
  2821. this._z = -qb._z;
  2822. cosHalfTheta = -cosHalfTheta;
  2823. } else {
  2824. this.copy(qb);
  2825. }
  2826. if (cosHalfTheta >= 1.0) {
  2827. this._w = w;
  2828. this._x = x;
  2829. this._y = y;
  2830. this._z = z;
  2831. return this;
  2832. }
  2833. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2834. if (sqrSinHalfTheta <= Number.EPSILON) {
  2835. var s = 1 - t;
  2836. this._w = s * w + t * this._w;
  2837. this._x = s * x + t * this._x;
  2838. this._y = s * y + t * this._y;
  2839. this._z = s * z + t * this._z;
  2840. this.normalize();
  2841. this._onChangeCallback();
  2842. return this;
  2843. }
  2844. var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
  2845. var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
  2846. var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
  2847. ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
  2848. this._w = w * ratioA + this._w * ratioB;
  2849. this._x = x * ratioA + this._x * ratioB;
  2850. this._y = y * ratioA + this._y * ratioB;
  2851. this._z = z * ratioA + this._z * ratioB;
  2852. this._onChangeCallback();
  2853. return this;
  2854. };
  2855. _proto.equals = function equals(quaternion) {
  2856. return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
  2857. };
  2858. _proto.fromArray = function fromArray(array, offset) {
  2859. if (offset === void 0) {
  2860. offset = 0;
  2861. }
  2862. this._x = array[offset];
  2863. this._y = array[offset + 1];
  2864. this._z = array[offset + 2];
  2865. this._w = array[offset + 3];
  2866. this._onChangeCallback();
  2867. return this;
  2868. };
  2869. _proto.toArray = function toArray(array, offset) {
  2870. if (array === void 0) {
  2871. array = [];
  2872. }
  2873. if (offset === void 0) {
  2874. offset = 0;
  2875. }
  2876. array[offset] = this._x;
  2877. array[offset + 1] = this._y;
  2878. array[offset + 2] = this._z;
  2879. array[offset + 3] = this._w;
  2880. return array;
  2881. };
  2882. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  2883. this._x = attribute.getX(index);
  2884. this._y = attribute.getY(index);
  2885. this._z = attribute.getZ(index);
  2886. this._w = attribute.getW(index);
  2887. return this;
  2888. };
  2889. _proto._onChange = function _onChange(callback) {
  2890. this._onChangeCallback = callback;
  2891. return this;
  2892. };
  2893. _proto._onChangeCallback = function _onChangeCallback() {};
  2894. _createClass(Quaternion, [{
  2895. key: "x",
  2896. get: function get() {
  2897. return this._x;
  2898. },
  2899. set: function set(value) {
  2900. this._x = value;
  2901. this._onChangeCallback();
  2902. }
  2903. }, {
  2904. key: "y",
  2905. get: function get() {
  2906. return this._y;
  2907. },
  2908. set: function set(value) {
  2909. this._y = value;
  2910. this._onChangeCallback();
  2911. }
  2912. }, {
  2913. key: "z",
  2914. get: function get() {
  2915. return this._z;
  2916. },
  2917. set: function set(value) {
  2918. this._z = value;
  2919. this._onChangeCallback();
  2920. }
  2921. }, {
  2922. key: "w",
  2923. get: function get() {
  2924. return this._w;
  2925. },
  2926. set: function set(value) {
  2927. this._w = value;
  2928. this._onChangeCallback();
  2929. }
  2930. }]);
  2931. return Quaternion;
  2932. }();
  2933. var Vector3 = /*#__PURE__*/function () {
  2934. function Vector3(x, y, z) {
  2935. if (x === void 0) {
  2936. x = 0;
  2937. }
  2938. if (y === void 0) {
  2939. y = 0;
  2940. }
  2941. if (z === void 0) {
  2942. z = 0;
  2943. }
  2944. Object.defineProperty(this, 'isVector3', {
  2945. value: true
  2946. });
  2947. this.x = x;
  2948. this.y = y;
  2949. this.z = z;
  2950. }
  2951. var _proto = Vector3.prototype;
  2952. _proto.set = function set(x, y, z) {
  2953. if (z === undefined) z = this.z; // sprite.scale.set(x,y)
  2954. this.x = x;
  2955. this.y = y;
  2956. this.z = z;
  2957. return this;
  2958. };
  2959. _proto.setScalar = function setScalar(scalar) {
  2960. this.x = scalar;
  2961. this.y = scalar;
  2962. this.z = scalar;
  2963. return this;
  2964. };
  2965. _proto.setX = function setX(x) {
  2966. this.x = x;
  2967. return this;
  2968. };
  2969. _proto.setY = function setY(y) {
  2970. this.y = y;
  2971. return this;
  2972. };
  2973. _proto.setZ = function setZ(z) {
  2974. this.z = z;
  2975. return this;
  2976. };
  2977. _proto.setComponent = function setComponent(index, value) {
  2978. switch (index) {
  2979. case 0:
  2980. this.x = value;
  2981. break;
  2982. case 1:
  2983. this.y = value;
  2984. break;
  2985. case 2:
  2986. this.z = value;
  2987. break;
  2988. default:
  2989. throw new Error('index is out of range: ' + index);
  2990. }
  2991. return this;
  2992. };
  2993. _proto.getComponent = function getComponent(index) {
  2994. switch (index) {
  2995. case 0:
  2996. return this.x;
  2997. case 1:
  2998. return this.y;
  2999. case 2:
  3000. return this.z;
  3001. default:
  3002. throw new Error('index is out of range: ' + index);
  3003. }
  3004. };
  3005. _proto.clone = function clone() {
  3006. return new this.constructor(this.x, this.y, this.z);
  3007. };
  3008. _proto.copy = function copy(v) {
  3009. this.x = v.x;
  3010. this.y = v.y;
  3011. this.z = v.z;
  3012. return this;
  3013. };
  3014. _proto.add = function add(v, w) {
  3015. if (w !== undefined) {
  3016. console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  3017. return this.addVectors(v, w);
  3018. }
  3019. this.x += v.x;
  3020. this.y += v.y;
  3021. this.z += v.z;
  3022. return this;
  3023. };
  3024. _proto.addScalar = function addScalar(s) {
  3025. this.x += s;
  3026. this.y += s;
  3027. this.z += s;
  3028. return this;
  3029. };
  3030. _proto.addVectors = function addVectors(a, b) {
  3031. this.x = a.x + b.x;
  3032. this.y = a.y + b.y;
  3033. this.z = a.z + b.z;
  3034. return this;
  3035. };
  3036. _proto.addScaledVector = function addScaledVector(v, s) {
  3037. this.x += v.x * s;
  3038. this.y += v.y * s;
  3039. this.z += v.z * s;
  3040. return this;
  3041. };
  3042. _proto.sub = function sub(v, w) {
  3043. if (w !== undefined) {
  3044. console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  3045. return this.subVectors(v, w);
  3046. }
  3047. this.x -= v.x;
  3048. this.y -= v.y;
  3049. this.z -= v.z;
  3050. return this;
  3051. };
  3052. _proto.subScalar = function subScalar(s) {
  3053. this.x -= s;
  3054. this.y -= s;
  3055. this.z -= s;
  3056. return this;
  3057. };
  3058. _proto.subVectors = function subVectors(a, b) {
  3059. this.x = a.x - b.x;
  3060. this.y = a.y - b.y;
  3061. this.z = a.z - b.z;
  3062. return this;
  3063. };
  3064. _proto.multiply = function multiply(v, w) {
  3065. if (w !== undefined) {
  3066. console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
  3067. return this.multiplyVectors(v, w);
  3068. }
  3069. this.x *= v.x;
  3070. this.y *= v.y;
  3071. this.z *= v.z;
  3072. return this;
  3073. };
  3074. _proto.multiplyScalar = function multiplyScalar(scalar) {
  3075. this.x *= scalar;
  3076. this.y *= scalar;
  3077. this.z *= scalar;
  3078. return this;
  3079. };
  3080. _proto.multiplyVectors = function multiplyVectors(a, b) {
  3081. this.x = a.x * b.x;
  3082. this.y = a.y * b.y;
  3083. this.z = a.z * b.z;
  3084. return this;
  3085. };
  3086. _proto.applyEuler = function applyEuler(euler) {
  3087. if (!(euler && euler.isEuler)) {
  3088. console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
  3089. }
  3090. return this.applyQuaternion(_quaternion.setFromEuler(euler));
  3091. };
  3092. _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
  3093. return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
  3094. };
  3095. _proto.applyMatrix3 = function applyMatrix3(m) {
  3096. var x = this.x,
  3097. y = this.y,
  3098. z = this.z;
  3099. var e = m.elements;
  3100. this.x = e[0] * x + e[3] * y + e[6] * z;
  3101. this.y = e[1] * x + e[4] * y + e[7] * z;
  3102. this.z = e[2] * x + e[5] * y + e[8] * z;
  3103. return this;
  3104. };
  3105. _proto.applyNormalMatrix = function applyNormalMatrix(m) {
  3106. return this.applyMatrix3(m).normalize();
  3107. };
  3108. _proto.applyMatrix4 = function applyMatrix4(m) {
  3109. var x = this.x,
  3110. y = this.y,
  3111. z = this.z;
  3112. var e = m.elements;
  3113. var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
  3114. this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
  3115. this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
  3116. this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
  3117. return this;
  3118. };
  3119. _proto.applyQuaternion = function applyQuaternion(q) {
  3120. var x = this.x,
  3121. y = this.y,
  3122. z = this.z;
  3123. var qx = q.x,
  3124. qy = q.y,
  3125. qz = q.z,
  3126. qw = q.w; // calculate quat * vector
  3127. var ix = qw * x + qy * z - qz * y;
  3128. var iy = qw * y + qz * x - qx * z;
  3129. var iz = qw * z + qx * y - qy * x;
  3130. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  3131. this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  3132. this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  3133. this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  3134. return this;
  3135. };
  3136. _proto.project = function project(camera) {
  3137. return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
  3138. };
  3139. _proto.unproject = function unproject(camera) {
  3140. return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
  3141. };
  3142. _proto.transformDirection = function transformDirection(m) {
  3143. // input: THREE.Matrix4 affine matrix
  3144. // vector interpreted as a direction
  3145. var x = this.x,
  3146. y = this.y,
  3147. z = this.z;
  3148. var e = m.elements;
  3149. this.x = e[0] * x + e[4] * y + e[8] * z;
  3150. this.y = e[1] * x + e[5] * y + e[9] * z;
  3151. this.z = e[2] * x + e[6] * y + e[10] * z;
  3152. return this.normalize();
  3153. };
  3154. _proto.divide = function divide(v) {
  3155. this.x /= v.x;
  3156. this.y /= v.y;
  3157. this.z /= v.z;
  3158. return this;
  3159. };
  3160. _proto.divideScalar = function divideScalar(scalar) {
  3161. return this.multiplyScalar(1 / scalar);
  3162. };
  3163. _proto.min = function min(v) {
  3164. this.x = Math.min(this.x, v.x);
  3165. this.y = Math.min(this.y, v.y);
  3166. this.z = Math.min(this.z, v.z);
  3167. return this;
  3168. };
  3169. _proto.max = function max(v) {
  3170. this.x = Math.max(this.x, v.x);
  3171. this.y = Math.max(this.y, v.y);
  3172. this.z = Math.max(this.z, v.z);
  3173. return this;
  3174. };
  3175. _proto.clamp = function clamp(min, max) {
  3176. // assumes min < max, componentwise
  3177. this.x = Math.max(min.x, Math.min(max.x, this.x));
  3178. this.y = Math.max(min.y, Math.min(max.y, this.y));
  3179. this.z = Math.max(min.z, Math.min(max.z, this.z));
  3180. return this;
  3181. };
  3182. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  3183. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  3184. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  3185. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  3186. return this;
  3187. };
  3188. _proto.clampLength = function clampLength(min, max) {
  3189. var length = this.length();
  3190. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  3191. };
  3192. _proto.floor = function floor() {
  3193. this.x = Math.floor(this.x);
  3194. this.y = Math.floor(this.y);
  3195. this.z = Math.floor(this.z);
  3196. return this;
  3197. };
  3198. _proto.ceil = function ceil() {
  3199. this.x = Math.ceil(this.x);
  3200. this.y = Math.ceil(this.y);
  3201. this.z = Math.ceil(this.z);
  3202. return this;
  3203. };
  3204. _proto.round = function round() {
  3205. this.x = Math.round(this.x);
  3206. this.y = Math.round(this.y);
  3207. this.z = Math.round(this.z);
  3208. return this;
  3209. };
  3210. _proto.roundToZero = function roundToZero() {
  3211. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  3212. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  3213. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  3214. return this;
  3215. };
  3216. _proto.negate = function negate() {
  3217. this.x = -this.x;
  3218. this.y = -this.y;
  3219. this.z = -this.z;
  3220. return this;
  3221. };
  3222. _proto.dot = function dot(v) {
  3223. return this.x * v.x + this.y * v.y + this.z * v.z;
  3224. } // TODO lengthSquared?
  3225. ;
  3226. _proto.lengthSq = function lengthSq() {
  3227. return this.x * this.x + this.y * this.y + this.z * this.z;
  3228. };
  3229. _proto.length = function length() {
  3230. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  3231. };
  3232. _proto.manhattanLength = function manhattanLength() {
  3233. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  3234. };
  3235. _proto.normalize = function normalize() {
  3236. return this.divideScalar(this.length() || 1);
  3237. };
  3238. _proto.setLength = function setLength(length) {
  3239. return this.normalize().multiplyScalar(length);
  3240. };
  3241. _proto.lerp = function lerp(v, alpha) {
  3242. this.x += (v.x - this.x) * alpha;
  3243. this.y += (v.y - this.y) * alpha;
  3244. this.z += (v.z - this.z) * alpha;
  3245. return this;
  3246. };
  3247. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  3248. this.x = v1.x + (v2.x - v1.x) * alpha;
  3249. this.y = v1.y + (v2.y - v1.y) * alpha;
  3250. this.z = v1.z + (v2.z - v1.z) * alpha;
  3251. return this;
  3252. };
  3253. _proto.cross = function cross(v, w) {
  3254. if (w !== undefined) {
  3255. console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
  3256. return this.crossVectors(v, w);
  3257. }
  3258. return this.crossVectors(this, v);
  3259. };
  3260. _proto.crossVectors = function crossVectors(a, b) {
  3261. var ax = a.x,
  3262. ay = a.y,
  3263. az = a.z;
  3264. var bx = b.x,
  3265. by = b.y,
  3266. bz = b.z;
  3267. this.x = ay * bz - az * by;
  3268. this.y = az * bx - ax * bz;
  3269. this.z = ax * by - ay * bx;
  3270. return this;
  3271. };
  3272. _proto.projectOnVector = function projectOnVector(v) {
  3273. var denominator = v.lengthSq();
  3274. if (denominator === 0) return this.set(0, 0, 0);
  3275. var scalar = v.dot(this) / denominator;
  3276. return this.copy(v).multiplyScalar(scalar);
  3277. };
  3278. _proto.projectOnPlane = function projectOnPlane(planeNormal) {
  3279. _vector.copy(this).projectOnVector(planeNormal);
  3280. return this.sub(_vector);
  3281. };
  3282. _proto.reflect = function reflect(normal) {
  3283. // reflect incident vector off plane orthogonal to normal
  3284. // normal is assumed to have unit length
  3285. return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
  3286. };
  3287. _proto.angleTo = function angleTo(v) {
  3288. var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
  3289. if (denominator === 0) return Math.PI / 2;
  3290. var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
  3291. return Math.acos(MathUtils.clamp(theta, -1, 1));
  3292. };
  3293. _proto.distanceTo = function distanceTo(v) {
  3294. return Math.sqrt(this.distanceToSquared(v));
  3295. };
  3296. _proto.distanceToSquared = function distanceToSquared(v) {
  3297. var dx = this.x - v.x,
  3298. dy = this.y - v.y,
  3299. dz = this.z - v.z;
  3300. return dx * dx + dy * dy + dz * dz;
  3301. };
  3302. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  3303. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
  3304. };
  3305. _proto.setFromSpherical = function setFromSpherical(s) {
  3306. return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
  3307. };
  3308. _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
  3309. var sinPhiRadius = Math.sin(phi) * radius;
  3310. this.x = sinPhiRadius * Math.sin(theta);
  3311. this.y = Math.cos(phi) * radius;
  3312. this.z = sinPhiRadius * Math.cos(theta);
  3313. return this;
  3314. };
  3315. _proto.setFromCylindrical = function setFromCylindrical(c) {
  3316. return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
  3317. };
  3318. _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
  3319. this.x = radius * Math.sin(theta);
  3320. this.y = y;
  3321. this.z = radius * Math.cos(theta);
  3322. return this;
  3323. };
  3324. _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
  3325. var e = m.elements;
  3326. this.x = e[12];
  3327. this.y = e[13];
  3328. this.z = e[14];
  3329. return this;
  3330. };
  3331. _proto.setFromMatrixScale = function setFromMatrixScale(m) {
  3332. var sx = this.setFromMatrixColumn(m, 0).length();
  3333. var sy = this.setFromMatrixColumn(m, 1).length();
  3334. var sz = this.setFromMatrixColumn(m, 2).length();
  3335. this.x = sx;
  3336. this.y = sy;
  3337. this.z = sz;
  3338. return this;
  3339. };
  3340. _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
  3341. return this.fromArray(m.elements, index * 4);
  3342. };
  3343. _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
  3344. return this.fromArray(m.elements, index * 3);
  3345. };
  3346. _proto.equals = function equals(v) {
  3347. return v.x === this.x && v.y === this.y && v.z === this.z;
  3348. };
  3349. _proto.fromArray = function fromArray(array, offset) {
  3350. if (offset === void 0) {
  3351. offset = 0;
  3352. }
  3353. this.x = array[offset];
  3354. this.y = array[offset + 1];
  3355. this.z = array[offset + 2];
  3356. return this;
  3357. };
  3358. _proto.toArray = function toArray(array, offset) {
  3359. if (array === void 0) {
  3360. array = [];
  3361. }
  3362. if (offset === void 0) {
  3363. offset = 0;
  3364. }
  3365. array[offset] = this.x;
  3366. array[offset + 1] = this.y;
  3367. array[offset + 2] = this.z;
  3368. return array;
  3369. };
  3370. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  3371. if (offset !== undefined) {
  3372. console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
  3373. }
  3374. this.x = attribute.getX(index);
  3375. this.y = attribute.getY(index);
  3376. this.z = attribute.getZ(index);
  3377. return this;
  3378. };
  3379. _proto.random = function random() {
  3380. this.x = Math.random();
  3381. this.y = Math.random();
  3382. this.z = Math.random();
  3383. return this;
  3384. };
  3385. return Vector3;
  3386. }();
  3387. var _vector = /*@__PURE__*/new Vector3();
  3388. var _quaternion = /*@__PURE__*/new Quaternion();
  3389. var Box3 = /*#__PURE__*/function () {
  3390. function Box3(min, max) {
  3391. Object.defineProperty(this, 'isBox3', {
  3392. value: true
  3393. });
  3394. this.min = min !== undefined ? min : new Vector3(+Infinity, +Infinity, +Infinity);
  3395. this.max = max !== undefined ? max : new Vector3(-Infinity, -Infinity, -Infinity);
  3396. }
  3397. var _proto = Box3.prototype;
  3398. _proto.set = function set(min, max) {
  3399. this.min.copy(min);
  3400. this.max.copy(max);
  3401. return this;
  3402. };
  3403. _proto.setFromArray = function setFromArray(array) {
  3404. var minX = +Infinity;
  3405. var minY = +Infinity;
  3406. var minZ = +Infinity;
  3407. var maxX = -Infinity;
  3408. var maxY = -Infinity;
  3409. var maxZ = -Infinity;
  3410. for (var i = 0, l = array.length; i < l; i += 3) {
  3411. var x = array[i];
  3412. var y = array[i + 1];
  3413. var z = array[i + 2];
  3414. if (x < minX) minX = x;
  3415. if (y < minY) minY = y;
  3416. if (z < minZ) minZ = z;
  3417. if (x > maxX) maxX = x;
  3418. if (y > maxY) maxY = y;
  3419. if (z > maxZ) maxZ = z;
  3420. }
  3421. this.min.set(minX, minY, minZ);
  3422. this.max.set(maxX, maxY, maxZ);
  3423. return this;
  3424. };
  3425. _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
  3426. var minX = +Infinity;
  3427. var minY = +Infinity;
  3428. var minZ = +Infinity;
  3429. var maxX = -Infinity;
  3430. var maxY = -Infinity;
  3431. var maxZ = -Infinity;
  3432. for (var i = 0, l = attribute.count; i < l; i++) {
  3433. var x = attribute.getX(i);
  3434. var y = attribute.getY(i);
  3435. var z = attribute.getZ(i);
  3436. if (x < minX) minX = x;
  3437. if (y < minY) minY = y;
  3438. if (z < minZ) minZ = z;
  3439. if (x > maxX) maxX = x;
  3440. if (y > maxY) maxY = y;
  3441. if (z > maxZ) maxZ = z;
  3442. }
  3443. this.min.set(minX, minY, minZ);
  3444. this.max.set(maxX, maxY, maxZ);
  3445. return this;
  3446. };
  3447. _proto.setFromPoints = function setFromPoints(points) {
  3448. this.makeEmpty();
  3449. for (var i = 0, il = points.length; i < il; i++) {
  3450. this.expandByPoint(points[i]);
  3451. }
  3452. return this;
  3453. };
  3454. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  3455. var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
  3456. this.min.copy(center).sub(halfSize);
  3457. this.max.copy(center).add(halfSize);
  3458. return this;
  3459. };
  3460. _proto.setFromObject = function setFromObject(object) {
  3461. this.makeEmpty();
  3462. return this.expandByObject(object);
  3463. };
  3464. _proto.clone = function clone() {
  3465. return new this.constructor().copy(this);
  3466. };
  3467. _proto.copy = function copy(box) {
  3468. this.min.copy(box.min);
  3469. this.max.copy(box.max);
  3470. return this;
  3471. };
  3472. _proto.makeEmpty = function makeEmpty() {
  3473. this.min.x = this.min.y = this.min.z = +Infinity;
  3474. this.max.x = this.max.y = this.max.z = -Infinity;
  3475. return this;
  3476. };
  3477. _proto.isEmpty = function isEmpty() {
  3478. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3479. return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  3480. };
  3481. _proto.getCenter = function getCenter(target) {
  3482. if (target === undefined) {
  3483. console.warn('THREE.Box3: .getCenter() target is now required');
  3484. target = new Vector3();
  3485. }
  3486. return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  3487. };
  3488. _proto.getSize = function getSize(target) {
  3489. if (target === undefined) {
  3490. console.warn('THREE.Box3: .getSize() target is now required');
  3491. target = new Vector3();
  3492. }
  3493. return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
  3494. };
  3495. _proto.expandByPoint = function expandByPoint(point) {
  3496. this.min.min(point);
  3497. this.max.max(point);
  3498. return this;
  3499. };
  3500. _proto.expandByVector = function expandByVector(vector) {
  3501. this.min.sub(vector);
  3502. this.max.add(vector);
  3503. return this;
  3504. };
  3505. _proto.expandByScalar = function expandByScalar(scalar) {
  3506. this.min.addScalar(-scalar);
  3507. this.max.addScalar(scalar);
  3508. return this;
  3509. };
  3510. _proto.expandByObject = function expandByObject(object) {
  3511. // Computes the world-axis-aligned bounding box of an object (including its children),
  3512. // accounting for both the object's, and children's, world transforms
  3513. object.updateWorldMatrix(false, false);
  3514. var geometry = object.geometry;
  3515. if (geometry !== undefined) {
  3516. if (geometry.boundingBox === null) {
  3517. geometry.computeBoundingBox();
  3518. }
  3519. _box.copy(geometry.boundingBox);
  3520. _box.applyMatrix4(object.matrixWorld);
  3521. this.union(_box);
  3522. }
  3523. var children = object.children;
  3524. for (var i = 0, l = children.length; i < l; i++) {
  3525. this.expandByObject(children[i]);
  3526. }
  3527. return this;
  3528. };
  3529. _proto.containsPoint = function containsPoint(point) {
  3530. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y || point.z < this.min.z || point.z > this.max.z ? false : true;
  3531. };
  3532. _proto.containsBox = function containsBox(box) {
  3533. return this.min.x <= box.min.x && box.max.x <= this.max.x && this.min.y <= box.min.y && box.max.y <= this.max.y && this.min.z <= box.min.z && box.max.z <= this.max.z;
  3534. };
  3535. _proto.getParameter = function getParameter(point, target) {
  3536. // This can potentially have a divide by zero if the box
  3537. // has a size dimension of 0.
  3538. if (target === undefined) {
  3539. console.warn('THREE.Box3: .getParameter() target is now required');
  3540. target = new Vector3();
  3541. }
  3542. return target.set((point.x - this.min.x) / (this.max.x - this.min.x), (point.y - this.min.y) / (this.max.y - this.min.y), (point.z - this.min.z) / (this.max.z - this.min.z));
  3543. };
  3544. _proto.intersectsBox = function intersectsBox(box) {
  3545. // using 6 splitting planes to rule out intersections.
  3546. return box.max.x < this.min.x || box.min.x > this.max.x || box.max.y < this.min.y || box.min.y > this.max.y || box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  3547. };
  3548. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3549. // Find the point on the AABB closest to the sphere center.
  3550. this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
  3551. return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
  3552. };
  3553. _proto.intersectsPlane = function intersectsPlane(plane) {
  3554. // We compute the minimum and maximum dot product values. If those values
  3555. // are on the same side (back or front) of the plane, then there is no intersection.
  3556. var min, max;
  3557. if (plane.normal.x > 0) {
  3558. min = plane.normal.x * this.min.x;
  3559. max = plane.normal.x * this.max.x;
  3560. } else {
  3561. min = plane.normal.x * this.max.x;
  3562. max = plane.normal.x * this.min.x;
  3563. }
  3564. if (plane.normal.y > 0) {
  3565. min += plane.normal.y * this.min.y;
  3566. max += plane.normal.y * this.max.y;
  3567. } else {
  3568. min += plane.normal.y * this.max.y;
  3569. max += plane.normal.y * this.min.y;
  3570. }
  3571. if (plane.normal.z > 0) {
  3572. min += plane.normal.z * this.min.z;
  3573. max += plane.normal.z * this.max.z;
  3574. } else {
  3575. min += plane.normal.z * this.max.z;
  3576. max += plane.normal.z * this.min.z;
  3577. }
  3578. return min <= -plane.constant && max >= -plane.constant;
  3579. };
  3580. _proto.intersectsTriangle = function intersectsTriangle(triangle) {
  3581. if (this.isEmpty()) {
  3582. return false;
  3583. } // compute box center and extents
  3584. this.getCenter(_center);
  3585. _extents.subVectors(this.max, _center); // translate triangle to aabb origin
  3586. _v0.subVectors(triangle.a, _center);
  3587. _v1.subVectors(triangle.b, _center);
  3588. _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
  3589. _f0.subVectors(_v1, _v0);
  3590. _f1.subVectors(_v2, _v1);
  3591. _f2.subVectors(_v0, _v2); // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3592. // make an axis testing of each of the 3 sides of the aabb against each of the 3 sides of the triangle = 9 axis of separation
  3593. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3594. var axes = [0, -_f0.z, _f0.y, 0, -_f1.z, _f1.y, 0, -_f2.z, _f2.y, _f0.z, 0, -_f0.x, _f1.z, 0, -_f1.x, _f2.z, 0, -_f2.x, -_f0.y, _f0.x, 0, -_f1.y, _f1.x, 0, -_f2.y, _f2.x, 0];
  3595. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  3596. return false;
  3597. } // test 3 face normals from the aabb
  3598. axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  3599. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  3600. return false;
  3601. } // finally testing the face normal of the triangle
  3602. // use already existing triangle edge vectors here
  3603. _triangleNormal.crossVectors(_f0, _f1);
  3604. axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
  3605. return satForAxes(axes, _v0, _v1, _v2, _extents);
  3606. };
  3607. _proto.clampPoint = function clampPoint(point, target) {
  3608. if (target === undefined) {
  3609. console.warn('THREE.Box3: .clampPoint() target is now required');
  3610. target = new Vector3();
  3611. }
  3612. return target.copy(point).clamp(this.min, this.max);
  3613. };
  3614. _proto.distanceToPoint = function distanceToPoint(point) {
  3615. var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
  3616. return clampedPoint.sub(point).length();
  3617. };
  3618. _proto.getBoundingSphere = function getBoundingSphere(target) {
  3619. if (target === undefined) {
  3620. console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
  3621. }
  3622. this.getCenter(target.center);
  3623. target.radius = this.getSize(_vector$1).length() * 0.5;
  3624. return target;
  3625. };
  3626. _proto.intersect = function intersect(box) {
  3627. this.min.max(box.min);
  3628. this.max.min(box.max); // ensure that if there is no overlap, the result is fully empty, not slightly empty with non-inf/+inf values that will cause subsequence intersects to erroneously return valid values.
  3629. if (this.isEmpty()) this.makeEmpty();
  3630. return this;
  3631. };
  3632. _proto.union = function union(box) {
  3633. this.min.min(box.min);
  3634. this.max.max(box.max);
  3635. return this;
  3636. };
  3637. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3638. // transform of empty box is an empty box.
  3639. if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  3640. _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
  3641. _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
  3642. _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
  3643. _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
  3644. _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
  3645. _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
  3646. _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
  3647. _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
  3648. this.setFromPoints(_points);
  3649. return this;
  3650. };
  3651. _proto.translate = function translate(offset) {
  3652. this.min.add(offset);
  3653. this.max.add(offset);
  3654. return this;
  3655. };
  3656. _proto.equals = function equals(box) {
  3657. return box.min.equals(this.min) && box.max.equals(this.max);
  3658. };
  3659. return Box3;
  3660. }();
  3661. function satForAxes(axes, v0, v1, v2, extents) {
  3662. for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
  3663. _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
  3664. var r = extents.x * Math.abs(_testAxis.x) + extents.y * Math.abs(_testAxis.y) + extents.z * Math.abs(_testAxis.z); // project all 3 vertices of the triangle onto the seperating axis
  3665. var p0 = v0.dot(_testAxis);
  3666. var p1 = v1.dot(_testAxis);
  3667. var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
  3668. if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
  3669. // points of the projected triangle are outside the projected half-length of the aabb
  3670. // the axis is seperating and we can exit
  3671. return false;
  3672. }
  3673. }
  3674. return true;
  3675. }
  3676. var _points = [/*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3()];
  3677. var _vector$1 = /*@__PURE__*/new Vector3();
  3678. var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
  3679. var _v0 = /*@__PURE__*/new Vector3();
  3680. var _v1 = /*@__PURE__*/new Vector3();
  3681. var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
  3682. var _f0 = /*@__PURE__*/new Vector3();
  3683. var _f1 = /*@__PURE__*/new Vector3();
  3684. var _f2 = /*@__PURE__*/new Vector3();
  3685. var _center = /*@__PURE__*/new Vector3();
  3686. var _extents = /*@__PURE__*/new Vector3();
  3687. var _triangleNormal = /*@__PURE__*/new Vector3();
  3688. var _testAxis = /*@__PURE__*/new Vector3();
  3689. var _box$1 = /*@__PURE__*/new Box3();
  3690. var Sphere = /*#__PURE__*/function () {
  3691. function Sphere(center, radius) {
  3692. this.center = center !== undefined ? center : new Vector3();
  3693. this.radius = radius !== undefined ? radius : -1;
  3694. }
  3695. var _proto = Sphere.prototype;
  3696. _proto.set = function set(center, radius) {
  3697. this.center.copy(center);
  3698. this.radius = radius;
  3699. return this;
  3700. };
  3701. _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
  3702. var center = this.center;
  3703. if (optionalCenter !== undefined) {
  3704. center.copy(optionalCenter);
  3705. } else {
  3706. _box$1.setFromPoints(points).getCenter(center);
  3707. }
  3708. var maxRadiusSq = 0;
  3709. for (var i = 0, il = points.length; i < il; i++) {
  3710. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
  3711. }
  3712. this.radius = Math.sqrt(maxRadiusSq);
  3713. return this;
  3714. };
  3715. _proto.clone = function clone() {
  3716. return new this.constructor().copy(this);
  3717. };
  3718. _proto.copy = function copy(sphere) {
  3719. this.center.copy(sphere.center);
  3720. this.radius = sphere.radius;
  3721. return this;
  3722. };
  3723. _proto.isEmpty = function isEmpty() {
  3724. return this.radius < 0;
  3725. };
  3726. _proto.makeEmpty = function makeEmpty() {
  3727. this.center.set(0, 0, 0);
  3728. this.radius = -1;
  3729. return this;
  3730. };
  3731. _proto.containsPoint = function containsPoint(point) {
  3732. return point.distanceToSquared(this.center) <= this.radius * this.radius;
  3733. };
  3734. _proto.distanceToPoint = function distanceToPoint(point) {
  3735. return point.distanceTo(this.center) - this.radius;
  3736. };
  3737. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3738. var radiusSum = this.radius + sphere.radius;
  3739. return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
  3740. };
  3741. _proto.intersectsBox = function intersectsBox(box) {
  3742. return box.intersectsSphere(this);
  3743. };
  3744. _proto.intersectsPlane = function intersectsPlane(plane) {
  3745. return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
  3746. };
  3747. _proto.clampPoint = function clampPoint(point, target) {
  3748. var deltaLengthSq = this.center.distanceToSquared(point);
  3749. if (target === undefined) {
  3750. console.warn('THREE.Sphere: .clampPoint() target is now required');
  3751. target = new Vector3();
  3752. }
  3753. target.copy(point);
  3754. if (deltaLengthSq > this.radius * this.radius) {
  3755. target.sub(this.center).normalize();
  3756. target.multiplyScalar(this.radius).add(this.center);
  3757. }
  3758. return target;
  3759. };
  3760. _proto.getBoundingBox = function getBoundingBox(target) {
  3761. if (target === undefined) {
  3762. console.warn('THREE.Sphere: .getBoundingBox() target is now required');
  3763. target = new Box3();
  3764. }
  3765. if (this.isEmpty()) {
  3766. // Empty sphere produces empty bounding box
  3767. target.makeEmpty();
  3768. return target;
  3769. }
  3770. target.set(this.center, this.center);
  3771. target.expandByScalar(this.radius);
  3772. return target;
  3773. };
  3774. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3775. this.center.applyMatrix4(matrix);
  3776. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3777. return this;
  3778. };
  3779. _proto.translate = function translate(offset) {
  3780. this.center.add(offset);
  3781. return this;
  3782. };
  3783. _proto.equals = function equals(sphere) {
  3784. return sphere.center.equals(this.center) && sphere.radius === this.radius;
  3785. };
  3786. return Sphere;
  3787. }();
  3788. var _vector$2 = /*@__PURE__*/new Vector3();
  3789. var _segCenter = /*@__PURE__*/new Vector3();
  3790. var _segDir = /*@__PURE__*/new Vector3();
  3791. var _diff = /*@__PURE__*/new Vector3();
  3792. var _edge1 = /*@__PURE__*/new Vector3();
  3793. var _edge2 = /*@__PURE__*/new Vector3();
  3794. var _normal = /*@__PURE__*/new Vector3();
  3795. var Ray = /*#__PURE__*/function () {
  3796. function Ray(origin, direction) {
  3797. this.origin = origin !== undefined ? origin : new Vector3();
  3798. this.direction = direction !== undefined ? direction : new Vector3(0, 0, -1);
  3799. }
  3800. var _proto = Ray.prototype;
  3801. _proto.set = function set(origin, direction) {
  3802. this.origin.copy(origin);
  3803. this.direction.copy(direction);
  3804. return this;
  3805. };
  3806. _proto.clone = function clone() {
  3807. return new this.constructor().copy(this);
  3808. };
  3809. _proto.copy = function copy(ray) {
  3810. this.origin.copy(ray.origin);
  3811. this.direction.copy(ray.direction);
  3812. return this;
  3813. };
  3814. _proto.at = function at(t, target) {
  3815. if (target === undefined) {
  3816. console.warn('THREE.Ray: .at() target is now required');
  3817. target = new Vector3();
  3818. }
  3819. return target.copy(this.direction).multiplyScalar(t).add(this.origin);
  3820. };
  3821. _proto.lookAt = function lookAt(v) {
  3822. this.direction.copy(v).sub(this.origin).normalize();
  3823. return this;
  3824. };
  3825. _proto.recast = function recast(t) {
  3826. this.origin.copy(this.at(t, _vector$2));
  3827. return this;
  3828. };
  3829. _proto.closestPointToPoint = function closestPointToPoint(point, target) {
  3830. if (target === undefined) {
  3831. console.warn('THREE.Ray: .closestPointToPoint() target is now required');
  3832. target = new Vector3();
  3833. }
  3834. target.subVectors(point, this.origin);
  3835. var directionDistance = target.dot(this.direction);
  3836. if (directionDistance < 0) {
  3837. return target.copy(this.origin);
  3838. }
  3839. return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3840. };
  3841. _proto.distanceToPoint = function distanceToPoint(point) {
  3842. return Math.sqrt(this.distanceSqToPoint(point));
  3843. };
  3844. _proto.distanceSqToPoint = function distanceSqToPoint(point) {
  3845. var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
  3846. if (directionDistance < 0) {
  3847. return this.origin.distanceToSquared(point);
  3848. }
  3849. _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3850. return _vector$2.distanceToSquared(point);
  3851. };
  3852. _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
  3853. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3854. // It returns the min distance between the ray and the segment
  3855. // defined by v0 and v1
  3856. // It can also set two optional targets :
  3857. // - The closest point on the ray
  3858. // - The closest point on the segment
  3859. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
  3860. _segDir.copy(v1).sub(v0).normalize();
  3861. _diff.copy(this.origin).sub(_segCenter);
  3862. var segExtent = v0.distanceTo(v1) * 0.5;
  3863. var a01 = -this.direction.dot(_segDir);
  3864. var b0 = _diff.dot(this.direction);
  3865. var b1 = -_diff.dot(_segDir);
  3866. var c = _diff.lengthSq();
  3867. var det = Math.abs(1 - a01 * a01);
  3868. var s0, s1, sqrDist, extDet;
  3869. if (det > 0) {
  3870. // The ray and segment are not parallel.
  3871. s0 = a01 * b1 - b0;
  3872. s1 = a01 * b0 - b1;
  3873. extDet = segExtent * det;
  3874. if (s0 >= 0) {
  3875. if (s1 >= -extDet) {
  3876. if (s1 <= extDet) {
  3877. // region 0
  3878. // Minimum at interior points of ray and segment.
  3879. var invDet = 1 / det;
  3880. s0 *= invDet;
  3881. s1 *= invDet;
  3882. sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
  3883. } else {
  3884. // region 1
  3885. s1 = segExtent;
  3886. s0 = Math.max(0, -(a01 * s1 + b0));
  3887. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3888. }
  3889. } else {
  3890. // region 5
  3891. s1 = -segExtent;
  3892. s0 = Math.max(0, -(a01 * s1 + b0));
  3893. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3894. }
  3895. } else {
  3896. if (s1 <= -extDet) {
  3897. // region 4
  3898. s0 = Math.max(0, -(-a01 * segExtent + b0));
  3899. s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3900. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3901. } else if (s1 <= extDet) {
  3902. // region 3
  3903. s0 = 0;
  3904. s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
  3905. sqrDist = s1 * (s1 + 2 * b1) + c;
  3906. } else {
  3907. // region 2
  3908. s0 = Math.max(0, -(a01 * segExtent + b0));
  3909. s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3910. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3911. }
  3912. }
  3913. } else {
  3914. // Ray and segment are parallel.
  3915. s1 = a01 > 0 ? -segExtent : segExtent;
  3916. s0 = Math.max(0, -(a01 * s1 + b0));
  3917. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3918. }
  3919. if (optionalPointOnRay) {
  3920. optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
  3921. }
  3922. if (optionalPointOnSegment) {
  3923. optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
  3924. }
  3925. return sqrDist;
  3926. };
  3927. _proto.intersectSphere = function intersectSphere(sphere, target) {
  3928. _vector$2.subVectors(sphere.center, this.origin);
  3929. var tca = _vector$2.dot(this.direction);
  3930. var d2 = _vector$2.dot(_vector$2) - tca * tca;
  3931. var radius2 = sphere.radius * sphere.radius;
  3932. if (d2 > radius2) return null;
  3933. var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
  3934. var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
  3935. var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
  3936. if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
  3937. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3938. // in order to always return an intersect point that is in front of the ray.
  3939. if (t0 < 0) return this.at(t1, target); // else t0 is in front of the ray, so return the first collision point scaled by t0
  3940. return this.at(t0, target);
  3941. };
  3942. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3943. return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
  3944. };
  3945. _proto.distanceToPlane = function distanceToPlane(plane) {
  3946. var denominator = plane.normal.dot(this.direction);
  3947. if (denominator === 0) {
  3948. // line is coplanar, return origin
  3949. if (plane.distanceToPoint(this.origin) === 0) {
  3950. return 0;
  3951. } // Null is preferable to undefined since undefined means.... it is undefined
  3952. return null;
  3953. }
  3954. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
  3955. return t >= 0 ? t : null;
  3956. };
  3957. _proto.intersectPlane = function intersectPlane(plane, target) {
  3958. var t = this.distanceToPlane(plane);
  3959. if (t === null) {
  3960. return null;
  3961. }
  3962. return this.at(t, target);
  3963. };
  3964. _proto.intersectsPlane = function intersectsPlane(plane) {
  3965. // check if the ray lies on the plane first
  3966. var distToPoint = plane.distanceToPoint(this.origin);
  3967. if (distToPoint === 0) {
  3968. return true;
  3969. }
  3970. var denominator = plane.normal.dot(this.direction);
  3971. if (denominator * distToPoint < 0) {
  3972. return true;
  3973. } // ray origin is behind the plane (and is pointing behind it)
  3974. return false;
  3975. };
  3976. _proto.intersectBox = function intersectBox(box, target) {
  3977. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3978. var invdirx = 1 / this.direction.x,
  3979. invdiry = 1 / this.direction.y,
  3980. invdirz = 1 / this.direction.z;
  3981. var origin = this.origin;
  3982. if (invdirx >= 0) {
  3983. tmin = (box.min.x - origin.x) * invdirx;
  3984. tmax = (box.max.x - origin.x) * invdirx;
  3985. } else {
  3986. tmin = (box.max.x - origin.x) * invdirx;
  3987. tmax = (box.min.x - origin.x) * invdirx;
  3988. }
  3989. if (invdiry >= 0) {
  3990. tymin = (box.min.y - origin.y) * invdiry;
  3991. tymax = (box.max.y - origin.y) * invdiry;
  3992. } else {
  3993. tymin = (box.max.y - origin.y) * invdiry;
  3994. tymax = (box.min.y - origin.y) * invdiry;
  3995. }
  3996. if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
  3997. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3998. if (tymin > tmin || tmin !== tmin) tmin = tymin;
  3999. if (tymax < tmax || tmax !== tmax) tmax = tymax;
  4000. if (invdirz >= 0) {
  4001. tzmin = (box.min.z - origin.z) * invdirz;
  4002. tzmax = (box.max.z - origin.z) * invdirz;
  4003. } else {
  4004. tzmin = (box.max.z - origin.z) * invdirz;
  4005. tzmax = (box.min.z - origin.z) * invdirz;
  4006. }
  4007. if (tmin > tzmax || tzmin > tmax) return null;
  4008. if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
  4009. if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
  4010. if (tmax < 0) return null;
  4011. return this.at(tmin >= 0 ? tmin : tmax, target);
  4012. };
  4013. _proto.intersectsBox = function intersectsBox(box) {
  4014. return this.intersectBox(box, _vector$2) !== null;
  4015. };
  4016. _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
  4017. // Compute the offset origin, edges, and normal.
  4018. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  4019. _edge1.subVectors(b, a);
  4020. _edge2.subVectors(c, a);
  4021. _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  4022. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  4023. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  4024. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  4025. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  4026. var DdN = this.direction.dot(_normal);
  4027. var sign;
  4028. if (DdN > 0) {
  4029. if (backfaceCulling) return null;
  4030. sign = 1;
  4031. } else if (DdN < 0) {
  4032. sign = -1;
  4033. DdN = -DdN;
  4034. } else {
  4035. return null;
  4036. }
  4037. _diff.subVectors(this.origin, a);
  4038. var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
  4039. if (DdQxE2 < 0) {
  4040. return null;
  4041. }
  4042. var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
  4043. if (DdE1xQ < 0) {
  4044. return null;
  4045. } // b1+b2 > 1, no intersection
  4046. if (DdQxE2 + DdE1xQ > DdN) {
  4047. return null;
  4048. } // Line intersects triangle, check if ray does.
  4049. var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
  4050. if (QdN < 0) {
  4051. return null;
  4052. } // Ray intersects triangle.
  4053. return this.at(QdN / DdN, target);
  4054. };
  4055. _proto.applyMatrix4 = function applyMatrix4(matrix4) {
  4056. this.origin.applyMatrix4(matrix4);
  4057. this.direction.transformDirection(matrix4);
  4058. return this;
  4059. };
  4060. _proto.equals = function equals(ray) {
  4061. return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
  4062. };
  4063. return Ray;
  4064. }();
  4065. var Matrix4 = /*#__PURE__*/function () {
  4066. function Matrix4() {
  4067. Object.defineProperty(this, 'isMatrix4', {
  4068. value: true
  4069. });
  4070. this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  4071. if (arguments.length > 0) {
  4072. console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
  4073. }
  4074. }
  4075. var _proto = Matrix4.prototype;
  4076. _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
  4077. var te = this.elements;
  4078. te[0] = n11;
  4079. te[4] = n12;
  4080. te[8] = n13;
  4081. te[12] = n14;
  4082. te[1] = n21;
  4083. te[5] = n22;
  4084. te[9] = n23;
  4085. te[13] = n24;
  4086. te[2] = n31;
  4087. te[6] = n32;
  4088. te[10] = n33;
  4089. te[14] = n34;
  4090. te[3] = n41;
  4091. te[7] = n42;
  4092. te[11] = n43;
  4093. te[15] = n44;
  4094. return this;
  4095. };
  4096. _proto.identity = function identity() {
  4097. this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4098. return this;
  4099. };
  4100. _proto.clone = function clone() {
  4101. return new Matrix4().fromArray(this.elements);
  4102. };
  4103. _proto.copy = function copy(m) {
  4104. var te = this.elements;
  4105. var me = m.elements;
  4106. te[0] = me[0];
  4107. te[1] = me[1];
  4108. te[2] = me[2];
  4109. te[3] = me[3];
  4110. te[4] = me[4];
  4111. te[5] = me[5];
  4112. te[6] = me[6];
  4113. te[7] = me[7];
  4114. te[8] = me[8];
  4115. te[9] = me[9];
  4116. te[10] = me[10];
  4117. te[11] = me[11];
  4118. te[12] = me[12];
  4119. te[13] = me[13];
  4120. te[14] = me[14];
  4121. te[15] = me[15];
  4122. return this;
  4123. };
  4124. _proto.copyPosition = function copyPosition(m) {
  4125. var te = this.elements,
  4126. me = m.elements;
  4127. te[12] = me[12];
  4128. te[13] = me[13];
  4129. te[14] = me[14];
  4130. return this;
  4131. };
  4132. _proto.setFromMatrix3 = function setFromMatrix3(m) {
  4133. var me = m.elements;
  4134. this.set(me[0], me[3], me[6], 0, me[1], me[4], me[7], 0, me[2], me[5], me[8], 0, 0, 0, 0, 1);
  4135. return this;
  4136. };
  4137. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  4138. xAxis.setFromMatrixColumn(this, 0);
  4139. yAxis.setFromMatrixColumn(this, 1);
  4140. zAxis.setFromMatrixColumn(this, 2);
  4141. return this;
  4142. };
  4143. _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
  4144. this.set(xAxis.x, yAxis.x, zAxis.x, 0, xAxis.y, yAxis.y, zAxis.y, 0, xAxis.z, yAxis.z, zAxis.z, 0, 0, 0, 0, 1);
  4145. return this;
  4146. };
  4147. _proto.extractRotation = function extractRotation(m) {
  4148. // this method does not support reflection matrices
  4149. var te = this.elements;
  4150. var me = m.elements;
  4151. var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
  4152. var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
  4153. var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
  4154. te[0] = me[0] * scaleX;
  4155. te[1] = me[1] * scaleX;
  4156. te[2] = me[2] * scaleX;
  4157. te[3] = 0;
  4158. te[4] = me[4] * scaleY;
  4159. te[5] = me[5] * scaleY;
  4160. te[6] = me[6] * scaleY;
  4161. te[7] = 0;
  4162. te[8] = me[8] * scaleZ;
  4163. te[9] = me[9] * scaleZ;
  4164. te[10] = me[10] * scaleZ;
  4165. te[11] = 0;
  4166. te[12] = 0;
  4167. te[13] = 0;
  4168. te[14] = 0;
  4169. te[15] = 1;
  4170. return this;
  4171. };
  4172. _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
  4173. if (!(euler && euler.isEuler)) {
  4174. console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
  4175. }
  4176. var te = this.elements;
  4177. var x = euler.x,
  4178. y = euler.y,
  4179. z = euler.z;
  4180. var a = Math.cos(x),
  4181. b = Math.sin(x);
  4182. var c = Math.cos(y),
  4183. d = Math.sin(y);
  4184. var e = Math.cos(z),
  4185. f = Math.sin(z);
  4186. if (euler.order === 'XYZ') {
  4187. var ae = a * e,
  4188. af = a * f,
  4189. be = b * e,
  4190. bf = b * f;
  4191. te[0] = c * e;
  4192. te[4] = -c * f;
  4193. te[8] = d;
  4194. te[1] = af + be * d;
  4195. te[5] = ae - bf * d;
  4196. te[9] = -b * c;
  4197. te[2] = bf - ae * d;
  4198. te[6] = be + af * d;
  4199. te[10] = a * c;
  4200. } else if (euler.order === 'YXZ') {
  4201. var ce = c * e,
  4202. cf = c * f,
  4203. de = d * e,
  4204. df = d * f;
  4205. te[0] = ce + df * b;
  4206. te[4] = de * b - cf;
  4207. te[8] = a * d;
  4208. te[1] = a * f;
  4209. te[5] = a * e;
  4210. te[9] = -b;
  4211. te[2] = cf * b - de;
  4212. te[6] = df + ce * b;
  4213. te[10] = a * c;
  4214. } else if (euler.order === 'ZXY') {
  4215. var _ce = c * e,
  4216. _cf = c * f,
  4217. _de = d * e,
  4218. _df = d * f;
  4219. te[0] = _ce - _df * b;
  4220. te[4] = -a * f;
  4221. te[8] = _de + _cf * b;
  4222. te[1] = _cf + _de * b;
  4223. te[5] = a * e;
  4224. te[9] = _df - _ce * b;
  4225. te[2] = -a * d;
  4226. te[6] = b;
  4227. te[10] = a * c;
  4228. } else if (euler.order === 'ZYX') {
  4229. var _ae = a * e,
  4230. _af = a * f,
  4231. _be = b * e,
  4232. _bf = b * f;
  4233. te[0] = c * e;
  4234. te[4] = _be * d - _af;
  4235. te[8] = _ae * d + _bf;
  4236. te[1] = c * f;
  4237. te[5] = _bf * d + _ae;
  4238. te[9] = _af * d - _be;
  4239. te[2] = -d;
  4240. te[6] = b * c;
  4241. te[10] = a * c;
  4242. } else if (euler.order === 'YZX') {
  4243. var ac = a * c,
  4244. ad = a * d,
  4245. bc = b * c,
  4246. bd = b * d;
  4247. te[0] = c * e;
  4248. te[4] = bd - ac * f;
  4249. te[8] = bc * f + ad;
  4250. te[1] = f;
  4251. te[5] = a * e;
  4252. te[9] = -b * e;
  4253. te[2] = -d * e;
  4254. te[6] = ad * f + bc;
  4255. te[10] = ac - bd * f;
  4256. } else if (euler.order === 'XZY') {
  4257. var _ac = a * c,
  4258. _ad = a * d,
  4259. _bc = b * c,
  4260. _bd = b * d;
  4261. te[0] = c * e;
  4262. te[4] = -f;
  4263. te[8] = d * e;
  4264. te[1] = _ac * f + _bd;
  4265. te[5] = a * e;
  4266. te[9] = _ad * f - _bc;
  4267. te[2] = _bc * f - _ad;
  4268. te[6] = b * e;
  4269. te[10] = _bd * f + _ac;
  4270. } // bottom row
  4271. te[3] = 0;
  4272. te[7] = 0;
  4273. te[11] = 0; // last column
  4274. te[12] = 0;
  4275. te[13] = 0;
  4276. te[14] = 0;
  4277. te[15] = 1;
  4278. return this;
  4279. };
  4280. _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
  4281. return this.compose(_zero, q, _one);
  4282. };
  4283. _proto.lookAt = function lookAt(eye, target, up) {
  4284. var te = this.elements;
  4285. _z.subVectors(eye, target);
  4286. if (_z.lengthSq() === 0) {
  4287. // eye and target are in the same position
  4288. _z.z = 1;
  4289. }
  4290. _z.normalize();
  4291. _x.crossVectors(up, _z);
  4292. if (_x.lengthSq() === 0) {
  4293. // up and z are parallel
  4294. if (Math.abs(up.z) === 1) {
  4295. _z.x += 0.0001;
  4296. } else {
  4297. _z.z += 0.0001;
  4298. }
  4299. _z.normalize();
  4300. _x.crossVectors(up, _z);
  4301. }
  4302. _x.normalize();
  4303. _y.crossVectors(_z, _x);
  4304. te[0] = _x.x;
  4305. te[4] = _y.x;
  4306. te[8] = _z.x;
  4307. te[1] = _x.y;
  4308. te[5] = _y.y;
  4309. te[9] = _z.y;
  4310. te[2] = _x.z;
  4311. te[6] = _y.z;
  4312. te[10] = _z.z;
  4313. return this;
  4314. };
  4315. _proto.multiply = function multiply(m, n) {
  4316. if (n !== undefined) {
  4317. console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
  4318. return this.multiplyMatrices(m, n);
  4319. }
  4320. return this.multiplyMatrices(this, m);
  4321. };
  4322. _proto.premultiply = function premultiply(m) {
  4323. return this.multiplyMatrices(m, this);
  4324. };
  4325. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  4326. var ae = a.elements;
  4327. var be = b.elements;
  4328. var te = this.elements;
  4329. var a11 = ae[0],
  4330. a12 = ae[4],
  4331. a13 = ae[8],
  4332. a14 = ae[12];
  4333. var a21 = ae[1],
  4334. a22 = ae[5],
  4335. a23 = ae[9],
  4336. a24 = ae[13];
  4337. var a31 = ae[2],
  4338. a32 = ae[6],
  4339. a33 = ae[10],
  4340. a34 = ae[14];
  4341. var a41 = ae[3],
  4342. a42 = ae[7],
  4343. a43 = ae[11],
  4344. a44 = ae[15];
  4345. var b11 = be[0],
  4346. b12 = be[4],
  4347. b13 = be[8],
  4348. b14 = be[12];
  4349. var b21 = be[1],
  4350. b22 = be[5],
  4351. b23 = be[9],
  4352. b24 = be[13];
  4353. var b31 = be[2],
  4354. b32 = be[6],
  4355. b33 = be[10],
  4356. b34 = be[14];
  4357. var b41 = be[3],
  4358. b42 = be[7],
  4359. b43 = be[11],
  4360. b44 = be[15];
  4361. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  4362. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  4363. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  4364. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  4365. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  4366. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  4367. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  4368. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  4369. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  4370. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  4371. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  4372. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  4373. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  4374. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  4375. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  4376. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  4377. return this;
  4378. };
  4379. _proto.multiplyScalar = function multiplyScalar(s) {
  4380. var te = this.elements;
  4381. te[0] *= s;
  4382. te[4] *= s;
  4383. te[8] *= s;
  4384. te[12] *= s;
  4385. te[1] *= s;
  4386. te[5] *= s;
  4387. te[9] *= s;
  4388. te[13] *= s;
  4389. te[2] *= s;
  4390. te[6] *= s;
  4391. te[10] *= s;
  4392. te[14] *= s;
  4393. te[3] *= s;
  4394. te[7] *= s;
  4395. te[11] *= s;
  4396. te[15] *= s;
  4397. return this;
  4398. };
  4399. _proto.determinant = function determinant() {
  4400. var te = this.elements;
  4401. var n11 = te[0],
  4402. n12 = te[4],
  4403. n13 = te[8],
  4404. n14 = te[12];
  4405. var n21 = te[1],
  4406. n22 = te[5],
  4407. n23 = te[9],
  4408. n24 = te[13];
  4409. var n31 = te[2],
  4410. n32 = te[6],
  4411. n33 = te[10],
  4412. n34 = te[14];
  4413. var n41 = te[3],
  4414. n42 = te[7],
  4415. n43 = te[11],
  4416. n44 = te[15]; //TODO: make this more efficient
  4417. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  4418. return n41 * (+n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34) + n42 * (+n11 * n23 * n34 - n11 * n24 * n33 + n14 * n21 * n33 - n13 * n21 * n34 + n13 * n24 * n31 - n14 * n23 * n31) + n43 * (+n11 * n24 * n32 - n11 * n22 * n34 - n14 * n21 * n32 + n12 * n21 * n34 + n14 * n22 * n31 - n12 * n24 * n31) + n44 * (-n13 * n22 * n31 - n11 * n23 * n32 + n11 * n22 * n33 + n13 * n21 * n32 - n12 * n21 * n33 + n12 * n23 * n31);
  4419. };
  4420. _proto.transpose = function transpose() {
  4421. var te = this.elements;
  4422. var tmp;
  4423. tmp = te[1];
  4424. te[1] = te[4];
  4425. te[4] = tmp;
  4426. tmp = te[2];
  4427. te[2] = te[8];
  4428. te[8] = tmp;
  4429. tmp = te[6];
  4430. te[6] = te[9];
  4431. te[9] = tmp;
  4432. tmp = te[3];
  4433. te[3] = te[12];
  4434. te[12] = tmp;
  4435. tmp = te[7];
  4436. te[7] = te[13];
  4437. te[13] = tmp;
  4438. tmp = te[11];
  4439. te[11] = te[14];
  4440. te[14] = tmp;
  4441. return this;
  4442. };
  4443. _proto.setPosition = function setPosition(x, y, z) {
  4444. var te = this.elements;
  4445. if (x.isVector3) {
  4446. te[12] = x.x;
  4447. te[13] = x.y;
  4448. te[14] = x.z;
  4449. } else {
  4450. te[12] = x;
  4451. te[13] = y;
  4452. te[14] = z;
  4453. }
  4454. return this;
  4455. };
  4456. _proto.invert = function invert() {
  4457. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  4458. var te = this.elements,
  4459. n11 = te[0],
  4460. n21 = te[1],
  4461. n31 = te[2],
  4462. n41 = te[3],
  4463. n12 = te[4],
  4464. n22 = te[5],
  4465. n32 = te[6],
  4466. n42 = te[7],
  4467. n13 = te[8],
  4468. n23 = te[9],
  4469. n33 = te[10],
  4470. n43 = te[11],
  4471. n14 = te[12],
  4472. n24 = te[13],
  4473. n34 = te[14],
  4474. n44 = te[15],
  4475. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  4476. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  4477. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  4478. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  4479. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  4480. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  4481. var detInv = 1 / det;
  4482. te[0] = t11 * detInv;
  4483. te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
  4484. te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
  4485. te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
  4486. te[4] = t12 * detInv;
  4487. te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
  4488. te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
  4489. te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
  4490. te[8] = t13 * detInv;
  4491. te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
  4492. te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
  4493. te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
  4494. te[12] = t14 * detInv;
  4495. te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
  4496. te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
  4497. te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
  4498. return this;
  4499. };
  4500. _proto.scale = function scale(v) {
  4501. var te = this.elements;
  4502. var x = v.x,
  4503. y = v.y,
  4504. z = v.z;
  4505. te[0] *= x;
  4506. te[4] *= y;
  4507. te[8] *= z;
  4508. te[1] *= x;
  4509. te[5] *= y;
  4510. te[9] *= z;
  4511. te[2] *= x;
  4512. te[6] *= y;
  4513. te[10] *= z;
  4514. te[3] *= x;
  4515. te[7] *= y;
  4516. te[11] *= z;
  4517. return this;
  4518. };
  4519. _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
  4520. var te = this.elements;
  4521. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  4522. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  4523. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  4524. return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
  4525. };
  4526. _proto.makeTranslation = function makeTranslation(x, y, z) {
  4527. this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
  4528. return this;
  4529. };
  4530. _proto.makeRotationX = function makeRotationX(theta) {
  4531. var c = Math.cos(theta),
  4532. s = Math.sin(theta);
  4533. this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
  4534. return this;
  4535. };
  4536. _proto.makeRotationY = function makeRotationY(theta) {
  4537. var c = Math.cos(theta),
  4538. s = Math.sin(theta);
  4539. this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
  4540. return this;
  4541. };
  4542. _proto.makeRotationZ = function makeRotationZ(theta) {
  4543. var c = Math.cos(theta),
  4544. s = Math.sin(theta);
  4545. this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4546. return this;
  4547. };
  4548. _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
  4549. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  4550. var c = Math.cos(angle);
  4551. var s = Math.sin(angle);
  4552. var t = 1 - c;
  4553. var x = axis.x,
  4554. y = axis.y,
  4555. z = axis.z;
  4556. var tx = t * x,
  4557. ty = t * y;
  4558. this.set(tx * x + c, tx * y - s * z, tx * z + s * y, 0, tx * y + s * z, ty * y + c, ty * z - s * x, 0, tx * z - s * y, ty * z + s * x, t * z * z + c, 0, 0, 0, 0, 1);
  4559. return this;
  4560. };
  4561. _proto.makeScale = function makeScale(x, y, z) {
  4562. this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
  4563. return this;
  4564. };
  4565. _proto.makeShear = function makeShear(x, y, z) {
  4566. this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
  4567. return this;
  4568. };
  4569. _proto.compose = function compose(position, quaternion, scale) {
  4570. var te = this.elements;
  4571. var x = quaternion._x,
  4572. y = quaternion._y,
  4573. z = quaternion._z,
  4574. w = quaternion._w;
  4575. var x2 = x + x,
  4576. y2 = y + y,
  4577. z2 = z + z;
  4578. var xx = x * x2,
  4579. xy = x * y2,
  4580. xz = x * z2;
  4581. var yy = y * y2,
  4582. yz = y * z2,
  4583. zz = z * z2;
  4584. var wx = w * x2,
  4585. wy = w * y2,
  4586. wz = w * z2;
  4587. var sx = scale.x,
  4588. sy = scale.y,
  4589. sz = scale.z;
  4590. te[0] = (1 - (yy + zz)) * sx;
  4591. te[1] = (xy + wz) * sx;
  4592. te[2] = (xz - wy) * sx;
  4593. te[3] = 0;
  4594. te[4] = (xy - wz) * sy;
  4595. te[5] = (1 - (xx + zz)) * sy;
  4596. te[6] = (yz + wx) * sy;
  4597. te[7] = 0;
  4598. te[8] = (xz + wy) * sz;
  4599. te[9] = (yz - wx) * sz;
  4600. te[10] = (1 - (xx + yy)) * sz;
  4601. te[11] = 0;
  4602. te[12] = position.x;
  4603. te[13] = position.y;
  4604. te[14] = position.z;
  4605. te[15] = 1;
  4606. return this;
  4607. };
  4608. _proto.decompose = function decompose(position, quaternion, scale) {
  4609. var te = this.elements;
  4610. var sx = _v1$1.set(te[0], te[1], te[2]).length();
  4611. var sy = _v1$1.set(te[4], te[5], te[6]).length();
  4612. var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
  4613. var det = this.determinant();
  4614. if (det < 0) sx = -sx;
  4615. position.x = te[12];
  4616. position.y = te[13];
  4617. position.z = te[14]; // scale the rotation part
  4618. _m1.copy(this);
  4619. var invSX = 1 / sx;
  4620. var invSY = 1 / sy;
  4621. var invSZ = 1 / sz;
  4622. _m1.elements[0] *= invSX;
  4623. _m1.elements[1] *= invSX;
  4624. _m1.elements[2] *= invSX;
  4625. _m1.elements[4] *= invSY;
  4626. _m1.elements[5] *= invSY;
  4627. _m1.elements[6] *= invSY;
  4628. _m1.elements[8] *= invSZ;
  4629. _m1.elements[9] *= invSZ;
  4630. _m1.elements[10] *= invSZ;
  4631. quaternion.setFromRotationMatrix(_m1);
  4632. scale.x = sx;
  4633. scale.y = sy;
  4634. scale.z = sz;
  4635. return this;
  4636. };
  4637. _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
  4638. if (far === undefined) {
  4639. console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
  4640. }
  4641. var te = this.elements;
  4642. var x = 2 * near / (right - left);
  4643. var y = 2 * near / (top - bottom);
  4644. var a = (right + left) / (right - left);
  4645. var b = (top + bottom) / (top - bottom);
  4646. var c = -(far + near) / (far - near);
  4647. var d = -2 * far * near / (far - near);
  4648. te[0] = x;
  4649. te[4] = 0;
  4650. te[8] = a;
  4651. te[12] = 0;
  4652. te[1] = 0;
  4653. te[5] = y;
  4654. te[9] = b;
  4655. te[13] = 0;
  4656. te[2] = 0;
  4657. te[6] = 0;
  4658. te[10] = c;
  4659. te[14] = d;
  4660. te[3] = 0;
  4661. te[7] = 0;
  4662. te[11] = -1;
  4663. te[15] = 0;
  4664. return this;
  4665. };
  4666. _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
  4667. var te = this.elements;
  4668. var w = 1.0 / (right - left);
  4669. var h = 1.0 / (top - bottom);
  4670. var p = 1.0 / (far - near);
  4671. var x = (right + left) * w;
  4672. var y = (top + bottom) * h;
  4673. var z = (far + near) * p;
  4674. te[0] = 2 * w;
  4675. te[4] = 0;
  4676. te[8] = 0;
  4677. te[12] = -x;
  4678. te[1] = 0;
  4679. te[5] = 2 * h;
  4680. te[9] = 0;
  4681. te[13] = -y;
  4682. te[2] = 0;
  4683. te[6] = 0;
  4684. te[10] = -2 * p;
  4685. te[14] = -z;
  4686. te[3] = 0;
  4687. te[7] = 0;
  4688. te[11] = 0;
  4689. te[15] = 1;
  4690. return this;
  4691. };
  4692. _proto.equals = function equals(matrix) {
  4693. var te = this.elements;
  4694. var me = matrix.elements;
  4695. for (var i = 0; i < 16; i++) {
  4696. if (te[i] !== me[i]) return false;
  4697. }
  4698. return true;
  4699. };
  4700. _proto.fromArray = function fromArray(array, offset) {
  4701. if (offset === void 0) {
  4702. offset = 0;
  4703. }
  4704. for (var i = 0; i < 16; i++) {
  4705. this.elements[i] = array[i + offset];
  4706. }
  4707. return this;
  4708. };
  4709. _proto.toArray = function toArray(array, offset) {
  4710. if (array === void 0) {
  4711. array = [];
  4712. }
  4713. if (offset === void 0) {
  4714. offset = 0;
  4715. }
  4716. var te = this.elements;
  4717. array[offset] = te[0];
  4718. array[offset + 1] = te[1];
  4719. array[offset + 2] = te[2];
  4720. array[offset + 3] = te[3];
  4721. array[offset + 4] = te[4];
  4722. array[offset + 5] = te[5];
  4723. array[offset + 6] = te[6];
  4724. array[offset + 7] = te[7];
  4725. array[offset + 8] = te[8];
  4726. array[offset + 9] = te[9];
  4727. array[offset + 10] = te[10];
  4728. array[offset + 11] = te[11];
  4729. array[offset + 12] = te[12];
  4730. array[offset + 13] = te[13];
  4731. array[offset + 14] = te[14];
  4732. array[offset + 15] = te[15];
  4733. return array;
  4734. };
  4735. return Matrix4;
  4736. }();
  4737. var _v1$1 = /*@__PURE__*/new Vector3();
  4738. var _m1 = /*@__PURE__*/new Matrix4();
  4739. var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
  4740. var _one = /*@__PURE__*/new Vector3(1, 1, 1);
  4741. var _x = /*@__PURE__*/new Vector3();
  4742. var _y = /*@__PURE__*/new Vector3();
  4743. var _z = /*@__PURE__*/new Vector3();
  4744. var Euler = /*#__PURE__*/function () {
  4745. function Euler(x, y, z, order) {
  4746. if (x === void 0) {
  4747. x = 0;
  4748. }
  4749. if (y === void 0) {
  4750. y = 0;
  4751. }
  4752. if (z === void 0) {
  4753. z = 0;
  4754. }
  4755. if (order === void 0) {
  4756. order = Euler.DefaultOrder;
  4757. }
  4758. Object.defineProperty(this, 'isEuler', {
  4759. value: true
  4760. });
  4761. this._x = x;
  4762. this._y = y;
  4763. this._z = z;
  4764. this._order = order;
  4765. }
  4766. var _proto = Euler.prototype;
  4767. _proto.set = function set(x, y, z, order) {
  4768. this._x = x;
  4769. this._y = y;
  4770. this._z = z;
  4771. this._order = order || this._order;
  4772. this._onChangeCallback();
  4773. return this;
  4774. };
  4775. _proto.clone = function clone() {
  4776. return new this.constructor(this._x, this._y, this._z, this._order);
  4777. };
  4778. _proto.copy = function copy(euler) {
  4779. this._x = euler._x;
  4780. this._y = euler._y;
  4781. this._z = euler._z;
  4782. this._order = euler._order;
  4783. this._onChangeCallback();
  4784. return this;
  4785. };
  4786. _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
  4787. var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4788. var te = m.elements;
  4789. var m11 = te[0],
  4790. m12 = te[4],
  4791. m13 = te[8];
  4792. var m21 = te[1],
  4793. m22 = te[5],
  4794. m23 = te[9];
  4795. var m31 = te[2],
  4796. m32 = te[6],
  4797. m33 = te[10];
  4798. order = order || this._order;
  4799. switch (order) {
  4800. case 'XYZ':
  4801. this._y = Math.asin(clamp(m13, -1, 1));
  4802. if (Math.abs(m13) < 0.9999999) {
  4803. this._x = Math.atan2(-m23, m33);
  4804. this._z = Math.atan2(-m12, m11);
  4805. } else {
  4806. this._x = Math.atan2(m32, m22);
  4807. this._z = 0;
  4808. }
  4809. break;
  4810. case 'YXZ':
  4811. this._x = Math.asin(-clamp(m23, -1, 1));
  4812. if (Math.abs(m23) < 0.9999999) {
  4813. this._y = Math.atan2(m13, m33);
  4814. this._z = Math.atan2(m21, m22);
  4815. } else {
  4816. this._y = Math.atan2(-m31, m11);
  4817. this._z = 0;
  4818. }
  4819. break;
  4820. case 'ZXY':
  4821. this._x = Math.asin(clamp(m32, -1, 1));
  4822. if (Math.abs(m32) < 0.9999999) {
  4823. this._y = Math.atan2(-m31, m33);
  4824. this._z = Math.atan2(-m12, m22);
  4825. } else {
  4826. this._y = 0;
  4827. this._z = Math.atan2(m21, m11);
  4828. }
  4829. break;
  4830. case 'ZYX':
  4831. this._y = Math.asin(-clamp(m31, -1, 1));
  4832. if (Math.abs(m31) < 0.9999999) {
  4833. this._x = Math.atan2(m32, m33);
  4834. this._z = Math.atan2(m21, m11);
  4835. } else {
  4836. this._x = 0;
  4837. this._z = Math.atan2(-m12, m22);
  4838. }
  4839. break;
  4840. case 'YZX':
  4841. this._z = Math.asin(clamp(m21, -1, 1));
  4842. if (Math.abs(m21) < 0.9999999) {
  4843. this._x = Math.atan2(-m23, m22);
  4844. this._y = Math.atan2(-m31, m11);
  4845. } else {
  4846. this._x = 0;
  4847. this._y = Math.atan2(m13, m33);
  4848. }
  4849. break;
  4850. case 'XZY':
  4851. this._z = Math.asin(-clamp(m12, -1, 1));
  4852. if (Math.abs(m12) < 0.9999999) {
  4853. this._x = Math.atan2(m32, m22);
  4854. this._y = Math.atan2(m13, m11);
  4855. } else {
  4856. this._x = Math.atan2(-m23, m33);
  4857. this._y = 0;
  4858. }
  4859. break;
  4860. default:
  4861. console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
  4862. }
  4863. this._order = order;
  4864. if (update !== false) this._onChangeCallback();
  4865. return this;
  4866. };
  4867. _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
  4868. _matrix.makeRotationFromQuaternion(q);
  4869. return this.setFromRotationMatrix(_matrix, order, update);
  4870. };
  4871. _proto.setFromVector3 = function setFromVector3(v, order) {
  4872. return this.set(v.x, v.y, v.z, order || this._order);
  4873. };
  4874. _proto.reorder = function reorder(newOrder) {
  4875. // WARNING: this discards revolution information -bhouston
  4876. _quaternion$1.setFromEuler(this);
  4877. return this.setFromQuaternion(_quaternion$1, newOrder);
  4878. };
  4879. _proto.equals = function equals(euler) {
  4880. return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
  4881. };
  4882. _proto.fromArray = function fromArray(array) {
  4883. this._x = array[0];
  4884. this._y = array[1];
  4885. this._z = array[2];
  4886. if (array[3] !== undefined) this._order = array[3];
  4887. this._onChangeCallback();
  4888. return this;
  4889. };
  4890. _proto.toArray = function toArray(array, offset) {
  4891. if (array === void 0) {
  4892. array = [];
  4893. }
  4894. if (offset === void 0) {
  4895. offset = 0;
  4896. }
  4897. array[offset] = this._x;
  4898. array[offset + 1] = this._y;
  4899. array[offset + 2] = this._z;
  4900. array[offset + 3] = this._order;
  4901. return array;
  4902. };
  4903. _proto.toVector3 = function toVector3(optionalResult) {
  4904. if (optionalResult) {
  4905. return optionalResult.set(this._x, this._y, this._z);
  4906. } else {
  4907. return new Vector3(this._x, this._y, this._z);
  4908. }
  4909. };
  4910. _proto._onChange = function _onChange(callback) {
  4911. this._onChangeCallback = callback;
  4912. return this;
  4913. };
  4914. _proto._onChangeCallback = function _onChangeCallback() {};
  4915. _createClass(Euler, [{
  4916. key: "x",
  4917. get: function get() {
  4918. return this._x;
  4919. },
  4920. set: function set(value) {
  4921. this._x = value;
  4922. this._onChangeCallback();
  4923. }
  4924. }, {
  4925. key: "y",
  4926. get: function get() {
  4927. return this._y;
  4928. },
  4929. set: function set(value) {
  4930. this._y = value;
  4931. this._onChangeCallback();
  4932. }
  4933. }, {
  4934. key: "z",
  4935. get: function get() {
  4936. return this._z;
  4937. },
  4938. set: function set(value) {
  4939. this._z = value;
  4940. this._onChangeCallback();
  4941. }
  4942. }, {
  4943. key: "order",
  4944. get: function get() {
  4945. return this._order;
  4946. },
  4947. set: function set(value) {
  4948. this._order = value;
  4949. this._onChangeCallback();
  4950. }
  4951. }]);
  4952. return Euler;
  4953. }();
  4954. Euler.DefaultOrder = 'XYZ';
  4955. Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
  4956. var _matrix = /*@__PURE__*/new Matrix4();
  4957. var _quaternion$1 = /*@__PURE__*/new Quaternion();
  4958. var Layers = /*#__PURE__*/function () {
  4959. function Layers() {
  4960. this.mask = 1 | 0;
  4961. }
  4962. var _proto = Layers.prototype;
  4963. _proto.set = function set(channel) {
  4964. this.mask = 1 << channel | 0;
  4965. };
  4966. _proto.enable = function enable(channel) {
  4967. this.mask |= 1 << channel | 0;
  4968. };
  4969. _proto.enableAll = function enableAll() {
  4970. this.mask = 0xffffffff | 0;
  4971. };
  4972. _proto.toggle = function toggle(channel) {
  4973. this.mask ^= 1 << channel | 0;
  4974. };
  4975. _proto.disable = function disable(channel) {
  4976. this.mask &= ~(1 << channel | 0);
  4977. };
  4978. _proto.disableAll = function disableAll() {
  4979. this.mask = 0;
  4980. };
  4981. _proto.test = function test(layers) {
  4982. return (this.mask & layers.mask) !== 0;
  4983. };
  4984. return Layers;
  4985. }();
  4986. var _object3DId = 0;
  4987. var _v1$2 = new Vector3();
  4988. var _q1 = new Quaternion();
  4989. var _m1$1 = new Matrix4();
  4990. var _target = new Vector3();
  4991. var _position = new Vector3();
  4992. var _scale = new Vector3();
  4993. var _quaternion$2 = new Quaternion();
  4994. var _xAxis = new Vector3(1, 0, 0);
  4995. var _yAxis = new Vector3(0, 1, 0);
  4996. var _zAxis = new Vector3(0, 0, 1);
  4997. var _addedEvent = {
  4998. type: 'added'
  4999. };
  5000. var _removedEvent = {
  5001. type: 'removed'
  5002. };
  5003. function Object3D() {
  5004. Object.defineProperty(this, 'id', {
  5005. value: _object3DId++
  5006. });
  5007. this.uuid = MathUtils.generateUUID();
  5008. this.name = '';
  5009. this.type = 'Object3D';
  5010. this.parent = null;
  5011. this.children = [];
  5012. this.up = Object3D.DefaultUp.clone();
  5013. var position = new Vector3();
  5014. var rotation = new Euler();
  5015. var quaternion = new Quaternion();
  5016. var scale = new Vector3(1, 1, 1);
  5017. function onRotationChange() {
  5018. quaternion.setFromEuler(rotation, false);
  5019. }
  5020. function onQuaternionChange() {
  5021. rotation.setFromQuaternion(quaternion, undefined, false);
  5022. }
  5023. rotation._onChange(onRotationChange);
  5024. quaternion._onChange(onQuaternionChange);
  5025. Object.defineProperties(this, {
  5026. position: {
  5027. configurable: true,
  5028. enumerable: true,
  5029. value: position
  5030. },
  5031. rotation: {
  5032. configurable: true,
  5033. enumerable: true,
  5034. value: rotation
  5035. },
  5036. quaternion: {
  5037. configurable: true,
  5038. enumerable: true,
  5039. value: quaternion
  5040. },
  5041. scale: {
  5042. configurable: true,
  5043. enumerable: true,
  5044. value: scale
  5045. },
  5046. modelViewMatrix: {
  5047. value: new Matrix4()
  5048. },
  5049. normalMatrix: {
  5050. value: new Matrix3()
  5051. }
  5052. });
  5053. this.matrix = new Matrix4();
  5054. this.matrixWorld = new Matrix4();
  5055. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  5056. this.matrixWorldNeedsUpdate = false;
  5057. this.layers = new Layers();
  5058. this.visible = true;
  5059. this.castShadow = false;
  5060. this.receiveShadow = false;
  5061. this.frustumCulled = true;
  5062. this.renderOrder = 0;
  5063. this.animations = [];
  5064. this.userData = {};
  5065. }
  5066. Object3D.DefaultUp = new Vector3(0, 1, 0);
  5067. Object3D.DefaultMatrixAutoUpdate = true;
  5068. Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5069. constructor: Object3D,
  5070. isObject3D: true,
  5071. onBeforeRender: function onBeforeRender() {},
  5072. onAfterRender: function onAfterRender() {},
  5073. applyMatrix4: function applyMatrix4(matrix) {
  5074. if (this.matrixAutoUpdate) this.updateMatrix();
  5075. this.matrix.premultiply(matrix);
  5076. this.matrix.decompose(this.position, this.quaternion, this.scale);
  5077. },
  5078. applyQuaternion: function applyQuaternion(q) {
  5079. this.quaternion.premultiply(q);
  5080. return this;
  5081. },
  5082. setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
  5083. // assumes axis is normalized
  5084. this.quaternion.setFromAxisAngle(axis, angle);
  5085. },
  5086. setRotationFromEuler: function setRotationFromEuler(euler) {
  5087. this.quaternion.setFromEuler(euler, true);
  5088. },
  5089. setRotationFromMatrix: function setRotationFromMatrix(m) {
  5090. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5091. this.quaternion.setFromRotationMatrix(m);
  5092. },
  5093. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  5094. // assumes q is normalized
  5095. this.quaternion.copy(q);
  5096. },
  5097. rotateOnAxis: function rotateOnAxis(axis, angle) {
  5098. // rotate object on axis in object space
  5099. // axis is assumed to be normalized
  5100. _q1.setFromAxisAngle(axis, angle);
  5101. this.quaternion.multiply(_q1);
  5102. return this;
  5103. },
  5104. rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
  5105. // rotate object on axis in world space
  5106. // axis is assumed to be normalized
  5107. // method assumes no rotated parent
  5108. _q1.setFromAxisAngle(axis, angle);
  5109. this.quaternion.premultiply(_q1);
  5110. return this;
  5111. },
  5112. rotateX: function rotateX(angle) {
  5113. return this.rotateOnAxis(_xAxis, angle);
  5114. },
  5115. rotateY: function rotateY(angle) {
  5116. return this.rotateOnAxis(_yAxis, angle);
  5117. },
  5118. rotateZ: function rotateZ(angle) {
  5119. return this.rotateOnAxis(_zAxis, angle);
  5120. },
  5121. translateOnAxis: function translateOnAxis(axis, distance) {
  5122. // translate object by distance along axis in object space
  5123. // axis is assumed to be normalized
  5124. _v1$2.copy(axis).applyQuaternion(this.quaternion);
  5125. this.position.add(_v1$2.multiplyScalar(distance));
  5126. return this;
  5127. },
  5128. translateX: function translateX(distance) {
  5129. return this.translateOnAxis(_xAxis, distance);
  5130. },
  5131. translateY: function translateY(distance) {
  5132. return this.translateOnAxis(_yAxis, distance);
  5133. },
  5134. translateZ: function translateZ(distance) {
  5135. return this.translateOnAxis(_zAxis, distance);
  5136. },
  5137. localToWorld: function localToWorld(vector) {
  5138. return vector.applyMatrix4(this.matrixWorld);
  5139. },
  5140. worldToLocal: function worldToLocal(vector) {
  5141. return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert());
  5142. },
  5143. lookAt: function lookAt(x, y, z) {
  5144. // This method does not support objects having non-uniformly-scaled parent(s)
  5145. if (x.isVector3) {
  5146. _target.copy(x);
  5147. } else {
  5148. _target.set(x, y, z);
  5149. }
  5150. var parent = this.parent;
  5151. this.updateWorldMatrix(true, false);
  5152. _position.setFromMatrixPosition(this.matrixWorld);
  5153. if (this.isCamera || this.isLight) {
  5154. _m1$1.lookAt(_position, _target, this.up);
  5155. } else {
  5156. _m1$1.lookAt(_target, _position, this.up);
  5157. }
  5158. this.quaternion.setFromRotationMatrix(_m1$1);
  5159. if (parent) {
  5160. _m1$1.extractRotation(parent.matrixWorld);
  5161. _q1.setFromRotationMatrix(_m1$1);
  5162. this.quaternion.premultiply(_q1.invert());
  5163. }
  5164. },
  5165. add: function add(object) {
  5166. if (arguments.length > 1) {
  5167. for (var i = 0; i < arguments.length; i++) {
  5168. this.add(arguments[i]);
  5169. }
  5170. return this;
  5171. }
  5172. if (object === this) {
  5173. console.error('THREE.Object3D.add: object can\'t be added as a child of itself.', object);
  5174. return this;
  5175. }
  5176. if (object && object.isObject3D) {
  5177. if (object.parent !== null) {
  5178. object.parent.remove(object);
  5179. }
  5180. object.parent = this;
  5181. this.children.push(object);
  5182. object.dispatchEvent(_addedEvent);
  5183. } else {
  5184. console.error('THREE.Object3D.add: object not an instance of THREE.Object3D.', object);
  5185. }
  5186. return this;
  5187. },
  5188. remove: function remove(object) {
  5189. if (arguments.length > 1) {
  5190. for (var i = 0; i < arguments.length; i++) {
  5191. this.remove(arguments[i]);
  5192. }
  5193. return this;
  5194. }
  5195. var index = this.children.indexOf(object);
  5196. if (index !== -1) {
  5197. object.parent = null;
  5198. this.children.splice(index, 1);
  5199. object.dispatchEvent(_removedEvent);
  5200. }
  5201. return this;
  5202. },
  5203. clear: function clear() {
  5204. for (var i = 0; i < this.children.length; i++) {
  5205. var object = this.children[i];
  5206. object.parent = null;
  5207. object.dispatchEvent(_removedEvent);
  5208. }
  5209. this.children.length = 0;
  5210. return this;
  5211. },
  5212. attach: function attach(object) {
  5213. // adds object as a child of this, while maintaining the object's world transform
  5214. this.updateWorldMatrix(true, false);
  5215. _m1$1.copy(this.matrixWorld).invert();
  5216. if (object.parent !== null) {
  5217. object.parent.updateWorldMatrix(true, false);
  5218. _m1$1.multiply(object.parent.matrixWorld);
  5219. }
  5220. object.applyMatrix4(_m1$1);
  5221. object.updateWorldMatrix(false, false);
  5222. this.add(object);
  5223. return this;
  5224. },
  5225. getObjectById: function getObjectById(id) {
  5226. return this.getObjectByProperty('id', id);
  5227. },
  5228. getObjectByName: function getObjectByName(name) {
  5229. return this.getObjectByProperty('name', name);
  5230. },
  5231. getObjectByProperty: function getObjectByProperty(name, value) {
  5232. if (this[name] === value) return this;
  5233. for (var i = 0, l = this.children.length; i < l; i++) {
  5234. var child = this.children[i];
  5235. var object = child.getObjectByProperty(name, value);
  5236. if (object !== undefined) {
  5237. return object;
  5238. }
  5239. }
  5240. return undefined;
  5241. },
  5242. getWorldPosition: function getWorldPosition(target) {
  5243. if (target === undefined) {
  5244. console.warn('THREE.Object3D: .getWorldPosition() target is now required');
  5245. target = new Vector3();
  5246. }
  5247. this.updateWorldMatrix(true, false);
  5248. return target.setFromMatrixPosition(this.matrixWorld);
  5249. },
  5250. getWorldQuaternion: function getWorldQuaternion(target) {
  5251. if (target === undefined) {
  5252. console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
  5253. target = new Quaternion();
  5254. }
  5255. this.updateWorldMatrix(true, false);
  5256. this.matrixWorld.decompose(_position, target, _scale);
  5257. return target;
  5258. },
  5259. getWorldScale: function getWorldScale(target) {
  5260. if (target === undefined) {
  5261. console.warn('THREE.Object3D: .getWorldScale() target is now required');
  5262. target = new Vector3();
  5263. }
  5264. this.updateWorldMatrix(true, false);
  5265. this.matrixWorld.decompose(_position, _quaternion$2, target);
  5266. return target;
  5267. },
  5268. getWorldDirection: function getWorldDirection(target) {
  5269. if (target === undefined) {
  5270. console.warn('THREE.Object3D: .getWorldDirection() target is now required');
  5271. target = new Vector3();
  5272. }
  5273. this.updateWorldMatrix(true, false);
  5274. var e = this.matrixWorld.elements;
  5275. return target.set(e[8], e[9], e[10]).normalize();
  5276. },
  5277. raycast: function raycast() {},
  5278. traverse: function traverse(callback) {
  5279. callback(this);
  5280. var children = this.children;
  5281. for (var i = 0, l = children.length; i < l; i++) {
  5282. children[i].traverse(callback);
  5283. }
  5284. },
  5285. traverseVisible: function traverseVisible(callback) {
  5286. if (this.visible === false) return;
  5287. callback(this);
  5288. var children = this.children;
  5289. for (var i = 0, l = children.length; i < l; i++) {
  5290. children[i].traverseVisible(callback);
  5291. }
  5292. },
  5293. traverseAncestors: function traverseAncestors(callback) {
  5294. var parent = this.parent;
  5295. if (parent !== null) {
  5296. callback(parent);
  5297. parent.traverseAncestors(callback);
  5298. }
  5299. },
  5300. updateMatrix: function updateMatrix() {
  5301. this.matrix.compose(this.position, this.quaternion, this.scale);
  5302. this.matrixWorldNeedsUpdate = true;
  5303. },
  5304. updateMatrixWorld: function updateMatrixWorld(force) {
  5305. if (this.matrixAutoUpdate) this.updateMatrix();
  5306. if (this.matrixWorldNeedsUpdate || force) {
  5307. if (this.parent === null) {
  5308. this.matrixWorld.copy(this.matrix);
  5309. } else {
  5310. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  5311. }
  5312. this.matrixWorldNeedsUpdate = false;
  5313. force = true;
  5314. } // update children
  5315. var children = this.children;
  5316. for (var i = 0, l = children.length; i < l; i++) {
  5317. children[i].updateMatrixWorld(force);
  5318. }
  5319. },
  5320. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  5321. var parent = this.parent;
  5322. if (updateParents === true && parent !== null) {
  5323. parent.updateWorldMatrix(true, false);
  5324. }
  5325. if (this.matrixAutoUpdate) this.updateMatrix();
  5326. if (this.parent === null) {
  5327. this.matrixWorld.copy(this.matrix);
  5328. } else {
  5329. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  5330. } // update children
  5331. if (updateChildren === true) {
  5332. var children = this.children;
  5333. for (var i = 0, l = children.length; i < l; i++) {
  5334. children[i].updateWorldMatrix(false, true);
  5335. }
  5336. }
  5337. },
  5338. toJSON: function toJSON(meta) {
  5339. // meta is a string when called from JSON.stringify
  5340. var isRootObject = meta === undefined || typeof meta === 'string';
  5341. var output = {}; // meta is a hash used to collect geometries, materials.
  5342. // not providing it implies that this is the root object
  5343. // being serialized.
  5344. if (isRootObject) {
  5345. // initialize meta obj
  5346. meta = {
  5347. geometries: {},
  5348. materials: {},
  5349. textures: {},
  5350. images: {},
  5351. shapes: {},
  5352. skeletons: {},
  5353. animations: {}
  5354. };
  5355. output.metadata = {
  5356. version: 4.5,
  5357. type: 'Object',
  5358. generator: 'Object3D.toJSON'
  5359. };
  5360. } // standard Object3D serialization
  5361. var object = {};
  5362. object.uuid = this.uuid;
  5363. object.type = this.type;
  5364. if (this.name !== '') object.name = this.name;
  5365. if (this.castShadow === true) object.castShadow = true;
  5366. if (this.receiveShadow === true) object.receiveShadow = true;
  5367. if (this.visible === false) object.visible = false;
  5368. if (this.frustumCulled === false) object.frustumCulled = false;
  5369. if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
  5370. if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
  5371. object.layers = this.layers.mask;
  5372. object.matrix = this.matrix.toArray();
  5373. if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
  5374. if (this.isInstancedMesh) {
  5375. object.type = 'InstancedMesh';
  5376. object.count = this.count;
  5377. object.instanceMatrix = this.instanceMatrix.toJSON();
  5378. } //
  5379. function serialize(library, element) {
  5380. if (library[element.uuid] === undefined) {
  5381. library[element.uuid] = element.toJSON(meta);
  5382. }
  5383. return element.uuid;
  5384. }
  5385. if (this.isMesh || this.isLine || this.isPoints) {
  5386. object.geometry = serialize(meta.geometries, this.geometry);
  5387. var parameters = this.geometry.parameters;
  5388. if (parameters !== undefined && parameters.shapes !== undefined) {
  5389. var shapes = parameters.shapes;
  5390. if (Array.isArray(shapes)) {
  5391. for (var i = 0, l = shapes.length; i < l; i++) {
  5392. var shape = shapes[i];
  5393. serialize(meta.shapes, shape);
  5394. }
  5395. } else {
  5396. serialize(meta.shapes, shapes);
  5397. }
  5398. }
  5399. }
  5400. if (this.isSkinnedMesh) {
  5401. object.bindMode = this.bindMode;
  5402. object.bindMatrix = this.bindMatrix.toArray();
  5403. if (this.skeleton !== undefined) {
  5404. serialize(meta.skeletons, this.skeleton);
  5405. object.skeleton = this.skeleton.uuid;
  5406. }
  5407. }
  5408. if (this.material !== undefined) {
  5409. if (Array.isArray(this.material)) {
  5410. var uuids = [];
  5411. for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
  5412. uuids.push(serialize(meta.materials, this.material[_i]));
  5413. }
  5414. object.material = uuids;
  5415. } else {
  5416. object.material = serialize(meta.materials, this.material);
  5417. }
  5418. } //
  5419. if (this.children.length > 0) {
  5420. object.children = [];
  5421. for (var _i2 = 0; _i2 < this.children.length; _i2++) {
  5422. object.children.push(this.children[_i2].toJSON(meta).object);
  5423. }
  5424. } //
  5425. if (this.animations.length > 0) {
  5426. object.animations = [];
  5427. for (var _i3 = 0; _i3 < this.animations.length; _i3++) {
  5428. var animation = this.animations[_i3];
  5429. object.animations.push(serialize(meta.animations, animation));
  5430. }
  5431. }
  5432. if (isRootObject) {
  5433. var geometries = extractFromCache(meta.geometries);
  5434. var materials = extractFromCache(meta.materials);
  5435. var textures = extractFromCache(meta.textures);
  5436. var images = extractFromCache(meta.images);
  5437. var _shapes = extractFromCache(meta.shapes);
  5438. var skeletons = extractFromCache(meta.skeletons);
  5439. var animations = extractFromCache(meta.animations);
  5440. if (geometries.length > 0) output.geometries = geometries;
  5441. if (materials.length > 0) output.materials = materials;
  5442. if (textures.length > 0) output.textures = textures;
  5443. if (images.length > 0) output.images = images;
  5444. if (_shapes.length > 0) output.shapes = _shapes;
  5445. if (skeletons.length > 0) output.skeletons = skeletons;
  5446. if (animations.length > 0) output.animations = animations;
  5447. }
  5448. output.object = object;
  5449. return output; // extract data from the cache hash
  5450. // remove metadata on each item
  5451. // and return as array
  5452. function extractFromCache(cache) {
  5453. var values = [];
  5454. for (var key in cache) {
  5455. var data = cache[key];
  5456. delete data.metadata;
  5457. values.push(data);
  5458. }
  5459. return values;
  5460. }
  5461. },
  5462. clone: function clone(recursive) {
  5463. return new this.constructor().copy(this, recursive);
  5464. },
  5465. copy: function copy(source, recursive) {
  5466. if (recursive === void 0) {
  5467. recursive = true;
  5468. }
  5469. this.name = source.name;
  5470. this.up.copy(source.up);
  5471. this.position.copy(source.position);
  5472. this.rotation.order = source.rotation.order;
  5473. this.quaternion.copy(source.quaternion);
  5474. this.scale.copy(source.scale);
  5475. this.matrix.copy(source.matrix);
  5476. this.matrixWorld.copy(source.matrixWorld);
  5477. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5478. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5479. this.layers.mask = source.layers.mask;
  5480. this.visible = source.visible;
  5481. this.castShadow = source.castShadow;
  5482. this.receiveShadow = source.receiveShadow;
  5483. this.frustumCulled = source.frustumCulled;
  5484. this.renderOrder = source.renderOrder;
  5485. this.userData = JSON.parse(JSON.stringify(source.userData));
  5486. if (recursive === true) {
  5487. for (var i = 0; i < source.children.length; i++) {
  5488. var child = source.children[i];
  5489. this.add(child.clone());
  5490. }
  5491. }
  5492. return this;
  5493. }
  5494. });
  5495. var _vector1 = /*@__PURE__*/new Vector3();
  5496. var _vector2 = /*@__PURE__*/new Vector3();
  5497. var _normalMatrix = /*@__PURE__*/new Matrix3();
  5498. var Plane = /*#__PURE__*/function () {
  5499. function Plane(normal, constant) {
  5500. Object.defineProperty(this, 'isPlane', {
  5501. value: true
  5502. }); // normal is assumed to be normalized
  5503. this.normal = normal !== undefined ? normal : new Vector3(1, 0, 0);
  5504. this.constant = constant !== undefined ? constant : 0;
  5505. }
  5506. var _proto = Plane.prototype;
  5507. _proto.set = function set(normal, constant) {
  5508. this.normal.copy(normal);
  5509. this.constant = constant;
  5510. return this;
  5511. };
  5512. _proto.setComponents = function setComponents(x, y, z, w) {
  5513. this.normal.set(x, y, z);
  5514. this.constant = w;
  5515. return this;
  5516. };
  5517. _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
  5518. this.normal.copy(normal);
  5519. this.constant = -point.dot(this.normal);
  5520. return this;
  5521. };
  5522. _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
  5523. var normal = _vector1.subVectors(c, b).cross(_vector2.subVectors(a, b)).normalize(); // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  5524. this.setFromNormalAndCoplanarPoint(normal, a);
  5525. return this;
  5526. };
  5527. _proto.clone = function clone() {
  5528. return new this.constructor().copy(this);
  5529. };
  5530. _proto.copy = function copy(plane) {
  5531. this.normal.copy(plane.normal);
  5532. this.constant = plane.constant;
  5533. return this;
  5534. };
  5535. _proto.normalize = function normalize() {
  5536. // Note: will lead to a divide by zero if the plane is invalid.
  5537. var inverseNormalLength = 1.0 / this.normal.length();
  5538. this.normal.multiplyScalar(inverseNormalLength);
  5539. this.constant *= inverseNormalLength;
  5540. return this;
  5541. };
  5542. _proto.negate = function negate() {
  5543. this.constant *= -1;
  5544. this.normal.negate();
  5545. return this;
  5546. };
  5547. _proto.distanceToPoint = function distanceToPoint(point) {
  5548. return this.normal.dot(point) + this.constant;
  5549. };
  5550. _proto.distanceToSphere = function distanceToSphere(sphere) {
  5551. return this.distanceToPoint(sphere.center) - sphere.radius;
  5552. };
  5553. _proto.projectPoint = function projectPoint(point, target) {
  5554. if (target === undefined) {
  5555. console.warn('THREE.Plane: .projectPoint() target is now required');
  5556. target = new Vector3();
  5557. }
  5558. return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
  5559. };
  5560. _proto.intersectLine = function intersectLine(line, target) {
  5561. if (target === undefined) {
  5562. console.warn('THREE.Plane: .intersectLine() target is now required');
  5563. target = new Vector3();
  5564. }
  5565. var direction = line.delta(_vector1);
  5566. var denominator = this.normal.dot(direction);
  5567. if (denominator === 0) {
  5568. // line is coplanar, return origin
  5569. if (this.distanceToPoint(line.start) === 0) {
  5570. return target.copy(line.start);
  5571. } // Unsure if this is the correct method to handle this case.
  5572. return undefined;
  5573. }
  5574. var t = -(line.start.dot(this.normal) + this.constant) / denominator;
  5575. if (t < 0 || t > 1) {
  5576. return undefined;
  5577. }
  5578. return target.copy(direction).multiplyScalar(t).add(line.start);
  5579. };
  5580. _proto.intersectsLine = function intersectsLine(line) {
  5581. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  5582. var startSign = this.distanceToPoint(line.start);
  5583. var endSign = this.distanceToPoint(line.end);
  5584. return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
  5585. };
  5586. _proto.intersectsBox = function intersectsBox(box) {
  5587. return box.intersectsPlane(this);
  5588. };
  5589. _proto.intersectsSphere = function intersectsSphere(sphere) {
  5590. return sphere.intersectsPlane(this);
  5591. };
  5592. _proto.coplanarPoint = function coplanarPoint(target) {
  5593. if (target === undefined) {
  5594. console.warn('THREE.Plane: .coplanarPoint() target is now required');
  5595. target = new Vector3();
  5596. }
  5597. return target.copy(this.normal).multiplyScalar(-this.constant);
  5598. };
  5599. _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
  5600. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
  5601. var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
  5602. var normal = this.normal.applyMatrix3(normalMatrix).normalize();
  5603. this.constant = -referencePoint.dot(normal);
  5604. return this;
  5605. };
  5606. _proto.translate = function translate(offset) {
  5607. this.constant -= offset.dot(this.normal);
  5608. return this;
  5609. };
  5610. _proto.equals = function equals(plane) {
  5611. return plane.normal.equals(this.normal) && plane.constant === this.constant;
  5612. };
  5613. return Plane;
  5614. }();
  5615. var _v0$1 = /*@__PURE__*/new Vector3();
  5616. var _v1$3 = /*@__PURE__*/new Vector3();
  5617. var _v2$1 = /*@__PURE__*/new Vector3();
  5618. var _v3 = /*@__PURE__*/new Vector3();
  5619. var _vab = /*@__PURE__*/new Vector3();
  5620. var _vac = /*@__PURE__*/new Vector3();
  5621. var _vbc = /*@__PURE__*/new Vector3();
  5622. var _vap = /*@__PURE__*/new Vector3();
  5623. var _vbp = /*@__PURE__*/new Vector3();
  5624. var _vcp = /*@__PURE__*/new Vector3();
  5625. var Triangle = /*#__PURE__*/function () {
  5626. function Triangle(a, b, c) {
  5627. this.a = a !== undefined ? a : new Vector3();
  5628. this.b = b !== undefined ? b : new Vector3();
  5629. this.c = c !== undefined ? c : new Vector3();
  5630. }
  5631. Triangle.getNormal = function getNormal(a, b, c, target) {
  5632. if (target === undefined) {
  5633. console.warn('THREE.Triangle: .getNormal() target is now required');
  5634. target = new Vector3();
  5635. }
  5636. target.subVectors(c, b);
  5637. _v0$1.subVectors(a, b);
  5638. target.cross(_v0$1);
  5639. var targetLengthSq = target.lengthSq();
  5640. if (targetLengthSq > 0) {
  5641. return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
  5642. }
  5643. return target.set(0, 0, 0);
  5644. } // static/instance method to calculate barycentric coordinates
  5645. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  5646. ;
  5647. Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
  5648. _v0$1.subVectors(c, a);
  5649. _v1$3.subVectors(b, a);
  5650. _v2$1.subVectors(point, a);
  5651. var dot00 = _v0$1.dot(_v0$1);
  5652. var dot01 = _v0$1.dot(_v1$3);
  5653. var dot02 = _v0$1.dot(_v2$1);
  5654. var dot11 = _v1$3.dot(_v1$3);
  5655. var dot12 = _v1$3.dot(_v2$1);
  5656. var denom = dot00 * dot11 - dot01 * dot01;
  5657. if (target === undefined) {
  5658. console.warn('THREE.Triangle: .getBarycoord() target is now required');
  5659. target = new Vector3();
  5660. } // collinear or singular triangle
  5661. if (denom === 0) {
  5662. // arbitrary location outside of triangle?
  5663. // not sure if this is the best idea, maybe should be returning undefined
  5664. return target.set(-2, -1, -1);
  5665. }
  5666. var invDenom = 1 / denom;
  5667. var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  5668. var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
  5669. return target.set(1 - u - v, v, u);
  5670. };
  5671. Triangle.containsPoint = function containsPoint(point, a, b, c) {
  5672. this.getBarycoord(point, a, b, c, _v3);
  5673. return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
  5674. };
  5675. Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
  5676. this.getBarycoord(point, p1, p2, p3, _v3);
  5677. target.set(0, 0);
  5678. target.addScaledVector(uv1, _v3.x);
  5679. target.addScaledVector(uv2, _v3.y);
  5680. target.addScaledVector(uv3, _v3.z);
  5681. return target;
  5682. };
  5683. Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
  5684. _v0$1.subVectors(c, b);
  5685. _v1$3.subVectors(a, b); // strictly front facing
  5686. return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
  5687. };
  5688. var _proto = Triangle.prototype;
  5689. _proto.set = function set(a, b, c) {
  5690. this.a.copy(a);
  5691. this.b.copy(b);
  5692. this.c.copy(c);
  5693. return this;
  5694. };
  5695. _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
  5696. this.a.copy(points[i0]);
  5697. this.b.copy(points[i1]);
  5698. this.c.copy(points[i2]);
  5699. return this;
  5700. };
  5701. _proto.clone = function clone() {
  5702. return new this.constructor().copy(this);
  5703. };
  5704. _proto.copy = function copy(triangle) {
  5705. this.a.copy(triangle.a);
  5706. this.b.copy(triangle.b);
  5707. this.c.copy(triangle.c);
  5708. return this;
  5709. };
  5710. _proto.getArea = function getArea() {
  5711. _v0$1.subVectors(this.c, this.b);
  5712. _v1$3.subVectors(this.a, this.b);
  5713. return _v0$1.cross(_v1$3).length() * 0.5;
  5714. };
  5715. _proto.getMidpoint = function getMidpoint(target) {
  5716. if (target === undefined) {
  5717. console.warn('THREE.Triangle: .getMidpoint() target is now required');
  5718. target = new Vector3();
  5719. }
  5720. return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  5721. };
  5722. _proto.getNormal = function getNormal(target) {
  5723. return Triangle.getNormal(this.a, this.b, this.c, target);
  5724. };
  5725. _proto.getPlane = function getPlane(target) {
  5726. if (target === undefined) {
  5727. console.warn('THREE.Triangle: .getPlane() target is now required');
  5728. target = new Plane();
  5729. }
  5730. return target.setFromCoplanarPoints(this.a, this.b, this.c);
  5731. };
  5732. _proto.getBarycoord = function getBarycoord(point, target) {
  5733. return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
  5734. };
  5735. _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
  5736. return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
  5737. };
  5738. _proto.containsPoint = function containsPoint(point) {
  5739. return Triangle.containsPoint(point, this.a, this.b, this.c);
  5740. };
  5741. _proto.isFrontFacing = function isFrontFacing(direction) {
  5742. return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
  5743. };
  5744. _proto.intersectsBox = function intersectsBox(box) {
  5745. return box.intersectsTriangle(this);
  5746. };
  5747. _proto.closestPointToPoint = function closestPointToPoint(p, target) {
  5748. if (target === undefined) {
  5749. console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
  5750. target = new Vector3();
  5751. }
  5752. var a = this.a,
  5753. b = this.b,
  5754. c = this.c;
  5755. var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  5756. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  5757. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  5758. // basically, we're distinguishing which of the voronoi regions of the triangle
  5759. // the point lies in with the minimum amount of redundant computation.
  5760. _vab.subVectors(b, a);
  5761. _vac.subVectors(c, a);
  5762. _vap.subVectors(p, a);
  5763. var d1 = _vab.dot(_vap);
  5764. var d2 = _vac.dot(_vap);
  5765. if (d1 <= 0 && d2 <= 0) {
  5766. // vertex region of A; barycentric coords (1, 0, 0)
  5767. return target.copy(a);
  5768. }
  5769. _vbp.subVectors(p, b);
  5770. var d3 = _vab.dot(_vbp);
  5771. var d4 = _vac.dot(_vbp);
  5772. if (d3 >= 0 && d4 <= d3) {
  5773. // vertex region of B; barycentric coords (0, 1, 0)
  5774. return target.copy(b);
  5775. }
  5776. var vc = d1 * d4 - d3 * d2;
  5777. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  5778. v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
  5779. return target.copy(a).addScaledVector(_vab, v);
  5780. }
  5781. _vcp.subVectors(p, c);
  5782. var d5 = _vab.dot(_vcp);
  5783. var d6 = _vac.dot(_vcp);
  5784. if (d6 >= 0 && d5 <= d6) {
  5785. // vertex region of C; barycentric coords (0, 0, 1)
  5786. return target.copy(c);
  5787. }
  5788. var vb = d5 * d2 - d1 * d6;
  5789. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  5790. w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
  5791. return target.copy(a).addScaledVector(_vac, w);
  5792. }
  5793. var va = d3 * d6 - d5 * d4;
  5794. if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
  5795. _vbc.subVectors(c, b);
  5796. w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
  5797. return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
  5798. } // face region
  5799. var denom = 1 / (va + vb + vc); // u = va * denom
  5800. v = vb * denom;
  5801. w = vc * denom;
  5802. return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
  5803. };
  5804. _proto.equals = function equals(triangle) {
  5805. return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
  5806. };
  5807. return Triangle;
  5808. }();
  5809. var materialId = 0;
  5810. function Material() {
  5811. Object.defineProperty(this, 'id', {
  5812. value: materialId++
  5813. });
  5814. this.uuid = MathUtils.generateUUID();
  5815. this.name = '';
  5816. this.type = 'Material';
  5817. this.fog = true;
  5818. this.blending = NormalBlending;
  5819. this.side = FrontSide;
  5820. this.vertexColors = false;
  5821. this.opacity = 1;
  5822. this.transparent = false;
  5823. this.blendSrc = SrcAlphaFactor;
  5824. this.blendDst = OneMinusSrcAlphaFactor;
  5825. this.blendEquation = AddEquation;
  5826. this.blendSrcAlpha = null;
  5827. this.blendDstAlpha = null;
  5828. this.blendEquationAlpha = null;
  5829. this.depthFunc = LessEqualDepth;
  5830. this.depthTest = true;
  5831. this.depthWrite = true;
  5832. this.stencilWriteMask = 0xff;
  5833. this.stencilFunc = AlwaysStencilFunc;
  5834. this.stencilRef = 0;
  5835. this.stencilFuncMask = 0xff;
  5836. this.stencilFail = KeepStencilOp;
  5837. this.stencilZFail = KeepStencilOp;
  5838. this.stencilZPass = KeepStencilOp;
  5839. this.stencilWrite = false;
  5840. this.clippingPlanes = null;
  5841. this.clipIntersection = false;
  5842. this.clipShadows = false;
  5843. this.shadowSide = null;
  5844. this.colorWrite = true;
  5845. this.precision = null; // override the renderer's default precision for this material
  5846. this.polygonOffset = false;
  5847. this.polygonOffsetFactor = 0;
  5848. this.polygonOffsetUnits = 0;
  5849. this.dithering = false;
  5850. this.alphaTest = 0;
  5851. this.premultipliedAlpha = false;
  5852. this.visible = true;
  5853. this.toneMapped = true;
  5854. this.userData = {};
  5855. this.version = 0;
  5856. }
  5857. Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5858. constructor: Material,
  5859. isMaterial: true,
  5860. onBeforeCompile: function onBeforeCompile()
  5861. /* shaderobject, renderer */
  5862. {},
  5863. customProgramCacheKey: function customProgramCacheKey() {
  5864. return this.onBeforeCompile.toString();
  5865. },
  5866. setValues: function setValues(values) {
  5867. if (values === undefined) return;
  5868. for (var key in values) {
  5869. var newValue = values[key];
  5870. if (newValue === undefined) {
  5871. console.warn('THREE.Material: \'' + key + '\' parameter is undefined.');
  5872. continue;
  5873. } // for backward compatability if shading is set in the constructor
  5874. if (key === 'shading') {
  5875. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  5876. this.flatShading = newValue === FlatShading ? true : false;
  5877. continue;
  5878. }
  5879. var currentValue = this[key];
  5880. if (currentValue === undefined) {
  5881. console.warn('THREE.' + this.type + ': \'' + key + '\' is not a property of this material.');
  5882. continue;
  5883. }
  5884. if (currentValue && currentValue.isColor) {
  5885. currentValue.set(newValue);
  5886. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  5887. currentValue.copy(newValue);
  5888. } else {
  5889. this[key] = newValue;
  5890. }
  5891. }
  5892. },
  5893. toJSON: function toJSON(meta) {
  5894. var isRoot = meta === undefined || typeof meta === 'string';
  5895. if (isRoot) {
  5896. meta = {
  5897. textures: {},
  5898. images: {}
  5899. };
  5900. }
  5901. var data = {
  5902. metadata: {
  5903. version: 4.5,
  5904. type: 'Material',
  5905. generator: 'Material.toJSON'
  5906. }
  5907. }; // standard Material serialization
  5908. data.uuid = this.uuid;
  5909. data.type = this.type;
  5910. if (this.name !== '') data.name = this.name;
  5911. if (this.color && this.color.isColor) data.color = this.color.getHex();
  5912. if (this.roughness !== undefined) data.roughness = this.roughness;
  5913. if (this.metalness !== undefined) data.metalness = this.metalness;
  5914. if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
  5915. if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
  5916. if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
  5917. if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
  5918. if (this.shininess !== undefined) data.shininess = this.shininess;
  5919. if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
  5920. if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
  5921. if (this.clearcoatMap && this.clearcoatMap.isTexture) {
  5922. data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
  5923. }
  5924. if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
  5925. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
  5926. }
  5927. if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
  5928. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
  5929. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5930. }
  5931. if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
  5932. if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
  5933. if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
  5934. if (this.lightMap && this.lightMap.isTexture) {
  5935. data.lightMap = this.lightMap.toJSON(meta).uuid;
  5936. data.lightMapIntensity = this.lightMapIntensity;
  5937. }
  5938. if (this.aoMap && this.aoMap.isTexture) {
  5939. data.aoMap = this.aoMap.toJSON(meta).uuid;
  5940. data.aoMapIntensity = this.aoMapIntensity;
  5941. }
  5942. if (this.bumpMap && this.bumpMap.isTexture) {
  5943. data.bumpMap = this.bumpMap.toJSON(meta).uuid;
  5944. data.bumpScale = this.bumpScale;
  5945. }
  5946. if (this.normalMap && this.normalMap.isTexture) {
  5947. data.normalMap = this.normalMap.toJSON(meta).uuid;
  5948. data.normalMapType = this.normalMapType;
  5949. data.normalScale = this.normalScale.toArray();
  5950. }
  5951. if (this.displacementMap && this.displacementMap.isTexture) {
  5952. data.displacementMap = this.displacementMap.toJSON(meta).uuid;
  5953. data.displacementScale = this.displacementScale;
  5954. data.displacementBias = this.displacementBias;
  5955. }
  5956. if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
  5957. if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
  5958. if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
  5959. if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
  5960. if (this.envMap && this.envMap.isTexture) {
  5961. data.envMap = this.envMap.toJSON(meta).uuid;
  5962. data.reflectivity = this.reflectivity; // Scale behind envMap
  5963. data.refractionRatio = this.refractionRatio;
  5964. if (this.combine !== undefined) data.combine = this.combine;
  5965. if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
  5966. }
  5967. if (this.gradientMap && this.gradientMap.isTexture) {
  5968. data.gradientMap = this.gradientMap.toJSON(meta).uuid;
  5969. }
  5970. if (this.size !== undefined) data.size = this.size;
  5971. if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
  5972. if (this.blending !== NormalBlending) data.blending = this.blending;
  5973. if (this.side !== FrontSide) data.side = this.side;
  5974. if (this.vertexColors) data.vertexColors = true;
  5975. if (this.opacity < 1) data.opacity = this.opacity;
  5976. if (this.transparent === true) data.transparent = this.transparent;
  5977. data.depthFunc = this.depthFunc;
  5978. data.depthTest = this.depthTest;
  5979. data.depthWrite = this.depthWrite;
  5980. data.stencilWrite = this.stencilWrite;
  5981. data.stencilWriteMask = this.stencilWriteMask;
  5982. data.stencilFunc = this.stencilFunc;
  5983. data.stencilRef = this.stencilRef;
  5984. data.stencilFuncMask = this.stencilFuncMask;
  5985. data.stencilFail = this.stencilFail;
  5986. data.stencilZFail = this.stencilZFail;
  5987. data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
  5988. if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
  5989. if (this.polygonOffset === true) data.polygonOffset = true;
  5990. if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5991. if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5992. if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
  5993. if (this.dashSize !== undefined) data.dashSize = this.dashSize;
  5994. if (this.gapSize !== undefined) data.gapSize = this.gapSize;
  5995. if (this.scale !== undefined) data.scale = this.scale;
  5996. if (this.dithering === true) data.dithering = true;
  5997. if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
  5998. if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
  5999. if (this.wireframe === true) data.wireframe = this.wireframe;
  6000. if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
  6001. if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
  6002. if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
  6003. if (this.morphTargets === true) data.morphTargets = true;
  6004. if (this.morphNormals === true) data.morphNormals = true;
  6005. if (this.skinning === true) data.skinning = true;
  6006. if (this.flatShading === true) data.flatShading = this.flatShading;
  6007. if (this.visible === false) data.visible = false;
  6008. if (this.toneMapped === false) data.toneMapped = false;
  6009. if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
  6010. function extractFromCache(cache) {
  6011. var values = [];
  6012. for (var key in cache) {
  6013. var _data = cache[key];
  6014. delete _data.metadata;
  6015. values.push(_data);
  6016. }
  6017. return values;
  6018. }
  6019. if (isRoot) {
  6020. var textures = extractFromCache(meta.textures);
  6021. var images = extractFromCache(meta.images);
  6022. if (textures.length > 0) data.textures = textures;
  6023. if (images.length > 0) data.images = images;
  6024. }
  6025. return data;
  6026. },
  6027. clone: function clone() {
  6028. return new this.constructor().copy(this);
  6029. },
  6030. copy: function copy(source) {
  6031. this.name = source.name;
  6032. this.fog = source.fog;
  6033. this.blending = source.blending;
  6034. this.side = source.side;
  6035. this.vertexColors = source.vertexColors;
  6036. this.opacity = source.opacity;
  6037. this.transparent = source.transparent;
  6038. this.blendSrc = source.blendSrc;
  6039. this.blendDst = source.blendDst;
  6040. this.blendEquation = source.blendEquation;
  6041. this.blendSrcAlpha = source.blendSrcAlpha;
  6042. this.blendDstAlpha = source.blendDstAlpha;
  6043. this.blendEquationAlpha = source.blendEquationAlpha;
  6044. this.depthFunc = source.depthFunc;
  6045. this.depthTest = source.depthTest;
  6046. this.depthWrite = source.depthWrite;
  6047. this.stencilWriteMask = source.stencilWriteMask;
  6048. this.stencilFunc = source.stencilFunc;
  6049. this.stencilRef = source.stencilRef;
  6050. this.stencilFuncMask = source.stencilFuncMask;
  6051. this.stencilFail = source.stencilFail;
  6052. this.stencilZFail = source.stencilZFail;
  6053. this.stencilZPass = source.stencilZPass;
  6054. this.stencilWrite = source.stencilWrite;
  6055. var srcPlanes = source.clippingPlanes;
  6056. var dstPlanes = null;
  6057. if (srcPlanes !== null) {
  6058. var n = srcPlanes.length;
  6059. dstPlanes = new Array(n);
  6060. for (var i = 0; i !== n; ++i) {
  6061. dstPlanes[i] = srcPlanes[i].clone();
  6062. }
  6063. }
  6064. this.clippingPlanes = dstPlanes;
  6065. this.clipIntersection = source.clipIntersection;
  6066. this.clipShadows = source.clipShadows;
  6067. this.shadowSide = source.shadowSide;
  6068. this.colorWrite = source.colorWrite;
  6069. this.precision = source.precision;
  6070. this.polygonOffset = source.polygonOffset;
  6071. this.polygonOffsetFactor = source.polygonOffsetFactor;
  6072. this.polygonOffsetUnits = source.polygonOffsetUnits;
  6073. this.dithering = source.dithering;
  6074. this.alphaTest = source.alphaTest;
  6075. this.premultipliedAlpha = source.premultipliedAlpha;
  6076. this.visible = source.visible;
  6077. this.toneMapped = source.toneMapped;
  6078. this.userData = JSON.parse(JSON.stringify(source.userData));
  6079. return this;
  6080. },
  6081. dispose: function dispose() {
  6082. this.dispatchEvent({
  6083. type: 'dispose'
  6084. });
  6085. }
  6086. });
  6087. Object.defineProperty(Material.prototype, 'needsUpdate', {
  6088. set: function set(value) {
  6089. if (value === true) this.version++;
  6090. }
  6091. });
  6092. var _colorKeywords = {
  6093. 'aliceblue': 0xF0F8FF,
  6094. 'antiquewhite': 0xFAEBD7,
  6095. 'aqua': 0x00FFFF,
  6096. 'aquamarine': 0x7FFFD4,
  6097. 'azure': 0xF0FFFF,
  6098. 'beige': 0xF5F5DC,
  6099. 'bisque': 0xFFE4C4,
  6100. 'black': 0x000000,
  6101. 'blanchedalmond': 0xFFEBCD,
  6102. 'blue': 0x0000FF,
  6103. 'blueviolet': 0x8A2BE2,
  6104. 'brown': 0xA52A2A,
  6105. 'burlywood': 0xDEB887,
  6106. 'cadetblue': 0x5F9EA0,
  6107. 'chartreuse': 0x7FFF00,
  6108. 'chocolate': 0xD2691E,
  6109. 'coral': 0xFF7F50,
  6110. 'cornflowerblue': 0x6495ED,
  6111. 'cornsilk': 0xFFF8DC,
  6112. 'crimson': 0xDC143C,
  6113. 'cyan': 0x00FFFF,
  6114. 'darkblue': 0x00008B,
  6115. 'darkcyan': 0x008B8B,
  6116. 'darkgoldenrod': 0xB8860B,
  6117. 'darkgray': 0xA9A9A9,
  6118. 'darkgreen': 0x006400,
  6119. 'darkgrey': 0xA9A9A9,
  6120. 'darkkhaki': 0xBDB76B,
  6121. 'darkmagenta': 0x8B008B,
  6122. 'darkolivegreen': 0x556B2F,
  6123. 'darkorange': 0xFF8C00,
  6124. 'darkorchid': 0x9932CC,
  6125. 'darkred': 0x8B0000,
  6126. 'darksalmon': 0xE9967A,
  6127. 'darkseagreen': 0x8FBC8F,
  6128. 'darkslateblue': 0x483D8B,
  6129. 'darkslategray': 0x2F4F4F,
  6130. 'darkslategrey': 0x2F4F4F,
  6131. 'darkturquoise': 0x00CED1,
  6132. 'darkviolet': 0x9400D3,
  6133. 'deeppink': 0xFF1493,
  6134. 'deepskyblue': 0x00BFFF,
  6135. 'dimgray': 0x696969,
  6136. 'dimgrey': 0x696969,
  6137. 'dodgerblue': 0x1E90FF,
  6138. 'firebrick': 0xB22222,
  6139. 'floralwhite': 0xFFFAF0,
  6140. 'forestgreen': 0x228B22,
  6141. 'fuchsia': 0xFF00FF,
  6142. 'gainsboro': 0xDCDCDC,
  6143. 'ghostwhite': 0xF8F8FF,
  6144. 'gold': 0xFFD700,
  6145. 'goldenrod': 0xDAA520,
  6146. 'gray': 0x808080,
  6147. 'green': 0x008000,
  6148. 'greenyellow': 0xADFF2F,
  6149. 'grey': 0x808080,
  6150. 'honeydew': 0xF0FFF0,
  6151. 'hotpink': 0xFF69B4,
  6152. 'indianred': 0xCD5C5C,
  6153. 'indigo': 0x4B0082,
  6154. 'ivory': 0xFFFFF0,
  6155. 'khaki': 0xF0E68C,
  6156. 'lavender': 0xE6E6FA,
  6157. 'lavenderblush': 0xFFF0F5,
  6158. 'lawngreen': 0x7CFC00,
  6159. 'lemonchiffon': 0xFFFACD,
  6160. 'lightblue': 0xADD8E6,
  6161. 'lightcoral': 0xF08080,
  6162. 'lightcyan': 0xE0FFFF,
  6163. 'lightgoldenrodyellow': 0xFAFAD2,
  6164. 'lightgray': 0xD3D3D3,
  6165. 'lightgreen': 0x90EE90,
  6166. 'lightgrey': 0xD3D3D3,
  6167. 'lightpink': 0xFFB6C1,
  6168. 'lightsalmon': 0xFFA07A,
  6169. 'lightseagreen': 0x20B2AA,
  6170. 'lightskyblue': 0x87CEFA,
  6171. 'lightslategray': 0x778899,
  6172. 'lightslategrey': 0x778899,
  6173. 'lightsteelblue': 0xB0C4DE,
  6174. 'lightyellow': 0xFFFFE0,
  6175. 'lime': 0x00FF00,
  6176. 'limegreen': 0x32CD32,
  6177. 'linen': 0xFAF0E6,
  6178. 'magenta': 0xFF00FF,
  6179. 'maroon': 0x800000,
  6180. 'mediumaquamarine': 0x66CDAA,
  6181. 'mediumblue': 0x0000CD,
  6182. 'mediumorchid': 0xBA55D3,
  6183. 'mediumpurple': 0x9370DB,
  6184. 'mediumseagreen': 0x3CB371,
  6185. 'mediumslateblue': 0x7B68EE,
  6186. 'mediumspringgreen': 0x00FA9A,
  6187. 'mediumturquoise': 0x48D1CC,
  6188. 'mediumvioletred': 0xC71585,
  6189. 'midnightblue': 0x191970,
  6190. 'mintcream': 0xF5FFFA,
  6191. 'mistyrose': 0xFFE4E1,
  6192. 'moccasin': 0xFFE4B5,
  6193. 'navajowhite': 0xFFDEAD,
  6194. 'navy': 0x000080,
  6195. 'oldlace': 0xFDF5E6,
  6196. 'olive': 0x808000,
  6197. 'olivedrab': 0x6B8E23,
  6198. 'orange': 0xFFA500,
  6199. 'orangered': 0xFF4500,
  6200. 'orchid': 0xDA70D6,
  6201. 'palegoldenrod': 0xEEE8AA,
  6202. 'palegreen': 0x98FB98,
  6203. 'paleturquoise': 0xAFEEEE,
  6204. 'palevioletred': 0xDB7093,
  6205. 'papayawhip': 0xFFEFD5,
  6206. 'peachpuff': 0xFFDAB9,
  6207. 'peru': 0xCD853F,
  6208. 'pink': 0xFFC0CB,
  6209. 'plum': 0xDDA0DD,
  6210. 'powderblue': 0xB0E0E6,
  6211. 'purple': 0x800080,
  6212. 'rebeccapurple': 0x663399,
  6213. 'red': 0xFF0000,
  6214. 'rosybrown': 0xBC8F8F,
  6215. 'royalblue': 0x4169E1,
  6216. 'saddlebrown': 0x8B4513,
  6217. 'salmon': 0xFA8072,
  6218. 'sandybrown': 0xF4A460,
  6219. 'seagreen': 0x2E8B57,
  6220. 'seashell': 0xFFF5EE,
  6221. 'sienna': 0xA0522D,
  6222. 'silver': 0xC0C0C0,
  6223. 'skyblue': 0x87CEEB,
  6224. 'slateblue': 0x6A5ACD,
  6225. 'slategray': 0x708090,
  6226. 'slategrey': 0x708090,
  6227. 'snow': 0xFFFAFA,
  6228. 'springgreen': 0x00FF7F,
  6229. 'steelblue': 0x4682B4,
  6230. 'tan': 0xD2B48C,
  6231. 'teal': 0x008080,
  6232. 'thistle': 0xD8BFD8,
  6233. 'tomato': 0xFF6347,
  6234. 'turquoise': 0x40E0D0,
  6235. 'violet': 0xEE82EE,
  6236. 'wheat': 0xF5DEB3,
  6237. 'white': 0xFFFFFF,
  6238. 'whitesmoke': 0xF5F5F5,
  6239. 'yellow': 0xFFFF00,
  6240. 'yellowgreen': 0x9ACD32
  6241. };
  6242. var _hslA = {
  6243. h: 0,
  6244. s: 0,
  6245. l: 0
  6246. };
  6247. var _hslB = {
  6248. h: 0,
  6249. s: 0,
  6250. l: 0
  6251. };
  6252. function hue2rgb(p, q, t) {
  6253. if (t < 0) t += 1;
  6254. if (t > 1) t -= 1;
  6255. if (t < 1 / 6) return p + (q - p) * 6 * t;
  6256. if (t < 1 / 2) return q;
  6257. if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  6258. return p;
  6259. }
  6260. function SRGBToLinear(c) {
  6261. return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
  6262. }
  6263. function LinearToSRGB(c) {
  6264. return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
  6265. }
  6266. var Color = /*#__PURE__*/function () {
  6267. function Color(r, g, b) {
  6268. Object.defineProperty(this, 'isColor', {
  6269. value: true
  6270. });
  6271. if (g === undefined && b === undefined) {
  6272. // r is THREE.Color, hex or string
  6273. return this.set(r);
  6274. }
  6275. return this.setRGB(r, g, b);
  6276. }
  6277. var _proto = Color.prototype;
  6278. _proto.set = function set(value) {
  6279. if (value && value.isColor) {
  6280. this.copy(value);
  6281. } else if (typeof value === 'number') {
  6282. this.setHex(value);
  6283. } else if (typeof value === 'string') {
  6284. this.setStyle(value);
  6285. }
  6286. return this;
  6287. };
  6288. _proto.setScalar = function setScalar(scalar) {
  6289. this.r = scalar;
  6290. this.g = scalar;
  6291. this.b = scalar;
  6292. return this;
  6293. };
  6294. _proto.setHex = function setHex(hex) {
  6295. hex = Math.floor(hex);
  6296. this.r = (hex >> 16 & 255) / 255;
  6297. this.g = (hex >> 8 & 255) / 255;
  6298. this.b = (hex & 255) / 255;
  6299. return this;
  6300. };
  6301. _proto.setRGB = function setRGB(r, g, b) {
  6302. this.r = r;
  6303. this.g = g;
  6304. this.b = b;
  6305. return this;
  6306. };
  6307. _proto.setHSL = function setHSL(h, s, l) {
  6308. // h,s,l ranges are in 0.0 - 1.0
  6309. h = MathUtils.euclideanModulo(h, 1);
  6310. s = MathUtils.clamp(s, 0, 1);
  6311. l = MathUtils.clamp(l, 0, 1);
  6312. if (s === 0) {
  6313. this.r = this.g = this.b = l;
  6314. } else {
  6315. var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  6316. var q = 2 * l - p;
  6317. this.r = hue2rgb(q, p, h + 1 / 3);
  6318. this.g = hue2rgb(q, p, h);
  6319. this.b = hue2rgb(q, p, h - 1 / 3);
  6320. }
  6321. return this;
  6322. };
  6323. _proto.setStyle = function setStyle(style) {
  6324. function handleAlpha(string) {
  6325. if (string === undefined) return;
  6326. if (parseFloat(string) < 1) {
  6327. console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
  6328. }
  6329. }
  6330. var m;
  6331. if (m = /^((?:rgb|hsl)a?)\(([^\)]*)\)/.exec(style)) {
  6332. // rgb / hsl
  6333. var color;
  6334. var name = m[1];
  6335. var components = m[2];
  6336. switch (name) {
  6337. case 'rgb':
  6338. case 'rgba':
  6339. if (color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6340. // rgb(255,0,0) rgba(255,0,0,0.5)
  6341. this.r = Math.min(255, parseInt(color[1], 10)) / 255;
  6342. this.g = Math.min(255, parseInt(color[2], 10)) / 255;
  6343. this.b = Math.min(255, parseInt(color[3], 10)) / 255;
  6344. handleAlpha(color[4]);
  6345. return this;
  6346. }
  6347. if (color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6348. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  6349. this.r = Math.min(100, parseInt(color[1], 10)) / 100;
  6350. this.g = Math.min(100, parseInt(color[2], 10)) / 100;
  6351. this.b = Math.min(100, parseInt(color[3], 10)) / 100;
  6352. handleAlpha(color[4]);
  6353. return this;
  6354. }
  6355. break;
  6356. case 'hsl':
  6357. case 'hsla':
  6358. if (color = /^\s*(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6359. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  6360. var h = parseFloat(color[1]) / 360;
  6361. var s = parseInt(color[2], 10) / 100;
  6362. var l = parseInt(color[3], 10) / 100;
  6363. handleAlpha(color[4]);
  6364. return this.setHSL(h, s, l);
  6365. }
  6366. break;
  6367. }
  6368. } else if (m = /^\#([A-Fa-f\d]+)$/.exec(style)) {
  6369. // hex color
  6370. var hex = m[1];
  6371. var size = hex.length;
  6372. if (size === 3) {
  6373. // #ff0
  6374. this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
  6375. this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
  6376. this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
  6377. return this;
  6378. } else if (size === 6) {
  6379. // #ff0000
  6380. this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
  6381. this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
  6382. this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
  6383. return this;
  6384. }
  6385. }
  6386. if (style && style.length > 0) {
  6387. return this.setColorName(style);
  6388. }
  6389. return this;
  6390. };
  6391. _proto.setColorName = function setColorName(style) {
  6392. // color keywords
  6393. var hex = _colorKeywords[style];
  6394. if (hex !== undefined) {
  6395. // red
  6396. this.setHex(hex);
  6397. } else {
  6398. // unknown color
  6399. console.warn('THREE.Color: Unknown color ' + style);
  6400. }
  6401. return this;
  6402. };
  6403. _proto.clone = function clone() {
  6404. return new this.constructor(this.r, this.g, this.b);
  6405. };
  6406. _proto.copy = function copy(color) {
  6407. this.r = color.r;
  6408. this.g = color.g;
  6409. this.b = color.b;
  6410. return this;
  6411. };
  6412. _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
  6413. if (gammaFactor === void 0) {
  6414. gammaFactor = 2.0;
  6415. }
  6416. this.r = Math.pow(color.r, gammaFactor);
  6417. this.g = Math.pow(color.g, gammaFactor);
  6418. this.b = Math.pow(color.b, gammaFactor);
  6419. return this;
  6420. };
  6421. _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
  6422. if (gammaFactor === void 0) {
  6423. gammaFactor = 2.0;
  6424. }
  6425. var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
  6426. this.r = Math.pow(color.r, safeInverse);
  6427. this.g = Math.pow(color.g, safeInverse);
  6428. this.b = Math.pow(color.b, safeInverse);
  6429. return this;
  6430. };
  6431. _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
  6432. this.copyGammaToLinear(this, gammaFactor);
  6433. return this;
  6434. };
  6435. _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
  6436. this.copyLinearToGamma(this, gammaFactor);
  6437. return this;
  6438. };
  6439. _proto.copySRGBToLinear = function copySRGBToLinear(color) {
  6440. this.r = SRGBToLinear(color.r);
  6441. this.g = SRGBToLinear(color.g);
  6442. this.b = SRGBToLinear(color.b);
  6443. return this;
  6444. };
  6445. _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
  6446. this.r = LinearToSRGB(color.r);
  6447. this.g = LinearToSRGB(color.g);
  6448. this.b = LinearToSRGB(color.b);
  6449. return this;
  6450. };
  6451. _proto.convertSRGBToLinear = function convertSRGBToLinear() {
  6452. this.copySRGBToLinear(this);
  6453. return this;
  6454. };
  6455. _proto.convertLinearToSRGB = function convertLinearToSRGB() {
  6456. this.copyLinearToSRGB(this);
  6457. return this;
  6458. };
  6459. _proto.getHex = function getHex() {
  6460. return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
  6461. };
  6462. _proto.getHexString = function getHexString() {
  6463. return ('000000' + this.getHex().toString(16)).slice(-6);
  6464. };
  6465. _proto.getHSL = function getHSL(target) {
  6466. // h,s,l ranges are in 0.0 - 1.0
  6467. if (target === undefined) {
  6468. console.warn('THREE.Color: .getHSL() target is now required');
  6469. target = {
  6470. h: 0,
  6471. s: 0,
  6472. l: 0
  6473. };
  6474. }
  6475. var r = this.r,
  6476. g = this.g,
  6477. b = this.b;
  6478. var max = Math.max(r, g, b);
  6479. var min = Math.min(r, g, b);
  6480. var hue, saturation;
  6481. var lightness = (min + max) / 2.0;
  6482. if (min === max) {
  6483. hue = 0;
  6484. saturation = 0;
  6485. } else {
  6486. var delta = max - min;
  6487. saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
  6488. switch (max) {
  6489. case r:
  6490. hue = (g - b) / delta + (g < b ? 6 : 0);
  6491. break;
  6492. case g:
  6493. hue = (b - r) / delta + 2;
  6494. break;
  6495. case b:
  6496. hue = (r - g) / delta + 4;
  6497. break;
  6498. }
  6499. hue /= 6;
  6500. }
  6501. target.h = hue;
  6502. target.s = saturation;
  6503. target.l = lightness;
  6504. return target;
  6505. };
  6506. _proto.getStyle = function getStyle() {
  6507. return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
  6508. };
  6509. _proto.offsetHSL = function offsetHSL(h, s, l) {
  6510. this.getHSL(_hslA);
  6511. _hslA.h += h;
  6512. _hslA.s += s;
  6513. _hslA.l += l;
  6514. this.setHSL(_hslA.h, _hslA.s, _hslA.l);
  6515. return this;
  6516. };
  6517. _proto.add = function add(color) {
  6518. this.r += color.r;
  6519. this.g += color.g;
  6520. this.b += color.b;
  6521. return this;
  6522. };
  6523. _proto.addColors = function addColors(color1, color2) {
  6524. this.r = color1.r + color2.r;
  6525. this.g = color1.g + color2.g;
  6526. this.b = color1.b + color2.b;
  6527. return this;
  6528. };
  6529. _proto.addScalar = function addScalar(s) {
  6530. this.r += s;
  6531. this.g += s;
  6532. this.b += s;
  6533. return this;
  6534. };
  6535. _proto.sub = function sub(color) {
  6536. this.r = Math.max(0, this.r - color.r);
  6537. this.g = Math.max(0, this.g - color.g);
  6538. this.b = Math.max(0, this.b - color.b);
  6539. return this;
  6540. };
  6541. _proto.multiply = function multiply(color) {
  6542. this.r *= color.r;
  6543. this.g *= color.g;
  6544. this.b *= color.b;
  6545. return this;
  6546. };
  6547. _proto.multiplyScalar = function multiplyScalar(s) {
  6548. this.r *= s;
  6549. this.g *= s;
  6550. this.b *= s;
  6551. return this;
  6552. };
  6553. _proto.lerp = function lerp(color, alpha) {
  6554. this.r += (color.r - this.r) * alpha;
  6555. this.g += (color.g - this.g) * alpha;
  6556. this.b += (color.b - this.b) * alpha;
  6557. return this;
  6558. };
  6559. _proto.lerpColors = function lerpColors(color1, color2, alpha) {
  6560. this.r = color1.r + (color2.r - color1.r) * alpha;
  6561. this.g = color1.g + (color2.g - color1.g) * alpha;
  6562. this.b = color1.b + (color2.b - color1.b) * alpha;
  6563. return this;
  6564. };
  6565. _proto.lerpHSL = function lerpHSL(color, alpha) {
  6566. this.getHSL(_hslA);
  6567. color.getHSL(_hslB);
  6568. var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
  6569. var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
  6570. var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
  6571. this.setHSL(h, s, l);
  6572. return this;
  6573. };
  6574. _proto.equals = function equals(c) {
  6575. return c.r === this.r && c.g === this.g && c.b === this.b;
  6576. };
  6577. _proto.fromArray = function fromArray(array, offset) {
  6578. if (offset === void 0) {
  6579. offset = 0;
  6580. }
  6581. this.r = array[offset];
  6582. this.g = array[offset + 1];
  6583. this.b = array[offset + 2];
  6584. return this;
  6585. };
  6586. _proto.toArray = function toArray(array, offset) {
  6587. if (array === void 0) {
  6588. array = [];
  6589. }
  6590. if (offset === void 0) {
  6591. offset = 0;
  6592. }
  6593. array[offset] = this.r;
  6594. array[offset + 1] = this.g;
  6595. array[offset + 2] = this.b;
  6596. return array;
  6597. };
  6598. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  6599. this.r = attribute.getX(index);
  6600. this.g = attribute.getY(index);
  6601. this.b = attribute.getZ(index);
  6602. if (attribute.normalized === true) {
  6603. // assuming Uint8Array
  6604. this.r /= 255;
  6605. this.g /= 255;
  6606. this.b /= 255;
  6607. }
  6608. return this;
  6609. };
  6610. _proto.toJSON = function toJSON() {
  6611. return this.getHex();
  6612. };
  6613. return Color;
  6614. }();
  6615. Color.NAMES = _colorKeywords;
  6616. Color.prototype.r = 1;
  6617. Color.prototype.g = 1;
  6618. Color.prototype.b = 1;
  6619. /**
  6620. * parameters = {
  6621. * color: <hex>,
  6622. * opacity: <float>,
  6623. * map: new THREE.Texture( <Image> ),
  6624. *
  6625. * lightMap: new THREE.Texture( <Image> ),
  6626. * lightMapIntensity: <float>
  6627. *
  6628. * aoMap: new THREE.Texture( <Image> ),
  6629. * aoMapIntensity: <float>
  6630. *
  6631. * specularMap: new THREE.Texture( <Image> ),
  6632. *
  6633. * alphaMap: new THREE.Texture( <Image> ),
  6634. *
  6635. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  6636. * combine: THREE.Multiply,
  6637. * reflectivity: <float>,
  6638. * refractionRatio: <float>,
  6639. *
  6640. * depthTest: <bool>,
  6641. * depthWrite: <bool>,
  6642. *
  6643. * wireframe: <boolean>,
  6644. * wireframeLinewidth: <float>,
  6645. *
  6646. * skinning: <bool>,
  6647. * morphTargets: <bool>
  6648. * }
  6649. */
  6650. function MeshBasicMaterial(parameters) {
  6651. Material.call(this);
  6652. this.type = 'MeshBasicMaterial';
  6653. this.color = new Color(0xffffff); // emissive
  6654. this.map = null;
  6655. this.lightMap = null;
  6656. this.lightMapIntensity = 1.0;
  6657. this.aoMap = null;
  6658. this.aoMapIntensity = 1.0;
  6659. this.specularMap = null;
  6660. this.alphaMap = null;
  6661. this.envMap = null;
  6662. this.combine = MultiplyOperation;
  6663. this.reflectivity = 1;
  6664. this.refractionRatio = 0.98;
  6665. this.wireframe = false;
  6666. this.wireframeLinewidth = 1;
  6667. this.wireframeLinecap = 'round';
  6668. this.wireframeLinejoin = 'round';
  6669. this.skinning = false;
  6670. this.morphTargets = false;
  6671. this.setValues(parameters);
  6672. }
  6673. MeshBasicMaterial.prototype = Object.create(Material.prototype);
  6674. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  6675. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  6676. MeshBasicMaterial.prototype.copy = function (source) {
  6677. Material.prototype.copy.call(this, source);
  6678. this.color.copy(source.color);
  6679. this.map = source.map;
  6680. this.lightMap = source.lightMap;
  6681. this.lightMapIntensity = source.lightMapIntensity;
  6682. this.aoMap = source.aoMap;
  6683. this.aoMapIntensity = source.aoMapIntensity;
  6684. this.specularMap = source.specularMap;
  6685. this.alphaMap = source.alphaMap;
  6686. this.envMap = source.envMap;
  6687. this.combine = source.combine;
  6688. this.reflectivity = source.reflectivity;
  6689. this.refractionRatio = source.refractionRatio;
  6690. this.wireframe = source.wireframe;
  6691. this.wireframeLinewidth = source.wireframeLinewidth;
  6692. this.wireframeLinecap = source.wireframeLinecap;
  6693. this.wireframeLinejoin = source.wireframeLinejoin;
  6694. this.skinning = source.skinning;
  6695. this.morphTargets = source.morphTargets;
  6696. return this;
  6697. };
  6698. var _vector$3 = new Vector3();
  6699. var _vector2$1 = new Vector2();
  6700. function BufferAttribute(array, itemSize, normalized) {
  6701. if (Array.isArray(array)) {
  6702. throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
  6703. }
  6704. this.name = '';
  6705. this.array = array;
  6706. this.itemSize = itemSize;
  6707. this.count = array !== undefined ? array.length / itemSize : 0;
  6708. this.normalized = normalized === true;
  6709. this.usage = StaticDrawUsage;
  6710. this.updateRange = {
  6711. offset: 0,
  6712. count: -1
  6713. };
  6714. this.version = 0;
  6715. }
  6716. Object.defineProperty(BufferAttribute.prototype, 'needsUpdate', {
  6717. set: function set(value) {
  6718. if (value === true) this.version++;
  6719. }
  6720. });
  6721. Object.assign(BufferAttribute.prototype, {
  6722. isBufferAttribute: true,
  6723. onUploadCallback: function onUploadCallback() {},
  6724. setUsage: function setUsage(value) {
  6725. this.usage = value;
  6726. return this;
  6727. },
  6728. copy: function copy(source) {
  6729. this.name = source.name;
  6730. this.array = new source.array.constructor(source.array);
  6731. this.itemSize = source.itemSize;
  6732. this.count = source.count;
  6733. this.normalized = source.normalized;
  6734. this.usage = source.usage;
  6735. return this;
  6736. },
  6737. copyAt: function copyAt(index1, attribute, index2) {
  6738. index1 *= this.itemSize;
  6739. index2 *= attribute.itemSize;
  6740. for (var i = 0, l = this.itemSize; i < l; i++) {
  6741. this.array[index1 + i] = attribute.array[index2 + i];
  6742. }
  6743. return this;
  6744. },
  6745. copyArray: function copyArray(array) {
  6746. this.array.set(array);
  6747. return this;
  6748. },
  6749. copyColorsArray: function copyColorsArray(colors) {
  6750. var array = this.array;
  6751. var offset = 0;
  6752. for (var i = 0, l = colors.length; i < l; i++) {
  6753. var color = colors[i];
  6754. if (color === undefined) {
  6755. console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
  6756. color = new Color();
  6757. }
  6758. array[offset++] = color.r;
  6759. array[offset++] = color.g;
  6760. array[offset++] = color.b;
  6761. }
  6762. return this;
  6763. },
  6764. copyVector2sArray: function copyVector2sArray(vectors) {
  6765. var array = this.array;
  6766. var offset = 0;
  6767. for (var i = 0, l = vectors.length; i < l; i++) {
  6768. var vector = vectors[i];
  6769. if (vector === undefined) {
  6770. console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
  6771. vector = new Vector2();
  6772. }
  6773. array[offset++] = vector.x;
  6774. array[offset++] = vector.y;
  6775. }
  6776. return this;
  6777. },
  6778. copyVector3sArray: function copyVector3sArray(vectors) {
  6779. var array = this.array;
  6780. var offset = 0;
  6781. for (var i = 0, l = vectors.length; i < l; i++) {
  6782. var vector = vectors[i];
  6783. if (vector === undefined) {
  6784. console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
  6785. vector = new Vector3();
  6786. }
  6787. array[offset++] = vector.x;
  6788. array[offset++] = vector.y;
  6789. array[offset++] = vector.z;
  6790. }
  6791. return this;
  6792. },
  6793. copyVector4sArray: function copyVector4sArray(vectors) {
  6794. var array = this.array;
  6795. var offset = 0;
  6796. for (var i = 0, l = vectors.length; i < l; i++) {
  6797. var vector = vectors[i];
  6798. if (vector === undefined) {
  6799. console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
  6800. vector = new Vector4();
  6801. }
  6802. array[offset++] = vector.x;
  6803. array[offset++] = vector.y;
  6804. array[offset++] = vector.z;
  6805. array[offset++] = vector.w;
  6806. }
  6807. return this;
  6808. },
  6809. applyMatrix3: function applyMatrix3(m) {
  6810. if (this.itemSize === 2) {
  6811. for (var i = 0, l = this.count; i < l; i++) {
  6812. _vector2$1.fromBufferAttribute(this, i);
  6813. _vector2$1.applyMatrix3(m);
  6814. this.setXY(i, _vector2$1.x, _vector2$1.y);
  6815. }
  6816. } else if (this.itemSize === 3) {
  6817. for (var _i = 0, _l = this.count; _i < _l; _i++) {
  6818. _vector$3.fromBufferAttribute(this, _i);
  6819. _vector$3.applyMatrix3(m);
  6820. this.setXYZ(_i, _vector$3.x, _vector$3.y, _vector$3.z);
  6821. }
  6822. }
  6823. return this;
  6824. },
  6825. applyMatrix4: function applyMatrix4(m) {
  6826. for (var i = 0, l = this.count; i < l; i++) {
  6827. _vector$3.x = this.getX(i);
  6828. _vector$3.y = this.getY(i);
  6829. _vector$3.z = this.getZ(i);
  6830. _vector$3.applyMatrix4(m);
  6831. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6832. }
  6833. return this;
  6834. },
  6835. applyNormalMatrix: function applyNormalMatrix(m) {
  6836. for (var i = 0, l = this.count; i < l; i++) {
  6837. _vector$3.x = this.getX(i);
  6838. _vector$3.y = this.getY(i);
  6839. _vector$3.z = this.getZ(i);
  6840. _vector$3.applyNormalMatrix(m);
  6841. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6842. }
  6843. return this;
  6844. },
  6845. transformDirection: function transformDirection(m) {
  6846. for (var i = 0, l = this.count; i < l; i++) {
  6847. _vector$3.x = this.getX(i);
  6848. _vector$3.y = this.getY(i);
  6849. _vector$3.z = this.getZ(i);
  6850. _vector$3.transformDirection(m);
  6851. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6852. }
  6853. return this;
  6854. },
  6855. set: function set(value, offset) {
  6856. if (offset === void 0) {
  6857. offset = 0;
  6858. }
  6859. this.array.set(value, offset);
  6860. return this;
  6861. },
  6862. getX: function getX(index) {
  6863. return this.array[index * this.itemSize];
  6864. },
  6865. setX: function setX(index, x) {
  6866. this.array[index * this.itemSize] = x;
  6867. return this;
  6868. },
  6869. getY: function getY(index) {
  6870. return this.array[index * this.itemSize + 1];
  6871. },
  6872. setY: function setY(index, y) {
  6873. this.array[index * this.itemSize + 1] = y;
  6874. return this;
  6875. },
  6876. getZ: function getZ(index) {
  6877. return this.array[index * this.itemSize + 2];
  6878. },
  6879. setZ: function setZ(index, z) {
  6880. this.array[index * this.itemSize + 2] = z;
  6881. return this;
  6882. },
  6883. getW: function getW(index) {
  6884. return this.array[index * this.itemSize + 3];
  6885. },
  6886. setW: function setW(index, w) {
  6887. this.array[index * this.itemSize + 3] = w;
  6888. return this;
  6889. },
  6890. setXY: function setXY(index, x, y) {
  6891. index *= this.itemSize;
  6892. this.array[index + 0] = x;
  6893. this.array[index + 1] = y;
  6894. return this;
  6895. },
  6896. setXYZ: function setXYZ(index, x, y, z) {
  6897. index *= this.itemSize;
  6898. this.array[index + 0] = x;
  6899. this.array[index + 1] = y;
  6900. this.array[index + 2] = z;
  6901. return this;
  6902. },
  6903. setXYZW: function setXYZW(index, x, y, z, w) {
  6904. index *= this.itemSize;
  6905. this.array[index + 0] = x;
  6906. this.array[index + 1] = y;
  6907. this.array[index + 2] = z;
  6908. this.array[index + 3] = w;
  6909. return this;
  6910. },
  6911. onUpload: function onUpload(callback) {
  6912. this.onUploadCallback = callback;
  6913. return this;
  6914. },
  6915. clone: function clone() {
  6916. return new this.constructor(this.array, this.itemSize).copy(this);
  6917. },
  6918. toJSON: function toJSON() {
  6919. return {
  6920. itemSize: this.itemSize,
  6921. type: this.array.constructor.name,
  6922. array: Array.prototype.slice.call(this.array),
  6923. normalized: this.normalized
  6924. };
  6925. }
  6926. }); //
  6927. function Int8BufferAttribute(array, itemSize, normalized) {
  6928. BufferAttribute.call(this, new Int8Array(array), itemSize, normalized);
  6929. }
  6930. Int8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6931. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6932. function Uint8BufferAttribute(array, itemSize, normalized) {
  6933. BufferAttribute.call(this, new Uint8Array(array), itemSize, normalized);
  6934. }
  6935. Uint8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6936. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6937. function Uint8ClampedBufferAttribute(array, itemSize, normalized) {
  6938. BufferAttribute.call(this, new Uint8ClampedArray(array), itemSize, normalized);
  6939. }
  6940. Uint8ClampedBufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6941. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6942. function Int16BufferAttribute(array, itemSize, normalized) {
  6943. BufferAttribute.call(this, new Int16Array(array), itemSize, normalized);
  6944. }
  6945. Int16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6946. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6947. function Uint16BufferAttribute(array, itemSize, normalized) {
  6948. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6949. }
  6950. Uint16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6951. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6952. function Int32BufferAttribute(array, itemSize, normalized) {
  6953. BufferAttribute.call(this, new Int32Array(array), itemSize, normalized);
  6954. }
  6955. Int32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6956. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6957. function Uint32BufferAttribute(array, itemSize, normalized) {
  6958. BufferAttribute.call(this, new Uint32Array(array), itemSize, normalized);
  6959. }
  6960. Uint32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6961. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6962. function Float16BufferAttribute(array, itemSize, normalized) {
  6963. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6964. }
  6965. Float16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6966. Float16BufferAttribute.prototype.constructor = Float16BufferAttribute;
  6967. Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
  6968. function Float32BufferAttribute(array, itemSize, normalized) {
  6969. BufferAttribute.call(this, new Float32Array(array), itemSize, normalized);
  6970. }
  6971. Float32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6972. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6973. function Float64BufferAttribute(array, itemSize, normalized) {
  6974. BufferAttribute.call(this, new Float64Array(array), itemSize, normalized);
  6975. }
  6976. Float64BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6977. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; //
  6978. function arrayMax(array) {
  6979. if (array.length === 0) return -Infinity;
  6980. var max = array[0];
  6981. for (var i = 1, l = array.length; i < l; ++i) {
  6982. if (array[i] > max) max = array[i];
  6983. }
  6984. return max;
  6985. }
  6986. var TYPED_ARRAYS = {
  6987. Int8Array: Int8Array,
  6988. Uint8Array: Uint8Array,
  6989. // Workaround for IE11 pre KB2929437. See #11440
  6990. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  6991. Int16Array: Int16Array,
  6992. Uint16Array: Uint16Array,
  6993. Int32Array: Int32Array,
  6994. Uint32Array: Uint32Array,
  6995. Float32Array: Float32Array,
  6996. Float64Array: Float64Array
  6997. };
  6998. function getTypedArray(type, buffer) {
  6999. return new TYPED_ARRAYS[type](buffer);
  7000. }
  7001. var _id = 0;
  7002. var _m1$2 = new Matrix4();
  7003. var _obj = new Object3D();
  7004. var _offset = new Vector3();
  7005. var _box$2 = new Box3();
  7006. var _boxMorphTargets = new Box3();
  7007. var _vector$4 = new Vector3();
  7008. function BufferGeometry() {
  7009. Object.defineProperty(this, 'id', {
  7010. value: _id++
  7011. });
  7012. this.uuid = MathUtils.generateUUID();
  7013. this.name = '';
  7014. this.type = 'BufferGeometry';
  7015. this.index = null;
  7016. this.attributes = {};
  7017. this.morphAttributes = {};
  7018. this.morphTargetsRelative = false;
  7019. this.groups = [];
  7020. this.boundingBox = null;
  7021. this.boundingSphere = null;
  7022. this.drawRange = {
  7023. start: 0,
  7024. count: Infinity
  7025. };
  7026. this.userData = {};
  7027. }
  7028. BufferGeometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  7029. constructor: BufferGeometry,
  7030. isBufferGeometry: true,
  7031. getIndex: function getIndex() {
  7032. return this.index;
  7033. },
  7034. setIndex: function setIndex(index) {
  7035. if (Array.isArray(index)) {
  7036. this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
  7037. } else {
  7038. this.index = index;
  7039. }
  7040. return this;
  7041. },
  7042. getAttribute: function getAttribute(name) {
  7043. return this.attributes[name];
  7044. },
  7045. setAttribute: function setAttribute(name, attribute) {
  7046. this.attributes[name] = attribute;
  7047. return this;
  7048. },
  7049. deleteAttribute: function deleteAttribute(name) {
  7050. delete this.attributes[name];
  7051. return this;
  7052. },
  7053. hasAttribute: function hasAttribute(name) {
  7054. return this.attributes[name] !== undefined;
  7055. },
  7056. addGroup: function addGroup(start, count, materialIndex) {
  7057. if (materialIndex === void 0) {
  7058. materialIndex = 0;
  7059. }
  7060. this.groups.push({
  7061. start: start,
  7062. count: count,
  7063. materialIndex: materialIndex
  7064. });
  7065. },
  7066. clearGroups: function clearGroups() {
  7067. this.groups = [];
  7068. },
  7069. setDrawRange: function setDrawRange(start, count) {
  7070. this.drawRange.start = start;
  7071. this.drawRange.count = count;
  7072. },
  7073. applyMatrix4: function applyMatrix4(matrix) {
  7074. var position = this.attributes.position;
  7075. if (position !== undefined) {
  7076. position.applyMatrix4(matrix);
  7077. position.needsUpdate = true;
  7078. }
  7079. var normal = this.attributes.normal;
  7080. if (normal !== undefined) {
  7081. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  7082. normal.applyNormalMatrix(normalMatrix);
  7083. normal.needsUpdate = true;
  7084. }
  7085. var tangent = this.attributes.tangent;
  7086. if (tangent !== undefined) {
  7087. tangent.transformDirection(matrix);
  7088. tangent.needsUpdate = true;
  7089. }
  7090. if (this.boundingBox !== null) {
  7091. this.computeBoundingBox();
  7092. }
  7093. if (this.boundingSphere !== null) {
  7094. this.computeBoundingSphere();
  7095. }
  7096. return this;
  7097. },
  7098. rotateX: function rotateX(angle) {
  7099. // rotate geometry around world x-axis
  7100. _m1$2.makeRotationX(angle);
  7101. this.applyMatrix4(_m1$2);
  7102. return this;
  7103. },
  7104. rotateY: function rotateY(angle) {
  7105. // rotate geometry around world y-axis
  7106. _m1$2.makeRotationY(angle);
  7107. this.applyMatrix4(_m1$2);
  7108. return this;
  7109. },
  7110. rotateZ: function rotateZ(angle) {
  7111. // rotate geometry around world z-axis
  7112. _m1$2.makeRotationZ(angle);
  7113. this.applyMatrix4(_m1$2);
  7114. return this;
  7115. },
  7116. translate: function translate(x, y, z) {
  7117. // translate geometry
  7118. _m1$2.makeTranslation(x, y, z);
  7119. this.applyMatrix4(_m1$2);
  7120. return this;
  7121. },
  7122. scale: function scale(x, y, z) {
  7123. // scale geometry
  7124. _m1$2.makeScale(x, y, z);
  7125. this.applyMatrix4(_m1$2);
  7126. return this;
  7127. },
  7128. lookAt: function lookAt(vector) {
  7129. _obj.lookAt(vector);
  7130. _obj.updateMatrix();
  7131. this.applyMatrix4(_obj.matrix);
  7132. return this;
  7133. },
  7134. center: function center() {
  7135. this.computeBoundingBox();
  7136. this.boundingBox.getCenter(_offset).negate();
  7137. this.translate(_offset.x, _offset.y, _offset.z);
  7138. return this;
  7139. },
  7140. setFromPoints: function setFromPoints(points) {
  7141. var position = [];
  7142. for (var i = 0, l = points.length; i < l; i++) {
  7143. var point = points[i];
  7144. position.push(point.x, point.y, point.z || 0);
  7145. }
  7146. this.setAttribute('position', new Float32BufferAttribute(position, 3));
  7147. return this;
  7148. },
  7149. computeBoundingBox: function computeBoundingBox() {
  7150. if (this.boundingBox === null) {
  7151. this.boundingBox = new Box3();
  7152. }
  7153. var position = this.attributes.position;
  7154. var morphAttributesPosition = this.morphAttributes.position;
  7155. if (position && position.isGLBufferAttribute) {
  7156. console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this);
  7157. this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
  7158. return;
  7159. }
  7160. if (position !== undefined) {
  7161. this.boundingBox.setFromBufferAttribute(position); // process morph attributes if present
  7162. if (morphAttributesPosition) {
  7163. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  7164. var morphAttribute = morphAttributesPosition[i];
  7165. _box$2.setFromBufferAttribute(morphAttribute);
  7166. if (this.morphTargetsRelative) {
  7167. _vector$4.addVectors(this.boundingBox.min, _box$2.min);
  7168. this.boundingBox.expandByPoint(_vector$4);
  7169. _vector$4.addVectors(this.boundingBox.max, _box$2.max);
  7170. this.boundingBox.expandByPoint(_vector$4);
  7171. } else {
  7172. this.boundingBox.expandByPoint(_box$2.min);
  7173. this.boundingBox.expandByPoint(_box$2.max);
  7174. }
  7175. }
  7176. }
  7177. } else {
  7178. this.boundingBox.makeEmpty();
  7179. }
  7180. if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
  7181. console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
  7182. }
  7183. },
  7184. computeBoundingSphere: function computeBoundingSphere() {
  7185. if (this.boundingSphere === null) {
  7186. this.boundingSphere = new Sphere();
  7187. }
  7188. var position = this.attributes.position;
  7189. var morphAttributesPosition = this.morphAttributes.position;
  7190. if (position && position.isGLBufferAttribute) {
  7191. console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this);
  7192. this.boundingSphere.set(new Vector3(), Infinity);
  7193. return;
  7194. }
  7195. if (position) {
  7196. // first, find the center of the bounding sphere
  7197. var center = this.boundingSphere.center;
  7198. _box$2.setFromBufferAttribute(position); // process morph attributes if present
  7199. if (morphAttributesPosition) {
  7200. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  7201. var morphAttribute = morphAttributesPosition[i];
  7202. _boxMorphTargets.setFromBufferAttribute(morphAttribute);
  7203. if (this.morphTargetsRelative) {
  7204. _vector$4.addVectors(_box$2.min, _boxMorphTargets.min);
  7205. _box$2.expandByPoint(_vector$4);
  7206. _vector$4.addVectors(_box$2.max, _boxMorphTargets.max);
  7207. _box$2.expandByPoint(_vector$4);
  7208. } else {
  7209. _box$2.expandByPoint(_boxMorphTargets.min);
  7210. _box$2.expandByPoint(_boxMorphTargets.max);
  7211. }
  7212. }
  7213. }
  7214. _box$2.getCenter(center); // second, try to find a boundingSphere with a radius smaller than the
  7215. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  7216. var maxRadiusSq = 0;
  7217. for (var _i = 0, _il = position.count; _i < _il; _i++) {
  7218. _vector$4.fromBufferAttribute(position, _i);
  7219. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  7220. } // process morph attributes if present
  7221. if (morphAttributesPosition) {
  7222. for (var _i2 = 0, _il2 = morphAttributesPosition.length; _i2 < _il2; _i2++) {
  7223. var _morphAttribute = morphAttributesPosition[_i2];
  7224. var morphTargetsRelative = this.morphTargetsRelative;
  7225. for (var j = 0, jl = _morphAttribute.count; j < jl; j++) {
  7226. _vector$4.fromBufferAttribute(_morphAttribute, j);
  7227. if (morphTargetsRelative) {
  7228. _offset.fromBufferAttribute(position, j);
  7229. _vector$4.add(_offset);
  7230. }
  7231. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  7232. }
  7233. }
  7234. }
  7235. this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
  7236. if (isNaN(this.boundingSphere.radius)) {
  7237. console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
  7238. }
  7239. }
  7240. },
  7241. computeFaceNormals: function computeFaceNormals() {// backwards compatibility
  7242. },
  7243. computeTangents: function computeTangents() {
  7244. var index = this.index;
  7245. var attributes = this.attributes; // based on http://www.terathon.com/code/tangent.html
  7246. // (per vertex tangents)
  7247. if (index === null || attributes.position === undefined || attributes.normal === undefined || attributes.uv === undefined) {
  7248. console.error('THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)');
  7249. return;
  7250. }
  7251. var indices = index.array;
  7252. var positions = attributes.position.array;
  7253. var normals = attributes.normal.array;
  7254. var uvs = attributes.uv.array;
  7255. var nVertices = positions.length / 3;
  7256. if (attributes.tangent === undefined) {
  7257. this.setAttribute('tangent', new BufferAttribute(new Float32Array(4 * nVertices), 4));
  7258. }
  7259. var tangents = attributes.tangent.array;
  7260. var tan1 = [],
  7261. tan2 = [];
  7262. for (var i = 0; i < nVertices; i++) {
  7263. tan1[i] = new Vector3();
  7264. tan2[i] = new Vector3();
  7265. }
  7266. var vA = new Vector3(),
  7267. vB = new Vector3(),
  7268. vC = new Vector3(),
  7269. uvA = new Vector2(),
  7270. uvB = new Vector2(),
  7271. uvC = new Vector2(),
  7272. sdir = new Vector3(),
  7273. tdir = new Vector3();
  7274. function handleTriangle(a, b, c) {
  7275. vA.fromArray(positions, a * 3);
  7276. vB.fromArray(positions, b * 3);
  7277. vC.fromArray(positions, c * 3);
  7278. uvA.fromArray(uvs, a * 2);
  7279. uvB.fromArray(uvs, b * 2);
  7280. uvC.fromArray(uvs, c * 2);
  7281. vB.sub(vA);
  7282. vC.sub(vA);
  7283. uvB.sub(uvA);
  7284. uvC.sub(uvA);
  7285. var r = 1.0 / (uvB.x * uvC.y - uvC.x * uvB.y); // silently ignore degenerate uv triangles having coincident or colinear vertices
  7286. if (!isFinite(r)) return;
  7287. sdir.copy(vB).multiplyScalar(uvC.y).addScaledVector(vC, -uvB.y).multiplyScalar(r);
  7288. tdir.copy(vC).multiplyScalar(uvB.x).addScaledVector(vB, -uvC.x).multiplyScalar(r);
  7289. tan1[a].add(sdir);
  7290. tan1[b].add(sdir);
  7291. tan1[c].add(sdir);
  7292. tan2[a].add(tdir);
  7293. tan2[b].add(tdir);
  7294. tan2[c].add(tdir);
  7295. }
  7296. var groups = this.groups;
  7297. if (groups.length === 0) {
  7298. groups = [{
  7299. start: 0,
  7300. count: indices.length
  7301. }];
  7302. }
  7303. for (var _i3 = 0, il = groups.length; _i3 < il; ++_i3) {
  7304. var group = groups[_i3];
  7305. var start = group.start;
  7306. var count = group.count;
  7307. for (var j = start, jl = start + count; j < jl; j += 3) {
  7308. handleTriangle(indices[j + 0], indices[j + 1], indices[j + 2]);
  7309. }
  7310. }
  7311. var tmp = new Vector3(),
  7312. tmp2 = new Vector3();
  7313. var n = new Vector3(),
  7314. n2 = new Vector3();
  7315. function handleVertex(v) {
  7316. n.fromArray(normals, v * 3);
  7317. n2.copy(n);
  7318. var t = tan1[v]; // Gram-Schmidt orthogonalize
  7319. tmp.copy(t);
  7320. tmp.sub(n.multiplyScalar(n.dot(t))).normalize(); // Calculate handedness
  7321. tmp2.crossVectors(n2, t);
  7322. var test = tmp2.dot(tan2[v]);
  7323. var w = test < 0.0 ? -1.0 : 1.0;
  7324. tangents[v * 4] = tmp.x;
  7325. tangents[v * 4 + 1] = tmp.y;
  7326. tangents[v * 4 + 2] = tmp.z;
  7327. tangents[v * 4 + 3] = w;
  7328. }
  7329. for (var _i4 = 0, _il3 = groups.length; _i4 < _il3; ++_i4) {
  7330. var _group = groups[_i4];
  7331. var _start = _group.start;
  7332. var _count = _group.count;
  7333. for (var _j = _start, _jl = _start + _count; _j < _jl; _j += 3) {
  7334. handleVertex(indices[_j + 0]);
  7335. handleVertex(indices[_j + 1]);
  7336. handleVertex(indices[_j + 2]);
  7337. }
  7338. }
  7339. },
  7340. computeVertexNormals: function computeVertexNormals() {
  7341. var index = this.index;
  7342. var positionAttribute = this.getAttribute('position');
  7343. if (positionAttribute !== undefined) {
  7344. var normalAttribute = this.getAttribute('normal');
  7345. if (normalAttribute === undefined) {
  7346. normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
  7347. this.setAttribute('normal', normalAttribute);
  7348. } else {
  7349. // reset existing normals to zero
  7350. for (var i = 0, il = normalAttribute.count; i < il; i++) {
  7351. normalAttribute.setXYZ(i, 0, 0, 0);
  7352. }
  7353. }
  7354. var pA = new Vector3(),
  7355. pB = new Vector3(),
  7356. pC = new Vector3();
  7357. var nA = new Vector3(),
  7358. nB = new Vector3(),
  7359. nC = new Vector3();
  7360. var cb = new Vector3(),
  7361. ab = new Vector3(); // indexed elements
  7362. if (index) {
  7363. for (var _i5 = 0, _il4 = index.count; _i5 < _il4; _i5 += 3) {
  7364. var vA = index.getX(_i5 + 0);
  7365. var vB = index.getX(_i5 + 1);
  7366. var vC = index.getX(_i5 + 2);
  7367. pA.fromBufferAttribute(positionAttribute, vA);
  7368. pB.fromBufferAttribute(positionAttribute, vB);
  7369. pC.fromBufferAttribute(positionAttribute, vC);
  7370. cb.subVectors(pC, pB);
  7371. ab.subVectors(pA, pB);
  7372. cb.cross(ab);
  7373. nA.fromBufferAttribute(normalAttribute, vA);
  7374. nB.fromBufferAttribute(normalAttribute, vB);
  7375. nC.fromBufferAttribute(normalAttribute, vC);
  7376. nA.add(cb);
  7377. nB.add(cb);
  7378. nC.add(cb);
  7379. normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
  7380. normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
  7381. normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
  7382. }
  7383. } else {
  7384. // non-indexed elements (unconnected triangle soup)
  7385. for (var _i6 = 0, _il5 = positionAttribute.count; _i6 < _il5; _i6 += 3) {
  7386. pA.fromBufferAttribute(positionAttribute, _i6 + 0);
  7387. pB.fromBufferAttribute(positionAttribute, _i6 + 1);
  7388. pC.fromBufferAttribute(positionAttribute, _i6 + 2);
  7389. cb.subVectors(pC, pB);
  7390. ab.subVectors(pA, pB);
  7391. cb.cross(ab);
  7392. normalAttribute.setXYZ(_i6 + 0, cb.x, cb.y, cb.z);
  7393. normalAttribute.setXYZ(_i6 + 1, cb.x, cb.y, cb.z);
  7394. normalAttribute.setXYZ(_i6 + 2, cb.x, cb.y, cb.z);
  7395. }
  7396. }
  7397. this.normalizeNormals();
  7398. normalAttribute.needsUpdate = true;
  7399. }
  7400. },
  7401. merge: function merge(geometry, offset) {
  7402. if (!(geometry && geometry.isBufferGeometry)) {
  7403. console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
  7404. return;
  7405. }
  7406. if (offset === undefined) {
  7407. offset = 0;
  7408. console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');
  7409. }
  7410. var attributes = this.attributes;
  7411. for (var key in attributes) {
  7412. if (geometry.attributes[key] === undefined) continue;
  7413. var attribute1 = attributes[key];
  7414. var attributeArray1 = attribute1.array;
  7415. var attribute2 = geometry.attributes[key];
  7416. var attributeArray2 = attribute2.array;
  7417. var attributeOffset = attribute2.itemSize * offset;
  7418. var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
  7419. for (var i = 0, j = attributeOffset; i < length; i++, j++) {
  7420. attributeArray1[j] = attributeArray2[i];
  7421. }
  7422. }
  7423. return this;
  7424. },
  7425. normalizeNormals: function normalizeNormals() {
  7426. var normals = this.attributes.normal;
  7427. for (var i = 0, il = normals.count; i < il; i++) {
  7428. _vector$4.fromBufferAttribute(normals, i);
  7429. _vector$4.normalize();
  7430. normals.setXYZ(i, _vector$4.x, _vector$4.y, _vector$4.z);
  7431. }
  7432. },
  7433. toNonIndexed: function toNonIndexed() {
  7434. function convertBufferAttribute(attribute, indices) {
  7435. var array = attribute.array;
  7436. var itemSize = attribute.itemSize;
  7437. var normalized = attribute.normalized;
  7438. var array2 = new array.constructor(indices.length * itemSize);
  7439. var index = 0,
  7440. index2 = 0;
  7441. for (var i = 0, l = indices.length; i < l; i++) {
  7442. index = indices[i] * itemSize;
  7443. for (var j = 0; j < itemSize; j++) {
  7444. array2[index2++] = array[index++];
  7445. }
  7446. }
  7447. return new BufferAttribute(array2, itemSize, normalized);
  7448. } //
  7449. if (this.index === null) {
  7450. console.warn('THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.');
  7451. return this;
  7452. }
  7453. var geometry2 = new BufferGeometry();
  7454. var indices = this.index.array;
  7455. var attributes = this.attributes; // attributes
  7456. for (var name in attributes) {
  7457. var attribute = attributes[name];
  7458. var newAttribute = convertBufferAttribute(attribute, indices);
  7459. geometry2.setAttribute(name, newAttribute);
  7460. } // morph attributes
  7461. var morphAttributes = this.morphAttributes;
  7462. for (var _name in morphAttributes) {
  7463. var morphArray = [];
  7464. var morphAttribute = morphAttributes[_name]; // morphAttribute: array of Float32BufferAttributes
  7465. for (var i = 0, il = morphAttribute.length; i < il; i++) {
  7466. var _attribute = morphAttribute[i];
  7467. var _newAttribute = convertBufferAttribute(_attribute, indices);
  7468. morphArray.push(_newAttribute);
  7469. }
  7470. geometry2.morphAttributes[_name] = morphArray;
  7471. }
  7472. geometry2.morphTargetsRelative = this.morphTargetsRelative; // groups
  7473. var groups = this.groups;
  7474. for (var _i7 = 0, l = groups.length; _i7 < l; _i7++) {
  7475. var group = groups[_i7];
  7476. geometry2.addGroup(group.start, group.count, group.materialIndex);
  7477. }
  7478. return geometry2;
  7479. },
  7480. toJSON: function toJSON() {
  7481. var data = {
  7482. metadata: {
  7483. version: 4.5,
  7484. type: 'BufferGeometry',
  7485. generator: 'BufferGeometry.toJSON'
  7486. }
  7487. }; // standard BufferGeometry serialization
  7488. data.uuid = this.uuid;
  7489. data.type = this.type;
  7490. if (this.name !== '') data.name = this.name;
  7491. if (Object.keys(this.userData).length > 0) data.userData = this.userData;
  7492. if (this.parameters !== undefined) {
  7493. var parameters = this.parameters;
  7494. for (var key in parameters) {
  7495. if (parameters[key] !== undefined) data[key] = parameters[key];
  7496. }
  7497. return data;
  7498. }
  7499. data.data = {
  7500. attributes: {}
  7501. };
  7502. var index = this.index;
  7503. if (index !== null) {
  7504. data.data.index = {
  7505. type: index.array.constructor.name,
  7506. array: Array.prototype.slice.call(index.array)
  7507. };
  7508. }
  7509. var attributes = this.attributes;
  7510. for (var _key in attributes) {
  7511. var attribute = attributes[_key];
  7512. var attributeData = attribute.toJSON(data.data);
  7513. if (attribute.name !== '') attributeData.name = attribute.name;
  7514. data.data.attributes[_key] = attributeData;
  7515. }
  7516. var morphAttributes = {};
  7517. var hasMorphAttributes = false;
  7518. for (var _key2 in this.morphAttributes) {
  7519. var attributeArray = this.morphAttributes[_key2];
  7520. var array = [];
  7521. for (var i = 0, il = attributeArray.length; i < il; i++) {
  7522. var _attribute2 = attributeArray[i];
  7523. var _attributeData = _attribute2.toJSON(data.data);
  7524. if (_attribute2.name !== '') _attributeData.name = _attribute2.name;
  7525. array.push(_attributeData);
  7526. }
  7527. if (array.length > 0) {
  7528. morphAttributes[_key2] = array;
  7529. hasMorphAttributes = true;
  7530. }
  7531. }
  7532. if (hasMorphAttributes) {
  7533. data.data.morphAttributes = morphAttributes;
  7534. data.data.morphTargetsRelative = this.morphTargetsRelative;
  7535. }
  7536. var groups = this.groups;
  7537. if (groups.length > 0) {
  7538. data.data.groups = JSON.parse(JSON.stringify(groups));
  7539. }
  7540. var boundingSphere = this.boundingSphere;
  7541. if (boundingSphere !== null) {
  7542. data.data.boundingSphere = {
  7543. center: boundingSphere.center.toArray(),
  7544. radius: boundingSphere.radius
  7545. };
  7546. }
  7547. return data;
  7548. },
  7549. clone: function clone() {
  7550. /*
  7551. // Handle primitives
  7552. const parameters = this.parameters;
  7553. if ( parameters !== undefined ) {
  7554. const values = [];
  7555. for ( const key in parameters ) {
  7556. values.push( parameters[ key ] );
  7557. }
  7558. const geometry = Object.create( this.constructor.prototype );
  7559. this.constructor.apply( geometry, values );
  7560. return geometry;
  7561. }
  7562. return new this.constructor().copy( this );
  7563. */
  7564. return new BufferGeometry().copy(this);
  7565. },
  7566. copy: function copy(source) {
  7567. // reset
  7568. this.index = null;
  7569. this.attributes = {};
  7570. this.morphAttributes = {};
  7571. this.groups = [];
  7572. this.boundingBox = null;
  7573. this.boundingSphere = null; // used for storing cloned, shared data
  7574. var data = {}; // name
  7575. this.name = source.name; // index
  7576. var index = source.index;
  7577. if (index !== null) {
  7578. this.setIndex(index.clone(data));
  7579. } // attributes
  7580. var attributes = source.attributes;
  7581. for (var name in attributes) {
  7582. var attribute = attributes[name];
  7583. this.setAttribute(name, attribute.clone(data));
  7584. } // morph attributes
  7585. var morphAttributes = source.morphAttributes;
  7586. for (var _name2 in morphAttributes) {
  7587. var array = [];
  7588. var morphAttribute = morphAttributes[_name2]; // morphAttribute: array of Float32BufferAttributes
  7589. for (var i = 0, l = morphAttribute.length; i < l; i++) {
  7590. array.push(morphAttribute[i].clone(data));
  7591. }
  7592. this.morphAttributes[_name2] = array;
  7593. }
  7594. this.morphTargetsRelative = source.morphTargetsRelative; // groups
  7595. var groups = source.groups;
  7596. for (var _i8 = 0, _l = groups.length; _i8 < _l; _i8++) {
  7597. var group = groups[_i8];
  7598. this.addGroup(group.start, group.count, group.materialIndex);
  7599. } // bounding box
  7600. var boundingBox = source.boundingBox;
  7601. if (boundingBox !== null) {
  7602. this.boundingBox = boundingBox.clone();
  7603. } // bounding sphere
  7604. var boundingSphere = source.boundingSphere;
  7605. if (boundingSphere !== null) {
  7606. this.boundingSphere = boundingSphere.clone();
  7607. } // draw range
  7608. this.drawRange.start = source.drawRange.start;
  7609. this.drawRange.count = source.drawRange.count; // user data
  7610. this.userData = source.userData;
  7611. return this;
  7612. },
  7613. dispose: function dispose() {
  7614. this.dispatchEvent({
  7615. type: 'dispose'
  7616. });
  7617. }
  7618. });
  7619. var _inverseMatrix = new Matrix4();
  7620. var _ray = new Ray();
  7621. var _sphere = new Sphere();
  7622. var _vA = new Vector3();
  7623. var _vB = new Vector3();
  7624. var _vC = new Vector3();
  7625. var _tempA = new Vector3();
  7626. var _tempB = new Vector3();
  7627. var _tempC = new Vector3();
  7628. var _morphA = new Vector3();
  7629. var _morphB = new Vector3();
  7630. var _morphC = new Vector3();
  7631. var _uvA = new Vector2();
  7632. var _uvB = new Vector2();
  7633. var _uvC = new Vector2();
  7634. var _intersectionPoint = new Vector3();
  7635. var _intersectionPointWorld = new Vector3();
  7636. function Mesh(geometry, material) {
  7637. if (geometry === void 0) {
  7638. geometry = new BufferGeometry();
  7639. }
  7640. if (material === void 0) {
  7641. material = new MeshBasicMaterial();
  7642. }
  7643. Object3D.call(this);
  7644. this.type = 'Mesh';
  7645. this.geometry = geometry;
  7646. this.material = material;
  7647. this.updateMorphTargets();
  7648. }
  7649. Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
  7650. constructor: Mesh,
  7651. isMesh: true,
  7652. copy: function copy(source) {
  7653. Object3D.prototype.copy.call(this, source);
  7654. if (source.morphTargetInfluences !== undefined) {
  7655. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  7656. }
  7657. if (source.morphTargetDictionary !== undefined) {
  7658. this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
  7659. }
  7660. this.material = source.material;
  7661. this.geometry = source.geometry;
  7662. return this;
  7663. },
  7664. updateMorphTargets: function updateMorphTargets() {
  7665. var geometry = this.geometry;
  7666. if (geometry.isBufferGeometry) {
  7667. var morphAttributes = geometry.morphAttributes;
  7668. var keys = Object.keys(morphAttributes);
  7669. if (keys.length > 0) {
  7670. var morphAttribute = morphAttributes[keys[0]];
  7671. if (morphAttribute !== undefined) {
  7672. this.morphTargetInfluences = [];
  7673. this.morphTargetDictionary = {};
  7674. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  7675. var name = morphAttribute[m].name || String(m);
  7676. this.morphTargetInfluences.push(0);
  7677. this.morphTargetDictionary[name] = m;
  7678. }
  7679. }
  7680. }
  7681. } else {
  7682. var morphTargets = geometry.morphTargets;
  7683. if (morphTargets !== undefined && morphTargets.length > 0) {
  7684. console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7685. }
  7686. }
  7687. },
  7688. raycast: function raycast(raycaster, intersects) {
  7689. var geometry = this.geometry;
  7690. var material = this.material;
  7691. var matrixWorld = this.matrixWorld;
  7692. if (material === undefined) return; // Checking boundingSphere distance to ray
  7693. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7694. _sphere.copy(geometry.boundingSphere);
  7695. _sphere.applyMatrix4(matrixWorld);
  7696. if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
  7697. _inverseMatrix.copy(matrixWorld).invert();
  7698. _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
  7699. if (geometry.boundingBox !== null) {
  7700. if (_ray.intersectsBox(geometry.boundingBox) === false) return;
  7701. }
  7702. var intersection;
  7703. if (geometry.isBufferGeometry) {
  7704. var index = geometry.index;
  7705. var position = geometry.attributes.position;
  7706. var morphPosition = geometry.morphAttributes.position;
  7707. var morphTargetsRelative = geometry.morphTargetsRelative;
  7708. var uv = geometry.attributes.uv;
  7709. var uv2 = geometry.attributes.uv2;
  7710. var groups = geometry.groups;
  7711. var drawRange = geometry.drawRange;
  7712. if (index !== null) {
  7713. // indexed buffer geometry
  7714. if (Array.isArray(material)) {
  7715. for (var i = 0, il = groups.length; i < il; i++) {
  7716. var group = groups[i];
  7717. var groupMaterial = material[group.materialIndex];
  7718. var start = Math.max(group.start, drawRange.start);
  7719. var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
  7720. for (var j = start, jl = end; j < jl; j += 3) {
  7721. var a = index.getX(j);
  7722. var b = index.getX(j + 1);
  7723. var c = index.getX(j + 2);
  7724. intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
  7725. if (intersection) {
  7726. intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
  7727. intersection.face.materialIndex = group.materialIndex;
  7728. intersects.push(intersection);
  7729. }
  7730. }
  7731. }
  7732. } else {
  7733. var _start = Math.max(0, drawRange.start);
  7734. var _end = Math.min(index.count, drawRange.start + drawRange.count);
  7735. for (var _i = _start, _il = _end; _i < _il; _i += 3) {
  7736. var _a = index.getX(_i);
  7737. var _b = index.getX(_i + 1);
  7738. var _c = index.getX(_i + 2);
  7739. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
  7740. if (intersection) {
  7741. intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
  7742. intersects.push(intersection);
  7743. }
  7744. }
  7745. }
  7746. } else if (position !== undefined) {
  7747. // non-indexed buffer geometry
  7748. if (Array.isArray(material)) {
  7749. for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
  7750. var _group = groups[_i2];
  7751. var _groupMaterial = material[_group.materialIndex];
  7752. var _start2 = Math.max(_group.start, drawRange.start);
  7753. var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
  7754. for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
  7755. var _a2 = _j;
  7756. var _b2 = _j + 1;
  7757. var _c2 = _j + 2;
  7758. intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
  7759. if (intersection) {
  7760. intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
  7761. intersection.face.materialIndex = _group.materialIndex;
  7762. intersects.push(intersection);
  7763. }
  7764. }
  7765. }
  7766. } else {
  7767. var _start3 = Math.max(0, drawRange.start);
  7768. var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
  7769. for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
  7770. var _a3 = _i3;
  7771. var _b3 = _i3 + 1;
  7772. var _c3 = _i3 + 2;
  7773. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
  7774. if (intersection) {
  7775. intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
  7776. intersects.push(intersection);
  7777. }
  7778. }
  7779. }
  7780. }
  7781. } else if (geometry.isGeometry) {
  7782. console.error('THREE.Mesh.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7783. }
  7784. }
  7785. });
  7786. function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
  7787. var intersect;
  7788. if (material.side === BackSide) {
  7789. intersect = ray.intersectTriangle(pC, pB, pA, true, point);
  7790. } else {
  7791. intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
  7792. }
  7793. if (intersect === null) return null;
  7794. _intersectionPointWorld.copy(point);
  7795. _intersectionPointWorld.applyMatrix4(object.matrixWorld);
  7796. var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
  7797. if (distance < raycaster.near || distance > raycaster.far) return null;
  7798. return {
  7799. distance: distance,
  7800. point: _intersectionPointWorld.clone(),
  7801. object: object
  7802. };
  7803. }
  7804. function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
  7805. _vA.fromBufferAttribute(position, a);
  7806. _vB.fromBufferAttribute(position, b);
  7807. _vC.fromBufferAttribute(position, c);
  7808. var morphInfluences = object.morphTargetInfluences;
  7809. if (material.morphTargets && morphPosition && morphInfluences) {
  7810. _morphA.set(0, 0, 0);
  7811. _morphB.set(0, 0, 0);
  7812. _morphC.set(0, 0, 0);
  7813. for (var i = 0, il = morphPosition.length; i < il; i++) {
  7814. var influence = morphInfluences[i];
  7815. var morphAttribute = morphPosition[i];
  7816. if (influence === 0) continue;
  7817. _tempA.fromBufferAttribute(morphAttribute, a);
  7818. _tempB.fromBufferAttribute(morphAttribute, b);
  7819. _tempC.fromBufferAttribute(morphAttribute, c);
  7820. if (morphTargetsRelative) {
  7821. _morphA.addScaledVector(_tempA, influence);
  7822. _morphB.addScaledVector(_tempB, influence);
  7823. _morphC.addScaledVector(_tempC, influence);
  7824. } else {
  7825. _morphA.addScaledVector(_tempA.sub(_vA), influence);
  7826. _morphB.addScaledVector(_tempB.sub(_vB), influence);
  7827. _morphC.addScaledVector(_tempC.sub(_vC), influence);
  7828. }
  7829. }
  7830. _vA.add(_morphA);
  7831. _vB.add(_morphB);
  7832. _vC.add(_morphC);
  7833. }
  7834. if (object.isSkinnedMesh) {
  7835. object.boneTransform(a, _vA);
  7836. object.boneTransform(b, _vB);
  7837. object.boneTransform(c, _vC);
  7838. }
  7839. var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
  7840. if (intersection) {
  7841. if (uv) {
  7842. _uvA.fromBufferAttribute(uv, a);
  7843. _uvB.fromBufferAttribute(uv, b);
  7844. _uvC.fromBufferAttribute(uv, c);
  7845. intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7846. }
  7847. if (uv2) {
  7848. _uvA.fromBufferAttribute(uv2, a);
  7849. _uvB.fromBufferAttribute(uv2, b);
  7850. _uvC.fromBufferAttribute(uv2, c);
  7851. intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7852. }
  7853. var face = {
  7854. a: a,
  7855. b: a,
  7856. c: c,
  7857. normal: new Vector3(),
  7858. materialIndex: 0
  7859. };
  7860. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7861. intersection.face = face;
  7862. }
  7863. return intersection;
  7864. }
  7865. var BoxGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7866. _inheritsLoose(BoxGeometry, _BufferGeometry);
  7867. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7868. var _this;
  7869. if (width === void 0) {
  7870. width = 1;
  7871. }
  7872. if (height === void 0) {
  7873. height = 1;
  7874. }
  7875. if (depth === void 0) {
  7876. depth = 1;
  7877. }
  7878. if (widthSegments === void 0) {
  7879. widthSegments = 1;
  7880. }
  7881. if (heightSegments === void 0) {
  7882. heightSegments = 1;
  7883. }
  7884. if (depthSegments === void 0) {
  7885. depthSegments = 1;
  7886. }
  7887. _this = _BufferGeometry.call(this) || this;
  7888. _this.type = 'BoxGeometry';
  7889. _this.parameters = {
  7890. width: width,
  7891. height: height,
  7892. depth: depth,
  7893. widthSegments: widthSegments,
  7894. heightSegments: heightSegments,
  7895. depthSegments: depthSegments
  7896. };
  7897. var scope = _assertThisInitialized(_this); // segments
  7898. widthSegments = Math.floor(widthSegments);
  7899. heightSegments = Math.floor(heightSegments);
  7900. depthSegments = Math.floor(depthSegments); // buffers
  7901. var indices = [];
  7902. var vertices = [];
  7903. var normals = [];
  7904. var uvs = []; // helper variables
  7905. var numberOfVertices = 0;
  7906. var groupStart = 0; // build each side of the box geometry
  7907. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7908. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7909. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7910. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7911. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7912. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7913. // build geometry
  7914. _this.setIndex(indices);
  7915. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7916. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7917. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7918. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7919. var segmentWidth = width / gridX;
  7920. var segmentHeight = height / gridY;
  7921. var widthHalf = width / 2;
  7922. var heightHalf = height / 2;
  7923. var depthHalf = depth / 2;
  7924. var gridX1 = gridX + 1;
  7925. var gridY1 = gridY + 1;
  7926. var vertexCounter = 0;
  7927. var groupCount = 0;
  7928. var vector = new Vector3(); // generate vertices, normals and uvs
  7929. for (var iy = 0; iy < gridY1; iy++) {
  7930. var y = iy * segmentHeight - heightHalf;
  7931. for (var ix = 0; ix < gridX1; ix++) {
  7932. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7933. vector[u] = x * udir;
  7934. vector[v] = y * vdir;
  7935. vector[w] = depthHalf; // now apply vector to vertex buffer
  7936. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7937. vector[u] = 0;
  7938. vector[v] = 0;
  7939. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7940. normals.push(vector.x, vector.y, vector.z); // uvs
  7941. uvs.push(ix / gridX);
  7942. uvs.push(1 - iy / gridY); // counters
  7943. vertexCounter += 1;
  7944. }
  7945. } // indices
  7946. // 1. you need three indices to draw a single face
  7947. // 2. a single segment consists of two faces
  7948. // 3. so we need to generate six (2*3) indices per segment
  7949. for (var _iy = 0; _iy < gridY; _iy++) {
  7950. for (var _ix = 0; _ix < gridX; _ix++) {
  7951. var a = numberOfVertices + _ix + gridX1 * _iy;
  7952. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7953. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7954. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7955. indices.push(a, b, d);
  7956. indices.push(b, c, d); // increase counter
  7957. groupCount += 6;
  7958. }
  7959. } // add a group to the geometry. this will ensure multi material support
  7960. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7961. groupStart += groupCount; // update total number of vertices
  7962. numberOfVertices += vertexCounter;
  7963. }
  7964. return _this;
  7965. }
  7966. return BoxGeometry;
  7967. }(BufferGeometry);
  7968. /**
  7969. * Uniform Utilities
  7970. */
  7971. function cloneUniforms(src) {
  7972. var dst = {};
  7973. for (var u in src) {
  7974. dst[u] = {};
  7975. for (var p in src[u]) {
  7976. var property = src[u][p];
  7977. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture)) {
  7978. dst[u][p] = property.clone();
  7979. } else if (Array.isArray(property)) {
  7980. dst[u][p] = property.slice();
  7981. } else {
  7982. dst[u][p] = property;
  7983. }
  7984. }
  7985. }
  7986. return dst;
  7987. }
  7988. function mergeUniforms(uniforms) {
  7989. var merged = {};
  7990. for (var u = 0; u < uniforms.length; u++) {
  7991. var tmp = cloneUniforms(uniforms[u]);
  7992. for (var p in tmp) {
  7993. merged[p] = tmp[p];
  7994. }
  7995. }
  7996. return merged;
  7997. } // Legacy
  7998. var UniformsUtils = {
  7999. clone: cloneUniforms,
  8000. merge: mergeUniforms
  8001. };
  8002. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  8003. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  8004. /**
  8005. * parameters = {
  8006. * defines: { "label" : "value" },
  8007. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  8008. *
  8009. * fragmentShader: <string>,
  8010. * vertexShader: <string>,
  8011. *
  8012. * wireframe: <boolean>,
  8013. * wireframeLinewidth: <float>,
  8014. *
  8015. * lights: <bool>,
  8016. *
  8017. * skinning: <bool>,
  8018. * morphTargets: <bool>,
  8019. * morphNormals: <bool>
  8020. * }
  8021. */
  8022. function ShaderMaterial(parameters) {
  8023. Material.call(this);
  8024. this.type = 'ShaderMaterial';
  8025. this.defines = {};
  8026. this.uniforms = {};
  8027. this.vertexShader = default_vertex;
  8028. this.fragmentShader = default_fragment;
  8029. this.linewidth = 1;
  8030. this.wireframe = false;
  8031. this.wireframeLinewidth = 1;
  8032. this.fog = false; // set to use scene fog
  8033. this.lights = false; // set to use scene lights
  8034. this.clipping = false; // set to use user-defined clipping planes
  8035. this.skinning = false; // set to use skinning attribute streams
  8036. this.morphTargets = false; // set to use morph targets
  8037. this.morphNormals = false; // set to use morph normals
  8038. this.extensions = {
  8039. derivatives: false,
  8040. // set to use derivatives
  8041. fragDepth: false,
  8042. // set to use fragment depth values
  8043. drawBuffers: false,
  8044. // set to use draw buffers
  8045. shaderTextureLOD: false // set to use shader texture LOD
  8046. }; // When rendered geometry doesn't include these attributes but the material does,
  8047. // use these default values in WebGL. This avoids errors when buffer data is missing.
  8048. this.defaultAttributeValues = {
  8049. 'color': [1, 1, 1],
  8050. 'uv': [0, 0],
  8051. 'uv2': [0, 0]
  8052. };
  8053. this.index0AttributeName = undefined;
  8054. this.uniformsNeedUpdate = false;
  8055. this.glslVersion = null;
  8056. if (parameters !== undefined) {
  8057. if (parameters.attributes !== undefined) {
  8058. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  8059. }
  8060. this.setValues(parameters);
  8061. }
  8062. }
  8063. ShaderMaterial.prototype = Object.create(Material.prototype);
  8064. ShaderMaterial.prototype.constructor = ShaderMaterial;
  8065. ShaderMaterial.prototype.isShaderMaterial = true;
  8066. ShaderMaterial.prototype.copy = function (source) {
  8067. Material.prototype.copy.call(this, source);
  8068. this.fragmentShader = source.fragmentShader;
  8069. this.vertexShader = source.vertexShader;
  8070. this.uniforms = cloneUniforms(source.uniforms);
  8071. this.defines = Object.assign({}, source.defines);
  8072. this.wireframe = source.wireframe;
  8073. this.wireframeLinewidth = source.wireframeLinewidth;
  8074. this.lights = source.lights;
  8075. this.clipping = source.clipping;
  8076. this.skinning = source.skinning;
  8077. this.morphTargets = source.morphTargets;
  8078. this.morphNormals = source.morphNormals;
  8079. this.extensions = Object.assign({}, source.extensions);
  8080. this.glslVersion = source.glslVersion;
  8081. return this;
  8082. };
  8083. ShaderMaterial.prototype.toJSON = function (meta) {
  8084. var data = Material.prototype.toJSON.call(this, meta);
  8085. data.glslVersion = this.glslVersion;
  8086. data.uniforms = {};
  8087. for (var name in this.uniforms) {
  8088. var uniform = this.uniforms[name];
  8089. var value = uniform.value;
  8090. if (value && value.isTexture) {
  8091. data.uniforms[name] = {
  8092. type: 't',
  8093. value: value.toJSON(meta).uuid
  8094. };
  8095. } else if (value && value.isColor) {
  8096. data.uniforms[name] = {
  8097. type: 'c',
  8098. value: value.getHex()
  8099. };
  8100. } else if (value && value.isVector2) {
  8101. data.uniforms[name] = {
  8102. type: 'v2',
  8103. value: value.toArray()
  8104. };
  8105. } else if (value && value.isVector3) {
  8106. data.uniforms[name] = {
  8107. type: 'v3',
  8108. value: value.toArray()
  8109. };
  8110. } else if (value && value.isVector4) {
  8111. data.uniforms[name] = {
  8112. type: 'v4',
  8113. value: value.toArray()
  8114. };
  8115. } else if (value && value.isMatrix3) {
  8116. data.uniforms[name] = {
  8117. type: 'm3',
  8118. value: value.toArray()
  8119. };
  8120. } else if (value && value.isMatrix4) {
  8121. data.uniforms[name] = {
  8122. type: 'm4',
  8123. value: value.toArray()
  8124. };
  8125. } else {
  8126. data.uniforms[name] = {
  8127. value: value
  8128. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  8129. }
  8130. }
  8131. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  8132. data.vertexShader = this.vertexShader;
  8133. data.fragmentShader = this.fragmentShader;
  8134. var extensions = {};
  8135. for (var key in this.extensions) {
  8136. if (this.extensions[key] === true) extensions[key] = true;
  8137. }
  8138. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  8139. return data;
  8140. };
  8141. function Camera() {
  8142. Object3D.call(this);
  8143. this.type = 'Camera';
  8144. this.matrixWorldInverse = new Matrix4();
  8145. this.projectionMatrix = new Matrix4();
  8146. this.projectionMatrixInverse = new Matrix4();
  8147. }
  8148. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  8149. constructor: Camera,
  8150. isCamera: true,
  8151. copy: function copy(source, recursive) {
  8152. Object3D.prototype.copy.call(this, source, recursive);
  8153. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  8154. this.projectionMatrix.copy(source.projectionMatrix);
  8155. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  8156. return this;
  8157. },
  8158. getWorldDirection: function getWorldDirection(target) {
  8159. if (target === undefined) {
  8160. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  8161. target = new Vector3();
  8162. }
  8163. this.updateWorldMatrix(true, false);
  8164. var e = this.matrixWorld.elements;
  8165. return target.set(-e[8], -e[9], -e[10]).normalize();
  8166. },
  8167. updateMatrixWorld: function updateMatrixWorld(force) {
  8168. Object3D.prototype.updateMatrixWorld.call(this, force);
  8169. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  8170. },
  8171. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  8172. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  8173. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  8174. },
  8175. clone: function clone() {
  8176. return new this.constructor().copy(this);
  8177. }
  8178. });
  8179. function PerspectiveCamera(fov, aspect, near, far) {
  8180. if (fov === void 0) {
  8181. fov = 50;
  8182. }
  8183. if (aspect === void 0) {
  8184. aspect = 1;
  8185. }
  8186. if (near === void 0) {
  8187. near = 0.1;
  8188. }
  8189. if (far === void 0) {
  8190. far = 2000;
  8191. }
  8192. Camera.call(this);
  8193. this.type = 'PerspectiveCamera';
  8194. this.fov = fov;
  8195. this.zoom = 1;
  8196. this.near = near;
  8197. this.far = far;
  8198. this.focus = 10;
  8199. this.aspect = aspect;
  8200. this.view = null;
  8201. this.filmGauge = 35; // width of the film (default in millimeters)
  8202. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  8203. this.updateProjectionMatrix();
  8204. }
  8205. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  8206. constructor: PerspectiveCamera,
  8207. isPerspectiveCamera: true,
  8208. copy: function copy(source, recursive) {
  8209. Camera.prototype.copy.call(this, source, recursive);
  8210. this.fov = source.fov;
  8211. this.zoom = source.zoom;
  8212. this.near = source.near;
  8213. this.far = source.far;
  8214. this.focus = source.focus;
  8215. this.aspect = source.aspect;
  8216. this.view = source.view === null ? null : Object.assign({}, source.view);
  8217. this.filmGauge = source.filmGauge;
  8218. this.filmOffset = source.filmOffset;
  8219. return this;
  8220. },
  8221. /**
  8222. * Sets the FOV by focal length in respect to the current .filmGauge.
  8223. *
  8224. * The default film gauge is 35, so that the focal length can be specified for
  8225. * a 35mm (full frame) camera.
  8226. *
  8227. * Values for focal length and film gauge must have the same unit.
  8228. */
  8229. setFocalLength: function setFocalLength(focalLength) {
  8230. /** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
  8231. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  8232. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  8233. this.updateProjectionMatrix();
  8234. },
  8235. /**
  8236. * Calculates the focal length from the current .fov and .filmGauge.
  8237. */
  8238. getFocalLength: function getFocalLength() {
  8239. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  8240. return 0.5 * this.getFilmHeight() / vExtentSlope;
  8241. },
  8242. getEffectiveFOV: function getEffectiveFOV() {
  8243. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  8244. },
  8245. getFilmWidth: function getFilmWidth() {
  8246. // film not completely covered in portrait format (aspect < 1)
  8247. return this.filmGauge * Math.min(this.aspect, 1);
  8248. },
  8249. getFilmHeight: function getFilmHeight() {
  8250. // film not completely covered in landscape format (aspect > 1)
  8251. return this.filmGauge / Math.max(this.aspect, 1);
  8252. },
  8253. /**
  8254. * Sets an offset in a larger frustum. This is useful for multi-window or
  8255. * multi-monitor/multi-machine setups.
  8256. *
  8257. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  8258. * the monitors are in grid like this
  8259. *
  8260. * +---+---+---+
  8261. * | A | B | C |
  8262. * +---+---+---+
  8263. * | D | E | F |
  8264. * +---+---+---+
  8265. *
  8266. * then for each monitor you would call it like this
  8267. *
  8268. * const w = 1920;
  8269. * const h = 1080;
  8270. * const fullWidth = w * 3;
  8271. * const fullHeight = h * 2;
  8272. *
  8273. * --A--
  8274. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8275. * --B--
  8276. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8277. * --C--
  8278. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8279. * --D--
  8280. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8281. * --E--
  8282. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8283. * --F--
  8284. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8285. *
  8286. * Note there is no reason monitors have to be the same size or in a grid.
  8287. */
  8288. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  8289. this.aspect = fullWidth / fullHeight;
  8290. if (this.view === null) {
  8291. this.view = {
  8292. enabled: true,
  8293. fullWidth: 1,
  8294. fullHeight: 1,
  8295. offsetX: 0,
  8296. offsetY: 0,
  8297. width: 1,
  8298. height: 1
  8299. };
  8300. }
  8301. this.view.enabled = true;
  8302. this.view.fullWidth = fullWidth;
  8303. this.view.fullHeight = fullHeight;
  8304. this.view.offsetX = x;
  8305. this.view.offsetY = y;
  8306. this.view.width = width;
  8307. this.view.height = height;
  8308. this.updateProjectionMatrix();
  8309. },
  8310. clearViewOffset: function clearViewOffset() {
  8311. if (this.view !== null) {
  8312. this.view.enabled = false;
  8313. }
  8314. this.updateProjectionMatrix();
  8315. },
  8316. updateProjectionMatrix: function updateProjectionMatrix() {
  8317. var near = this.near;
  8318. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  8319. var height = 2 * top;
  8320. var width = this.aspect * height;
  8321. var left = -0.5 * width;
  8322. var view = this.view;
  8323. if (this.view !== null && this.view.enabled) {
  8324. var fullWidth = view.fullWidth,
  8325. fullHeight = view.fullHeight;
  8326. left += view.offsetX * width / fullWidth;
  8327. top -= view.offsetY * height / fullHeight;
  8328. width *= view.width / fullWidth;
  8329. height *= view.height / fullHeight;
  8330. }
  8331. var skew = this.filmOffset;
  8332. if (skew !== 0) left += near * skew / this.getFilmWidth();
  8333. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  8334. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  8335. },
  8336. toJSON: function toJSON(meta) {
  8337. var data = Object3D.prototype.toJSON.call(this, meta);
  8338. data.object.fov = this.fov;
  8339. data.object.zoom = this.zoom;
  8340. data.object.near = this.near;
  8341. data.object.far = this.far;
  8342. data.object.focus = this.focus;
  8343. data.object.aspect = this.aspect;
  8344. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  8345. data.object.filmGauge = this.filmGauge;
  8346. data.object.filmOffset = this.filmOffset;
  8347. return data;
  8348. }
  8349. });
  8350. var fov = 90,
  8351. aspect = 1;
  8352. function CubeCamera(near, far, renderTarget) {
  8353. Object3D.call(this);
  8354. this.type = 'CubeCamera';
  8355. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  8356. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  8357. return;
  8358. }
  8359. this.renderTarget = renderTarget;
  8360. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  8361. cameraPX.layers = this.layers;
  8362. cameraPX.up.set(0, -1, 0);
  8363. cameraPX.lookAt(new Vector3(1, 0, 0));
  8364. this.add(cameraPX);
  8365. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  8366. cameraNX.layers = this.layers;
  8367. cameraNX.up.set(0, -1, 0);
  8368. cameraNX.lookAt(new Vector3(-1, 0, 0));
  8369. this.add(cameraNX);
  8370. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  8371. cameraPY.layers = this.layers;
  8372. cameraPY.up.set(0, 0, 1);
  8373. cameraPY.lookAt(new Vector3(0, 1, 0));
  8374. this.add(cameraPY);
  8375. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  8376. cameraNY.layers = this.layers;
  8377. cameraNY.up.set(0, 0, -1);
  8378. cameraNY.lookAt(new Vector3(0, -1, 0));
  8379. this.add(cameraNY);
  8380. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  8381. cameraPZ.layers = this.layers;
  8382. cameraPZ.up.set(0, -1, 0);
  8383. cameraPZ.lookAt(new Vector3(0, 0, 1));
  8384. this.add(cameraPZ);
  8385. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  8386. cameraNZ.layers = this.layers;
  8387. cameraNZ.up.set(0, -1, 0);
  8388. cameraNZ.lookAt(new Vector3(0, 0, -1));
  8389. this.add(cameraNZ);
  8390. this.update = function (renderer, scene) {
  8391. if (this.parent === null) this.updateMatrixWorld();
  8392. var currentXrEnabled = renderer.xr.enabled;
  8393. var currentRenderTarget = renderer.getRenderTarget();
  8394. renderer.xr.enabled = false;
  8395. var generateMipmaps = renderTarget.texture.generateMipmaps;
  8396. renderTarget.texture.generateMipmaps = false;
  8397. renderer.setRenderTarget(renderTarget, 0);
  8398. renderer.render(scene, cameraPX);
  8399. renderer.setRenderTarget(renderTarget, 1);
  8400. renderer.render(scene, cameraNX);
  8401. renderer.setRenderTarget(renderTarget, 2);
  8402. renderer.render(scene, cameraPY);
  8403. renderer.setRenderTarget(renderTarget, 3);
  8404. renderer.render(scene, cameraNY);
  8405. renderer.setRenderTarget(renderTarget, 4);
  8406. renderer.render(scene, cameraPZ);
  8407. renderTarget.texture.generateMipmaps = generateMipmaps;
  8408. renderer.setRenderTarget(renderTarget, 5);
  8409. renderer.render(scene, cameraNZ);
  8410. renderer.setRenderTarget(currentRenderTarget);
  8411. renderer.xr.enabled = currentXrEnabled;
  8412. };
  8413. }
  8414. CubeCamera.prototype = Object.create(Object3D.prototype);
  8415. CubeCamera.prototype.constructor = CubeCamera;
  8416. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  8417. images = images !== undefined ? images : [];
  8418. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  8419. format = format !== undefined ? format : RGBFormat;
  8420. Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8421. this.flipY = false; // Why CubeTexture._needsFlipEnvMap is necessary:
  8422. //
  8423. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  8424. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  8425. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  8426. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  8427. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  8428. // when using WebGLCubeRenderTarget.texture as a cube texture.
  8429. this._needsFlipEnvMap = true;
  8430. }
  8431. CubeTexture.prototype = Object.create(Texture.prototype);
  8432. CubeTexture.prototype.constructor = CubeTexture;
  8433. CubeTexture.prototype.isCubeTexture = true;
  8434. Object.defineProperty(CubeTexture.prototype, 'images', {
  8435. get: function get() {
  8436. return this.image;
  8437. },
  8438. set: function set(value) {
  8439. this.image = value;
  8440. }
  8441. });
  8442. var WebGLCubeRenderTarget = /*#__PURE__*/function (_WebGLRenderTarget) {
  8443. _inheritsLoose(WebGLCubeRenderTarget, _WebGLRenderTarget);
  8444. function WebGLCubeRenderTarget(size, options, dummy) {
  8445. var _this;
  8446. if (Number.isInteger(options)) {
  8447. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  8448. options = dummy;
  8449. }
  8450. _this = _WebGLRenderTarget.call(this, size, size, options) || this;
  8451. Object.defineProperty(_assertThisInitialized(_this), 'isWebGLCubeRenderTarget', {
  8452. value: true
  8453. });
  8454. options = options || {};
  8455. _this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  8456. _this.texture._needsFlipEnvMap = false;
  8457. return _this;
  8458. }
  8459. var _proto = WebGLCubeRenderTarget.prototype;
  8460. _proto.fromEquirectangularTexture = function fromEquirectangularTexture(renderer, texture) {
  8461. this.texture.type = texture.type;
  8462. this.texture.format = RGBAFormat; // see #18859
  8463. this.texture.encoding = texture.encoding;
  8464. this.texture.generateMipmaps = texture.generateMipmaps;
  8465. this.texture.minFilter = texture.minFilter;
  8466. this.texture.magFilter = texture.magFilter;
  8467. var shader = {
  8468. uniforms: {
  8469. tEquirect: {
  8470. value: null
  8471. }
  8472. },
  8473. vertexShader:
  8474. /* glsl */
  8475. "\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\tvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n\t\t\t\t\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvWorldDirection = transformDirection( position, modelMatrix );\n\n\t\t\t\t\t#include <begin_vertex>\n\t\t\t\t\t#include <project_vertex>\n\n\t\t\t\t}\n\t\t\t",
  8476. fragmentShader:
  8477. /* glsl */
  8478. "\n\n\t\t\t\tuniform sampler2D tEquirect;\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\t#include <common>\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvec3 direction = normalize( vWorldDirection );\n\n\t\t\t\t\tvec2 sampleUV = equirectUv( direction );\n\n\t\t\t\t\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\n\t\t\t\t}\n\t\t\t"
  8479. };
  8480. var geometry = new BoxGeometry(5, 5, 5);
  8481. var material = new ShaderMaterial({
  8482. name: 'CubemapFromEquirect',
  8483. uniforms: cloneUniforms(shader.uniforms),
  8484. vertexShader: shader.vertexShader,
  8485. fragmentShader: shader.fragmentShader,
  8486. side: BackSide,
  8487. blending: NoBlending
  8488. });
  8489. material.uniforms.tEquirect.value = texture;
  8490. var mesh = new Mesh(geometry, material);
  8491. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  8492. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  8493. var camera = new CubeCamera(1, 10, this);
  8494. camera.update(renderer, mesh);
  8495. texture.minFilter = currentMinFilter;
  8496. mesh.geometry.dispose();
  8497. mesh.material.dispose();
  8498. return this;
  8499. };
  8500. _proto.clear = function clear(renderer, color, depth, stencil) {
  8501. var currentRenderTarget = renderer.getRenderTarget();
  8502. for (var i = 0; i < 6; i++) {
  8503. renderer.setRenderTarget(this, i);
  8504. renderer.clear(color, depth, stencil);
  8505. }
  8506. renderer.setRenderTarget(currentRenderTarget);
  8507. };
  8508. return WebGLCubeRenderTarget;
  8509. }(WebGLRenderTarget);
  8510. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  8511. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8512. this.image = {
  8513. data: data || null,
  8514. width: width || 1,
  8515. height: height || 1
  8516. };
  8517. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8518. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8519. this.generateMipmaps = false;
  8520. this.flipY = false;
  8521. this.unpackAlignment = 1;
  8522. this.needsUpdate = true;
  8523. }
  8524. DataTexture.prototype = Object.create(Texture.prototype);
  8525. DataTexture.prototype.constructor = DataTexture;
  8526. DataTexture.prototype.isDataTexture = true;
  8527. var _sphere$1 = /*@__PURE__*/new Sphere();
  8528. var _vector$5 = /*@__PURE__*/new Vector3();
  8529. var Frustum = /*#__PURE__*/function () {
  8530. function Frustum(p0, p1, p2, p3, p4, p5) {
  8531. this.planes = [p0 !== undefined ? p0 : new Plane(), p1 !== undefined ? p1 : new Plane(), p2 !== undefined ? p2 : new Plane(), p3 !== undefined ? p3 : new Plane(), p4 !== undefined ? p4 : new Plane(), p5 !== undefined ? p5 : new Plane()];
  8532. }
  8533. var _proto = Frustum.prototype;
  8534. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  8535. var planes = this.planes;
  8536. planes[0].copy(p0);
  8537. planes[1].copy(p1);
  8538. planes[2].copy(p2);
  8539. planes[3].copy(p3);
  8540. planes[4].copy(p4);
  8541. planes[5].copy(p5);
  8542. return this;
  8543. };
  8544. _proto.clone = function clone() {
  8545. return new this.constructor().copy(this);
  8546. };
  8547. _proto.copy = function copy(frustum) {
  8548. var planes = this.planes;
  8549. for (var i = 0; i < 6; i++) {
  8550. planes[i].copy(frustum.planes[i]);
  8551. }
  8552. return this;
  8553. };
  8554. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  8555. var planes = this.planes;
  8556. var me = m.elements;
  8557. var me0 = me[0],
  8558. me1 = me[1],
  8559. me2 = me[2],
  8560. me3 = me[3];
  8561. var me4 = me[4],
  8562. me5 = me[5],
  8563. me6 = me[6],
  8564. me7 = me[7];
  8565. var me8 = me[8],
  8566. me9 = me[9],
  8567. me10 = me[10],
  8568. me11 = me[11];
  8569. var me12 = me[12],
  8570. me13 = me[13],
  8571. me14 = me[14],
  8572. me15 = me[15];
  8573. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  8574. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  8575. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  8576. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  8577. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  8578. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  8579. return this;
  8580. };
  8581. _proto.intersectsObject = function intersectsObject(object) {
  8582. var geometry = object.geometry;
  8583. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  8584. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  8585. return this.intersectsSphere(_sphere$1);
  8586. };
  8587. _proto.intersectsSprite = function intersectsSprite(sprite) {
  8588. _sphere$1.center.set(0, 0, 0);
  8589. _sphere$1.radius = 0.7071067811865476;
  8590. _sphere$1.applyMatrix4(sprite.matrixWorld);
  8591. return this.intersectsSphere(_sphere$1);
  8592. };
  8593. _proto.intersectsSphere = function intersectsSphere(sphere) {
  8594. var planes = this.planes;
  8595. var center = sphere.center;
  8596. var negRadius = -sphere.radius;
  8597. for (var i = 0; i < 6; i++) {
  8598. var distance = planes[i].distanceToPoint(center);
  8599. if (distance < negRadius) {
  8600. return false;
  8601. }
  8602. }
  8603. return true;
  8604. };
  8605. _proto.intersectsBox = function intersectsBox(box) {
  8606. var planes = this.planes;
  8607. for (var i = 0; i < 6; i++) {
  8608. var plane = planes[i]; // corner at max distance
  8609. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8610. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8611. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8612. if (plane.distanceToPoint(_vector$5) < 0) {
  8613. return false;
  8614. }
  8615. }
  8616. return true;
  8617. };
  8618. _proto.containsPoint = function containsPoint(point) {
  8619. var planes = this.planes;
  8620. for (var i = 0; i < 6; i++) {
  8621. if (planes[i].distanceToPoint(point) < 0) {
  8622. return false;
  8623. }
  8624. }
  8625. return true;
  8626. };
  8627. return Frustum;
  8628. }();
  8629. function WebGLAnimation() {
  8630. var context = null;
  8631. var isAnimating = false;
  8632. var animationLoop = null;
  8633. var requestId = null;
  8634. function onAnimationFrame(time, frame) {
  8635. animationLoop(time, frame);
  8636. requestId = context.requestAnimationFrame(onAnimationFrame);
  8637. }
  8638. return {
  8639. start: function start() {
  8640. if (isAnimating === true) return;
  8641. if (animationLoop === null) return;
  8642. requestId = context.requestAnimationFrame(onAnimationFrame);
  8643. isAnimating = true;
  8644. },
  8645. stop: function stop() {
  8646. context.cancelAnimationFrame(requestId);
  8647. isAnimating = false;
  8648. },
  8649. setAnimationLoop: function setAnimationLoop(callback) {
  8650. animationLoop = callback;
  8651. },
  8652. setContext: function setContext(value) {
  8653. context = value;
  8654. }
  8655. };
  8656. }
  8657. function WebGLAttributes(gl, capabilities) {
  8658. var isWebGL2 = capabilities.isWebGL2;
  8659. var buffers = new WeakMap();
  8660. function createBuffer(attribute, bufferType) {
  8661. var array = attribute.array;
  8662. var usage = attribute.usage;
  8663. var buffer = gl.createBuffer();
  8664. gl.bindBuffer(bufferType, buffer);
  8665. gl.bufferData(bufferType, array, usage);
  8666. attribute.onUploadCallback();
  8667. var type = 5126;
  8668. if (array instanceof Float32Array) {
  8669. type = 5126;
  8670. } else if (array instanceof Float64Array) {
  8671. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  8672. } else if (array instanceof Uint16Array) {
  8673. if (attribute.isFloat16BufferAttribute) {
  8674. if (isWebGL2) {
  8675. type = 5131;
  8676. } else {
  8677. console.warn('THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.');
  8678. }
  8679. } else {
  8680. type = 5123;
  8681. }
  8682. } else if (array instanceof Int16Array) {
  8683. type = 5122;
  8684. } else if (array instanceof Uint32Array) {
  8685. type = 5125;
  8686. } else if (array instanceof Int32Array) {
  8687. type = 5124;
  8688. } else if (array instanceof Int8Array) {
  8689. type = 5120;
  8690. } else if (array instanceof Uint8Array) {
  8691. type = 5121;
  8692. }
  8693. return {
  8694. buffer: buffer,
  8695. type: type,
  8696. bytesPerElement: array.BYTES_PER_ELEMENT,
  8697. version: attribute.version
  8698. };
  8699. }
  8700. function updateBuffer(buffer, attribute, bufferType) {
  8701. var array = attribute.array;
  8702. var updateRange = attribute.updateRange;
  8703. gl.bindBuffer(bufferType, buffer);
  8704. if (updateRange.count === -1) {
  8705. // Not using update ranges
  8706. gl.bufferSubData(bufferType, 0, array);
  8707. } else {
  8708. if (isWebGL2) {
  8709. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8710. } else {
  8711. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8712. }
  8713. updateRange.count = -1; // reset range
  8714. }
  8715. } //
  8716. function get(attribute) {
  8717. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8718. return buffers.get(attribute);
  8719. }
  8720. function remove(attribute) {
  8721. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8722. var data = buffers.get(attribute);
  8723. if (data) {
  8724. gl.deleteBuffer(data.buffer);
  8725. buffers.delete(attribute);
  8726. }
  8727. }
  8728. function update(attribute, bufferType) {
  8729. if (attribute.isGLBufferAttribute) {
  8730. var cached = buffers.get(attribute);
  8731. if (!cached || cached.version < attribute.version) {
  8732. buffers.set(attribute, {
  8733. buffer: attribute.buffer,
  8734. type: attribute.type,
  8735. bytesPerElement: attribute.elementSize,
  8736. version: attribute.version
  8737. });
  8738. }
  8739. return;
  8740. }
  8741. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8742. var data = buffers.get(attribute);
  8743. if (data === undefined) {
  8744. buffers.set(attribute, createBuffer(attribute, bufferType));
  8745. } else if (data.version < attribute.version) {
  8746. updateBuffer(data.buffer, attribute, bufferType);
  8747. data.version = attribute.version;
  8748. }
  8749. }
  8750. return {
  8751. get: get,
  8752. remove: remove,
  8753. update: update
  8754. };
  8755. }
  8756. var PlaneGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8757. _inheritsLoose(PlaneGeometry, _BufferGeometry);
  8758. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  8759. var _this;
  8760. if (width === void 0) {
  8761. width = 1;
  8762. }
  8763. if (height === void 0) {
  8764. height = 1;
  8765. }
  8766. if (widthSegments === void 0) {
  8767. widthSegments = 1;
  8768. }
  8769. if (heightSegments === void 0) {
  8770. heightSegments = 1;
  8771. }
  8772. _this = _BufferGeometry.call(this) || this;
  8773. _this.type = 'PlaneGeometry';
  8774. _this.parameters = {
  8775. width: width,
  8776. height: height,
  8777. widthSegments: widthSegments,
  8778. heightSegments: heightSegments
  8779. };
  8780. var width_half = width / 2;
  8781. var height_half = height / 2;
  8782. var gridX = Math.floor(widthSegments);
  8783. var gridY = Math.floor(heightSegments);
  8784. var gridX1 = gridX + 1;
  8785. var gridY1 = gridY + 1;
  8786. var segment_width = width / gridX;
  8787. var segment_height = height / gridY; //
  8788. var indices = [];
  8789. var vertices = [];
  8790. var normals = [];
  8791. var uvs = [];
  8792. for (var iy = 0; iy < gridY1; iy++) {
  8793. var y = iy * segment_height - height_half;
  8794. for (var ix = 0; ix < gridX1; ix++) {
  8795. var x = ix * segment_width - width_half;
  8796. vertices.push(x, -y, 0);
  8797. normals.push(0, 0, 1);
  8798. uvs.push(ix / gridX);
  8799. uvs.push(1 - iy / gridY);
  8800. }
  8801. }
  8802. for (var _iy = 0; _iy < gridY; _iy++) {
  8803. for (var _ix = 0; _ix < gridX; _ix++) {
  8804. var a = _ix + gridX1 * _iy;
  8805. var b = _ix + gridX1 * (_iy + 1);
  8806. var c = _ix + 1 + gridX1 * (_iy + 1);
  8807. var d = _ix + 1 + gridX1 * _iy;
  8808. indices.push(a, b, d);
  8809. indices.push(b, c, d);
  8810. }
  8811. }
  8812. _this.setIndex(indices);
  8813. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8814. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8815. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8816. return _this;
  8817. }
  8818. return PlaneGeometry;
  8819. }(BufferGeometry);
  8820. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8821. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8822. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8823. var aomap_fragment = "#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\treflectedLight.indirectDiffuse *= ambientOcclusion;\n\t#if defined( USE_ENVMAP ) && defined( STANDARD )\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );\n\t#endif\n#endif";
  8824. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8825. var begin_vertex = "vec3 transformed = vec3( position );";
  8826. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8827. var bsdfs = "vec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\treturn vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n#else\n\tif( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t}\n\treturn 1.0;\n#endif\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nvec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );\n\tvec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;\n\treturn Fr * fresnel + F0;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\treturn 1.0 / ( gl * gv );\n}\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( incidentLight.direction + viewDir );\n\tfloat dotNL = saturate( dot( normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( G * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\nvec3 BRDF_Specular_GGX_Environment( const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\treturn specularColor * brdf.x + brdf.y;\n}\nvoid BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tvec3 F = F_Schlick_RoughnessDependent( specularColor, dotNV, roughness );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\tvec3 FssEss = F * brdf.x + brdf.y;\n\tfloat Ess = brdf.x + brdf.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nfloat G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie(float roughness, float NoH) {\n\tfloat invAlpha = 1.0 / roughness;\n\tfloat cos2h = NoH * NoH;\n\tfloat sin2h = max(1.0 - cos2h, 0.0078125);\treturn (2.0 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2.0 * PI);\n}\nfloat V_Neubelt(float NoV, float NoL) {\n\treturn saturate(1.0 / (4.0 * (NoL + NoV - NoL * NoV)));\n}\nvec3 BRDF_Specular_Sheen( const in float roughness, const in vec3 L, const in GeometricContext geometry, vec3 specularColor ) {\n\tvec3 N = geometry.normal;\n\tvec3 V = geometry.viewDir;\n\tvec3 H = normalize( V + L );\n\tfloat dotNH = saturate( dot( N, H ) );\n\treturn specularColor * D_Charlie( roughness, dotNH ) * V_Neubelt( dot(N, V), dot(N, L) );\n}\n#endif";
  8828. var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 ) * faceDirection;\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif";
  8829. var clipping_planes_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvec4 plane;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\tplane = clippingPlanes[ i ];\n\t\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\t}\n\t#pragma unroll_loop_end\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\tbool clipped = true;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\tif ( clipped ) discard;\n\t#endif\n#endif";
  8830. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8831. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8832. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8833. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8834. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8835. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8836. var color_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvColor = vec3( 1.0 );\n#endif\n#ifdef USE_COLOR\n\tvColor.xyz *= color.xyz;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.xyz *= instanceColor.xyz;\n#endif";
  8837. var common = "#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement(a) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract(sin(sn) * c);\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat max3( vec3 v ) { return max( max( v.x, v.y ), v.z ); }\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\nstruct GeometricContext {\n\tvec3 position;\n\tvec3 normal;\n\tvec3 viewDir;\n#ifdef CLEARCOAT\n\tvec3 clearcoatNormal;\n#endif\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\tfloat distance = dot( planeNormal, point - pointOnPlane );\n\treturn - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nfloat linearToRelativeLuminance( const in vec3 color ) {\n\tvec3 weights = vec3( 0.2126, 0.7152, 0.0722 );\n\treturn dot( weights, color.rgb );\n}\nbool isPerspectiveMatrix( mat4 m ) {\n\treturn m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n\tfloat u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n\tfloat v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\treturn vec2( u, v );\n}";
  8838. var cube_uv_reflection_fragment = "#ifdef ENVMAP_TYPE_CUBE_UV\n\t#define cubeUV_maxMipLevel 8.0\n\t#define cubeUV_minMipLevel 4.0\n\t#define cubeUV_maxTileSize 256.0\n\t#define cubeUV_minTileSize 16.0\n\tfloat getFace( vec3 direction ) {\n\t\tvec3 absDirection = abs( direction );\n\t\tfloat face = - 1.0;\n\t\tif ( absDirection.x > absDirection.z ) {\n\t\t\tif ( absDirection.x > absDirection.y )\n\t\t\t\tface = direction.x > 0.0 ? 0.0 : 3.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t} else {\n\t\t\tif ( absDirection.z > absDirection.y )\n\t\t\t\tface = direction.z > 0.0 ? 2.0 : 5.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t}\n\t\treturn face;\n\t}\n\tvec2 getUV( vec3 direction, float face ) {\n\t\tvec2 uv;\n\t\tif ( face == 0.0 ) {\n\t\t\tuv = vec2( direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 1.0 ) {\n\t\t\tuv = vec2( - direction.x, - direction.z ) / abs( direction.y );\n\t\t} else if ( face == 2.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.y ) / abs( direction.z );\n\t\t} else if ( face == 3.0 ) {\n\t\t\tuv = vec2( - direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 4.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.z ) / abs( direction.y );\n\t\t} else {\n\t\t\tuv = vec2( direction.x, direction.y ) / abs( direction.z );\n\t\t}\n\t\treturn 0.5 * ( uv + 1.0 );\n\t}\n\tvec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {\n\t\tfloat face = getFace( direction );\n\t\tfloat filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );\n\t\tmipInt = max( mipInt, cubeUV_minMipLevel );\n\t\tfloat faceSize = exp2( mipInt );\n\t\tfloat texelSize = 1.0 / ( 3.0 * cubeUV_maxTileSize );\n\t\tvec2 uv = getUV( direction, face ) * ( faceSize - 1.0 );\n\t\tvec2 f = fract( uv );\n\t\tuv += 0.5 - f;\n\t\tif ( face > 2.0 ) {\n\t\t\tuv.y += faceSize;\n\t\t\tface -= 3.0;\n\t\t}\n\t\tuv.x += face * faceSize;\n\t\tif ( mipInt < cubeUV_maxMipLevel ) {\n\t\t\tuv.y += 2.0 * cubeUV_maxTileSize;\n\t\t}\n\t\tuv.y += filterInt * 2.0 * cubeUV_minTileSize;\n\t\tuv.x += 3.0 * max( 0.0, cubeUV_maxTileSize - 2.0 * faceSize );\n\t\tuv *= texelSize;\n\t\tvec3 tl = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.x += texelSize;\n\t\tvec3 tr = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.y += texelSize;\n\t\tvec3 br = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.x -= texelSize;\n\t\tvec3 bl = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tvec3 tm = mix( tl, tr, f.x );\n\t\tvec3 bm = mix( bl, br, f.x );\n\t\treturn mix( tm, bm, f.y );\n\t}\n\t#define r0 1.0\n\t#define v0 0.339\n\t#define m0 - 2.0\n\t#define r1 0.8\n\t#define v1 0.276\n\t#define m1 - 1.0\n\t#define r4 0.4\n\t#define v4 0.046\n\t#define m4 2.0\n\t#define r5 0.305\n\t#define v5 0.016\n\t#define m5 3.0\n\t#define r6 0.21\n\t#define v6 0.0038\n\t#define m6 4.0\n\tfloat roughnessToMip( float roughness ) {\n\t\tfloat mip = 0.0;\n\t\tif ( roughness >= r1 ) {\n\t\t\tmip = ( r0 - roughness ) * ( m1 - m0 ) / ( r0 - r1 ) + m0;\n\t\t} else if ( roughness >= r4 ) {\n\t\t\tmip = ( r1 - roughness ) * ( m4 - m1 ) / ( r1 - r4 ) + m1;\n\t\t} else if ( roughness >= r5 ) {\n\t\t\tmip = ( r4 - roughness ) * ( m5 - m4 ) / ( r4 - r5 ) + m4;\n\t\t} else if ( roughness >= r6 ) {\n\t\t\tmip = ( r5 - roughness ) * ( m6 - m5 ) / ( r5 - r6 ) + m5;\n\t\t} else {\n\t\t\tmip = - 2.0 * log2( 1.16 * roughness );\t\t}\n\t\treturn mip;\n\t}\n\tvec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {\n\t\tfloat mip = clamp( roughnessToMip( roughness ), m0, cubeUV_maxMipLevel );\n\t\tfloat mipF = fract( mip );\n\t\tfloat mipInt = floor( mip );\n\t\tvec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );\n\t\tif ( mipF == 0.0 ) {\n\t\t\treturn vec4( color0, 1.0 );\n\t\t} else {\n\t\t\tvec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );\n\t\t\treturn vec4( mix( color0, color1, mipF ), 1.0 );\n\t\t}\n\t}\n#endif";
  8839. var defaultnormal_vertex = "vec3 transformedNormal = objectNormal;\n#ifdef USE_INSTANCING\n\tmat3 m = mat3( instanceMatrix );\n\ttransformedNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );\n\ttransformedNormal = m * transformedNormal;\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = ( modelViewMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif";
  8840. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8841. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8842. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8843. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8844. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8845. var encodings_pars_fragment = "\nvec4 LinearToLinear( in vec4 value ) {\n\treturn value;\n}\nvec4 GammaToLinear( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( gammaFactor ) ), value.a );\n}\nvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( 1.0 / gammaFactor ) ), value.a );\n}\nvec4 sRGBToLinear( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );\n}\nvec4 LinearTosRGB( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}\nvec4 RGBEToLinear( in vec4 value ) {\n\treturn vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );\n}\nvec4 LinearToRGBE( in vec4 value ) {\n\tfloat maxComponent = max( max( value.r, value.g ), value.b );\n\tfloat fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );\n\treturn vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );\n}\nvec4 RGBMToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * value.a * maxRange, 1.0 );\n}\nvec4 LinearToRGBM( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat M = clamp( maxRGB / maxRange, 0.0, 1.0 );\n\tM = ceil( M * 255.0 ) / 255.0;\n\treturn vec4( value.rgb / ( M * maxRange ), M );\n}\nvec4 RGBDToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );\n}\nvec4 LinearToRGBD( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat D = max( maxRange / maxRGB, 1.0 );\n\tD = clamp( floor( D ) / 255.0, 0.0, 1.0 );\n\treturn vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );\n}\nconst mat3 cLogLuvM = mat3( 0.2209, 0.3390, 0.4184, 0.1138, 0.6780, 0.7319, 0.0102, 0.1130, 0.2969 );\nvec4 LinearToLogLuv( in vec4 value ) {\n\tvec3 Xp_Y_XYZp = cLogLuvM * value.rgb;\n\tXp_Y_XYZp = max( Xp_Y_XYZp, vec3( 1e-6, 1e-6, 1e-6 ) );\n\tvec4 vResult;\n\tvResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;\n\tfloat Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;\n\tvResult.w = fract( Le );\n\tvResult.z = ( Le - ( floor( vResult.w * 255.0 ) ) / 255.0 ) / 255.0;\n\treturn vResult;\n}\nconst mat3 cLogLuvInverseM = mat3( 6.0014, -2.7008, -1.7996, -1.3320, 3.1029, -5.7721, 0.3008, -1.0882, 5.6268 );\nvec4 LogLuvToLinear( in vec4 value ) {\n\tfloat Le = value.z * 255.0 + value.w;\n\tvec3 Xp_Y_XYZp;\n\tXp_Y_XYZp.y = exp2( ( Le - 127.0 ) / 2.0 );\n\tXp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;\n\tXp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;\n\tvec3 vRGB = cLogLuvInverseM * Xp_Y_XYZp.rgb;\n\treturn vec4( max( vRGB, 0.0 ), 1.0 );\n}";
  8846. var envmap_fragment = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 envColor = textureCubeUV( envMap, reflectVec, 0.0 );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\t#ifndef ENVMAP_TYPE_CUBE_UV\n\t\tenvColor = envMapTexelToLinear( envColor );\n\t#endif\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif";
  8847. var envmap_common_pars_fragment = "#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform float flipEnvMap;\n\tuniform int maxMipLevel;\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\t\n#endif";
  8848. var envmap_pars_fragment = "#ifdef USE_ENVMAP\n\tuniform float reflectivity;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\tvarying vec3 vWorldPosition;\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif";
  8849. var envmap_pars_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) ||defined( PHONG )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\t\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif";
  8850. var envmap_vertex = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif";
  8851. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8852. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8853. var fog_fragment = "#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = 1.0 - exp( - fogDensity * fogDensity * fogDepth * fogDepth );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, fogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif";
  8854. var fog_pars_fragment = "#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float fogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif";
  8855. var gradientmap_pars_fragment = "#ifdef USE_GRADIENTMAP\n\tuniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\tfloat dotNL = dot( normal, lightDirection );\n\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t#ifdef USE_GRADIENTMAP\n\t\treturn texture2D( gradientMap, coord ).rgb;\n\t#else\n\t\treturn ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );\n\t#endif\n}";
  8856. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8857. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8858. var lights_lambert_vertex = "vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\nvIndirectFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n\tvLightBack = vec3( 0.0 );\n\tvIndirectBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\nvIndirectFront += getAmbientLightIrradiance( ambientLightColor );\nvIndirectFront += getLightProbeIrradiance( lightProbe, geometry );\n#ifdef DOUBLE_SIDED\n\tvIndirectBack += getAmbientLightIrradiance( ambientLightColor );\n\tvIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry );\n#endif\n#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tgetPointDirectLightIrradiance( pointLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tgetSpotDirectLightIrradiance( spotLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tgetDirectionalDirectLightIrradiance( directionalLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\tvIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif";
  8859. var lights_pars_begin = "uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\nuniform vec3 lightProbe[ 9 ];\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in GeometricContext geometry ) {\n\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treturn irradiance;\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tdirectLight.color = directionalLight.color;\n\t\tdirectLight.direction = directionalLight.direction;\n\t\tdirectLight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = pointLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tdirectLight.color = pointLight.color;\n\t\tdirectLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\n\t\tdirectLight.visible = ( directLight.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = spotLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tfloat angleCos = dot( directLight.direction, spotLight.direction );\n\t\tif ( angleCos > spotLight.coneCos ) {\n\t\t\tfloat spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\t\tdirectLight.color = spotLight.color;\n\t\t\tdirectLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tdirectLight.visible = true;\n\t\t} else {\n\t\t\tdirectLight.color = vec3( 0.0 );\n\t\t\tdirectLight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n\t\tfloat dotNL = dot( geometry.normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tirradiance *= PI;\n\t\t#endif\n\t\treturn irradiance;\n\t}\n#endif";
  8860. var envmap_physical_pars_fragment = "#if defined( USE_ENVMAP )\n\t#ifdef ENVMAP_MODE_REFRACTION\n\t\tuniform float refractionRatio;\n\t#endif\n\tvec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\n\t\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 );\n\t\t#else\n\t\t\tvec4 envMapColor = vec4( 0.0 );\n\t\t#endif\n\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t}\n\tfloat getSpecularMIPLevel( const in float roughness, const in int maxMIPLevel ) {\n\t\tfloat maxMIPLevelScalar = float( maxMIPLevel );\n\t\tfloat sigma = PI * roughness * roughness / ( 1.0 + roughness );\n\t\tfloat desiredMIPLevel = maxMIPLevelScalar + log2( sigma );\n\t\treturn clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n\t}\n\tvec3 getLightProbeIndirectRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in int maxMIPLevel ) {\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( -viewDir, normal );\n\t\t\treflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( -viewDir, normal, refractionRatio );\n\t\t#endif\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tfloat specularMIPLevel = getSpecularMIPLevel( roughness, maxMIPLevel );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );\n\t\t#endif\n\t\treturn envMapColor.rgb * envMapIntensity;\n\t}\n#endif";
  8861. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8862. var lights_toon_pars_fragment = "varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct ToonMaterial {\n\tvec3 diffuseColor;\n};\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\tvec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Toon\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Toon\n#define Material_LightProbeLOD( material )\t(0)";
  8863. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8864. var lights_phong_pars_fragment = "varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct BlinnPhongMaterial {\n\tvec3 diffuseColor;\n\tvec3 specularColor;\n\tfloat specularShininess;\n\tfloat specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong\n#define Material_LightProbeLOD( material )\t(0)";
  8865. var lights_physical_fragment = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.specularRoughness = max( roughnessFactor, 0.0525 );material.specularRoughness += geometryRoughness;\nmaterial.specularRoughness = min( material.specularRoughness, 1.0 );\n#ifdef REFLECTIVITY\n\tmaterial.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );\n#endif\n#ifdef CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheen;\n#endif";
  8866. var lights_physical_pars_fragment = "struct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tfloat specularRoughness;\n\tvec3 specularColor;\n#ifdef CLEARCOAT\n\tfloat clearcoat;\n\tfloat clearcoatRoughness;\n#endif\n#ifdef USE_SHEEN\n\tvec3 sheenColor;\n#endif\n};\n#define MAXIMUM_SPECULAR_COEFFICIENT 0.16\n#define DEFAULT_SPECULAR_COEFFICIENT 0.04\nfloat clearcoatDHRApprox( const in float roughness, const in float dotNL ) {\n\treturn DEFAULT_SPECULAR_COEFFICIENT + ( 1.0 - DEFAULT_SPECULAR_COEFFICIENT ) * ( pow( 1.0 - dotNL, 5.0 ) * pow( 1.0 - roughness, 2.0 ) );\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometry.normal;\n\t\tvec3 viewDir = geometry.viewDir;\n\t\tvec3 position = geometry.position;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.specularRoughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\t#ifdef CLEARCOAT\n\t\tfloat ccDotNL = saturate( dot( geometry.clearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = ccDotNL * directLight.color;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tccIrradiance *= PI;\n\t\t#endif\n\t\tfloat clearcoatDHR = material.clearcoat * clearcoatDHRApprox( material.clearcoatRoughness, ccDotNL );\n\t\treflectedLight.directSpecular += ccIrradiance * material.clearcoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.clearcoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearcoatRoughness );\n\t#else\n\t\tfloat clearcoatDHR = 0.0;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\treflectedLight.directSpecular += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Specular_Sheen(\n\t\t\tmaterial.specularRoughness,\n\t\t\tdirectLight.direction,\n\t\t\tgeometry,\n\t\t\tmaterial.sheenColor\n\t\t);\n\t#else\n\t\treflectedLight.directSpecular += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.normal, material.specularColor, material.specularRoughness);\n\t#endif\n\treflectedLight.directDiffuse += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifdef CLEARCOAT\n\t\tfloat ccDotNV = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular += clearcoatRadiance * material.clearcoat * BRDF_Specular_GGX_Environment( geometry.viewDir, geometry.clearcoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearcoatRoughness );\n\t\tfloat ccDotNL = ccDotNV;\n\t\tfloat clearcoatDHR = material.clearcoat * clearcoatDHRApprox( material.clearcoatRoughness, ccDotNL );\n\t#else\n\t\tfloat clearcoatDHR = 0.0;\n\t#endif\n\tfloat clearcoatInv = 1.0 - clearcoatDHR;\n\tvec3 singleScattering = vec3( 0.0 );\n\tvec3 multiScattering = vec3( 0.0 );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\tBRDF_Specular_Multiscattering_Environment( geometry, material.specularColor, material.specularRoughness, singleScattering, multiScattering );\n\tvec3 diffuse = material.diffuseColor * ( 1.0 - ( singleScattering + multiScattering ) );\n\treflectedLight.indirectSpecular += clearcoatInv * radiance * singleScattering;\n\treflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\n\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}";
  8867. var lights_fragment_begin = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n#ifdef CLEARCOAT\n\tgeometry.clearcoatNormal = clearcoatNormal;\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointDirectLightIrradiance( pointLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotDirectLightIrradiance( spotLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\tirradiance += getLightProbeIrradiance( lightProbe, geometry );\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif";
  8868. var lights_fragment_maps = "#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\t\tvec3 lightMapIrradiance = lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tlightMapIrradiance *= PI;\n\t\t#endif\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tiblIrradiance += getLightProbeIndirectIrradiance( geometry, maxMipLevel );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tradiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.normal, material.specularRoughness, maxMipLevel );\n\t#ifdef CLEARCOAT\n\t\tclearcoatRadiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.clearcoatNormal, material.clearcoatRoughness, maxMipLevel );\n\t#endif\n#endif";
  8869. var lights_fragment_end = "#if defined( RE_IndirectDiffuse )\n\tRE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometry, material, reflectedLight );\n#endif";
  8870. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  8871. var logdepthbuf_pars_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif";
  8872. var logdepthbuf_pars_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t\tvarying float vIsPerspective;\n\t#else\n\t\tuniform float logDepthBufFC;\n\t#endif\n#endif";
  8873. var logdepthbuf_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n\t#else\n\t\tif ( isPerspectiveMatrix( projectionMatrix ) ) {\n\t\t\tgl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n\t\t\tgl_Position.z *= gl_Position.w;\n\t\t}\n\t#endif\n#endif";
  8874. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8875. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8876. var map_particle_fragment = "#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n#endif\n#ifdef USE_MAP\n\tvec4 mapTexel = texture2D( map, uv );\n\tdiffuseColor *= mapTexelToLinear( mapTexel );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif";
  8877. var map_particle_pars_fragment = "#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tuniform mat3 uvTransform;\n#endif\n#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8878. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8879. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8880. var morphnormal_vertex = "#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\tobjectNormal += morphNormal0 * morphTargetInfluences[ 0 ];\n\tobjectNormal += morphNormal1 * morphTargetInfluences[ 1 ];\n\tobjectNormal += morphNormal2 * morphTargetInfluences[ 2 ];\n\tobjectNormal += morphNormal3 * morphTargetInfluences[ 3 ];\n#endif";
  8881. var morphtarget_pars_vertex = "#ifdef USE_MORPHTARGETS\n\tuniform float morphTargetBaseInfluence;\n\t#ifndef USE_MORPHNORMALS\n\t\tuniform float morphTargetInfluences[ 8 ];\n\t#else\n\t\tuniform float morphTargetInfluences[ 4 ];\n\t#endif\n#endif";
  8882. var morphtarget_vertex = "#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\ttransformed += morphTarget0 * morphTargetInfluences[ 0 ];\n\ttransformed += morphTarget1 * morphTargetInfluences[ 1 ];\n\ttransformed += morphTarget2 * morphTargetInfluences[ 2 ];\n\ttransformed += morphTarget3 * morphTargetInfluences[ 3 ];\n\t#ifndef USE_MORPHNORMALS\n\t\ttransformed += morphTarget4 * morphTargetInfluences[ 4 ];\n\t\ttransformed += morphTarget5 * morphTargetInfluences[ 5 ];\n\t\ttransformed += morphTarget6 * morphTargetInfluences[ 6 ];\n\t\ttransformed += morphTarget7 * morphTargetInfluences[ 7 ];\n\t#endif\n#endif";
  8883. var normal_fragment_begin = "float faceDirection = float( gl_FrontFacing ) * 2.0 - 1.0;\n#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\t#ifdef USE_TANGENT\n\t\tvec3 tangent = normalize( vTangent );\n\t\tvec3 bitangent = normalize( vBitangent );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\ttangent = tangent * faceDirection;\n\t\t\tbitangent = bitangent * faceDirection;\n\t\t#endif\n\t\t#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t#endif\n\t#endif\n#endif\nvec3 geometryNormal = normal;";
  8884. var normal_fragment_maps = "#ifdef OBJECTSPACE_NORMALMAP\n\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( TANGENTSPACE_NORMALMAP )\n\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\t#ifdef USE_TANGENT\n\t\tnormal = normalize( vTBN * mapN );\n\t#else\n\t\tnormal = perturbNormal2Arb( -vViewPosition, normal, mapN, faceDirection );\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif";
  8885. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( TANGENTSPACE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP ) )\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 mapN, float faceDirection ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\n\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\tvec3 N = normalize( surf_norm );\n\t\tmat3 tsn = mat3( S, T, N );\n\t\tmapN.xy *= faceDirection;\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif";
  8886. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8887. var clearcoat_normal_fragment_maps = "#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\t#ifdef USE_TANGENT\n\t\tclearcoatNormal = normalize( vTBN * clearcoatMapN );\n\t#else\n\t\tclearcoatNormal = perturbNormal2Arb( - vViewPosition, clearcoatNormal, clearcoatMapN, faceDirection );\n\t#endif\n#endif";
  8888. var clearcoat_pars_fragment = "#ifdef USE_CLEARCOATMAP\n\tuniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform sampler2D clearcoatRoughnessMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearcoatNormalMap;\n\tuniform vec2 clearcoatNormalScale;\n#endif";
  8889. var packing = "vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\nconst float ShiftRight8 = 1. / 256.;\nvec4 packDepthToRGBA( const in float v ) {\n\tvec4 r = vec4( fract( v * PackFactors ), v );\n\tr.yzw -= r.xyz * ShiftRight8;\treturn r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors );\n}\nvec4 pack2HalfToRGBA( vec2 v ) {\n\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ));\n\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w);\n}\nvec2 unpackRGBATo2Half( vec4 v ) {\n\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n\treturn linearClipZ * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn (( near + viewZ ) * far ) / (( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * invClipZ - far );\n}";
  8890. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8891. var project_vertex = "vec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_INSTANCING\n\tmvPosition = instanceMatrix * mvPosition;\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;";
  8892. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8893. var dithering_pars_fragment = "#ifdef DITHERING\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif";
  8894. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8895. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8896. var shadowmap_pars_fragment = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tvec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {\n\t\treturn unpackRGBATo2Half( texture2D( shadow, uv ) );\n\t}\n\tfloat VSMShadow (sampler2D shadow, vec2 uv, float compare ){\n\t\tfloat occlusion = 1.0;\n\t\tvec2 distribution = texture2DDistribution( shadow, uv );\n\t\tfloat hard_shadow = step( compare , distribution.x );\n\t\tif (hard_shadow != 1.0 ) {\n\t\t\tfloat distance = compare - distribution.x ;\n\t\t\tfloat variance = max( 0.00000, distribution.y * distribution.y );\n\t\t\tfloat softness_probability = variance / (variance + distance * distance );\t\t\tsoftness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 );\t\t\tocclusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );\n\t\t}\n\t\treturn occlusion;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n\t\tbool inFrustum = all( inFrustumVec );\n\t\tbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\t\tbool frustumTest = all( frustumTestVec );\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tfloat dx2 = dx0 / 2.0;\n\t\t\tfloat dy2 = dy0 / 2.0;\n\t\t\tfloat dx3 = dx1 / 2.0;\n\t\t\tfloat dy3 = dy1 / 2.0;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 17.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx = texelSize.x;\n\t\t\tfloat dy = texelSize.y;\n\t\t\tvec2 uv = shadowCoord.xy;\n\t\t\tvec2 f = fract( uv * shadowMapSize + 0.5 );\n\t\t\tuv -= f * texelSize;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, uv, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ), \n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ), \n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t f.y )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_VSM )\n\t\t\tshadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn shadow;\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tfloat dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\tdp += shadowBias;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\treturn (\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\treturn texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t#endif\n\t}\n#endif";
  8897. var shadowmap_pars_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif";
  8898. var shadowmap_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0 || NUM_SPOT_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0\n\t\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\tvec4 shadowWorldPosition;\n\t#endif\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n#endif";
  8899. var shadowmask_pars_fragment = "float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}";
  8900. var skinbase_vertex = "#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif";
  8901. var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform highp sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif";
  8902. var skinning_vertex = "#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif";
  8903. var skinnormal_vertex = "#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif";
  8904. var specularmap_fragment = "float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif";
  8905. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8906. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8907. var tonemapping_pars_fragment = "#ifndef saturate\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 RRTAndODTFit( vec3 v ) {\n\tvec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n\tvec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n\treturn a / b;\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tconst mat3 ACESInputMat = mat3(\n\t\tvec3( 0.59719, 0.07600, 0.02840 ),\t\tvec3( 0.35458, 0.90834, 0.13383 ),\n\t\tvec3( 0.04823, 0.01566, 0.83777 )\n\t);\n\tconst mat3 ACESOutputMat = mat3(\n\t\tvec3( 1.60475, -0.10208, -0.00327 ),\t\tvec3( -0.53108, 1.10813, -0.07276 ),\n\t\tvec3( -0.07367, -0.00605, 1.07602 )\n\t);\n\tcolor *= toneMappingExposure / 0.6;\n\tcolor = ACESInputMat * color;\n\tcolor = RRTAndODTFit( color );\n\tcolor = ACESOutputMat * color;\n\treturn saturate( color );\n}\nvec3 CustomToneMapping( vec3 color ) { return color; }";
  8908. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8909. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8910. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8911. var uv_pars_vertex = "#ifdef USE_UV\n\t#ifdef UVS_VERTEX_ONLY\n\t\tvec2 vUv;\n\t#else\n\t\tvarying vec2 vUv;\n\t#endif\n\tuniform mat3 uvTransform;\n#endif";
  8912. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8913. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8914. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n\tuniform mat3 uv2Transform;\n#endif";
  8915. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8916. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = vec4( transformed, 1.0 );\n\t#ifdef USE_INSTANCING\n\t\tworldPosition = instanceMatrix * worldPosition;\n\t#endif\n\tworldPosition = modelMatrix * worldPosition;\n#endif";
  8917. var background_frag = "uniform sampler2D t2D;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  8918. var background_vert = "varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}";
  8919. var cube_frag = "#include <envmap_common_pars_fragment>\nuniform float opacity;\nvarying vec3 vWorldDirection;\n#include <cube_uv_reflection_fragment>\nvoid main() {\n\tvec3 vReflect = vWorldDirection;\n\t#include <envmap_fragment>\n\tgl_FragColor = envColor;\n\tgl_FragColor.a *= opacity;\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  8920. var cube_vert = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}";
  8921. var depth_frag = "#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <logdepthbuf_fragment>\n\tfloat fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( fragCoordZ );\n\t#endif\n}";
  8922. var depth_vert = "#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvHighPrecisionZW = gl_Position.zw;\n}";
  8923. var distanceRGBA_frag = "#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}";
  8924. var distanceRGBA_vert = "#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition.xyz;\n}";
  8925. var equirect_frag = "uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV = equirectUv( direction );\n\tvec4 texColor = texture2D( tEquirect, sampleUV );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  8926. var equirect_vert = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}";
  8927. var linedashed_frag = "uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <color_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";
  8928. var linedashed_vert = "uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";
  8929. var meshbasic_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\n\t\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\t\treflectedLight.indirectDiffuse += lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include <aomap_fragment>\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  8930. var meshbasic_vert = "#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_ENVMAP\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <envmap_vertex>\n\t#include <fog_vertex>\n}";
  8931. var meshlambert_frag = "uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <emissivemap_fragment>\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.indirectDiffuse += ( gl_FrontFacing ) ? vIndirectFront : vIndirectBack;\n\t#else\n\t\treflectedLight.indirectDiffuse += vIndirectFront;\n\t#endif\n\t#include <lightmap_fragment>\n\treflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n\t#else\n\t\treflectedLight.directDiffuse = vLightFront;\n\t#endif\n\treflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  8932. var meshlambert_vert = "#define LAMBERT\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <lights_lambert_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  8933. var meshmatcap_frag = "#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t\tmatcapColor = matcapTexelToLinear( matcapColor );\n\t#else\n\t\tvec4 matcapColor = vec4( 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  8934. var meshmatcap_vert = "#define MATCAP\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <color_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#ifndef FLAT_SHADED\n\t\tvNormal = normalize( transformedNormal );\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n\tvViewPosition = - mvPosition.xyz;\n}";
  8935. var meshtoon_frag = "#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <lights_toon_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_toon_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  8936. var meshtoon_vert = "#define TOON\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  8937. var meshphong_frag = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  8938. var meshphong_vert = "#define PHONG\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  8939. var meshphysical_frag = "#define STANDARD\n#ifdef PHYSICAL\n\t#define REFLECTIVITY\n\t#define CLEARCOAT\n\t#define TRANSMISSION\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef TRANSMISSION\n\tuniform float transmission;\n#endif\n#ifdef REFLECTIVITY\n\tuniform float reflectivity;\n#endif\n#ifdef CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheen;\n#endif\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <transmissionmap_pars_fragment>\n#include <bsdfs>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <lights_physical_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#ifdef TRANSMISSION\n\t\tfloat totalTransmission = transmission;\n\t#endif\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <transmissionmap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#ifdef TRANSMISSION\n\t\tdiffuseColor.a *= mix( saturate( 1. - totalTransmission + linearToRelativeLuminance( reflectedLight.directSpecular + reflectedLight.indirectSpecular ) ), 1.0, metalness );\n\t#endif\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  8940. var meshphysical_vert = "#define STANDARD\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  8941. var normal_frag = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}";
  8942. var normal_vert = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}";
  8943. var points_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_particle_fragment>\n\t#include <color_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";
  8944. var points_vert = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <fog_vertex>\n}";
  8945. var shadow_frag = "uniform vec3 color;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  8946. var shadow_vert = "#include <common>\n#include <fog_pars_vertex>\n#include <shadowmap_pars_vertex>\nvoid main() {\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  8947. var sprite_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  8948. var sprite_vert = "uniform float rotation;\nuniform vec2 center;\n#include <common>\n#include <uv_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\tvec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n\tvec2 scale;\n\tscale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n\tscale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";
  8949. var ShaderChunk = {
  8950. alphamap_fragment: alphamap_fragment,
  8951. alphamap_pars_fragment: alphamap_pars_fragment,
  8952. alphatest_fragment: alphatest_fragment,
  8953. aomap_fragment: aomap_fragment,
  8954. aomap_pars_fragment: aomap_pars_fragment,
  8955. begin_vertex: begin_vertex,
  8956. beginnormal_vertex: beginnormal_vertex,
  8957. bsdfs: bsdfs,
  8958. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8959. clipping_planes_fragment: clipping_planes_fragment,
  8960. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8961. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8962. clipping_planes_vertex: clipping_planes_vertex,
  8963. color_fragment: color_fragment,
  8964. color_pars_fragment: color_pars_fragment,
  8965. color_pars_vertex: color_pars_vertex,
  8966. color_vertex: color_vertex,
  8967. common: common,
  8968. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8969. defaultnormal_vertex: defaultnormal_vertex,
  8970. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8971. displacementmap_vertex: displacementmap_vertex,
  8972. emissivemap_fragment: emissivemap_fragment,
  8973. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8974. encodings_fragment: encodings_fragment,
  8975. encodings_pars_fragment: encodings_pars_fragment,
  8976. envmap_fragment: envmap_fragment,
  8977. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8978. envmap_pars_fragment: envmap_pars_fragment,
  8979. envmap_pars_vertex: envmap_pars_vertex,
  8980. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8981. envmap_vertex: envmap_vertex,
  8982. fog_vertex: fog_vertex,
  8983. fog_pars_vertex: fog_pars_vertex,
  8984. fog_fragment: fog_fragment,
  8985. fog_pars_fragment: fog_pars_fragment,
  8986. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8987. lightmap_fragment: lightmap_fragment,
  8988. lightmap_pars_fragment: lightmap_pars_fragment,
  8989. lights_lambert_vertex: lights_lambert_vertex,
  8990. lights_pars_begin: lights_pars_begin,
  8991. lights_toon_fragment: lights_toon_fragment,
  8992. lights_toon_pars_fragment: lights_toon_pars_fragment,
  8993. lights_phong_fragment: lights_phong_fragment,
  8994. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8995. lights_physical_fragment: lights_physical_fragment,
  8996. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8997. lights_fragment_begin: lights_fragment_begin,
  8998. lights_fragment_maps: lights_fragment_maps,
  8999. lights_fragment_end: lights_fragment_end,
  9000. logdepthbuf_fragment: logdepthbuf_fragment,
  9001. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  9002. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  9003. logdepthbuf_vertex: logdepthbuf_vertex,
  9004. map_fragment: map_fragment,
  9005. map_pars_fragment: map_pars_fragment,
  9006. map_particle_fragment: map_particle_fragment,
  9007. map_particle_pars_fragment: map_particle_pars_fragment,
  9008. metalnessmap_fragment: metalnessmap_fragment,
  9009. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  9010. morphnormal_vertex: morphnormal_vertex,
  9011. morphtarget_pars_vertex: morphtarget_pars_vertex,
  9012. morphtarget_vertex: morphtarget_vertex,
  9013. normal_fragment_begin: normal_fragment_begin,
  9014. normal_fragment_maps: normal_fragment_maps,
  9015. normalmap_pars_fragment: normalmap_pars_fragment,
  9016. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  9017. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  9018. clearcoat_pars_fragment: clearcoat_pars_fragment,
  9019. packing: packing,
  9020. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  9021. project_vertex: project_vertex,
  9022. dithering_fragment: dithering_fragment,
  9023. dithering_pars_fragment: dithering_pars_fragment,
  9024. roughnessmap_fragment: roughnessmap_fragment,
  9025. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  9026. shadowmap_pars_fragment: shadowmap_pars_fragment,
  9027. shadowmap_pars_vertex: shadowmap_pars_vertex,
  9028. shadowmap_vertex: shadowmap_vertex,
  9029. shadowmask_pars_fragment: shadowmask_pars_fragment,
  9030. skinbase_vertex: skinbase_vertex,
  9031. skinning_pars_vertex: skinning_pars_vertex,
  9032. skinning_vertex: skinning_vertex,
  9033. skinnormal_vertex: skinnormal_vertex,
  9034. specularmap_fragment: specularmap_fragment,
  9035. specularmap_pars_fragment: specularmap_pars_fragment,
  9036. tonemapping_fragment: tonemapping_fragment,
  9037. tonemapping_pars_fragment: tonemapping_pars_fragment,
  9038. transmissionmap_fragment: transmissionmap_fragment,
  9039. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  9040. uv_pars_fragment: uv_pars_fragment,
  9041. uv_pars_vertex: uv_pars_vertex,
  9042. uv_vertex: uv_vertex,
  9043. uv2_pars_fragment: uv2_pars_fragment,
  9044. uv2_pars_vertex: uv2_pars_vertex,
  9045. uv2_vertex: uv2_vertex,
  9046. worldpos_vertex: worldpos_vertex,
  9047. background_frag: background_frag,
  9048. background_vert: background_vert,
  9049. cube_frag: cube_frag,
  9050. cube_vert: cube_vert,
  9051. depth_frag: depth_frag,
  9052. depth_vert: depth_vert,
  9053. distanceRGBA_frag: distanceRGBA_frag,
  9054. distanceRGBA_vert: distanceRGBA_vert,
  9055. equirect_frag: equirect_frag,
  9056. equirect_vert: equirect_vert,
  9057. linedashed_frag: linedashed_frag,
  9058. linedashed_vert: linedashed_vert,
  9059. meshbasic_frag: meshbasic_frag,
  9060. meshbasic_vert: meshbasic_vert,
  9061. meshlambert_frag: meshlambert_frag,
  9062. meshlambert_vert: meshlambert_vert,
  9063. meshmatcap_frag: meshmatcap_frag,
  9064. meshmatcap_vert: meshmatcap_vert,
  9065. meshtoon_frag: meshtoon_frag,
  9066. meshtoon_vert: meshtoon_vert,
  9067. meshphong_frag: meshphong_frag,
  9068. meshphong_vert: meshphong_vert,
  9069. meshphysical_frag: meshphysical_frag,
  9070. meshphysical_vert: meshphysical_vert,
  9071. normal_frag: normal_frag,
  9072. normal_vert: normal_vert,
  9073. points_frag: points_frag,
  9074. points_vert: points_vert,
  9075. shadow_frag: shadow_frag,
  9076. shadow_vert: shadow_vert,
  9077. sprite_frag: sprite_frag,
  9078. sprite_vert: sprite_vert
  9079. };
  9080. /**
  9081. * Uniforms library for shared webgl shaders
  9082. */
  9083. var UniformsLib = {
  9084. common: {
  9085. diffuse: {
  9086. value: new Color(0xeeeeee)
  9087. },
  9088. opacity: {
  9089. value: 1.0
  9090. },
  9091. map: {
  9092. value: null
  9093. },
  9094. uvTransform: {
  9095. value: new Matrix3()
  9096. },
  9097. uv2Transform: {
  9098. value: new Matrix3()
  9099. },
  9100. alphaMap: {
  9101. value: null
  9102. }
  9103. },
  9104. specularmap: {
  9105. specularMap: {
  9106. value: null
  9107. }
  9108. },
  9109. envmap: {
  9110. envMap: {
  9111. value: null
  9112. },
  9113. flipEnvMap: {
  9114. value: -1
  9115. },
  9116. reflectivity: {
  9117. value: 1.0
  9118. },
  9119. refractionRatio: {
  9120. value: 0.98
  9121. },
  9122. maxMipLevel: {
  9123. value: 0
  9124. }
  9125. },
  9126. aomap: {
  9127. aoMap: {
  9128. value: null
  9129. },
  9130. aoMapIntensity: {
  9131. value: 1
  9132. }
  9133. },
  9134. lightmap: {
  9135. lightMap: {
  9136. value: null
  9137. },
  9138. lightMapIntensity: {
  9139. value: 1
  9140. }
  9141. },
  9142. emissivemap: {
  9143. emissiveMap: {
  9144. value: null
  9145. }
  9146. },
  9147. bumpmap: {
  9148. bumpMap: {
  9149. value: null
  9150. },
  9151. bumpScale: {
  9152. value: 1
  9153. }
  9154. },
  9155. normalmap: {
  9156. normalMap: {
  9157. value: null
  9158. },
  9159. normalScale: {
  9160. value: new Vector2(1, 1)
  9161. }
  9162. },
  9163. displacementmap: {
  9164. displacementMap: {
  9165. value: null
  9166. },
  9167. displacementScale: {
  9168. value: 1
  9169. },
  9170. displacementBias: {
  9171. value: 0
  9172. }
  9173. },
  9174. roughnessmap: {
  9175. roughnessMap: {
  9176. value: null
  9177. }
  9178. },
  9179. metalnessmap: {
  9180. metalnessMap: {
  9181. value: null
  9182. }
  9183. },
  9184. gradientmap: {
  9185. gradientMap: {
  9186. value: null
  9187. }
  9188. },
  9189. fog: {
  9190. fogDensity: {
  9191. value: 0.00025
  9192. },
  9193. fogNear: {
  9194. value: 1
  9195. },
  9196. fogFar: {
  9197. value: 2000
  9198. },
  9199. fogColor: {
  9200. value: new Color(0xffffff)
  9201. }
  9202. },
  9203. lights: {
  9204. ambientLightColor: {
  9205. value: []
  9206. },
  9207. lightProbe: {
  9208. value: []
  9209. },
  9210. directionalLights: {
  9211. value: [],
  9212. properties: {
  9213. direction: {},
  9214. color: {}
  9215. }
  9216. },
  9217. directionalLightShadows: {
  9218. value: [],
  9219. properties: {
  9220. shadowBias: {},
  9221. shadowNormalBias: {},
  9222. shadowRadius: {},
  9223. shadowMapSize: {}
  9224. }
  9225. },
  9226. directionalShadowMap: {
  9227. value: []
  9228. },
  9229. directionalShadowMatrix: {
  9230. value: []
  9231. },
  9232. spotLights: {
  9233. value: [],
  9234. properties: {
  9235. color: {},
  9236. position: {},
  9237. direction: {},
  9238. distance: {},
  9239. coneCos: {},
  9240. penumbraCos: {},
  9241. decay: {}
  9242. }
  9243. },
  9244. spotLightShadows: {
  9245. value: [],
  9246. properties: {
  9247. shadowBias: {},
  9248. shadowNormalBias: {},
  9249. shadowRadius: {},
  9250. shadowMapSize: {}
  9251. }
  9252. },
  9253. spotShadowMap: {
  9254. value: []
  9255. },
  9256. spotShadowMatrix: {
  9257. value: []
  9258. },
  9259. pointLights: {
  9260. value: [],
  9261. properties: {
  9262. color: {},
  9263. position: {},
  9264. decay: {},
  9265. distance: {}
  9266. }
  9267. },
  9268. pointLightShadows: {
  9269. value: [],
  9270. properties: {
  9271. shadowBias: {},
  9272. shadowNormalBias: {},
  9273. shadowRadius: {},
  9274. shadowMapSize: {},
  9275. shadowCameraNear: {},
  9276. shadowCameraFar: {}
  9277. }
  9278. },
  9279. pointShadowMap: {
  9280. value: []
  9281. },
  9282. pointShadowMatrix: {
  9283. value: []
  9284. },
  9285. hemisphereLights: {
  9286. value: [],
  9287. properties: {
  9288. direction: {},
  9289. skyColor: {},
  9290. groundColor: {}
  9291. }
  9292. },
  9293. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  9294. rectAreaLights: {
  9295. value: [],
  9296. properties: {
  9297. color: {},
  9298. position: {},
  9299. width: {},
  9300. height: {}
  9301. }
  9302. },
  9303. ltc_1: {
  9304. value: null
  9305. },
  9306. ltc_2: {
  9307. value: null
  9308. }
  9309. },
  9310. points: {
  9311. diffuse: {
  9312. value: new Color(0xeeeeee)
  9313. },
  9314. opacity: {
  9315. value: 1.0
  9316. },
  9317. size: {
  9318. value: 1.0
  9319. },
  9320. scale: {
  9321. value: 1.0
  9322. },
  9323. map: {
  9324. value: null
  9325. },
  9326. alphaMap: {
  9327. value: null
  9328. },
  9329. uvTransform: {
  9330. value: new Matrix3()
  9331. }
  9332. },
  9333. sprite: {
  9334. diffuse: {
  9335. value: new Color(0xeeeeee)
  9336. },
  9337. opacity: {
  9338. value: 1.0
  9339. },
  9340. center: {
  9341. value: new Vector2(0.5, 0.5)
  9342. },
  9343. rotation: {
  9344. value: 0.0
  9345. },
  9346. map: {
  9347. value: null
  9348. },
  9349. alphaMap: {
  9350. value: null
  9351. },
  9352. uvTransform: {
  9353. value: new Matrix3()
  9354. }
  9355. }
  9356. };
  9357. var ShaderLib = {
  9358. basic: {
  9359. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  9360. vertexShader: ShaderChunk.meshbasic_vert,
  9361. fragmentShader: ShaderChunk.meshbasic_frag
  9362. },
  9363. lambert: {
  9364. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  9365. emissive: {
  9366. value: new Color(0x000000)
  9367. }
  9368. }]),
  9369. vertexShader: ShaderChunk.meshlambert_vert,
  9370. fragmentShader: ShaderChunk.meshlambert_frag
  9371. },
  9372. phong: {
  9373. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  9374. emissive: {
  9375. value: new Color(0x000000)
  9376. },
  9377. specular: {
  9378. value: new Color(0x111111)
  9379. },
  9380. shininess: {
  9381. value: 30
  9382. }
  9383. }]),
  9384. vertexShader: ShaderChunk.meshphong_vert,
  9385. fragmentShader: ShaderChunk.meshphong_frag
  9386. },
  9387. standard: {
  9388. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.roughnessmap, UniformsLib.metalnessmap, UniformsLib.fog, UniformsLib.lights, {
  9389. emissive: {
  9390. value: new Color(0x000000)
  9391. },
  9392. roughness: {
  9393. value: 1.0
  9394. },
  9395. metalness: {
  9396. value: 0.0
  9397. },
  9398. envMapIntensity: {
  9399. value: 1
  9400. } // temporary
  9401. }]),
  9402. vertexShader: ShaderChunk.meshphysical_vert,
  9403. fragmentShader: ShaderChunk.meshphysical_frag
  9404. },
  9405. toon: {
  9406. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  9407. emissive: {
  9408. value: new Color(0x000000)
  9409. }
  9410. }]),
  9411. vertexShader: ShaderChunk.meshtoon_vert,
  9412. fragmentShader: ShaderChunk.meshtoon_frag
  9413. },
  9414. matcap: {
  9415. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  9416. matcap: {
  9417. value: null
  9418. }
  9419. }]),
  9420. vertexShader: ShaderChunk.meshmatcap_vert,
  9421. fragmentShader: ShaderChunk.meshmatcap_frag
  9422. },
  9423. points: {
  9424. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  9425. vertexShader: ShaderChunk.points_vert,
  9426. fragmentShader: ShaderChunk.points_frag
  9427. },
  9428. dashed: {
  9429. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  9430. scale: {
  9431. value: 1
  9432. },
  9433. dashSize: {
  9434. value: 1
  9435. },
  9436. totalSize: {
  9437. value: 2
  9438. }
  9439. }]),
  9440. vertexShader: ShaderChunk.linedashed_vert,
  9441. fragmentShader: ShaderChunk.linedashed_frag
  9442. },
  9443. depth: {
  9444. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  9445. vertexShader: ShaderChunk.depth_vert,
  9446. fragmentShader: ShaderChunk.depth_frag
  9447. },
  9448. normal: {
  9449. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  9450. opacity: {
  9451. value: 1.0
  9452. }
  9453. }]),
  9454. vertexShader: ShaderChunk.normal_vert,
  9455. fragmentShader: ShaderChunk.normal_frag
  9456. },
  9457. sprite: {
  9458. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  9459. vertexShader: ShaderChunk.sprite_vert,
  9460. fragmentShader: ShaderChunk.sprite_frag
  9461. },
  9462. background: {
  9463. uniforms: {
  9464. uvTransform: {
  9465. value: new Matrix3()
  9466. },
  9467. t2D: {
  9468. value: null
  9469. }
  9470. },
  9471. vertexShader: ShaderChunk.background_vert,
  9472. fragmentShader: ShaderChunk.background_frag
  9473. },
  9474. /* -------------------------------------------------------------------------
  9475. // Cube map shader
  9476. ------------------------------------------------------------------------- */
  9477. cube: {
  9478. uniforms: mergeUniforms([UniformsLib.envmap, {
  9479. opacity: {
  9480. value: 1.0
  9481. }
  9482. }]),
  9483. vertexShader: ShaderChunk.cube_vert,
  9484. fragmentShader: ShaderChunk.cube_frag
  9485. },
  9486. equirect: {
  9487. uniforms: {
  9488. tEquirect: {
  9489. value: null
  9490. }
  9491. },
  9492. vertexShader: ShaderChunk.equirect_vert,
  9493. fragmentShader: ShaderChunk.equirect_frag
  9494. },
  9495. distanceRGBA: {
  9496. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  9497. referencePosition: {
  9498. value: new Vector3()
  9499. },
  9500. nearDistance: {
  9501. value: 1
  9502. },
  9503. farDistance: {
  9504. value: 1000
  9505. }
  9506. }]),
  9507. vertexShader: ShaderChunk.distanceRGBA_vert,
  9508. fragmentShader: ShaderChunk.distanceRGBA_frag
  9509. },
  9510. shadow: {
  9511. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  9512. color: {
  9513. value: new Color(0x00000)
  9514. },
  9515. opacity: {
  9516. value: 1.0
  9517. }
  9518. }]),
  9519. vertexShader: ShaderChunk.shadow_vert,
  9520. fragmentShader: ShaderChunk.shadow_frag
  9521. }
  9522. };
  9523. ShaderLib.physical = {
  9524. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  9525. clearcoat: {
  9526. value: 0
  9527. },
  9528. clearcoatMap: {
  9529. value: null
  9530. },
  9531. clearcoatRoughness: {
  9532. value: 0
  9533. },
  9534. clearcoatRoughnessMap: {
  9535. value: null
  9536. },
  9537. clearcoatNormalScale: {
  9538. value: new Vector2(1, 1)
  9539. },
  9540. clearcoatNormalMap: {
  9541. value: null
  9542. },
  9543. sheen: {
  9544. value: new Color(0x000000)
  9545. },
  9546. transmission: {
  9547. value: 0
  9548. },
  9549. transmissionMap: {
  9550. value: null
  9551. }
  9552. }]),
  9553. vertexShader: ShaderChunk.meshphysical_vert,
  9554. fragmentShader: ShaderChunk.meshphysical_frag
  9555. };
  9556. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  9557. var clearColor = new Color(0x000000);
  9558. var clearAlpha = 0;
  9559. var planeMesh;
  9560. var boxMesh;
  9561. var currentBackground = null;
  9562. var currentBackgroundVersion = 0;
  9563. var currentTonemapping = null;
  9564. function render(renderList, scene, camera, forceClear) {
  9565. var background = scene.isScene === true ? scene.background : null;
  9566. if (background && background.isTexture) {
  9567. background = cubemaps.get(background);
  9568. } // Ignore background in AR
  9569. // TODO: Reconsider this.
  9570. var xr = renderer.xr;
  9571. var session = xr.getSession && xr.getSession();
  9572. if (session && session.environmentBlendMode === 'additive') {
  9573. background = null;
  9574. }
  9575. if (background === null) {
  9576. setClear(clearColor, clearAlpha);
  9577. } else if (background && background.isColor) {
  9578. setClear(background, 1);
  9579. forceClear = true;
  9580. }
  9581. if (renderer.autoClear || forceClear) {
  9582. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  9583. }
  9584. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  9585. if (boxMesh === undefined) {
  9586. boxMesh = new Mesh(new BoxGeometry(1, 1, 1), new ShaderMaterial({
  9587. name: 'BackgroundCubeMaterial',
  9588. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  9589. vertexShader: ShaderLib.cube.vertexShader,
  9590. fragmentShader: ShaderLib.cube.fragmentShader,
  9591. side: BackSide,
  9592. depthTest: false,
  9593. depthWrite: false,
  9594. fog: false
  9595. }));
  9596. boxMesh.geometry.deleteAttribute('normal');
  9597. boxMesh.geometry.deleteAttribute('uv');
  9598. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  9599. this.matrixWorld.copyPosition(camera.matrixWorld);
  9600. }; // enable code injection for non-built-in material
  9601. Object.defineProperty(boxMesh.material, 'envMap', {
  9602. get: function get() {
  9603. return this.uniforms.envMap.value;
  9604. }
  9605. });
  9606. objects.update(boxMesh);
  9607. }
  9608. if (background.isWebGLCubeRenderTarget) {
  9609. // TODO Deprecate
  9610. background = background.texture;
  9611. }
  9612. boxMesh.material.uniforms.envMap.value = background;
  9613. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  9614. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9615. boxMesh.material.needsUpdate = true;
  9616. currentBackground = background;
  9617. currentBackgroundVersion = background.version;
  9618. currentTonemapping = renderer.toneMapping;
  9619. } // push to the pre-sorted opaque render list
  9620. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  9621. } else if (background && background.isTexture) {
  9622. if (planeMesh === undefined) {
  9623. planeMesh = new Mesh(new PlaneGeometry(2, 2), new ShaderMaterial({
  9624. name: 'BackgroundMaterial',
  9625. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  9626. vertexShader: ShaderLib.background.vertexShader,
  9627. fragmentShader: ShaderLib.background.fragmentShader,
  9628. side: FrontSide,
  9629. depthTest: false,
  9630. depthWrite: false,
  9631. fog: false
  9632. }));
  9633. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  9634. Object.defineProperty(planeMesh.material, 'map', {
  9635. get: function get() {
  9636. return this.uniforms.t2D.value;
  9637. }
  9638. });
  9639. objects.update(planeMesh);
  9640. }
  9641. planeMesh.material.uniforms.t2D.value = background;
  9642. if (background.matrixAutoUpdate === true) {
  9643. background.updateMatrix();
  9644. }
  9645. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  9646. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9647. planeMesh.material.needsUpdate = true;
  9648. currentBackground = background;
  9649. currentBackgroundVersion = background.version;
  9650. currentTonemapping = renderer.toneMapping;
  9651. } // push to the pre-sorted opaque render list
  9652. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  9653. }
  9654. }
  9655. function setClear(color, alpha) {
  9656. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  9657. }
  9658. return {
  9659. getClearColor: function getClearColor() {
  9660. return clearColor;
  9661. },
  9662. setClearColor: function setClearColor(color, alpha) {
  9663. if (alpha === void 0) {
  9664. alpha = 1;
  9665. }
  9666. clearColor.set(color);
  9667. clearAlpha = alpha;
  9668. setClear(clearColor, clearAlpha);
  9669. },
  9670. getClearAlpha: function getClearAlpha() {
  9671. return clearAlpha;
  9672. },
  9673. setClearAlpha: function setClearAlpha(alpha) {
  9674. clearAlpha = alpha;
  9675. setClear(clearColor, clearAlpha);
  9676. },
  9677. render: render
  9678. };
  9679. }
  9680. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  9681. var maxVertexAttributes = gl.getParameter(34921);
  9682. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  9683. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9684. var bindingStates = {};
  9685. var defaultState = createBindingState(null);
  9686. var currentState = defaultState;
  9687. function setup(object, material, program, geometry, index) {
  9688. var updateBuffers = false;
  9689. if (vaoAvailable) {
  9690. var state = getBindingState(geometry, program, material);
  9691. if (currentState !== state) {
  9692. currentState = state;
  9693. bindVertexArrayObject(currentState.object);
  9694. }
  9695. updateBuffers = needsUpdate(geometry, index);
  9696. if (updateBuffers) saveCache(geometry, index);
  9697. } else {
  9698. var wireframe = material.wireframe === true;
  9699. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9700. currentState.geometry = geometry.id;
  9701. currentState.program = program.id;
  9702. currentState.wireframe = wireframe;
  9703. updateBuffers = true;
  9704. }
  9705. }
  9706. if (object.isInstancedMesh === true) {
  9707. updateBuffers = true;
  9708. }
  9709. if (index !== null) {
  9710. attributes.update(index, 34963);
  9711. }
  9712. if (updateBuffers) {
  9713. setupVertexAttributes(object, material, program, geometry);
  9714. if (index !== null) {
  9715. gl.bindBuffer(34963, attributes.get(index).buffer);
  9716. }
  9717. }
  9718. }
  9719. function createVertexArrayObject() {
  9720. if (capabilities.isWebGL2) return gl.createVertexArray();
  9721. return extension.createVertexArrayOES();
  9722. }
  9723. function bindVertexArrayObject(vao) {
  9724. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9725. return extension.bindVertexArrayOES(vao);
  9726. }
  9727. function deleteVertexArrayObject(vao) {
  9728. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9729. return extension.deleteVertexArrayOES(vao);
  9730. }
  9731. function getBindingState(geometry, program, material) {
  9732. var wireframe = material.wireframe === true;
  9733. var programMap = bindingStates[geometry.id];
  9734. if (programMap === undefined) {
  9735. programMap = {};
  9736. bindingStates[geometry.id] = programMap;
  9737. }
  9738. var stateMap = programMap[program.id];
  9739. if (stateMap === undefined) {
  9740. stateMap = {};
  9741. programMap[program.id] = stateMap;
  9742. }
  9743. var state = stateMap[wireframe];
  9744. if (state === undefined) {
  9745. state = createBindingState(createVertexArrayObject());
  9746. stateMap[wireframe] = state;
  9747. }
  9748. return state;
  9749. }
  9750. function createBindingState(vao) {
  9751. var newAttributes = [];
  9752. var enabledAttributes = [];
  9753. var attributeDivisors = [];
  9754. for (var i = 0; i < maxVertexAttributes; i++) {
  9755. newAttributes[i] = 0;
  9756. enabledAttributes[i] = 0;
  9757. attributeDivisors[i] = 0;
  9758. }
  9759. return {
  9760. // for backward compatibility on non-VAO support browser
  9761. geometry: null,
  9762. program: null,
  9763. wireframe: false,
  9764. newAttributes: newAttributes,
  9765. enabledAttributes: enabledAttributes,
  9766. attributeDivisors: attributeDivisors,
  9767. object: vao,
  9768. attributes: {},
  9769. index: null
  9770. };
  9771. }
  9772. function needsUpdate(geometry, index) {
  9773. var cachedAttributes = currentState.attributes;
  9774. var geometryAttributes = geometry.attributes;
  9775. var attributesNum = 0;
  9776. for (var key in geometryAttributes) {
  9777. var cachedAttribute = cachedAttributes[key];
  9778. var geometryAttribute = geometryAttributes[key];
  9779. if (cachedAttribute === undefined) return true;
  9780. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9781. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9782. attributesNum++;
  9783. }
  9784. if (currentState.attributesNum !== attributesNum) return true;
  9785. if (currentState.index !== index) return true;
  9786. return false;
  9787. }
  9788. function saveCache(geometry, index) {
  9789. var cache = {};
  9790. var attributes = geometry.attributes;
  9791. var attributesNum = 0;
  9792. for (var key in attributes) {
  9793. var attribute = attributes[key];
  9794. var data = {};
  9795. data.attribute = attribute;
  9796. if (attribute.data) {
  9797. data.data = attribute.data;
  9798. }
  9799. cache[key] = data;
  9800. attributesNum++;
  9801. }
  9802. currentState.attributes = cache;
  9803. currentState.attributesNum = attributesNum;
  9804. currentState.index = index;
  9805. }
  9806. function initAttributes() {
  9807. var newAttributes = currentState.newAttributes;
  9808. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9809. newAttributes[i] = 0;
  9810. }
  9811. }
  9812. function enableAttribute(attribute) {
  9813. enableAttributeAndDivisor(attribute, 0);
  9814. }
  9815. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9816. var newAttributes = currentState.newAttributes;
  9817. var enabledAttributes = currentState.enabledAttributes;
  9818. var attributeDivisors = currentState.attributeDivisors;
  9819. newAttributes[attribute] = 1;
  9820. if (enabledAttributes[attribute] === 0) {
  9821. gl.enableVertexAttribArray(attribute);
  9822. enabledAttributes[attribute] = 1;
  9823. }
  9824. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9825. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9826. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9827. attributeDivisors[attribute] = meshPerAttribute;
  9828. }
  9829. }
  9830. function disableUnusedAttributes() {
  9831. var newAttributes = currentState.newAttributes;
  9832. var enabledAttributes = currentState.enabledAttributes;
  9833. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9834. if (enabledAttributes[i] !== newAttributes[i]) {
  9835. gl.disableVertexAttribArray(i);
  9836. enabledAttributes[i] = 0;
  9837. }
  9838. }
  9839. }
  9840. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9841. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9842. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9843. } else {
  9844. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9845. }
  9846. }
  9847. function setupVertexAttributes(object, material, program, geometry) {
  9848. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9849. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9850. }
  9851. initAttributes();
  9852. var geometryAttributes = geometry.attributes;
  9853. var programAttributes = program.getAttributes();
  9854. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9855. for (var name in programAttributes) {
  9856. var programAttribute = programAttributes[name];
  9857. if (programAttribute >= 0) {
  9858. var geometryAttribute = geometryAttributes[name];
  9859. if (geometryAttribute !== undefined) {
  9860. var normalized = geometryAttribute.normalized;
  9861. var size = geometryAttribute.itemSize;
  9862. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9863. if (attribute === undefined) continue;
  9864. var buffer = attribute.buffer;
  9865. var type = attribute.type;
  9866. var bytesPerElement = attribute.bytesPerElement;
  9867. if (geometryAttribute.isInterleavedBufferAttribute) {
  9868. var data = geometryAttribute.data;
  9869. var stride = data.stride;
  9870. var offset = geometryAttribute.offset;
  9871. if (data && data.isInstancedInterleavedBuffer) {
  9872. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9873. if (geometry._maxInstanceCount === undefined) {
  9874. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9875. }
  9876. } else {
  9877. enableAttribute(programAttribute);
  9878. }
  9879. gl.bindBuffer(34962, buffer);
  9880. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9881. } else {
  9882. if (geometryAttribute.isInstancedBufferAttribute) {
  9883. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9884. if (geometry._maxInstanceCount === undefined) {
  9885. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9886. }
  9887. } else {
  9888. enableAttribute(programAttribute);
  9889. }
  9890. gl.bindBuffer(34962, buffer);
  9891. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9892. }
  9893. } else if (name === 'instanceMatrix') {
  9894. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9895. if (_attribute === undefined) continue;
  9896. var _buffer = _attribute.buffer;
  9897. var _type = _attribute.type;
  9898. enableAttributeAndDivisor(programAttribute + 0, 1);
  9899. enableAttributeAndDivisor(programAttribute + 1, 1);
  9900. enableAttributeAndDivisor(programAttribute + 2, 1);
  9901. enableAttributeAndDivisor(programAttribute + 3, 1);
  9902. gl.bindBuffer(34962, _buffer);
  9903. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9904. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9905. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9906. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9907. } else if (name === 'instanceColor') {
  9908. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9909. if (_attribute2 === undefined) continue;
  9910. var _buffer2 = _attribute2.buffer;
  9911. var _type2 = _attribute2.type;
  9912. enableAttributeAndDivisor(programAttribute, 1);
  9913. gl.bindBuffer(34962, _buffer2);
  9914. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9915. } else if (materialDefaultAttributeValues !== undefined) {
  9916. var value = materialDefaultAttributeValues[name];
  9917. if (value !== undefined) {
  9918. switch (value.length) {
  9919. case 2:
  9920. gl.vertexAttrib2fv(programAttribute, value);
  9921. break;
  9922. case 3:
  9923. gl.vertexAttrib3fv(programAttribute, value);
  9924. break;
  9925. case 4:
  9926. gl.vertexAttrib4fv(programAttribute, value);
  9927. break;
  9928. default:
  9929. gl.vertexAttrib1fv(programAttribute, value);
  9930. }
  9931. }
  9932. }
  9933. }
  9934. }
  9935. disableUnusedAttributes();
  9936. }
  9937. function dispose() {
  9938. reset();
  9939. for (var geometryId in bindingStates) {
  9940. var programMap = bindingStates[geometryId];
  9941. for (var programId in programMap) {
  9942. var stateMap = programMap[programId];
  9943. for (var wireframe in stateMap) {
  9944. deleteVertexArrayObject(stateMap[wireframe].object);
  9945. delete stateMap[wireframe];
  9946. }
  9947. delete programMap[programId];
  9948. }
  9949. delete bindingStates[geometryId];
  9950. }
  9951. }
  9952. function releaseStatesOfGeometry(geometry) {
  9953. if (bindingStates[geometry.id] === undefined) return;
  9954. var programMap = bindingStates[geometry.id];
  9955. for (var programId in programMap) {
  9956. var stateMap = programMap[programId];
  9957. for (var wireframe in stateMap) {
  9958. deleteVertexArrayObject(stateMap[wireframe].object);
  9959. delete stateMap[wireframe];
  9960. }
  9961. delete programMap[programId];
  9962. }
  9963. delete bindingStates[geometry.id];
  9964. }
  9965. function releaseStatesOfProgram(program) {
  9966. for (var geometryId in bindingStates) {
  9967. var programMap = bindingStates[geometryId];
  9968. if (programMap[program.id] === undefined) continue;
  9969. var stateMap = programMap[program.id];
  9970. for (var wireframe in stateMap) {
  9971. deleteVertexArrayObject(stateMap[wireframe].object);
  9972. delete stateMap[wireframe];
  9973. }
  9974. delete programMap[program.id];
  9975. }
  9976. }
  9977. function reset() {
  9978. resetDefaultState();
  9979. if (currentState === defaultState) return;
  9980. currentState = defaultState;
  9981. bindVertexArrayObject(currentState.object);
  9982. } // for backward-compatilibity
  9983. function resetDefaultState() {
  9984. defaultState.geometry = null;
  9985. defaultState.program = null;
  9986. defaultState.wireframe = false;
  9987. }
  9988. return {
  9989. setup: setup,
  9990. reset: reset,
  9991. resetDefaultState: resetDefaultState,
  9992. dispose: dispose,
  9993. releaseStatesOfGeometry: releaseStatesOfGeometry,
  9994. releaseStatesOfProgram: releaseStatesOfProgram,
  9995. initAttributes: initAttributes,
  9996. enableAttribute: enableAttribute,
  9997. disableUnusedAttributes: disableUnusedAttributes
  9998. };
  9999. }
  10000. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  10001. var isWebGL2 = capabilities.isWebGL2;
  10002. var mode;
  10003. function setMode(value) {
  10004. mode = value;
  10005. }
  10006. function render(start, count) {
  10007. gl.drawArrays(mode, start, count);
  10008. info.update(count, mode, 1);
  10009. }
  10010. function renderInstances(start, count, primcount) {
  10011. if (primcount === 0) return;
  10012. var extension, methodName;
  10013. if (isWebGL2) {
  10014. extension = gl;
  10015. methodName = 'drawArraysInstanced';
  10016. } else {
  10017. extension = extensions.get('ANGLE_instanced_arrays');
  10018. methodName = 'drawArraysInstancedANGLE';
  10019. if (extension === null) {
  10020. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  10021. return;
  10022. }
  10023. }
  10024. extension[methodName](mode, start, count, primcount);
  10025. info.update(count, mode, primcount);
  10026. } //
  10027. this.setMode = setMode;
  10028. this.render = render;
  10029. this.renderInstances = renderInstances;
  10030. }
  10031. function WebGLCapabilities(gl, extensions, parameters) {
  10032. var maxAnisotropy;
  10033. function getMaxAnisotropy() {
  10034. if (maxAnisotropy !== undefined) return maxAnisotropy;
  10035. if (extensions.has('EXT_texture_filter_anisotropic') === true) {
  10036. var extension = extensions.get('EXT_texture_filter_anisotropic');
  10037. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  10038. } else {
  10039. maxAnisotropy = 0;
  10040. }
  10041. return maxAnisotropy;
  10042. }
  10043. function getMaxPrecision(precision) {
  10044. if (precision === 'highp') {
  10045. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  10046. return 'highp';
  10047. }
  10048. precision = 'mediump';
  10049. }
  10050. if (precision === 'mediump') {
  10051. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  10052. return 'mediump';
  10053. }
  10054. }
  10055. return 'lowp';
  10056. }
  10057. /* eslint-disable no-undef */
  10058. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  10059. /* eslint-enable no-undef */
  10060. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  10061. var maxPrecision = getMaxPrecision(precision);
  10062. if (maxPrecision !== precision) {
  10063. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  10064. precision = maxPrecision;
  10065. }
  10066. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  10067. var maxTextures = gl.getParameter(34930);
  10068. var maxVertexTextures = gl.getParameter(35660);
  10069. var maxTextureSize = gl.getParameter(3379);
  10070. var maxCubemapSize = gl.getParameter(34076);
  10071. var maxAttributes = gl.getParameter(34921);
  10072. var maxVertexUniforms = gl.getParameter(36347);
  10073. var maxVaryings = gl.getParameter(36348);
  10074. var maxFragmentUniforms = gl.getParameter(36349);
  10075. var vertexTextures = maxVertexTextures > 0;
  10076. var floatFragmentTextures = isWebGL2 || extensions.has('OES_texture_float');
  10077. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  10078. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  10079. return {
  10080. isWebGL2: isWebGL2,
  10081. getMaxAnisotropy: getMaxAnisotropy,
  10082. getMaxPrecision: getMaxPrecision,
  10083. precision: precision,
  10084. logarithmicDepthBuffer: logarithmicDepthBuffer,
  10085. maxTextures: maxTextures,
  10086. maxVertexTextures: maxVertexTextures,
  10087. maxTextureSize: maxTextureSize,
  10088. maxCubemapSize: maxCubemapSize,
  10089. maxAttributes: maxAttributes,
  10090. maxVertexUniforms: maxVertexUniforms,
  10091. maxVaryings: maxVaryings,
  10092. maxFragmentUniforms: maxFragmentUniforms,
  10093. vertexTextures: vertexTextures,
  10094. floatFragmentTextures: floatFragmentTextures,
  10095. floatVertexTextures: floatVertexTextures,
  10096. maxSamples: maxSamples
  10097. };
  10098. }
  10099. function WebGLClipping(properties) {
  10100. var scope = this;
  10101. var globalState = null,
  10102. numGlobalPlanes = 0,
  10103. localClippingEnabled = false,
  10104. renderingShadows = false;
  10105. var plane = new Plane(),
  10106. viewNormalMatrix = new Matrix3(),
  10107. uniform = {
  10108. value: null,
  10109. needsUpdate: false
  10110. };
  10111. this.uniform = uniform;
  10112. this.numPlanes = 0;
  10113. this.numIntersection = 0;
  10114. this.init = function (planes, enableLocalClipping, camera) {
  10115. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  10116. // run another frame in order to reset the state:
  10117. numGlobalPlanes !== 0 || localClippingEnabled;
  10118. localClippingEnabled = enableLocalClipping;
  10119. globalState = projectPlanes(planes, camera, 0);
  10120. numGlobalPlanes = planes.length;
  10121. return enabled;
  10122. };
  10123. this.beginShadows = function () {
  10124. renderingShadows = true;
  10125. projectPlanes(null);
  10126. };
  10127. this.endShadows = function () {
  10128. renderingShadows = false;
  10129. resetGlobalState();
  10130. };
  10131. this.setState = function (material, camera, useCache) {
  10132. var planes = material.clippingPlanes,
  10133. clipIntersection = material.clipIntersection,
  10134. clipShadows = material.clipShadows;
  10135. var materialProperties = properties.get(material);
  10136. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  10137. // there's no local clipping
  10138. if (renderingShadows) {
  10139. // there's no global clipping
  10140. projectPlanes(null);
  10141. } else {
  10142. resetGlobalState();
  10143. }
  10144. } else {
  10145. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  10146. lGlobal = nGlobal * 4;
  10147. var dstArray = materialProperties.clippingState || null;
  10148. uniform.value = dstArray; // ensure unique state
  10149. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  10150. for (var i = 0; i !== lGlobal; ++i) {
  10151. dstArray[i] = globalState[i];
  10152. }
  10153. materialProperties.clippingState = dstArray;
  10154. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  10155. this.numPlanes += nGlobal;
  10156. }
  10157. };
  10158. function resetGlobalState() {
  10159. if (uniform.value !== globalState) {
  10160. uniform.value = globalState;
  10161. uniform.needsUpdate = numGlobalPlanes > 0;
  10162. }
  10163. scope.numPlanes = numGlobalPlanes;
  10164. scope.numIntersection = 0;
  10165. }
  10166. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  10167. var nPlanes = planes !== null ? planes.length : 0;
  10168. var dstArray = null;
  10169. if (nPlanes !== 0) {
  10170. dstArray = uniform.value;
  10171. if (skipTransform !== true || dstArray === null) {
  10172. var flatSize = dstOffset + nPlanes * 4,
  10173. viewMatrix = camera.matrixWorldInverse;
  10174. viewNormalMatrix.getNormalMatrix(viewMatrix);
  10175. if (dstArray === null || dstArray.length < flatSize) {
  10176. dstArray = new Float32Array(flatSize);
  10177. }
  10178. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  10179. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  10180. plane.normal.toArray(dstArray, i4);
  10181. dstArray[i4 + 3] = plane.constant;
  10182. }
  10183. }
  10184. uniform.value = dstArray;
  10185. uniform.needsUpdate = true;
  10186. }
  10187. scope.numPlanes = nPlanes;
  10188. scope.numIntersection = 0;
  10189. return dstArray;
  10190. }
  10191. }
  10192. function WebGLCubeMaps(renderer) {
  10193. var cubemaps = new WeakMap();
  10194. function mapTextureMapping(texture, mapping) {
  10195. if (mapping === EquirectangularReflectionMapping) {
  10196. texture.mapping = CubeReflectionMapping;
  10197. } else if (mapping === EquirectangularRefractionMapping) {
  10198. texture.mapping = CubeRefractionMapping;
  10199. }
  10200. return texture;
  10201. }
  10202. function get(texture) {
  10203. if (texture && texture.isTexture) {
  10204. var mapping = texture.mapping;
  10205. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  10206. if (cubemaps.has(texture)) {
  10207. var cubemap = cubemaps.get(texture).texture;
  10208. return mapTextureMapping(cubemap, texture.mapping);
  10209. } else {
  10210. var image = texture.image;
  10211. if (image && image.height > 0) {
  10212. var currentRenderList = renderer.getRenderList();
  10213. var currentRenderTarget = renderer.getRenderTarget();
  10214. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  10215. renderTarget.fromEquirectangularTexture(renderer, texture);
  10216. cubemaps.set(texture, renderTarget);
  10217. renderer.setRenderTarget(currentRenderTarget);
  10218. renderer.setRenderList(currentRenderList);
  10219. texture.addEventListener('dispose', onTextureDispose);
  10220. return mapTextureMapping(renderTarget.texture, texture.mapping);
  10221. } else {
  10222. // image not yet ready. try the conversion next frame
  10223. return null;
  10224. }
  10225. }
  10226. }
  10227. }
  10228. return texture;
  10229. }
  10230. function onTextureDispose(event) {
  10231. var texture = event.target;
  10232. texture.removeEventListener('dispose', onTextureDispose);
  10233. var cubemap = cubemaps.get(texture);
  10234. if (cubemap !== undefined) {
  10235. cubemaps.delete(texture);
  10236. cubemap.dispose();
  10237. }
  10238. }
  10239. function dispose() {
  10240. cubemaps = new WeakMap();
  10241. }
  10242. return {
  10243. get: get,
  10244. dispose: dispose
  10245. };
  10246. }
  10247. function WebGLExtensions(gl) {
  10248. var extensions = {};
  10249. function getExtension(name) {
  10250. if (extensions[name] !== undefined) {
  10251. return extensions[name];
  10252. }
  10253. var extension;
  10254. switch (name) {
  10255. case 'WEBGL_depth_texture':
  10256. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  10257. break;
  10258. case 'EXT_texture_filter_anisotropic':
  10259. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  10260. break;
  10261. case 'WEBGL_compressed_texture_s3tc':
  10262. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  10263. break;
  10264. case 'WEBGL_compressed_texture_pvrtc':
  10265. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  10266. break;
  10267. default:
  10268. extension = gl.getExtension(name);
  10269. }
  10270. extensions[name] = extension;
  10271. return extension;
  10272. }
  10273. return {
  10274. has: function has(name) {
  10275. return getExtension(name) !== null;
  10276. },
  10277. init: function init(capabilities) {
  10278. if (capabilities.isWebGL2) {
  10279. getExtension('EXT_color_buffer_float');
  10280. } else {
  10281. getExtension('WEBGL_depth_texture');
  10282. getExtension('OES_texture_float');
  10283. getExtension('OES_texture_half_float');
  10284. getExtension('OES_texture_half_float_linear');
  10285. getExtension('OES_standard_derivatives');
  10286. getExtension('OES_element_index_uint');
  10287. getExtension('OES_vertex_array_object');
  10288. getExtension('ANGLE_instanced_arrays');
  10289. }
  10290. getExtension('OES_texture_float_linear');
  10291. getExtension('EXT_color_buffer_half_float');
  10292. },
  10293. get: function get(name) {
  10294. var extension = getExtension(name);
  10295. if (extension === null) {
  10296. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  10297. }
  10298. return extension;
  10299. }
  10300. };
  10301. }
  10302. function WebGLGeometries(gl, attributes, info, bindingStates) {
  10303. var geometries = {};
  10304. var wireframeAttributes = new WeakMap();
  10305. function onGeometryDispose(event) {
  10306. var geometry = event.target;
  10307. if (geometry.index !== null) {
  10308. attributes.remove(geometry.index);
  10309. }
  10310. for (var name in geometry.attributes) {
  10311. attributes.remove(geometry.attributes[name]);
  10312. }
  10313. geometry.removeEventListener('dispose', onGeometryDispose);
  10314. delete geometries[geometry.id];
  10315. var attribute = wireframeAttributes.get(geometry);
  10316. if (attribute) {
  10317. attributes.remove(attribute);
  10318. wireframeAttributes.delete(geometry);
  10319. }
  10320. bindingStates.releaseStatesOfGeometry(geometry);
  10321. if (geometry.isInstancedBufferGeometry === true) {
  10322. delete geometry._maxInstanceCount;
  10323. } //
  10324. info.memory.geometries--;
  10325. }
  10326. function get(object, geometry) {
  10327. if (geometries[geometry.id] === true) return geometry;
  10328. geometry.addEventListener('dispose', onGeometryDispose);
  10329. geometries[geometry.id] = true;
  10330. info.memory.geometries++;
  10331. return geometry;
  10332. }
  10333. function update(geometry) {
  10334. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  10335. for (var name in geometryAttributes) {
  10336. attributes.update(geometryAttributes[name], 34962);
  10337. } // morph targets
  10338. var morphAttributes = geometry.morphAttributes;
  10339. for (var _name in morphAttributes) {
  10340. var array = morphAttributes[_name];
  10341. for (var i = 0, l = array.length; i < l; i++) {
  10342. attributes.update(array[i], 34962);
  10343. }
  10344. }
  10345. }
  10346. function updateWireframeAttribute(geometry) {
  10347. var indices = [];
  10348. var geometryIndex = geometry.index;
  10349. var geometryPosition = geometry.attributes.position;
  10350. var version = 0;
  10351. if (geometryIndex !== null) {
  10352. var array = geometryIndex.array;
  10353. version = geometryIndex.version;
  10354. for (var i = 0, l = array.length; i < l; i += 3) {
  10355. var a = array[i + 0];
  10356. var b = array[i + 1];
  10357. var c = array[i + 2];
  10358. indices.push(a, b, b, c, c, a);
  10359. }
  10360. } else {
  10361. var _array = geometryPosition.array;
  10362. version = geometryPosition.version;
  10363. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  10364. var _a = _i + 0;
  10365. var _b = _i + 1;
  10366. var _c = _i + 2;
  10367. indices.push(_a, _b, _b, _c, _c, _a);
  10368. }
  10369. }
  10370. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  10371. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  10372. //
  10373. var previousAttribute = wireframeAttributes.get(geometry);
  10374. if (previousAttribute) attributes.remove(previousAttribute); //
  10375. wireframeAttributes.set(geometry, attribute);
  10376. }
  10377. function getWireframeAttribute(geometry) {
  10378. var currentAttribute = wireframeAttributes.get(geometry);
  10379. if (currentAttribute) {
  10380. var geometryIndex = geometry.index;
  10381. if (geometryIndex !== null) {
  10382. // if the attribute is obsolete, create a new one
  10383. if (currentAttribute.version < geometryIndex.version) {
  10384. updateWireframeAttribute(geometry);
  10385. }
  10386. }
  10387. } else {
  10388. updateWireframeAttribute(geometry);
  10389. }
  10390. return wireframeAttributes.get(geometry);
  10391. }
  10392. return {
  10393. get: get,
  10394. update: update,
  10395. getWireframeAttribute: getWireframeAttribute
  10396. };
  10397. }
  10398. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  10399. var isWebGL2 = capabilities.isWebGL2;
  10400. var mode;
  10401. function setMode(value) {
  10402. mode = value;
  10403. }
  10404. var type, bytesPerElement;
  10405. function setIndex(value) {
  10406. type = value.type;
  10407. bytesPerElement = value.bytesPerElement;
  10408. }
  10409. function render(start, count) {
  10410. gl.drawElements(mode, count, type, start * bytesPerElement);
  10411. info.update(count, mode, 1);
  10412. }
  10413. function renderInstances(start, count, primcount) {
  10414. if (primcount === 0) return;
  10415. var extension, methodName;
  10416. if (isWebGL2) {
  10417. extension = gl;
  10418. methodName = 'drawElementsInstanced';
  10419. } else {
  10420. extension = extensions.get('ANGLE_instanced_arrays');
  10421. methodName = 'drawElementsInstancedANGLE';
  10422. if (extension === null) {
  10423. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  10424. return;
  10425. }
  10426. }
  10427. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  10428. info.update(count, mode, primcount);
  10429. } //
  10430. this.setMode = setMode;
  10431. this.setIndex = setIndex;
  10432. this.render = render;
  10433. this.renderInstances = renderInstances;
  10434. }
  10435. function WebGLInfo(gl) {
  10436. var memory = {
  10437. geometries: 0,
  10438. textures: 0
  10439. };
  10440. var render = {
  10441. frame: 0,
  10442. calls: 0,
  10443. triangles: 0,
  10444. points: 0,
  10445. lines: 0
  10446. };
  10447. function update(count, mode, instanceCount) {
  10448. render.calls++;
  10449. switch (mode) {
  10450. case 4:
  10451. render.triangles += instanceCount * (count / 3);
  10452. break;
  10453. case 1:
  10454. render.lines += instanceCount * (count / 2);
  10455. break;
  10456. case 3:
  10457. render.lines += instanceCount * (count - 1);
  10458. break;
  10459. case 2:
  10460. render.lines += instanceCount * count;
  10461. break;
  10462. case 0:
  10463. render.points += instanceCount * count;
  10464. break;
  10465. default:
  10466. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  10467. break;
  10468. }
  10469. }
  10470. function reset() {
  10471. render.frame++;
  10472. render.calls = 0;
  10473. render.triangles = 0;
  10474. render.points = 0;
  10475. render.lines = 0;
  10476. }
  10477. return {
  10478. memory: memory,
  10479. render: render,
  10480. programs: null,
  10481. autoReset: true,
  10482. reset: reset,
  10483. update: update
  10484. };
  10485. }
  10486. function numericalSort(a, b) {
  10487. return a[0] - b[0];
  10488. }
  10489. function absNumericalSort(a, b) {
  10490. return Math.abs(b[1]) - Math.abs(a[1]);
  10491. }
  10492. function WebGLMorphtargets(gl) {
  10493. var influencesList = {};
  10494. var morphInfluences = new Float32Array(8);
  10495. var workInfluences = [];
  10496. for (var i = 0; i < 8; i++) {
  10497. workInfluences[i] = [i, 0];
  10498. }
  10499. function update(object, geometry, material, program) {
  10500. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  10501. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  10502. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  10503. var influences = influencesList[geometry.id];
  10504. if (influences === undefined) {
  10505. // initialise list
  10506. influences = [];
  10507. for (var _i = 0; _i < length; _i++) {
  10508. influences[_i] = [_i, 0];
  10509. }
  10510. influencesList[geometry.id] = influences;
  10511. } // Collect influences
  10512. for (var _i2 = 0; _i2 < length; _i2++) {
  10513. var influence = influences[_i2];
  10514. influence[0] = _i2;
  10515. influence[1] = objectInfluences[_i2];
  10516. }
  10517. influences.sort(absNumericalSort);
  10518. for (var _i3 = 0; _i3 < 8; _i3++) {
  10519. if (_i3 < length && influences[_i3][1]) {
  10520. workInfluences[_i3][0] = influences[_i3][0];
  10521. workInfluences[_i3][1] = influences[_i3][1];
  10522. } else {
  10523. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  10524. workInfluences[_i3][1] = 0;
  10525. }
  10526. }
  10527. workInfluences.sort(numericalSort);
  10528. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  10529. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  10530. var morphInfluencesSum = 0;
  10531. for (var _i4 = 0; _i4 < 8; _i4++) {
  10532. var _influence = workInfluences[_i4];
  10533. var index = _influence[0];
  10534. var value = _influence[1];
  10535. if (index !== Number.MAX_SAFE_INTEGER && value) {
  10536. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  10537. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  10538. }
  10539. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  10540. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  10541. }
  10542. morphInfluences[_i4] = value;
  10543. morphInfluencesSum += value;
  10544. } else {
  10545. if (morphTargets && geometry.hasAttribute('morphTarget' + _i4) === true) {
  10546. geometry.deleteAttribute('morphTarget' + _i4);
  10547. }
  10548. if (morphNormals && geometry.hasAttribute('morphNormal' + _i4) === true) {
  10549. geometry.deleteAttribute('morphNormal' + _i4);
  10550. }
  10551. morphInfluences[_i4] = 0;
  10552. }
  10553. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  10554. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  10555. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  10556. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  10557. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  10558. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  10559. }
  10560. return {
  10561. update: update
  10562. };
  10563. }
  10564. function WebGLObjects(gl, geometries, attributes, info) {
  10565. var updateMap = new WeakMap();
  10566. function update(object) {
  10567. var frame = info.render.frame;
  10568. var geometry = object.geometry;
  10569. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  10570. if (updateMap.get(buffergeometry) !== frame) {
  10571. geometries.update(buffergeometry);
  10572. updateMap.set(buffergeometry, frame);
  10573. }
  10574. if (object.isInstancedMesh) {
  10575. if (object.hasEventListener('dispose', onInstancedMeshDispose) === false) {
  10576. object.addEventListener('dispose', onInstancedMeshDispose);
  10577. }
  10578. attributes.update(object.instanceMatrix, 34962);
  10579. if (object.instanceColor !== null) {
  10580. attributes.update(object.instanceColor, 34962);
  10581. }
  10582. }
  10583. return buffergeometry;
  10584. }
  10585. function dispose() {
  10586. updateMap = new WeakMap();
  10587. }
  10588. function onInstancedMeshDispose(event) {
  10589. var instancedMesh = event.target;
  10590. instancedMesh.removeEventListener('dispose', onInstancedMeshDispose);
  10591. attributes.remove(instancedMesh.instanceMatrix);
  10592. if (instancedMesh.instanceColor !== null) attributes.remove(instancedMesh.instanceColor);
  10593. }
  10594. return {
  10595. update: update,
  10596. dispose: dispose
  10597. };
  10598. }
  10599. function DataTexture2DArray(data, width, height, depth) {
  10600. if (data === void 0) {
  10601. data = null;
  10602. }
  10603. if (width === void 0) {
  10604. width = 1;
  10605. }
  10606. if (height === void 0) {
  10607. height = 1;
  10608. }
  10609. if (depth === void 0) {
  10610. depth = 1;
  10611. }
  10612. Texture.call(this, null);
  10613. this.image = {
  10614. data: data,
  10615. width: width,
  10616. height: height,
  10617. depth: depth
  10618. };
  10619. this.magFilter = NearestFilter;
  10620. this.minFilter = NearestFilter;
  10621. this.wrapR = ClampToEdgeWrapping;
  10622. this.generateMipmaps = false;
  10623. this.flipY = false;
  10624. this.needsUpdate = true;
  10625. }
  10626. DataTexture2DArray.prototype = Object.create(Texture.prototype);
  10627. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  10628. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  10629. function DataTexture3D(data, width, height, depth) {
  10630. if (data === void 0) {
  10631. data = null;
  10632. }
  10633. if (width === void 0) {
  10634. width = 1;
  10635. }
  10636. if (height === void 0) {
  10637. height = 1;
  10638. }
  10639. if (depth === void 0) {
  10640. depth = 1;
  10641. }
  10642. // We're going to add .setXXX() methods for setting properties later.
  10643. // Users can still set in DataTexture3D directly.
  10644. //
  10645. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  10646. // texture.anisotropy = 16;
  10647. //
  10648. // See #14839
  10649. Texture.call(this, null);
  10650. this.image = {
  10651. data: data,
  10652. width: width,
  10653. height: height,
  10654. depth: depth
  10655. };
  10656. this.magFilter = NearestFilter;
  10657. this.minFilter = NearestFilter;
  10658. this.wrapR = ClampToEdgeWrapping;
  10659. this.generateMipmaps = false;
  10660. this.flipY = false;
  10661. this.needsUpdate = true;
  10662. }
  10663. DataTexture3D.prototype = Object.create(Texture.prototype);
  10664. DataTexture3D.prototype.constructor = DataTexture3D;
  10665. DataTexture3D.prototype.isDataTexture3D = true;
  10666. /**
  10667. * Uniforms of a program.
  10668. * Those form a tree structure with a special top-level container for the root,
  10669. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10670. *
  10671. *
  10672. * Properties of inner nodes including the top-level container:
  10673. *
  10674. * .seq - array of nested uniforms
  10675. * .map - nested uniforms by name
  10676. *
  10677. *
  10678. * Methods of all nodes except the top-level container:
  10679. *
  10680. * .setValue( gl, value, [textures] )
  10681. *
  10682. * uploads a uniform value(s)
  10683. * the 'textures' parameter is needed for sampler uniforms
  10684. *
  10685. *
  10686. * Static methods of the top-level container (textures factorizations):
  10687. *
  10688. * .upload( gl, seq, values, textures )
  10689. *
  10690. * sets uniforms in 'seq' to 'values[id].value'
  10691. *
  10692. * .seqWithValue( seq, values ) : filteredSeq
  10693. *
  10694. * filters 'seq' entries with corresponding entry in values
  10695. *
  10696. *
  10697. * Methods of the top-level container (textures factorizations):
  10698. *
  10699. * .setValue( gl, name, value, textures )
  10700. *
  10701. * sets uniform with name 'name' to 'value'
  10702. *
  10703. * .setOptional( gl, obj, prop )
  10704. *
  10705. * like .set for an optional property of the object
  10706. *
  10707. */
  10708. var emptyTexture = new Texture();
  10709. var emptyTexture2dArray = new DataTexture2DArray();
  10710. var emptyTexture3d = new DataTexture3D();
  10711. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  10712. // Array Caches (provide typed arrays for temporary by size)
  10713. var arrayCacheF32 = [];
  10714. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  10715. var mat4array = new Float32Array(16);
  10716. var mat3array = new Float32Array(9);
  10717. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  10718. function flatten(array, nBlocks, blockSize) {
  10719. var firstElem = array[0];
  10720. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  10721. // see http://jacksondunstan.com/articles/983
  10722. var n = nBlocks * blockSize;
  10723. var r = arrayCacheF32[n];
  10724. if (r === undefined) {
  10725. r = new Float32Array(n);
  10726. arrayCacheF32[n] = r;
  10727. }
  10728. if (nBlocks !== 0) {
  10729. firstElem.toArray(r, 0);
  10730. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  10731. offset += blockSize;
  10732. array[i].toArray(r, offset);
  10733. }
  10734. }
  10735. return r;
  10736. }
  10737. function arraysEqual(a, b) {
  10738. if (a.length !== b.length) return false;
  10739. for (var i = 0, l = a.length; i < l; i++) {
  10740. if (a[i] !== b[i]) return false;
  10741. }
  10742. return true;
  10743. }
  10744. function copyArray(a, b) {
  10745. for (var i = 0, l = b.length; i < l; i++) {
  10746. a[i] = b[i];
  10747. }
  10748. } // Texture unit allocation
  10749. function allocTexUnits(textures, n) {
  10750. var r = arrayCacheI32[n];
  10751. if (r === undefined) {
  10752. r = new Int32Array(n);
  10753. arrayCacheI32[n] = r;
  10754. }
  10755. for (var i = 0; i !== n; ++i) {
  10756. r[i] = textures.allocateTextureUnit();
  10757. }
  10758. return r;
  10759. } // --- Setters ---
  10760. // Note: Defining these methods externally, because they come in a bunch
  10761. // and this way their names minify.
  10762. // Single scalar
  10763. function setValueV1f(gl, v) {
  10764. var cache = this.cache;
  10765. if (cache[0] === v) return;
  10766. gl.uniform1f(this.addr, v);
  10767. cache[0] = v;
  10768. } // Single float vector (from flat array or THREE.VectorN)
  10769. function setValueV2f(gl, v) {
  10770. var cache = this.cache;
  10771. if (v.x !== undefined) {
  10772. if (cache[0] !== v.x || cache[1] !== v.y) {
  10773. gl.uniform2f(this.addr, v.x, v.y);
  10774. cache[0] = v.x;
  10775. cache[1] = v.y;
  10776. }
  10777. } else {
  10778. if (arraysEqual(cache, v)) return;
  10779. gl.uniform2fv(this.addr, v);
  10780. copyArray(cache, v);
  10781. }
  10782. }
  10783. function setValueV3f(gl, v) {
  10784. var cache = this.cache;
  10785. if (v.x !== undefined) {
  10786. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10787. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10788. cache[0] = v.x;
  10789. cache[1] = v.y;
  10790. cache[2] = v.z;
  10791. }
  10792. } else if (v.r !== undefined) {
  10793. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10794. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10795. cache[0] = v.r;
  10796. cache[1] = v.g;
  10797. cache[2] = v.b;
  10798. }
  10799. } else {
  10800. if (arraysEqual(cache, v)) return;
  10801. gl.uniform3fv(this.addr, v);
  10802. copyArray(cache, v);
  10803. }
  10804. }
  10805. function setValueV4f(gl, v) {
  10806. var cache = this.cache;
  10807. if (v.x !== undefined) {
  10808. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10809. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10810. cache[0] = v.x;
  10811. cache[1] = v.y;
  10812. cache[2] = v.z;
  10813. cache[3] = v.w;
  10814. }
  10815. } else {
  10816. if (arraysEqual(cache, v)) return;
  10817. gl.uniform4fv(this.addr, v);
  10818. copyArray(cache, v);
  10819. }
  10820. } // Single matrix (from flat array or MatrixN)
  10821. function setValueM2(gl, v) {
  10822. var cache = this.cache;
  10823. var elements = v.elements;
  10824. if (elements === undefined) {
  10825. if (arraysEqual(cache, v)) return;
  10826. gl.uniformMatrix2fv(this.addr, false, v);
  10827. copyArray(cache, v);
  10828. } else {
  10829. if (arraysEqual(cache, elements)) return;
  10830. mat2array.set(elements);
  10831. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10832. copyArray(cache, elements);
  10833. }
  10834. }
  10835. function setValueM3(gl, v) {
  10836. var cache = this.cache;
  10837. var elements = v.elements;
  10838. if (elements === undefined) {
  10839. if (arraysEqual(cache, v)) return;
  10840. gl.uniformMatrix3fv(this.addr, false, v);
  10841. copyArray(cache, v);
  10842. } else {
  10843. if (arraysEqual(cache, elements)) return;
  10844. mat3array.set(elements);
  10845. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10846. copyArray(cache, elements);
  10847. }
  10848. }
  10849. function setValueM4(gl, v) {
  10850. var cache = this.cache;
  10851. var elements = v.elements;
  10852. if (elements === undefined) {
  10853. if (arraysEqual(cache, v)) return;
  10854. gl.uniformMatrix4fv(this.addr, false, v);
  10855. copyArray(cache, v);
  10856. } else {
  10857. if (arraysEqual(cache, elements)) return;
  10858. mat4array.set(elements);
  10859. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10860. copyArray(cache, elements);
  10861. }
  10862. } // Single texture (2D / Cube)
  10863. function setValueT1(gl, v, textures) {
  10864. var cache = this.cache;
  10865. var unit = textures.allocateTextureUnit();
  10866. if (cache[0] !== unit) {
  10867. gl.uniform1i(this.addr, unit);
  10868. cache[0] = unit;
  10869. }
  10870. textures.safeSetTexture2D(v || emptyTexture, unit);
  10871. }
  10872. function setValueT2DArray1(gl, v, textures) {
  10873. var cache = this.cache;
  10874. var unit = textures.allocateTextureUnit();
  10875. if (cache[0] !== unit) {
  10876. gl.uniform1i(this.addr, unit);
  10877. cache[0] = unit;
  10878. }
  10879. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10880. }
  10881. function setValueT3D1(gl, v, textures) {
  10882. var cache = this.cache;
  10883. var unit = textures.allocateTextureUnit();
  10884. if (cache[0] !== unit) {
  10885. gl.uniform1i(this.addr, unit);
  10886. cache[0] = unit;
  10887. }
  10888. textures.setTexture3D(v || emptyTexture3d, unit);
  10889. }
  10890. function setValueT6(gl, v, textures) {
  10891. var cache = this.cache;
  10892. var unit = textures.allocateTextureUnit();
  10893. if (cache[0] !== unit) {
  10894. gl.uniform1i(this.addr, unit);
  10895. cache[0] = unit;
  10896. }
  10897. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10898. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10899. function setValueV1i(gl, v) {
  10900. var cache = this.cache;
  10901. if (cache[0] === v) return;
  10902. gl.uniform1i(this.addr, v);
  10903. cache[0] = v;
  10904. }
  10905. function setValueV2i(gl, v) {
  10906. var cache = this.cache;
  10907. if (arraysEqual(cache, v)) return;
  10908. gl.uniform2iv(this.addr, v);
  10909. copyArray(cache, v);
  10910. }
  10911. function setValueV3i(gl, v) {
  10912. var cache = this.cache;
  10913. if (arraysEqual(cache, v)) return;
  10914. gl.uniform3iv(this.addr, v);
  10915. copyArray(cache, v);
  10916. }
  10917. function setValueV4i(gl, v) {
  10918. var cache = this.cache;
  10919. if (arraysEqual(cache, v)) return;
  10920. gl.uniform4iv(this.addr, v);
  10921. copyArray(cache, v);
  10922. } // uint
  10923. function setValueV1ui(gl, v) {
  10924. var cache = this.cache;
  10925. if (cache[0] === v) return;
  10926. gl.uniform1ui(this.addr, v);
  10927. cache[0] = v;
  10928. } // Helper to pick the right setter for the singular case
  10929. function getSingularSetter(type) {
  10930. switch (type) {
  10931. case 0x1406:
  10932. return setValueV1f;
  10933. // FLOAT
  10934. case 0x8b50:
  10935. return setValueV2f;
  10936. // _VEC2
  10937. case 0x8b51:
  10938. return setValueV3f;
  10939. // _VEC3
  10940. case 0x8b52:
  10941. return setValueV4f;
  10942. // _VEC4
  10943. case 0x8b5a:
  10944. return setValueM2;
  10945. // _MAT2
  10946. case 0x8b5b:
  10947. return setValueM3;
  10948. // _MAT3
  10949. case 0x8b5c:
  10950. return setValueM4;
  10951. // _MAT4
  10952. case 0x1404:
  10953. case 0x8b56:
  10954. return setValueV1i;
  10955. // INT, BOOL
  10956. case 0x8b53:
  10957. case 0x8b57:
  10958. return setValueV2i;
  10959. // _VEC2
  10960. case 0x8b54:
  10961. case 0x8b58:
  10962. return setValueV3i;
  10963. // _VEC3
  10964. case 0x8b55:
  10965. case 0x8b59:
  10966. return setValueV4i;
  10967. // _VEC4
  10968. case 0x1405:
  10969. return setValueV1ui;
  10970. // UINT
  10971. case 0x8b5e: // SAMPLER_2D
  10972. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10973. case 0x8dca: // INT_SAMPLER_2D
  10974. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10975. case 0x8b62:
  10976. // SAMPLER_2D_SHADOW
  10977. return setValueT1;
  10978. case 0x8b5f: // SAMPLER_3D
  10979. case 0x8dcb: // INT_SAMPLER_3D
  10980. case 0x8dd3:
  10981. // UNSIGNED_INT_SAMPLER_3D
  10982. return setValueT3D1;
  10983. case 0x8b60: // SAMPLER_CUBE
  10984. case 0x8dcc: // INT_SAMPLER_CUBE
  10985. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10986. case 0x8dc5:
  10987. // SAMPLER_CUBE_SHADOW
  10988. return setValueT6;
  10989. case 0x8dc1: // SAMPLER_2D_ARRAY
  10990. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10991. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10992. case 0x8dc4:
  10993. // SAMPLER_2D_ARRAY_SHADOW
  10994. return setValueT2DArray1;
  10995. }
  10996. } // Array of scalars
  10997. function setValueV1fArray(gl, v) {
  10998. gl.uniform1fv(this.addr, v);
  10999. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  11000. function setValueV1iArray(gl, v) {
  11001. gl.uniform1iv(this.addr, v);
  11002. }
  11003. function setValueV2iArray(gl, v) {
  11004. gl.uniform2iv(this.addr, v);
  11005. }
  11006. function setValueV3iArray(gl, v) {
  11007. gl.uniform3iv(this.addr, v);
  11008. }
  11009. function setValueV4iArray(gl, v) {
  11010. gl.uniform4iv(this.addr, v);
  11011. } // Array of vectors (flat or from THREE classes)
  11012. function setValueV2fArray(gl, v) {
  11013. var data = flatten(v, this.size, 2);
  11014. gl.uniform2fv(this.addr, data);
  11015. }
  11016. function setValueV3fArray(gl, v) {
  11017. var data = flatten(v, this.size, 3);
  11018. gl.uniform3fv(this.addr, data);
  11019. }
  11020. function setValueV4fArray(gl, v) {
  11021. var data = flatten(v, this.size, 4);
  11022. gl.uniform4fv(this.addr, data);
  11023. } // Array of matrices (flat or from THREE clases)
  11024. function setValueM2Array(gl, v) {
  11025. var data = flatten(v, this.size, 4);
  11026. gl.uniformMatrix2fv(this.addr, false, data);
  11027. }
  11028. function setValueM3Array(gl, v) {
  11029. var data = flatten(v, this.size, 9);
  11030. gl.uniformMatrix3fv(this.addr, false, data);
  11031. }
  11032. function setValueM4Array(gl, v) {
  11033. var data = flatten(v, this.size, 16);
  11034. gl.uniformMatrix4fv(this.addr, false, data);
  11035. } // Array of textures (2D / Cube)
  11036. function setValueT1Array(gl, v, textures) {
  11037. var n = v.length;
  11038. var units = allocTexUnits(textures, n);
  11039. gl.uniform1iv(this.addr, units);
  11040. for (var i = 0; i !== n; ++i) {
  11041. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  11042. }
  11043. }
  11044. function setValueT6Array(gl, v, textures) {
  11045. var n = v.length;
  11046. var units = allocTexUnits(textures, n);
  11047. gl.uniform1iv(this.addr, units);
  11048. for (var i = 0; i !== n; ++i) {
  11049. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  11050. }
  11051. } // Helper to pick the right setter for a pure (bottom-level) array
  11052. function getPureArraySetter(type) {
  11053. switch (type) {
  11054. case 0x1406:
  11055. return setValueV1fArray;
  11056. // FLOAT
  11057. case 0x8b50:
  11058. return setValueV2fArray;
  11059. // _VEC2
  11060. case 0x8b51:
  11061. return setValueV3fArray;
  11062. // _VEC3
  11063. case 0x8b52:
  11064. return setValueV4fArray;
  11065. // _VEC4
  11066. case 0x8b5a:
  11067. return setValueM2Array;
  11068. // _MAT2
  11069. case 0x8b5b:
  11070. return setValueM3Array;
  11071. // _MAT3
  11072. case 0x8b5c:
  11073. return setValueM4Array;
  11074. // _MAT4
  11075. case 0x1404:
  11076. case 0x8b56:
  11077. return setValueV1iArray;
  11078. // INT, BOOL
  11079. case 0x8b53:
  11080. case 0x8b57:
  11081. return setValueV2iArray;
  11082. // _VEC2
  11083. case 0x8b54:
  11084. case 0x8b58:
  11085. return setValueV3iArray;
  11086. // _VEC3
  11087. case 0x8b55:
  11088. case 0x8b59:
  11089. return setValueV4iArray;
  11090. // _VEC4
  11091. case 0x8b5e: // SAMPLER_2D
  11092. case 0x8d66: // SAMPLER_EXTERNAL_OES
  11093. case 0x8dca: // INT_SAMPLER_2D
  11094. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  11095. case 0x8b62:
  11096. // SAMPLER_2D_SHADOW
  11097. return setValueT1Array;
  11098. case 0x8b60: // SAMPLER_CUBE
  11099. case 0x8dcc: // INT_SAMPLER_CUBE
  11100. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  11101. case 0x8dc5:
  11102. // SAMPLER_CUBE_SHADOW
  11103. return setValueT6Array;
  11104. }
  11105. } // --- Uniform Classes ---
  11106. function SingleUniform(id, activeInfo, addr) {
  11107. this.id = id;
  11108. this.addr = addr;
  11109. this.cache = [];
  11110. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  11111. }
  11112. function PureArrayUniform(id, activeInfo, addr) {
  11113. this.id = id;
  11114. this.addr = addr;
  11115. this.cache = [];
  11116. this.size = activeInfo.size;
  11117. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  11118. }
  11119. PureArrayUniform.prototype.updateCache = function (data) {
  11120. var cache = this.cache;
  11121. if (data instanceof Float32Array && cache.length !== data.length) {
  11122. this.cache = new Float32Array(data.length);
  11123. }
  11124. copyArray(cache, data);
  11125. };
  11126. function StructuredUniform(id) {
  11127. this.id = id;
  11128. this.seq = [];
  11129. this.map = {};
  11130. }
  11131. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  11132. var seq = this.seq;
  11133. for (var i = 0, n = seq.length; i !== n; ++i) {
  11134. var u = seq[i];
  11135. u.setValue(gl, value[u.id], textures);
  11136. }
  11137. }; // --- Top-level ---
  11138. // Parser - builds up the property tree from the path strings
  11139. var RePathPart = /(\w+)(\])?(\[|\.)?/g; // extracts
  11140. // - the identifier (member name or array index)
  11141. // - followed by an optional right bracket (found when array index)
  11142. // - followed by an optional left bracket or dot (type of subscript)
  11143. //
  11144. // Note: These portions can be read in a non-overlapping fashion and
  11145. // allow straightforward parsing of the hierarchy that WebGL encodes
  11146. // in the uniform names.
  11147. function addUniform(container, uniformObject) {
  11148. container.seq.push(uniformObject);
  11149. container.map[uniformObject.id] = uniformObject;
  11150. }
  11151. function parseUniform(activeInfo, addr, container) {
  11152. var path = activeInfo.name,
  11153. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  11154. RePathPart.lastIndex = 0;
  11155. while (true) {
  11156. var match = RePathPart.exec(path),
  11157. matchEnd = RePathPart.lastIndex;
  11158. var id = match[1];
  11159. var idIsIndex = match[2] === ']',
  11160. subscript = match[3];
  11161. if (idIsIndex) id = id | 0; // convert to integer
  11162. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  11163. // bare name or "pure" bottom-level array "[0]" suffix
  11164. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  11165. break;
  11166. } else {
  11167. // step into inner node / create it in case it doesn't exist
  11168. var map = container.map;
  11169. var next = map[id];
  11170. if (next === undefined) {
  11171. next = new StructuredUniform(id);
  11172. addUniform(container, next);
  11173. }
  11174. container = next;
  11175. }
  11176. }
  11177. } // Root Container
  11178. function WebGLUniforms(gl, program) {
  11179. this.seq = [];
  11180. this.map = {};
  11181. var n = gl.getProgramParameter(program, 35718);
  11182. for (var i = 0; i < n; ++i) {
  11183. var info = gl.getActiveUniform(program, i),
  11184. addr = gl.getUniformLocation(program, info.name);
  11185. parseUniform(info, addr, this);
  11186. }
  11187. }
  11188. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  11189. var u = this.map[name];
  11190. if (u !== undefined) u.setValue(gl, value, textures);
  11191. };
  11192. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  11193. var v = object[name];
  11194. if (v !== undefined) this.setValue(gl, name, v);
  11195. }; // Static interface
  11196. WebGLUniforms.upload = function (gl, seq, values, textures) {
  11197. for (var i = 0, n = seq.length; i !== n; ++i) {
  11198. var u = seq[i],
  11199. v = values[u.id];
  11200. if (v.needsUpdate !== false) {
  11201. // note: always updating when .needsUpdate is undefined
  11202. u.setValue(gl, v.value, textures);
  11203. }
  11204. }
  11205. };
  11206. WebGLUniforms.seqWithValue = function (seq, values) {
  11207. var r = [];
  11208. for (var i = 0, n = seq.length; i !== n; ++i) {
  11209. var u = seq[i];
  11210. if (u.id in values) r.push(u);
  11211. }
  11212. return r;
  11213. };
  11214. function WebGLShader(gl, type, string) {
  11215. var shader = gl.createShader(type);
  11216. gl.shaderSource(shader, string);
  11217. gl.compileShader(shader);
  11218. return shader;
  11219. }
  11220. var programIdCount = 0;
  11221. function addLineNumbers(string) {
  11222. var lines = string.split('\n');
  11223. for (var i = 0; i < lines.length; i++) {
  11224. lines[i] = i + 1 + ': ' + lines[i];
  11225. }
  11226. return lines.join('\n');
  11227. }
  11228. function getEncodingComponents(encoding) {
  11229. switch (encoding) {
  11230. case LinearEncoding:
  11231. return ['Linear', '( value )'];
  11232. case sRGBEncoding:
  11233. return ['sRGB', '( value )'];
  11234. case RGBEEncoding:
  11235. return ['RGBE', '( value )'];
  11236. case RGBM7Encoding:
  11237. return ['RGBM', '( value, 7.0 )'];
  11238. case RGBM16Encoding:
  11239. return ['RGBM', '( value, 16.0 )'];
  11240. case RGBDEncoding:
  11241. return ['RGBD', '( value, 256.0 )'];
  11242. case GammaEncoding:
  11243. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  11244. case LogLuvEncoding:
  11245. return ['LogLuv', '( value )'];
  11246. default:
  11247. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  11248. return ['Linear', '( value )'];
  11249. }
  11250. }
  11251. function getShaderErrors(gl, shader, type) {
  11252. var status = gl.getShaderParameter(shader, 35713);
  11253. var log = gl.getShaderInfoLog(shader).trim();
  11254. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  11255. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  11256. var source = gl.getShaderSource(shader);
  11257. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  11258. }
  11259. function getTexelDecodingFunction(functionName, encoding) {
  11260. var components = getEncodingComponents(encoding);
  11261. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  11262. }
  11263. function getTexelEncodingFunction(functionName, encoding) {
  11264. var components = getEncodingComponents(encoding);
  11265. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  11266. }
  11267. function getToneMappingFunction(functionName, toneMapping) {
  11268. var toneMappingName;
  11269. switch (toneMapping) {
  11270. case LinearToneMapping:
  11271. toneMappingName = 'Linear';
  11272. break;
  11273. case ReinhardToneMapping:
  11274. toneMappingName = 'Reinhard';
  11275. break;
  11276. case CineonToneMapping:
  11277. toneMappingName = 'OptimizedCineon';
  11278. break;
  11279. case ACESFilmicToneMapping:
  11280. toneMappingName = 'ACESFilmic';
  11281. break;
  11282. case CustomToneMapping:
  11283. toneMappingName = 'Custom';
  11284. break;
  11285. default:
  11286. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  11287. toneMappingName = 'Linear';
  11288. }
  11289. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  11290. }
  11291. function generateExtensions(parameters) {
  11292. var chunks = [parameters.extensionDerivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.tangentSpaceNormalMap || parameters.clearcoatNormalMap || parameters.flatShading || parameters.shaderID === 'physical' ? '#extension GL_OES_standard_derivatives : enable' : '', (parameters.extensionFragDepth || parameters.logarithmicDepthBuffer) && parameters.rendererExtensionFragDepth ? '#extension GL_EXT_frag_depth : enable' : '', parameters.extensionDrawBuffers && parameters.rendererExtensionDrawBuffers ? '#extension GL_EXT_draw_buffers : require' : '', (parameters.extensionShaderTextureLOD || parameters.envMap) && parameters.rendererExtensionShaderTextureLod ? '#extension GL_EXT_shader_texture_lod : enable' : ''];
  11293. return chunks.filter(filterEmptyLine).join('\n');
  11294. }
  11295. function generateDefines(defines) {
  11296. var chunks = [];
  11297. for (var name in defines) {
  11298. var value = defines[name];
  11299. if (value === false) continue;
  11300. chunks.push('#define ' + name + ' ' + value);
  11301. }
  11302. return chunks.join('\n');
  11303. }
  11304. function fetchAttributeLocations(gl, program) {
  11305. var attributes = {};
  11306. var n = gl.getProgramParameter(program, 35721);
  11307. for (var i = 0; i < n; i++) {
  11308. var info = gl.getActiveAttrib(program, i);
  11309. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  11310. attributes[name] = gl.getAttribLocation(program, name);
  11311. }
  11312. return attributes;
  11313. }
  11314. function filterEmptyLine(string) {
  11315. return string !== '';
  11316. }
  11317. function replaceLightNums(string, parameters) {
  11318. return string.replace(/NUM_DIR_LIGHTS/g, parameters.numDirLights).replace(/NUM_SPOT_LIGHTS/g, parameters.numSpotLights).replace(/NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g, parameters.numPointLights).replace(/NUM_HEMI_LIGHTS/g, parameters.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g, parameters.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS/g, parameters.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g, parameters.numPointLightShadows);
  11319. }
  11320. function replaceClippingPlaneNums(string, parameters) {
  11321. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  11322. } // Resolve Includes
  11323. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  11324. function resolveIncludes(string) {
  11325. return string.replace(includePattern, includeReplacer);
  11326. }
  11327. function includeReplacer(match, include) {
  11328. var string = ShaderChunk[include];
  11329. if (string === undefined) {
  11330. throw new Error('Can not resolve #include <' + include + '>');
  11331. }
  11332. return resolveIncludes(string);
  11333. } // Unroll Loops
  11334. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  11335. var unrollLoopPattern = /#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;
  11336. function unrollLoops(string) {
  11337. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  11338. }
  11339. function deprecatedLoopReplacer(match, start, end, snippet) {
  11340. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  11341. return loopReplacer(match, start, end, snippet);
  11342. }
  11343. function loopReplacer(match, start, end, snippet) {
  11344. var string = '';
  11345. for (var i = parseInt(start); i < parseInt(end); i++) {
  11346. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  11347. }
  11348. return string;
  11349. } //
  11350. function generatePrecision(parameters) {
  11351. var precisionstring = 'precision ' + parameters.precision + ' float;\nprecision ' + parameters.precision + ' int;';
  11352. if (parameters.precision === 'highp') {
  11353. precisionstring += '\n#define HIGH_PRECISION';
  11354. } else if (parameters.precision === 'mediump') {
  11355. precisionstring += '\n#define MEDIUM_PRECISION';
  11356. } else if (parameters.precision === 'lowp') {
  11357. precisionstring += '\n#define LOW_PRECISION';
  11358. }
  11359. return precisionstring;
  11360. }
  11361. function generateShadowMapTypeDefine(parameters) {
  11362. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  11363. if (parameters.shadowMapType === PCFShadowMap) {
  11364. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  11365. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  11366. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  11367. } else if (parameters.shadowMapType === VSMShadowMap) {
  11368. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  11369. }
  11370. return shadowMapTypeDefine;
  11371. }
  11372. function generateEnvMapTypeDefine(parameters) {
  11373. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11374. if (parameters.envMap) {
  11375. switch (parameters.envMapMode) {
  11376. case CubeReflectionMapping:
  11377. case CubeRefractionMapping:
  11378. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11379. break;
  11380. case CubeUVReflectionMapping:
  11381. case CubeUVRefractionMapping:
  11382. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  11383. break;
  11384. }
  11385. }
  11386. return envMapTypeDefine;
  11387. }
  11388. function generateEnvMapModeDefine(parameters) {
  11389. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  11390. if (parameters.envMap) {
  11391. switch (parameters.envMapMode) {
  11392. case CubeRefractionMapping:
  11393. case CubeUVRefractionMapping:
  11394. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  11395. break;
  11396. }
  11397. }
  11398. return envMapModeDefine;
  11399. }
  11400. function generateEnvMapBlendingDefine(parameters) {
  11401. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  11402. if (parameters.envMap) {
  11403. switch (parameters.combine) {
  11404. case MultiplyOperation:
  11405. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  11406. break;
  11407. case MixOperation:
  11408. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  11409. break;
  11410. case AddOperation:
  11411. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  11412. break;
  11413. }
  11414. }
  11415. return envMapBlendingDefine;
  11416. }
  11417. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  11418. var gl = renderer.getContext();
  11419. var defines = parameters.defines;
  11420. var vertexShader = parameters.vertexShader;
  11421. var fragmentShader = parameters.fragmentShader;
  11422. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  11423. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  11424. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  11425. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  11426. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  11427. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  11428. var customDefines = generateDefines(defines);
  11429. var program = gl.createProgram();
  11430. var prefixVertex, prefixFragment;
  11431. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : '';
  11432. if (parameters.isRawShaderMaterial) {
  11433. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  11434. if (prefixVertex.length > 0) {
  11435. prefixVertex += '\n';
  11436. }
  11437. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  11438. if (prefixFragment.length > 0) {
  11439. prefixFragment += '\n';
  11440. }
  11441. } else {
  11442. prefixVertex = [generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.instancing ? '#define USE_INSTANCING' : '', parameters.instancingColor ? '#define USE_INSTANCING_COLOR' : '', parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '', '#define GAMMA_FACTOR ' + gammaFactorDefine, '#define MAX_BONES ' + parameters.maxBones, parameters.useFog && parameters.fog ? '#define USE_FOG' : '', parameters.useFog && parameters.fogExp2 ? '#define FOG_EXP2' : '', parameters.map ? '#define USE_MAP' : '', parameters.envMap ? '#define USE_ENVMAP' : '', parameters.envMap ? '#define ' + envMapModeDefine : '', parameters.lightMap ? '#define USE_LIGHTMAP' : '', parameters.aoMap ? '#define USE_AOMAP' : '', parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '', parameters.bumpMap ? '#define USE_BUMPMAP' : '', parameters.normalMap ? '#define USE_NORMALMAP' : '', parameters.normalMap && parameters.objectSpaceNormalMap ? '#define OBJECTSPACE_NORMALMAP' : '', parameters.normalMap && parameters.tangentSpaceNormalMap ? '#define TANGENTSPACE_NORMALMAP' : '', parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '', parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '', parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '', parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '', parameters.specularMap ? '#define USE_SPECULARMAP' : '', parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '', parameters.metalnessMap ? '#define USE_METALNESSMAP' : '', parameters.alphaMap ? '#define USE_ALPHAMAP' : '', parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '', parameters.vertexTangents ? '#define USE_TANGENT' : '', parameters.vertexColors ? '#define USE_COLOR' : '', parameters.vertexUvs ? '#define USE_UV' : '', parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '', parameters.flatShading ? '#define FLAT_SHADED' : '', parameters.skinning ? '#define USE_SKINNING' : '', parameters.useVertexTexture ? '#define BONE_TEXTURE' : '', parameters.morphTargets ? '#define USE_MORPHTARGETS' : '', parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '', parameters.doubleSided ? '#define DOUBLE_SIDED' : '', parameters.flipSided ? '#define FLIP_SIDED' : '', parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '', parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '', parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '', parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '', parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ? '#define USE_LOGDEPTHBUF_EXT' : '', 'uniform mat4 modelMatrix;', 'uniform mat4 modelViewMatrix;', 'uniform mat4 projectionMatrix;', 'uniform mat4 viewMatrix;', 'uniform mat3 normalMatrix;', 'uniform vec3 cameraPosition;', 'uniform bool isOrthographic;', '#ifdef USE_INSTANCING', ' attribute mat4 instanceMatrix;', '#endif', '#ifdef USE_INSTANCING_COLOR', ' attribute vec3 instanceColor;', '#endif', 'attribute vec3 position;', 'attribute vec3 normal;', 'attribute vec2 uv;', '#ifdef USE_TANGENT', ' attribute vec4 tangent;', '#endif', '#ifdef USE_COLOR', ' attribute vec3 color;', '#endif', '#ifdef USE_MORPHTARGETS', ' attribute vec3 morphTarget0;', ' attribute vec3 morphTarget1;', ' attribute vec3 morphTarget2;', ' attribute vec3 morphTarget3;', ' #ifdef USE_MORPHNORMALS', ' attribute vec3 morphNormal0;', ' attribute vec3 morphNormal1;', ' attribute vec3 morphNormal2;', ' attribute vec3 morphNormal3;', ' #else', ' attribute vec3 morphTarget4;', ' attribute vec3 morphTarget5;', ' attribute vec3 morphTarget6;', ' attribute vec3 morphTarget7;', ' #endif', '#endif', '#ifdef USE_SKINNING', ' attribute vec4 skinIndex;', ' attribute vec4 skinWeight;', '#endif', '\n'].filter(filterEmptyLine).join('\n');
  11443. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  11444. '#define GAMMA_FACTOR ' + gammaFactorDefine, parameters.useFog && parameters.fog ? '#define USE_FOG' : '', parameters.useFog && parameters.fogExp2 ? '#define FOG_EXP2' : '', parameters.map ? '#define USE_MAP' : '', parameters.matcap ? '#define USE_MATCAP' : '', parameters.envMap ? '#define USE_ENVMAP' : '', parameters.envMap ? '#define ' + envMapTypeDefine : '', parameters.envMap ? '#define ' + envMapModeDefine : '', parameters.envMap ? '#define ' + envMapBlendingDefine : '', parameters.lightMap ? '#define USE_LIGHTMAP' : '', parameters.aoMap ? '#define USE_AOMAP' : '', parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '', parameters.bumpMap ? '#define USE_BUMPMAP' : '', parameters.normalMap ? '#define USE_NORMALMAP' : '', parameters.normalMap && parameters.objectSpaceNormalMap ? '#define OBJECTSPACE_NORMALMAP' : '', parameters.normalMap && parameters.tangentSpaceNormalMap ? '#define TANGENTSPACE_NORMALMAP' : '', parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '', parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '', parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '', parameters.specularMap ? '#define USE_SPECULARMAP' : '', parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '', parameters.metalnessMap ? '#define USE_METALNESSMAP' : '', parameters.alphaMap ? '#define USE_ALPHAMAP' : '', parameters.sheen ? '#define USE_SHEEN' : '', parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '', parameters.vertexTangents ? '#define USE_TANGENT' : '', parameters.vertexColors || parameters.instancingColor ? '#define USE_COLOR' : '', parameters.vertexUvs ? '#define USE_UV' : '', parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '', parameters.gradientMap ? '#define USE_GRADIENTMAP' : '', parameters.flatShading ? '#define FLAT_SHADED' : '', parameters.doubleSided ? '#define DOUBLE_SIDED' : '', parameters.flipSided ? '#define FLIP_SIDED' : '', parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '', parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '', parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '', parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '', parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '', parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ? '#define USE_LOGDEPTHBUF_EXT' : '', (parameters.extensionShaderTextureLOD || parameters.envMap) && parameters.rendererExtensionShaderTextureLod ? '#define TEXTURE_LOD_EXT' : '', 'uniform mat4 viewMatrix;', 'uniform vec3 cameraPosition;', 'uniform bool isOrthographic;', parameters.toneMapping !== NoToneMapping ? '#define TONE_MAPPING' : '', parameters.toneMapping !== NoToneMapping ? ShaderChunk['tonemapping_pars_fragment'] : '', // this code is required here because it is used by the toneMapping() function defined below
  11445. parameters.toneMapping !== NoToneMapping ? getToneMappingFunction('toneMapping', parameters.toneMapping) : '', parameters.dithering ? '#define DITHERING' : '', ShaderChunk['encodings_pars_fragment'], // this code is required here because it is used by the various encoding/decoding function defined below
  11446. parameters.map ? getTexelDecodingFunction('mapTexelToLinear', parameters.mapEncoding) : '', parameters.matcap ? getTexelDecodingFunction('matcapTexelToLinear', parameters.matcapEncoding) : '', parameters.envMap ? getTexelDecodingFunction('envMapTexelToLinear', parameters.envMapEncoding) : '', parameters.emissiveMap ? getTexelDecodingFunction('emissiveMapTexelToLinear', parameters.emissiveMapEncoding) : '', parameters.lightMap ? getTexelDecodingFunction('lightMapTexelToLinear', parameters.lightMapEncoding) : '', getTexelEncodingFunction('linearToOutputTexel', parameters.outputEncoding), parameters.depthPacking ? '#define DEPTH_PACKING ' + parameters.depthPacking : '', '\n'].filter(filterEmptyLine).join('\n');
  11447. }
  11448. vertexShader = resolveIncludes(vertexShader);
  11449. vertexShader = replaceLightNums(vertexShader, parameters);
  11450. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  11451. fragmentShader = resolveIncludes(fragmentShader);
  11452. fragmentShader = replaceLightNums(fragmentShader, parameters);
  11453. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  11454. vertexShader = unrollLoops(vertexShader);
  11455. fragmentShader = unrollLoops(fragmentShader);
  11456. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  11457. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  11458. versionString = '#version 300 es\n';
  11459. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  11460. prefixFragment = ['#define varying in', parameters.glslVersion === GLSL3 ? '' : 'out highp vec4 pc_fragColor;', parameters.glslVersion === GLSL3 ? '' : '#define gl_FragColor pc_fragColor', '#define gl_FragDepthEXT gl_FragDepth', '#define texture2D texture', '#define textureCube texture', '#define texture2DProj textureProj', '#define texture2DLodEXT textureLod', '#define texture2DProjLodEXT textureProjLod', '#define textureCubeLodEXT textureLod', '#define texture2DGradEXT textureGrad', '#define texture2DProjGradEXT textureProjGrad', '#define textureCubeGradEXT textureGrad'].join('\n') + '\n' + prefixFragment;
  11461. }
  11462. var vertexGlsl = versionString + prefixVertex + vertexShader;
  11463. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  11464. // console.log( '*FRAGMENT*', fragmentGlsl );
  11465. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  11466. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  11467. gl.attachShader(program, glVertexShader);
  11468. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  11469. if (parameters.index0AttributeName !== undefined) {
  11470. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  11471. } else if (parameters.morphTargets === true) {
  11472. // programs with morphTargets displace position out of attribute 0
  11473. gl.bindAttribLocation(program, 0, 'position');
  11474. }
  11475. gl.linkProgram(program); // check for link errors
  11476. if (renderer.debug.checkShaderErrors) {
  11477. var programLog = gl.getProgramInfoLog(program).trim();
  11478. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  11479. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  11480. var runnable = true;
  11481. var haveDiagnostics = true;
  11482. if (gl.getProgramParameter(program, 35714) === false) {
  11483. runnable = false;
  11484. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  11485. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  11486. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  11487. } else if (programLog !== '') {
  11488. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  11489. } else if (vertexLog === '' || fragmentLog === '') {
  11490. haveDiagnostics = false;
  11491. }
  11492. if (haveDiagnostics) {
  11493. this.diagnostics = {
  11494. runnable: runnable,
  11495. programLog: programLog,
  11496. vertexShader: {
  11497. log: vertexLog,
  11498. prefix: prefixVertex
  11499. },
  11500. fragmentShader: {
  11501. log: fragmentLog,
  11502. prefix: prefixFragment
  11503. }
  11504. };
  11505. }
  11506. } // Clean up
  11507. // Crashes in iOS9 and iOS10. #18402
  11508. // gl.detachShader( program, glVertexShader );
  11509. // gl.detachShader( program, glFragmentShader );
  11510. gl.deleteShader(glVertexShader);
  11511. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  11512. var cachedUniforms;
  11513. this.getUniforms = function () {
  11514. if (cachedUniforms === undefined) {
  11515. cachedUniforms = new WebGLUniforms(gl, program);
  11516. }
  11517. return cachedUniforms;
  11518. }; // set up caching for attribute locations
  11519. var cachedAttributes;
  11520. this.getAttributes = function () {
  11521. if (cachedAttributes === undefined) {
  11522. cachedAttributes = fetchAttributeLocations(gl, program);
  11523. }
  11524. return cachedAttributes;
  11525. }; // free resource
  11526. this.destroy = function () {
  11527. bindingStates.releaseStatesOfProgram(this);
  11528. gl.deleteProgram(program);
  11529. this.program = undefined;
  11530. }; //
  11531. this.name = parameters.shaderName;
  11532. this.id = programIdCount++;
  11533. this.cacheKey = cacheKey;
  11534. this.usedTimes = 1;
  11535. this.program = program;
  11536. this.vertexShader = glVertexShader;
  11537. this.fragmentShader = glFragmentShader;
  11538. return this;
  11539. }
  11540. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  11541. var programs = [];
  11542. var isWebGL2 = capabilities.isWebGL2;
  11543. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  11544. var floatVertexTextures = capabilities.floatVertexTextures;
  11545. var maxVertexUniforms = capabilities.maxVertexUniforms;
  11546. var vertexTextures = capabilities.vertexTextures;
  11547. var precision = capabilities.precision;
  11548. var shaderIDs = {
  11549. MeshDepthMaterial: 'depth',
  11550. MeshDistanceMaterial: 'distanceRGBA',
  11551. MeshNormalMaterial: 'normal',
  11552. MeshBasicMaterial: 'basic',
  11553. MeshLambertMaterial: 'lambert',
  11554. MeshPhongMaterial: 'phong',
  11555. MeshToonMaterial: 'toon',
  11556. MeshStandardMaterial: 'physical',
  11557. MeshPhysicalMaterial: 'physical',
  11558. MeshMatcapMaterial: 'matcap',
  11559. LineBasicMaterial: 'basic',
  11560. LineDashedMaterial: 'dashed',
  11561. PointsMaterial: 'points',
  11562. ShadowMaterial: 'shadow',
  11563. SpriteMaterial: 'sprite'
  11564. };
  11565. var parameterNames = ['precision', 'isWebGL2', 'supportsVertexTextures', 'outputEncoding', 'instancing', 'instancingColor', 'map', 'mapEncoding', 'matcap', 'matcapEncoding', 'envMap', 'envMapMode', 'envMapEncoding', 'envMapCubeUV', 'lightMap', 'lightMapEncoding', 'aoMap', 'emissiveMap', 'emissiveMapEncoding', 'bumpMap', 'normalMap', 'objectSpaceNormalMap', 'tangentSpaceNormalMap', 'clearcoatMap', 'clearcoatRoughnessMap', 'clearcoatNormalMap', 'displacementMap', 'specularMap', 'roughnessMap', 'metalnessMap', 'gradientMap', 'alphaMap', 'combine', 'vertexColors', 'vertexTangents', 'vertexUvs', 'uvsVertexOnly', 'fog', 'useFog', 'fogExp2', 'flatShading', 'sizeAttenuation', 'logarithmicDepthBuffer', 'skinning', 'maxBones', 'useVertexTexture', 'morphTargets', 'morphNormals', 'maxMorphTargets', 'maxMorphNormals', 'premultipliedAlpha', 'numDirLights', 'numPointLights', 'numSpotLights', 'numHemiLights', 'numRectAreaLights', 'numDirLightShadows', 'numPointLightShadows', 'numSpotLightShadows', 'shadowMapEnabled', 'shadowMapType', 'toneMapping', 'physicallyCorrectLights', 'alphaTest', 'doubleSided', 'flipSided', 'numClippingPlanes', 'numClipIntersection', 'depthPacking', 'dithering', 'sheen', 'transmissionMap'];
  11566. function getMaxBones(object) {
  11567. var skeleton = object.skeleton;
  11568. var bones = skeleton.bones;
  11569. if (floatVertexTextures) {
  11570. return 1024;
  11571. } else {
  11572. // default for when object is not specified
  11573. // ( for example when prebuilding shader to be used with multiple objects )
  11574. //
  11575. // - leave some extra space for other uniforms
  11576. // - limit here is ANGLE's 254 max uniform vectors
  11577. // (up to 54 should be safe)
  11578. var nVertexUniforms = maxVertexUniforms;
  11579. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  11580. var maxBones = Math.min(nVertexMatrices, bones.length);
  11581. if (maxBones < bones.length) {
  11582. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  11583. return 0;
  11584. }
  11585. return maxBones;
  11586. }
  11587. }
  11588. function getTextureEncodingFromMap(map) {
  11589. var encoding;
  11590. if (map && map.isTexture) {
  11591. encoding = map.encoding;
  11592. } else if (map && map.isWebGLRenderTarget) {
  11593. console.warn('THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.');
  11594. encoding = map.texture.encoding;
  11595. } else {
  11596. encoding = LinearEncoding;
  11597. }
  11598. return encoding;
  11599. }
  11600. function getParameters(material, lights, shadows, scene, object) {
  11601. var fog = scene.fog;
  11602. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  11603. var envMap = cubemaps.get(material.envMap || environment);
  11604. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  11605. // (not to blow over maxLights budget)
  11606. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  11607. if (material.precision !== null) {
  11608. precision = capabilities.getMaxPrecision(material.precision);
  11609. if (precision !== material.precision) {
  11610. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  11611. }
  11612. }
  11613. var vertexShader, fragmentShader;
  11614. if (shaderID) {
  11615. var shader = ShaderLib[shaderID];
  11616. vertexShader = shader.vertexShader;
  11617. fragmentShader = shader.fragmentShader;
  11618. } else {
  11619. vertexShader = material.vertexShader;
  11620. fragmentShader = material.fragmentShader;
  11621. }
  11622. var currentRenderTarget = renderer.getRenderTarget();
  11623. var parameters = {
  11624. isWebGL2: isWebGL2,
  11625. shaderID: shaderID,
  11626. shaderName: material.type,
  11627. vertexShader: vertexShader,
  11628. fragmentShader: fragmentShader,
  11629. defines: material.defines,
  11630. isRawShaderMaterial: material.isRawShaderMaterial === true,
  11631. glslVersion: material.glslVersion,
  11632. precision: precision,
  11633. instancing: object.isInstancedMesh === true,
  11634. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  11635. supportsVertexTextures: vertexTextures,
  11636. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  11637. map: !!material.map,
  11638. mapEncoding: getTextureEncodingFromMap(material.map),
  11639. matcap: !!material.matcap,
  11640. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  11641. envMap: !!envMap,
  11642. envMapMode: envMap && envMap.mapping,
  11643. envMapEncoding: getTextureEncodingFromMap(envMap),
  11644. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  11645. lightMap: !!material.lightMap,
  11646. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  11647. aoMap: !!material.aoMap,
  11648. emissiveMap: !!material.emissiveMap,
  11649. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  11650. bumpMap: !!material.bumpMap,
  11651. normalMap: !!material.normalMap,
  11652. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11653. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11654. clearcoatMap: !!material.clearcoatMap,
  11655. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  11656. clearcoatNormalMap: !!material.clearcoatNormalMap,
  11657. displacementMap: !!material.displacementMap,
  11658. roughnessMap: !!material.roughnessMap,
  11659. metalnessMap: !!material.metalnessMap,
  11660. specularMap: !!material.specularMap,
  11661. alphaMap: !!material.alphaMap,
  11662. gradientMap: !!material.gradientMap,
  11663. sheen: !!material.sheen,
  11664. transmissionMap: !!material.transmissionMap,
  11665. combine: material.combine,
  11666. vertexTangents: material.normalMap && material.vertexTangents,
  11667. vertexColors: material.vertexColors,
  11668. vertexUvs: !!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatMap || !!material.clearcoatRoughnessMap || !!material.clearcoatNormalMap || !!material.displacementMap || !!material.transmissionMap,
  11669. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  11670. fog: !!fog,
  11671. useFog: material.fog,
  11672. fogExp2: fog && fog.isFogExp2,
  11673. flatShading: !!material.flatShading,
  11674. sizeAttenuation: material.sizeAttenuation,
  11675. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11676. skinning: material.skinning && maxBones > 0,
  11677. maxBones: maxBones,
  11678. useVertexTexture: floatVertexTextures,
  11679. morphTargets: material.morphTargets,
  11680. morphNormals: material.morphNormals,
  11681. maxMorphTargets: renderer.maxMorphTargets,
  11682. maxMorphNormals: renderer.maxMorphNormals,
  11683. numDirLights: lights.directional.length,
  11684. numPointLights: lights.point.length,
  11685. numSpotLights: lights.spot.length,
  11686. numRectAreaLights: lights.rectArea.length,
  11687. numHemiLights: lights.hemi.length,
  11688. numDirLightShadows: lights.directionalShadowMap.length,
  11689. numPointLightShadows: lights.pointShadowMap.length,
  11690. numSpotLightShadows: lights.spotShadowMap.length,
  11691. numClippingPlanes: clipping.numPlanes,
  11692. numClipIntersection: clipping.numIntersection,
  11693. dithering: material.dithering,
  11694. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11695. shadowMapType: renderer.shadowMap.type,
  11696. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11697. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11698. premultipliedAlpha: material.premultipliedAlpha,
  11699. alphaTest: material.alphaTest,
  11700. doubleSided: material.side === DoubleSide,
  11701. flipSided: material.side === BackSide,
  11702. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  11703. index0AttributeName: material.index0AttributeName,
  11704. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11705. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11706. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11707. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11708. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  11709. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  11710. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  11711. customProgramCacheKey: material.customProgramCacheKey()
  11712. };
  11713. return parameters;
  11714. }
  11715. function getProgramCacheKey(parameters) {
  11716. var array = [];
  11717. if (parameters.shaderID) {
  11718. array.push(parameters.shaderID);
  11719. } else {
  11720. array.push(parameters.fragmentShader);
  11721. array.push(parameters.vertexShader);
  11722. }
  11723. if (parameters.defines !== undefined) {
  11724. for (var name in parameters.defines) {
  11725. array.push(name);
  11726. array.push(parameters.defines[name]);
  11727. }
  11728. }
  11729. if (parameters.isRawShaderMaterial === false) {
  11730. for (var i = 0; i < parameterNames.length; i++) {
  11731. array.push(parameters[parameterNames[i]]);
  11732. }
  11733. array.push(renderer.outputEncoding);
  11734. array.push(renderer.gammaFactor);
  11735. }
  11736. array.push(parameters.customProgramCacheKey);
  11737. return array.join();
  11738. }
  11739. function getUniforms(material) {
  11740. var shaderID = shaderIDs[material.type];
  11741. var uniforms;
  11742. if (shaderID) {
  11743. var shader = ShaderLib[shaderID];
  11744. uniforms = UniformsUtils.clone(shader.uniforms);
  11745. } else {
  11746. uniforms = material.uniforms;
  11747. }
  11748. return uniforms;
  11749. }
  11750. function acquireProgram(parameters, cacheKey) {
  11751. var program; // Check if code has been already compiled
  11752. for (var p = 0, pl = programs.length; p < pl; p++) {
  11753. var preexistingProgram = programs[p];
  11754. if (preexistingProgram.cacheKey === cacheKey) {
  11755. program = preexistingProgram;
  11756. ++program.usedTimes;
  11757. break;
  11758. }
  11759. }
  11760. if (program === undefined) {
  11761. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11762. programs.push(program);
  11763. }
  11764. return program;
  11765. }
  11766. function releaseProgram(program) {
  11767. if (--program.usedTimes === 0) {
  11768. // Remove from unordered set
  11769. var i = programs.indexOf(program);
  11770. programs[i] = programs[programs.length - 1];
  11771. programs.pop(); // Free WebGL resources
  11772. program.destroy();
  11773. }
  11774. }
  11775. return {
  11776. getParameters: getParameters,
  11777. getProgramCacheKey: getProgramCacheKey,
  11778. getUniforms: getUniforms,
  11779. acquireProgram: acquireProgram,
  11780. releaseProgram: releaseProgram,
  11781. // Exposed for resource monitoring & error feedback via renderer.info:
  11782. programs: programs
  11783. };
  11784. }
  11785. function WebGLProperties() {
  11786. var properties = new WeakMap();
  11787. function get(object) {
  11788. var map = properties.get(object);
  11789. if (map === undefined) {
  11790. map = {};
  11791. properties.set(object, map);
  11792. }
  11793. return map;
  11794. }
  11795. function remove(object) {
  11796. properties.delete(object);
  11797. }
  11798. function update(object, key, value) {
  11799. properties.get(object)[key] = value;
  11800. }
  11801. function dispose() {
  11802. properties = new WeakMap();
  11803. }
  11804. return {
  11805. get: get,
  11806. remove: remove,
  11807. update: update,
  11808. dispose: dispose
  11809. };
  11810. }
  11811. function painterSortStable(a, b) {
  11812. if (a.groupOrder !== b.groupOrder) {
  11813. return a.groupOrder - b.groupOrder;
  11814. } else if (a.renderOrder !== b.renderOrder) {
  11815. return a.renderOrder - b.renderOrder;
  11816. } else if (a.program !== b.program) {
  11817. return a.program.id - b.program.id;
  11818. } else if (a.material.id !== b.material.id) {
  11819. return a.material.id - b.material.id;
  11820. } else if (a.z !== b.z) {
  11821. return a.z - b.z;
  11822. } else {
  11823. return a.id - b.id;
  11824. }
  11825. }
  11826. function reversePainterSortStable(a, b) {
  11827. if (a.groupOrder !== b.groupOrder) {
  11828. return a.groupOrder - b.groupOrder;
  11829. } else if (a.renderOrder !== b.renderOrder) {
  11830. return a.renderOrder - b.renderOrder;
  11831. } else if (a.z !== b.z) {
  11832. return b.z - a.z;
  11833. } else {
  11834. return a.id - b.id;
  11835. }
  11836. }
  11837. function WebGLRenderList(properties) {
  11838. var renderItems = [];
  11839. var renderItemsIndex = 0;
  11840. var opaque = [];
  11841. var transparent = [];
  11842. var defaultProgram = {
  11843. id: -1
  11844. };
  11845. function init() {
  11846. renderItemsIndex = 0;
  11847. opaque.length = 0;
  11848. transparent.length = 0;
  11849. }
  11850. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11851. var renderItem = renderItems[renderItemsIndex];
  11852. var materialProperties = properties.get(material);
  11853. if (renderItem === undefined) {
  11854. renderItem = {
  11855. id: object.id,
  11856. object: object,
  11857. geometry: geometry,
  11858. material: material,
  11859. program: materialProperties.program || defaultProgram,
  11860. groupOrder: groupOrder,
  11861. renderOrder: object.renderOrder,
  11862. z: z,
  11863. group: group
  11864. };
  11865. renderItems[renderItemsIndex] = renderItem;
  11866. } else {
  11867. renderItem.id = object.id;
  11868. renderItem.object = object;
  11869. renderItem.geometry = geometry;
  11870. renderItem.material = material;
  11871. renderItem.program = materialProperties.program || defaultProgram;
  11872. renderItem.groupOrder = groupOrder;
  11873. renderItem.renderOrder = object.renderOrder;
  11874. renderItem.z = z;
  11875. renderItem.group = group;
  11876. }
  11877. renderItemsIndex++;
  11878. return renderItem;
  11879. }
  11880. function push(object, geometry, material, groupOrder, z, group) {
  11881. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11882. (material.transparent === true ? transparent : opaque).push(renderItem);
  11883. }
  11884. function unshift(object, geometry, material, groupOrder, z, group) {
  11885. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11886. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11887. }
  11888. function sort(customOpaqueSort, customTransparentSort) {
  11889. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11890. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11891. }
  11892. function finish() {
  11893. // Clear references from inactive renderItems in the list
  11894. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11895. var renderItem = renderItems[i];
  11896. if (renderItem.id === null) break;
  11897. renderItem.id = null;
  11898. renderItem.object = null;
  11899. renderItem.geometry = null;
  11900. renderItem.material = null;
  11901. renderItem.program = null;
  11902. renderItem.group = null;
  11903. }
  11904. }
  11905. return {
  11906. opaque: opaque,
  11907. transparent: transparent,
  11908. init: init,
  11909. push: push,
  11910. unshift: unshift,
  11911. finish: finish,
  11912. sort: sort
  11913. };
  11914. }
  11915. function WebGLRenderLists(properties) {
  11916. var lists = new WeakMap();
  11917. function get(scene, camera) {
  11918. var cameras = lists.get(scene);
  11919. var list;
  11920. if (cameras === undefined) {
  11921. list = new WebGLRenderList(properties);
  11922. lists.set(scene, new WeakMap());
  11923. lists.get(scene).set(camera, list);
  11924. } else {
  11925. list = cameras.get(camera);
  11926. if (list === undefined) {
  11927. list = new WebGLRenderList(properties);
  11928. cameras.set(camera, list);
  11929. }
  11930. }
  11931. return list;
  11932. }
  11933. function dispose() {
  11934. lists = new WeakMap();
  11935. }
  11936. return {
  11937. get: get,
  11938. dispose: dispose
  11939. };
  11940. }
  11941. function UniformsCache() {
  11942. var lights = {};
  11943. return {
  11944. get: function get(light) {
  11945. if (lights[light.id] !== undefined) {
  11946. return lights[light.id];
  11947. }
  11948. var uniforms;
  11949. switch (light.type) {
  11950. case 'DirectionalLight':
  11951. uniforms = {
  11952. direction: new Vector3(),
  11953. color: new Color()
  11954. };
  11955. break;
  11956. case 'SpotLight':
  11957. uniforms = {
  11958. position: new Vector3(),
  11959. direction: new Vector3(),
  11960. color: new Color(),
  11961. distance: 0,
  11962. coneCos: 0,
  11963. penumbraCos: 0,
  11964. decay: 0
  11965. };
  11966. break;
  11967. case 'PointLight':
  11968. uniforms = {
  11969. position: new Vector3(),
  11970. color: new Color(),
  11971. distance: 0,
  11972. decay: 0
  11973. };
  11974. break;
  11975. case 'HemisphereLight':
  11976. uniforms = {
  11977. direction: new Vector3(),
  11978. skyColor: new Color(),
  11979. groundColor: new Color()
  11980. };
  11981. break;
  11982. case 'RectAreaLight':
  11983. uniforms = {
  11984. color: new Color(),
  11985. position: new Vector3(),
  11986. halfWidth: new Vector3(),
  11987. halfHeight: new Vector3()
  11988. };
  11989. break;
  11990. }
  11991. lights[light.id] = uniforms;
  11992. return uniforms;
  11993. }
  11994. };
  11995. }
  11996. function ShadowUniformsCache() {
  11997. var lights = {};
  11998. return {
  11999. get: function get(light) {
  12000. if (lights[light.id] !== undefined) {
  12001. return lights[light.id];
  12002. }
  12003. var uniforms;
  12004. switch (light.type) {
  12005. case 'DirectionalLight':
  12006. uniforms = {
  12007. shadowBias: 0,
  12008. shadowNormalBias: 0,
  12009. shadowRadius: 1,
  12010. shadowMapSize: new Vector2()
  12011. };
  12012. break;
  12013. case 'SpotLight':
  12014. uniforms = {
  12015. shadowBias: 0,
  12016. shadowNormalBias: 0,
  12017. shadowRadius: 1,
  12018. shadowMapSize: new Vector2()
  12019. };
  12020. break;
  12021. case 'PointLight':
  12022. uniforms = {
  12023. shadowBias: 0,
  12024. shadowNormalBias: 0,
  12025. shadowRadius: 1,
  12026. shadowMapSize: new Vector2(),
  12027. shadowCameraNear: 1,
  12028. shadowCameraFar: 1000
  12029. };
  12030. break;
  12031. // TODO (abelnation): set RectAreaLight shadow uniforms
  12032. }
  12033. lights[light.id] = uniforms;
  12034. return uniforms;
  12035. }
  12036. };
  12037. }
  12038. var nextVersion = 0;
  12039. function shadowCastingLightsFirst(lightA, lightB) {
  12040. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  12041. }
  12042. function WebGLLights(extensions, capabilities) {
  12043. var cache = new UniformsCache();
  12044. var shadowCache = ShadowUniformsCache();
  12045. var state = {
  12046. version: 0,
  12047. hash: {
  12048. directionalLength: -1,
  12049. pointLength: -1,
  12050. spotLength: -1,
  12051. rectAreaLength: -1,
  12052. hemiLength: -1,
  12053. numDirectionalShadows: -1,
  12054. numPointShadows: -1,
  12055. numSpotShadows: -1
  12056. },
  12057. ambient: [0, 0, 0],
  12058. probe: [],
  12059. directional: [],
  12060. directionalShadow: [],
  12061. directionalShadowMap: [],
  12062. directionalShadowMatrix: [],
  12063. spot: [],
  12064. spotShadow: [],
  12065. spotShadowMap: [],
  12066. spotShadowMatrix: [],
  12067. rectArea: [],
  12068. rectAreaLTC1: null,
  12069. rectAreaLTC2: null,
  12070. point: [],
  12071. pointShadow: [],
  12072. pointShadowMap: [],
  12073. pointShadowMatrix: [],
  12074. hemi: []
  12075. };
  12076. for (var i = 0; i < 9; i++) {
  12077. state.probe.push(new Vector3());
  12078. }
  12079. var vector3 = new Vector3();
  12080. var matrix4 = new Matrix4();
  12081. var matrix42 = new Matrix4();
  12082. function setup(lights) {
  12083. var r = 0,
  12084. g = 0,
  12085. b = 0;
  12086. for (var _i = 0; _i < 9; _i++) {
  12087. state.probe[_i].set(0, 0, 0);
  12088. }
  12089. var directionalLength = 0;
  12090. var pointLength = 0;
  12091. var spotLength = 0;
  12092. var rectAreaLength = 0;
  12093. var hemiLength = 0;
  12094. var numDirectionalShadows = 0;
  12095. var numPointShadows = 0;
  12096. var numSpotShadows = 0;
  12097. lights.sort(shadowCastingLightsFirst);
  12098. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  12099. var light = lights[_i2];
  12100. var color = light.color;
  12101. var intensity = light.intensity;
  12102. var distance = light.distance;
  12103. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  12104. if (light.isAmbientLight) {
  12105. r += color.r * intensity;
  12106. g += color.g * intensity;
  12107. b += color.b * intensity;
  12108. } else if (light.isLightProbe) {
  12109. for (var j = 0; j < 9; j++) {
  12110. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  12111. }
  12112. } else if (light.isDirectionalLight) {
  12113. var uniforms = cache.get(light);
  12114. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  12115. if (light.castShadow) {
  12116. var shadow = light.shadow;
  12117. var shadowUniforms = shadowCache.get(light);
  12118. shadowUniforms.shadowBias = shadow.bias;
  12119. shadowUniforms.shadowNormalBias = shadow.normalBias;
  12120. shadowUniforms.shadowRadius = shadow.radius;
  12121. shadowUniforms.shadowMapSize = shadow.mapSize;
  12122. state.directionalShadow[directionalLength] = shadowUniforms;
  12123. state.directionalShadowMap[directionalLength] = shadowMap;
  12124. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  12125. numDirectionalShadows++;
  12126. }
  12127. state.directional[directionalLength] = uniforms;
  12128. directionalLength++;
  12129. } else if (light.isSpotLight) {
  12130. var _uniforms = cache.get(light);
  12131. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  12132. _uniforms.color.copy(color).multiplyScalar(intensity);
  12133. _uniforms.distance = distance;
  12134. _uniforms.coneCos = Math.cos(light.angle);
  12135. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  12136. _uniforms.decay = light.decay;
  12137. if (light.castShadow) {
  12138. var _shadow = light.shadow;
  12139. var _shadowUniforms = shadowCache.get(light);
  12140. _shadowUniforms.shadowBias = _shadow.bias;
  12141. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  12142. _shadowUniforms.shadowRadius = _shadow.radius;
  12143. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  12144. state.spotShadow[spotLength] = _shadowUniforms;
  12145. state.spotShadowMap[spotLength] = shadowMap;
  12146. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  12147. numSpotShadows++;
  12148. }
  12149. state.spot[spotLength] = _uniforms;
  12150. spotLength++;
  12151. } else if (light.isRectAreaLight) {
  12152. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  12153. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  12154. // (b) intensity is the brightness of the light
  12155. _uniforms2.color.copy(color).multiplyScalar(intensity);
  12156. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  12157. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  12158. state.rectArea[rectAreaLength] = _uniforms2;
  12159. rectAreaLength++;
  12160. } else if (light.isPointLight) {
  12161. var _uniforms3 = cache.get(light);
  12162. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  12163. _uniforms3.distance = light.distance;
  12164. _uniforms3.decay = light.decay;
  12165. if (light.castShadow) {
  12166. var _shadow2 = light.shadow;
  12167. var _shadowUniforms2 = shadowCache.get(light);
  12168. _shadowUniforms2.shadowBias = _shadow2.bias;
  12169. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  12170. _shadowUniforms2.shadowRadius = _shadow2.radius;
  12171. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  12172. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  12173. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  12174. state.pointShadow[pointLength] = _shadowUniforms2;
  12175. state.pointShadowMap[pointLength] = shadowMap;
  12176. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  12177. numPointShadows++;
  12178. }
  12179. state.point[pointLength] = _uniforms3;
  12180. pointLength++;
  12181. } else if (light.isHemisphereLight) {
  12182. var _uniforms4 = cache.get(light);
  12183. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  12184. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  12185. state.hemi[hemiLength] = _uniforms4;
  12186. hemiLength++;
  12187. }
  12188. }
  12189. if (rectAreaLength > 0) {
  12190. if (capabilities.isWebGL2) {
  12191. // WebGL 2
  12192. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12193. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12194. } else {
  12195. // WebGL 1
  12196. if (extensions.has('OES_texture_float_linear') === true) {
  12197. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12198. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12199. } else if (extensions.has('OES_texture_half_float_linear') === true) {
  12200. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  12201. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  12202. } else {
  12203. console.error('THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.');
  12204. }
  12205. }
  12206. }
  12207. state.ambient[0] = r;
  12208. state.ambient[1] = g;
  12209. state.ambient[2] = b;
  12210. var hash = state.hash;
  12211. if (hash.directionalLength !== directionalLength || hash.pointLength !== pointLength || hash.spotLength !== spotLength || hash.rectAreaLength !== rectAreaLength || hash.hemiLength !== hemiLength || hash.numDirectionalShadows !== numDirectionalShadows || hash.numPointShadows !== numPointShadows || hash.numSpotShadows !== numSpotShadows) {
  12212. state.directional.length = directionalLength;
  12213. state.spot.length = spotLength;
  12214. state.rectArea.length = rectAreaLength;
  12215. state.point.length = pointLength;
  12216. state.hemi.length = hemiLength;
  12217. state.directionalShadow.length = numDirectionalShadows;
  12218. state.directionalShadowMap.length = numDirectionalShadows;
  12219. state.pointShadow.length = numPointShadows;
  12220. state.pointShadowMap.length = numPointShadows;
  12221. state.spotShadow.length = numSpotShadows;
  12222. state.spotShadowMap.length = numSpotShadows;
  12223. state.directionalShadowMatrix.length = numDirectionalShadows;
  12224. state.pointShadowMatrix.length = numPointShadows;
  12225. state.spotShadowMatrix.length = numSpotShadows;
  12226. hash.directionalLength = directionalLength;
  12227. hash.pointLength = pointLength;
  12228. hash.spotLength = spotLength;
  12229. hash.rectAreaLength = rectAreaLength;
  12230. hash.hemiLength = hemiLength;
  12231. hash.numDirectionalShadows = numDirectionalShadows;
  12232. hash.numPointShadows = numPointShadows;
  12233. hash.numSpotShadows = numSpotShadows;
  12234. state.version = nextVersion++;
  12235. }
  12236. }
  12237. function setupView(lights, camera) {
  12238. var directionalLength = 0;
  12239. var pointLength = 0;
  12240. var spotLength = 0;
  12241. var rectAreaLength = 0;
  12242. var hemiLength = 0;
  12243. var viewMatrix = camera.matrixWorldInverse;
  12244. for (var _i3 = 0, l = lights.length; _i3 < l; _i3++) {
  12245. var light = lights[_i3];
  12246. if (light.isDirectionalLight) {
  12247. var uniforms = state.directional[directionalLength];
  12248. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  12249. vector3.setFromMatrixPosition(light.target.matrixWorld);
  12250. uniforms.direction.sub(vector3);
  12251. uniforms.direction.transformDirection(viewMatrix);
  12252. directionalLength++;
  12253. } else if (light.isSpotLight) {
  12254. var _uniforms5 = state.spot[spotLength];
  12255. _uniforms5.position.setFromMatrixPosition(light.matrixWorld);
  12256. _uniforms5.position.applyMatrix4(viewMatrix);
  12257. _uniforms5.direction.setFromMatrixPosition(light.matrixWorld);
  12258. vector3.setFromMatrixPosition(light.target.matrixWorld);
  12259. _uniforms5.direction.sub(vector3);
  12260. _uniforms5.direction.transformDirection(viewMatrix);
  12261. spotLength++;
  12262. } else if (light.isRectAreaLight) {
  12263. var _uniforms6 = state.rectArea[rectAreaLength];
  12264. _uniforms6.position.setFromMatrixPosition(light.matrixWorld);
  12265. _uniforms6.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  12266. matrix42.identity();
  12267. matrix4.copy(light.matrixWorld);
  12268. matrix4.premultiply(viewMatrix);
  12269. matrix42.extractRotation(matrix4);
  12270. _uniforms6.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  12271. _uniforms6.halfHeight.set(0.0, light.height * 0.5, 0.0);
  12272. _uniforms6.halfWidth.applyMatrix4(matrix42);
  12273. _uniforms6.halfHeight.applyMatrix4(matrix42);
  12274. rectAreaLength++;
  12275. } else if (light.isPointLight) {
  12276. var _uniforms7 = state.point[pointLength];
  12277. _uniforms7.position.setFromMatrixPosition(light.matrixWorld);
  12278. _uniforms7.position.applyMatrix4(viewMatrix);
  12279. pointLength++;
  12280. } else if (light.isHemisphereLight) {
  12281. var _uniforms8 = state.hemi[hemiLength];
  12282. _uniforms8.direction.setFromMatrixPosition(light.matrixWorld);
  12283. _uniforms8.direction.transformDirection(viewMatrix);
  12284. _uniforms8.direction.normalize();
  12285. hemiLength++;
  12286. }
  12287. }
  12288. }
  12289. return {
  12290. setup: setup,
  12291. setupView: setupView,
  12292. state: state
  12293. };
  12294. }
  12295. function WebGLRenderState(extensions, capabilities) {
  12296. var lights = new WebGLLights(extensions, capabilities);
  12297. var lightsArray = [];
  12298. var shadowsArray = [];
  12299. function init() {
  12300. lightsArray.length = 0;
  12301. shadowsArray.length = 0;
  12302. }
  12303. function pushLight(light) {
  12304. lightsArray.push(light);
  12305. }
  12306. function pushShadow(shadowLight) {
  12307. shadowsArray.push(shadowLight);
  12308. }
  12309. function setupLights() {
  12310. lights.setup(lightsArray);
  12311. }
  12312. function setupLightsView(camera) {
  12313. lights.setupView(lightsArray, camera);
  12314. }
  12315. var state = {
  12316. lightsArray: lightsArray,
  12317. shadowsArray: shadowsArray,
  12318. lights: lights
  12319. };
  12320. return {
  12321. init: init,
  12322. state: state,
  12323. setupLights: setupLights,
  12324. setupLightsView: setupLightsView,
  12325. pushLight: pushLight,
  12326. pushShadow: pushShadow
  12327. };
  12328. }
  12329. function WebGLRenderStates(extensions, capabilities) {
  12330. var renderStates = new WeakMap();
  12331. function get(scene, renderCallDepth) {
  12332. if (renderCallDepth === void 0) {
  12333. renderCallDepth = 0;
  12334. }
  12335. var renderState;
  12336. if (renderStates.has(scene) === false) {
  12337. renderState = new WebGLRenderState(extensions, capabilities);
  12338. renderStates.set(scene, []);
  12339. renderStates.get(scene).push(renderState);
  12340. } else {
  12341. if (renderCallDepth >= renderStates.get(scene).length) {
  12342. renderState = new WebGLRenderState(extensions, capabilities);
  12343. renderStates.get(scene).push(renderState);
  12344. } else {
  12345. renderState = renderStates.get(scene)[renderCallDepth];
  12346. }
  12347. }
  12348. return renderState;
  12349. }
  12350. function dispose() {
  12351. renderStates = new WeakMap();
  12352. }
  12353. return {
  12354. get: get,
  12355. dispose: dispose
  12356. };
  12357. }
  12358. /**
  12359. * parameters = {
  12360. *
  12361. * opacity: <float>,
  12362. *
  12363. * map: new THREE.Texture( <Image> ),
  12364. *
  12365. * alphaMap: new THREE.Texture( <Image> ),
  12366. *
  12367. * displacementMap: new THREE.Texture( <Image> ),
  12368. * displacementScale: <float>,
  12369. * displacementBias: <float>,
  12370. *
  12371. * wireframe: <boolean>,
  12372. * wireframeLinewidth: <float>
  12373. * }
  12374. */
  12375. function MeshDepthMaterial(parameters) {
  12376. Material.call(this);
  12377. this.type = 'MeshDepthMaterial';
  12378. this.depthPacking = BasicDepthPacking;
  12379. this.skinning = false;
  12380. this.morphTargets = false;
  12381. this.map = null;
  12382. this.alphaMap = null;
  12383. this.displacementMap = null;
  12384. this.displacementScale = 1;
  12385. this.displacementBias = 0;
  12386. this.wireframe = false;
  12387. this.wireframeLinewidth = 1;
  12388. this.fog = false;
  12389. this.setValues(parameters);
  12390. }
  12391. MeshDepthMaterial.prototype = Object.create(Material.prototype);
  12392. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  12393. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  12394. MeshDepthMaterial.prototype.copy = function (source) {
  12395. Material.prototype.copy.call(this, source);
  12396. this.depthPacking = source.depthPacking;
  12397. this.skinning = source.skinning;
  12398. this.morphTargets = source.morphTargets;
  12399. this.map = source.map;
  12400. this.alphaMap = source.alphaMap;
  12401. this.displacementMap = source.displacementMap;
  12402. this.displacementScale = source.displacementScale;
  12403. this.displacementBias = source.displacementBias;
  12404. this.wireframe = source.wireframe;
  12405. this.wireframeLinewidth = source.wireframeLinewidth;
  12406. return this;
  12407. };
  12408. /**
  12409. * parameters = {
  12410. *
  12411. * referencePosition: <float>,
  12412. * nearDistance: <float>,
  12413. * farDistance: <float>,
  12414. *
  12415. * skinning: <bool>,
  12416. * morphTargets: <bool>,
  12417. *
  12418. * map: new THREE.Texture( <Image> ),
  12419. *
  12420. * alphaMap: new THREE.Texture( <Image> ),
  12421. *
  12422. * displacementMap: new THREE.Texture( <Image> ),
  12423. * displacementScale: <float>,
  12424. * displacementBias: <float>
  12425. *
  12426. * }
  12427. */
  12428. function MeshDistanceMaterial(parameters) {
  12429. Material.call(this);
  12430. this.type = 'MeshDistanceMaterial';
  12431. this.referencePosition = new Vector3();
  12432. this.nearDistance = 1;
  12433. this.farDistance = 1000;
  12434. this.skinning = false;
  12435. this.morphTargets = false;
  12436. this.map = null;
  12437. this.alphaMap = null;
  12438. this.displacementMap = null;
  12439. this.displacementScale = 1;
  12440. this.displacementBias = 0;
  12441. this.fog = false;
  12442. this.setValues(parameters);
  12443. }
  12444. MeshDistanceMaterial.prototype = Object.create(Material.prototype);
  12445. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  12446. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  12447. MeshDistanceMaterial.prototype.copy = function (source) {
  12448. Material.prototype.copy.call(this, source);
  12449. this.referencePosition.copy(source.referencePosition);
  12450. this.nearDistance = source.nearDistance;
  12451. this.farDistance = source.farDistance;
  12452. this.skinning = source.skinning;
  12453. this.morphTargets = source.morphTargets;
  12454. this.map = source.map;
  12455. this.alphaMap = source.alphaMap;
  12456. this.displacementMap = source.displacementMap;
  12457. this.displacementScale = source.displacementScale;
  12458. this.displacementBias = source.displacementBias;
  12459. return this;
  12460. };
  12461. var vsm_frag = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy ) / resolution ) );\n\tfor ( float i = -1.0; i < 1.0 ; i += SAMPLE_RATE) {\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( i, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, i ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean * HALF_SAMPLE_RATE;\n\tsquared_mean = squared_mean * HALF_SAMPLE_RATE;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}";
  12462. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  12463. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  12464. var _frustum = new Frustum();
  12465. var _shadowMapSize = new Vector2(),
  12466. _viewportSize = new Vector2(),
  12467. _viewport = new Vector4(),
  12468. _depthMaterials = [],
  12469. _distanceMaterials = [],
  12470. _materialCache = {};
  12471. var shadowSide = {
  12472. 0: BackSide,
  12473. 1: FrontSide,
  12474. 2: DoubleSide
  12475. };
  12476. var shadowMaterialVertical = new ShaderMaterial({
  12477. defines: {
  12478. SAMPLE_RATE: 2.0 / 8.0,
  12479. HALF_SAMPLE_RATE: 1.0 / 8.0
  12480. },
  12481. uniforms: {
  12482. shadow_pass: {
  12483. value: null
  12484. },
  12485. resolution: {
  12486. value: new Vector2()
  12487. },
  12488. radius: {
  12489. value: 4.0
  12490. }
  12491. },
  12492. vertexShader: vsm_vert,
  12493. fragmentShader: vsm_frag
  12494. });
  12495. var shadowMaterialHorizontal = shadowMaterialVertical.clone();
  12496. shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1;
  12497. var fullScreenTri = new BufferGeometry();
  12498. fullScreenTri.setAttribute('position', new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  12499. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  12500. var scope = this;
  12501. this.enabled = false;
  12502. this.autoUpdate = true;
  12503. this.needsUpdate = false;
  12504. this.type = PCFShadowMap;
  12505. this.render = function (lights, scene, camera) {
  12506. if (scope.enabled === false) return;
  12507. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  12508. if (lights.length === 0) return;
  12509. var currentRenderTarget = _renderer.getRenderTarget();
  12510. var activeCubeFace = _renderer.getActiveCubeFace();
  12511. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  12512. var _state = _renderer.state; // Set GL state for depth map.
  12513. _state.setBlending(NoBlending);
  12514. _state.buffers.color.setClear(1, 1, 1, 1);
  12515. _state.buffers.depth.setTest(true);
  12516. _state.setScissorTest(false); // render depth map
  12517. for (var i = 0, il = lights.length; i < il; i++) {
  12518. var light = lights[i];
  12519. var shadow = light.shadow;
  12520. if (shadow === undefined) {
  12521. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  12522. continue;
  12523. }
  12524. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  12525. _shadowMapSize.copy(shadow.mapSize);
  12526. var shadowFrameExtents = shadow.getFrameExtents();
  12527. _shadowMapSize.multiply(shadowFrameExtents);
  12528. _viewportSize.copy(shadow.mapSize);
  12529. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  12530. if (_shadowMapSize.x > maxTextureSize) {
  12531. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  12532. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  12533. shadow.mapSize.x = _viewportSize.x;
  12534. }
  12535. if (_shadowMapSize.y > maxTextureSize) {
  12536. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  12537. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  12538. shadow.mapSize.y = _viewportSize.y;
  12539. }
  12540. }
  12541. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12542. var pars = {
  12543. minFilter: LinearFilter,
  12544. magFilter: LinearFilter,
  12545. format: RGBAFormat
  12546. };
  12547. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12548. shadow.map.texture.name = light.name + '.shadowMap';
  12549. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12550. shadow.camera.updateProjectionMatrix();
  12551. }
  12552. if (shadow.map === null) {
  12553. var _pars = {
  12554. minFilter: NearestFilter,
  12555. magFilter: NearestFilter,
  12556. format: RGBAFormat
  12557. };
  12558. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  12559. shadow.map.texture.name = light.name + '.shadowMap';
  12560. shadow.camera.updateProjectionMatrix();
  12561. }
  12562. _renderer.setRenderTarget(shadow.map);
  12563. _renderer.clear();
  12564. var viewportCount = shadow.getViewportCount();
  12565. for (var vp = 0; vp < viewportCount; vp++) {
  12566. var viewport = shadow.getViewport(vp);
  12567. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  12568. _state.viewport(_viewport);
  12569. shadow.updateMatrices(light, vp);
  12570. _frustum = shadow.getFrustum();
  12571. renderObject(scene, camera, shadow.camera, light, this.type);
  12572. } // do blur pass for VSM
  12573. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12574. VSMPass(shadow, camera);
  12575. }
  12576. shadow.needsUpdate = false;
  12577. }
  12578. scope.needsUpdate = false;
  12579. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  12580. };
  12581. function VSMPass(shadow, camera) {
  12582. var geometry = _objects.update(fullScreenMesh); // vertical pass
  12583. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  12584. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  12585. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  12586. _renderer.setRenderTarget(shadow.mapPass);
  12587. _renderer.clear();
  12588. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizontal pass
  12589. shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  12590. shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize;
  12591. shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;
  12592. _renderer.setRenderTarget(shadow.map);
  12593. _renderer.clear();
  12594. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null);
  12595. }
  12596. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12597. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12598. var material = _depthMaterials[index];
  12599. if (material === undefined) {
  12600. material = new MeshDepthMaterial({
  12601. depthPacking: RGBADepthPacking,
  12602. morphTargets: useMorphing,
  12603. skinning: useSkinning
  12604. });
  12605. _depthMaterials[index] = material;
  12606. }
  12607. return material;
  12608. }
  12609. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12610. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12611. var material = _distanceMaterials[index];
  12612. if (material === undefined) {
  12613. material = new MeshDistanceMaterial({
  12614. morphTargets: useMorphing,
  12615. skinning: useSkinning
  12616. });
  12617. _distanceMaterials[index] = material;
  12618. }
  12619. return material;
  12620. }
  12621. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  12622. var result = null;
  12623. var getMaterialVariant = getDepthMaterialVariant;
  12624. var customMaterial = object.customDepthMaterial;
  12625. if (light.isPointLight === true) {
  12626. getMaterialVariant = getDistanceMaterialVariant;
  12627. customMaterial = object.customDistanceMaterial;
  12628. }
  12629. if (customMaterial === undefined) {
  12630. var useMorphing = false;
  12631. if (material.morphTargets === true) {
  12632. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  12633. }
  12634. var useSkinning = false;
  12635. if (object.isSkinnedMesh === true) {
  12636. if (material.skinning === true) {
  12637. useSkinning = true;
  12638. } else {
  12639. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  12640. }
  12641. }
  12642. var useInstancing = object.isInstancedMesh === true;
  12643. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  12644. } else {
  12645. result = customMaterial;
  12646. }
  12647. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  12648. // in this case we need a unique material instance reflecting the
  12649. // appropriate state
  12650. var keyA = result.uuid,
  12651. keyB = material.uuid;
  12652. var materialsForVariant = _materialCache[keyA];
  12653. if (materialsForVariant === undefined) {
  12654. materialsForVariant = {};
  12655. _materialCache[keyA] = materialsForVariant;
  12656. }
  12657. var cachedMaterial = materialsForVariant[keyB];
  12658. if (cachedMaterial === undefined) {
  12659. cachedMaterial = result.clone();
  12660. materialsForVariant[keyB] = cachedMaterial;
  12661. }
  12662. result = cachedMaterial;
  12663. }
  12664. result.visible = material.visible;
  12665. result.wireframe = material.wireframe;
  12666. if (type === VSMShadowMap) {
  12667. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  12668. } else {
  12669. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  12670. }
  12671. result.clipShadows = material.clipShadows;
  12672. result.clippingPlanes = material.clippingPlanes;
  12673. result.clipIntersection = material.clipIntersection;
  12674. result.wireframeLinewidth = material.wireframeLinewidth;
  12675. result.linewidth = material.linewidth;
  12676. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  12677. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  12678. result.nearDistance = shadowCameraNear;
  12679. result.farDistance = shadowCameraFar;
  12680. }
  12681. return result;
  12682. }
  12683. function renderObject(object, camera, shadowCamera, light, type) {
  12684. if (object.visible === false) return;
  12685. var visible = object.layers.test(camera.layers);
  12686. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  12687. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  12688. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  12689. var geometry = _objects.update(object);
  12690. var material = object.material;
  12691. if (Array.isArray(material)) {
  12692. var groups = geometry.groups;
  12693. for (var k = 0, kl = groups.length; k < kl; k++) {
  12694. var group = groups[k];
  12695. var groupMaterial = material[group.materialIndex];
  12696. if (groupMaterial && groupMaterial.visible) {
  12697. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  12698. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  12699. }
  12700. }
  12701. } else if (material.visible) {
  12702. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  12703. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  12704. }
  12705. }
  12706. }
  12707. var children = object.children;
  12708. for (var i = 0, l = children.length; i < l; i++) {
  12709. renderObject(children[i], camera, shadowCamera, light, type);
  12710. }
  12711. }
  12712. }
  12713. function WebGLState(gl, extensions, capabilities) {
  12714. var _equationToGL, _factorToGL;
  12715. var isWebGL2 = capabilities.isWebGL2;
  12716. function ColorBuffer() {
  12717. var locked = false;
  12718. var color = new Vector4();
  12719. var currentColorMask = null;
  12720. var currentColorClear = new Vector4(0, 0, 0, 0);
  12721. return {
  12722. setMask: function setMask(colorMask) {
  12723. if (currentColorMask !== colorMask && !locked) {
  12724. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  12725. currentColorMask = colorMask;
  12726. }
  12727. },
  12728. setLocked: function setLocked(lock) {
  12729. locked = lock;
  12730. },
  12731. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  12732. if (premultipliedAlpha === true) {
  12733. r *= a;
  12734. g *= a;
  12735. b *= a;
  12736. }
  12737. color.set(r, g, b, a);
  12738. if (currentColorClear.equals(color) === false) {
  12739. gl.clearColor(r, g, b, a);
  12740. currentColorClear.copy(color);
  12741. }
  12742. },
  12743. reset: function reset() {
  12744. locked = false;
  12745. currentColorMask = null;
  12746. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  12747. }
  12748. };
  12749. }
  12750. function DepthBuffer() {
  12751. var locked = false;
  12752. var currentDepthMask = null;
  12753. var currentDepthFunc = null;
  12754. var currentDepthClear = null;
  12755. return {
  12756. setTest: function setTest(depthTest) {
  12757. if (depthTest) {
  12758. enable(2929);
  12759. } else {
  12760. disable(2929);
  12761. }
  12762. },
  12763. setMask: function setMask(depthMask) {
  12764. if (currentDepthMask !== depthMask && !locked) {
  12765. gl.depthMask(depthMask);
  12766. currentDepthMask = depthMask;
  12767. }
  12768. },
  12769. setFunc: function setFunc(depthFunc) {
  12770. if (currentDepthFunc !== depthFunc) {
  12771. if (depthFunc) {
  12772. switch (depthFunc) {
  12773. case NeverDepth:
  12774. gl.depthFunc(512);
  12775. break;
  12776. case AlwaysDepth:
  12777. gl.depthFunc(519);
  12778. break;
  12779. case LessDepth:
  12780. gl.depthFunc(513);
  12781. break;
  12782. case LessEqualDepth:
  12783. gl.depthFunc(515);
  12784. break;
  12785. case EqualDepth:
  12786. gl.depthFunc(514);
  12787. break;
  12788. case GreaterEqualDepth:
  12789. gl.depthFunc(518);
  12790. break;
  12791. case GreaterDepth:
  12792. gl.depthFunc(516);
  12793. break;
  12794. case NotEqualDepth:
  12795. gl.depthFunc(517);
  12796. break;
  12797. default:
  12798. gl.depthFunc(515);
  12799. }
  12800. } else {
  12801. gl.depthFunc(515);
  12802. }
  12803. currentDepthFunc = depthFunc;
  12804. }
  12805. },
  12806. setLocked: function setLocked(lock) {
  12807. locked = lock;
  12808. },
  12809. setClear: function setClear(depth) {
  12810. if (currentDepthClear !== depth) {
  12811. gl.clearDepth(depth);
  12812. currentDepthClear = depth;
  12813. }
  12814. },
  12815. reset: function reset() {
  12816. locked = false;
  12817. currentDepthMask = null;
  12818. currentDepthFunc = null;
  12819. currentDepthClear = null;
  12820. }
  12821. };
  12822. }
  12823. function StencilBuffer() {
  12824. var locked = false;
  12825. var currentStencilMask = null;
  12826. var currentStencilFunc = null;
  12827. var currentStencilRef = null;
  12828. var currentStencilFuncMask = null;
  12829. var currentStencilFail = null;
  12830. var currentStencilZFail = null;
  12831. var currentStencilZPass = null;
  12832. var currentStencilClear = null;
  12833. return {
  12834. setTest: function setTest(stencilTest) {
  12835. if (!locked) {
  12836. if (stencilTest) {
  12837. enable(2960);
  12838. } else {
  12839. disable(2960);
  12840. }
  12841. }
  12842. },
  12843. setMask: function setMask(stencilMask) {
  12844. if (currentStencilMask !== stencilMask && !locked) {
  12845. gl.stencilMask(stencilMask);
  12846. currentStencilMask = stencilMask;
  12847. }
  12848. },
  12849. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12850. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12851. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12852. currentStencilFunc = stencilFunc;
  12853. currentStencilRef = stencilRef;
  12854. currentStencilFuncMask = stencilMask;
  12855. }
  12856. },
  12857. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12858. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12859. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12860. currentStencilFail = stencilFail;
  12861. currentStencilZFail = stencilZFail;
  12862. currentStencilZPass = stencilZPass;
  12863. }
  12864. },
  12865. setLocked: function setLocked(lock) {
  12866. locked = lock;
  12867. },
  12868. setClear: function setClear(stencil) {
  12869. if (currentStencilClear !== stencil) {
  12870. gl.clearStencil(stencil);
  12871. currentStencilClear = stencil;
  12872. }
  12873. },
  12874. reset: function reset() {
  12875. locked = false;
  12876. currentStencilMask = null;
  12877. currentStencilFunc = null;
  12878. currentStencilRef = null;
  12879. currentStencilFuncMask = null;
  12880. currentStencilFail = null;
  12881. currentStencilZFail = null;
  12882. currentStencilZPass = null;
  12883. currentStencilClear = null;
  12884. }
  12885. };
  12886. } //
  12887. var colorBuffer = new ColorBuffer();
  12888. var depthBuffer = new DepthBuffer();
  12889. var stencilBuffer = new StencilBuffer();
  12890. var enabledCapabilities = {};
  12891. var currentProgram = null;
  12892. var currentBlendingEnabled = null;
  12893. var currentBlending = null;
  12894. var currentBlendEquation = null;
  12895. var currentBlendSrc = null;
  12896. var currentBlendDst = null;
  12897. var currentBlendEquationAlpha = null;
  12898. var currentBlendSrcAlpha = null;
  12899. var currentBlendDstAlpha = null;
  12900. var currentPremultipledAlpha = false;
  12901. var currentFlipSided = null;
  12902. var currentCullFace = null;
  12903. var currentLineWidth = null;
  12904. var currentPolygonOffsetFactor = null;
  12905. var currentPolygonOffsetUnits = null;
  12906. var maxTextures = gl.getParameter(35661);
  12907. var lineWidthAvailable = false;
  12908. var version = 0;
  12909. var glVersion = gl.getParameter(7938);
  12910. if (glVersion.indexOf('WebGL') !== -1) {
  12911. version = parseFloat(/^WebGL (\d)/.exec(glVersion)[1]);
  12912. lineWidthAvailable = version >= 1.0;
  12913. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12914. version = parseFloat(/^OpenGL ES (\d)/.exec(glVersion)[1]);
  12915. lineWidthAvailable = version >= 2.0;
  12916. }
  12917. var currentTextureSlot = null;
  12918. var currentBoundTextures = {};
  12919. var currentScissor = new Vector4();
  12920. var currentViewport = new Vector4();
  12921. function createTexture(type, target, count) {
  12922. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12923. var texture = gl.createTexture();
  12924. gl.bindTexture(type, texture);
  12925. gl.texParameteri(type, 10241, 9728);
  12926. gl.texParameteri(type, 10240, 9728);
  12927. for (var i = 0; i < count; i++) {
  12928. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12929. }
  12930. return texture;
  12931. }
  12932. var emptyTextures = {};
  12933. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12934. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12935. colorBuffer.setClear(0, 0, 0, 1);
  12936. depthBuffer.setClear(1);
  12937. stencilBuffer.setClear(0);
  12938. enable(2929);
  12939. depthBuffer.setFunc(LessEqualDepth);
  12940. setFlipSided(false);
  12941. setCullFace(CullFaceBack);
  12942. enable(2884);
  12943. setBlending(NoBlending); //
  12944. function enable(id) {
  12945. if (enabledCapabilities[id] !== true) {
  12946. gl.enable(id);
  12947. enabledCapabilities[id] = true;
  12948. }
  12949. }
  12950. function disable(id) {
  12951. if (enabledCapabilities[id] !== false) {
  12952. gl.disable(id);
  12953. enabledCapabilities[id] = false;
  12954. }
  12955. }
  12956. function useProgram(program) {
  12957. if (currentProgram !== program) {
  12958. gl.useProgram(program);
  12959. currentProgram = program;
  12960. return true;
  12961. }
  12962. return false;
  12963. }
  12964. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  12965. if (isWebGL2) {
  12966. equationToGL[MinEquation] = 32775;
  12967. equationToGL[MaxEquation] = 32776;
  12968. } else {
  12969. var extension = extensions.get('EXT_blend_minmax');
  12970. if (extension !== null) {
  12971. equationToGL[MinEquation] = extension.MIN_EXT;
  12972. equationToGL[MaxEquation] = extension.MAX_EXT;
  12973. }
  12974. }
  12975. var factorToGL = (_factorToGL = {}, _factorToGL[ZeroFactor] = 0, _factorToGL[OneFactor] = 1, _factorToGL[SrcColorFactor] = 768, _factorToGL[SrcAlphaFactor] = 770, _factorToGL[SrcAlphaSaturateFactor] = 776, _factorToGL[DstColorFactor] = 774, _factorToGL[DstAlphaFactor] = 772, _factorToGL[OneMinusSrcColorFactor] = 769, _factorToGL[OneMinusSrcAlphaFactor] = 771, _factorToGL[OneMinusDstColorFactor] = 775, _factorToGL[OneMinusDstAlphaFactor] = 773, _factorToGL);
  12976. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  12977. if (blending === NoBlending) {
  12978. if (currentBlendingEnabled) {
  12979. disable(3042);
  12980. currentBlendingEnabled = false;
  12981. }
  12982. return;
  12983. }
  12984. if (!currentBlendingEnabled) {
  12985. enable(3042);
  12986. currentBlendingEnabled = true;
  12987. }
  12988. if (blending !== CustomBlending) {
  12989. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  12990. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  12991. gl.blendEquation(32774);
  12992. currentBlendEquation = AddEquation;
  12993. currentBlendEquationAlpha = AddEquation;
  12994. }
  12995. if (premultipliedAlpha) {
  12996. switch (blending) {
  12997. case NormalBlending:
  12998. gl.blendFuncSeparate(1, 771, 1, 771);
  12999. break;
  13000. case AdditiveBlending:
  13001. gl.blendFunc(1, 1);
  13002. break;
  13003. case SubtractiveBlending:
  13004. gl.blendFuncSeparate(0, 0, 769, 771);
  13005. break;
  13006. case MultiplyBlending:
  13007. gl.blendFuncSeparate(0, 768, 0, 770);
  13008. break;
  13009. default:
  13010. console.error('THREE.WebGLState: Invalid blending: ', blending);
  13011. break;
  13012. }
  13013. } else {
  13014. switch (blending) {
  13015. case NormalBlending:
  13016. gl.blendFuncSeparate(770, 771, 1, 771);
  13017. break;
  13018. case AdditiveBlending:
  13019. gl.blendFunc(770, 1);
  13020. break;
  13021. case SubtractiveBlending:
  13022. gl.blendFunc(0, 769);
  13023. break;
  13024. case MultiplyBlending:
  13025. gl.blendFunc(0, 768);
  13026. break;
  13027. default:
  13028. console.error('THREE.WebGLState: Invalid blending: ', blending);
  13029. break;
  13030. }
  13031. }
  13032. currentBlendSrc = null;
  13033. currentBlendDst = null;
  13034. currentBlendSrcAlpha = null;
  13035. currentBlendDstAlpha = null;
  13036. currentBlending = blending;
  13037. currentPremultipledAlpha = premultipliedAlpha;
  13038. }
  13039. return;
  13040. } // custom blending
  13041. blendEquationAlpha = blendEquationAlpha || blendEquation;
  13042. blendSrcAlpha = blendSrcAlpha || blendSrc;
  13043. blendDstAlpha = blendDstAlpha || blendDst;
  13044. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  13045. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  13046. currentBlendEquation = blendEquation;
  13047. currentBlendEquationAlpha = blendEquationAlpha;
  13048. }
  13049. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  13050. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  13051. currentBlendSrc = blendSrc;
  13052. currentBlendDst = blendDst;
  13053. currentBlendSrcAlpha = blendSrcAlpha;
  13054. currentBlendDstAlpha = blendDstAlpha;
  13055. }
  13056. currentBlending = blending;
  13057. currentPremultipledAlpha = null;
  13058. }
  13059. function setMaterial(material, frontFaceCW) {
  13060. material.side === DoubleSide ? disable(2884) : enable(2884);
  13061. var flipSided = material.side === BackSide;
  13062. if (frontFaceCW) flipSided = !flipSided;
  13063. setFlipSided(flipSided);
  13064. material.blending === NormalBlending && material.transparent === false ? setBlending(NoBlending) : setBlending(material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha);
  13065. depthBuffer.setFunc(material.depthFunc);
  13066. depthBuffer.setTest(material.depthTest);
  13067. depthBuffer.setMask(material.depthWrite);
  13068. colorBuffer.setMask(material.colorWrite);
  13069. var stencilWrite = material.stencilWrite;
  13070. stencilBuffer.setTest(stencilWrite);
  13071. if (stencilWrite) {
  13072. stencilBuffer.setMask(material.stencilWriteMask);
  13073. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  13074. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  13075. }
  13076. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  13077. } //
  13078. function setFlipSided(flipSided) {
  13079. if (currentFlipSided !== flipSided) {
  13080. if (flipSided) {
  13081. gl.frontFace(2304);
  13082. } else {
  13083. gl.frontFace(2305);
  13084. }
  13085. currentFlipSided = flipSided;
  13086. }
  13087. }
  13088. function setCullFace(cullFace) {
  13089. if (cullFace !== CullFaceNone) {
  13090. enable(2884);
  13091. if (cullFace !== currentCullFace) {
  13092. if (cullFace === CullFaceBack) {
  13093. gl.cullFace(1029);
  13094. } else if (cullFace === CullFaceFront) {
  13095. gl.cullFace(1028);
  13096. } else {
  13097. gl.cullFace(1032);
  13098. }
  13099. }
  13100. } else {
  13101. disable(2884);
  13102. }
  13103. currentCullFace = cullFace;
  13104. }
  13105. function setLineWidth(width) {
  13106. if (width !== currentLineWidth) {
  13107. if (lineWidthAvailable) gl.lineWidth(width);
  13108. currentLineWidth = width;
  13109. }
  13110. }
  13111. function setPolygonOffset(polygonOffset, factor, units) {
  13112. if (polygonOffset) {
  13113. enable(32823);
  13114. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  13115. gl.polygonOffset(factor, units);
  13116. currentPolygonOffsetFactor = factor;
  13117. currentPolygonOffsetUnits = units;
  13118. }
  13119. } else {
  13120. disable(32823);
  13121. }
  13122. }
  13123. function setScissorTest(scissorTest) {
  13124. if (scissorTest) {
  13125. enable(3089);
  13126. } else {
  13127. disable(3089);
  13128. }
  13129. } // texture
  13130. function activeTexture(webglSlot) {
  13131. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  13132. if (currentTextureSlot !== webglSlot) {
  13133. gl.activeTexture(webglSlot);
  13134. currentTextureSlot = webglSlot;
  13135. }
  13136. }
  13137. function bindTexture(webglType, webglTexture) {
  13138. if (currentTextureSlot === null) {
  13139. activeTexture();
  13140. }
  13141. var boundTexture = currentBoundTextures[currentTextureSlot];
  13142. if (boundTexture === undefined) {
  13143. boundTexture = {
  13144. type: undefined,
  13145. texture: undefined
  13146. };
  13147. currentBoundTextures[currentTextureSlot] = boundTexture;
  13148. }
  13149. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  13150. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  13151. boundTexture.type = webglType;
  13152. boundTexture.texture = webglTexture;
  13153. }
  13154. }
  13155. function unbindTexture() {
  13156. var boundTexture = currentBoundTextures[currentTextureSlot];
  13157. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  13158. gl.bindTexture(boundTexture.type, null);
  13159. boundTexture.type = undefined;
  13160. boundTexture.texture = undefined;
  13161. }
  13162. }
  13163. function compressedTexImage2D() {
  13164. try {
  13165. gl.compressedTexImage2D.apply(gl, arguments);
  13166. } catch (error) {
  13167. console.error('THREE.WebGLState:', error);
  13168. }
  13169. }
  13170. function texImage2D() {
  13171. try {
  13172. gl.texImage2D.apply(gl, arguments);
  13173. } catch (error) {
  13174. console.error('THREE.WebGLState:', error);
  13175. }
  13176. }
  13177. function texImage3D() {
  13178. try {
  13179. gl.texImage3D.apply(gl, arguments);
  13180. } catch (error) {
  13181. console.error('THREE.WebGLState:', error);
  13182. }
  13183. } //
  13184. function scissor(scissor) {
  13185. if (currentScissor.equals(scissor) === false) {
  13186. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  13187. currentScissor.copy(scissor);
  13188. }
  13189. }
  13190. function viewport(viewport) {
  13191. if (currentViewport.equals(viewport) === false) {
  13192. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  13193. currentViewport.copy(viewport);
  13194. }
  13195. } //
  13196. function reset() {
  13197. enabledCapabilities = {};
  13198. currentTextureSlot = null;
  13199. currentBoundTextures = {};
  13200. currentProgram = null;
  13201. currentBlendingEnabled = null;
  13202. currentBlending = null;
  13203. currentBlendEquation = null;
  13204. currentBlendSrc = null;
  13205. currentBlendDst = null;
  13206. currentBlendEquationAlpha = null;
  13207. currentBlendSrcAlpha = null;
  13208. currentBlendDstAlpha = null;
  13209. currentPremultipledAlpha = false;
  13210. currentFlipSided = null;
  13211. currentCullFace = null;
  13212. currentLineWidth = null;
  13213. currentPolygonOffsetFactor = null;
  13214. currentPolygonOffsetUnits = null;
  13215. colorBuffer.reset();
  13216. depthBuffer.reset();
  13217. stencilBuffer.reset();
  13218. }
  13219. return {
  13220. buffers: {
  13221. color: colorBuffer,
  13222. depth: depthBuffer,
  13223. stencil: stencilBuffer
  13224. },
  13225. enable: enable,
  13226. disable: disable,
  13227. useProgram: useProgram,
  13228. setBlending: setBlending,
  13229. setMaterial: setMaterial,
  13230. setFlipSided: setFlipSided,
  13231. setCullFace: setCullFace,
  13232. setLineWidth: setLineWidth,
  13233. setPolygonOffset: setPolygonOffset,
  13234. setScissorTest: setScissorTest,
  13235. activeTexture: activeTexture,
  13236. bindTexture: bindTexture,
  13237. unbindTexture: unbindTexture,
  13238. compressedTexImage2D: compressedTexImage2D,
  13239. texImage2D: texImage2D,
  13240. texImage3D: texImage3D,
  13241. scissor: scissor,
  13242. viewport: viewport,
  13243. reset: reset
  13244. };
  13245. }
  13246. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  13247. var _wrappingToGL, _filterToGL;
  13248. var isWebGL2 = capabilities.isWebGL2;
  13249. var maxTextures = capabilities.maxTextures;
  13250. var maxCubemapSize = capabilities.maxCubemapSize;
  13251. var maxTextureSize = capabilities.maxTextureSize;
  13252. var maxSamples = capabilities.maxSamples;
  13253. var _videoTextures = new WeakMap();
  13254. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  13255. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  13256. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  13257. var useOffscreenCanvas = false;
  13258. try {
  13259. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext('2d') !== null;
  13260. } catch (err) {// Ignore any errors
  13261. }
  13262. function createCanvas(width, height) {
  13263. // Use OffscreenCanvas when available. Specially needed in web workers
  13264. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  13265. }
  13266. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  13267. var scale = 1; // handle case if texture exceeds max size
  13268. if (image.width > maxSize || image.height > maxSize) {
  13269. scale = maxSize / Math.max(image.width, image.height);
  13270. } // only perform resize if necessary
  13271. if (scale < 1 || needsPowerOfTwo === true) {
  13272. // only perform resize for certain image types
  13273. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  13274. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  13275. var width = floor(scale * image.width);
  13276. var height = floor(scale * image.height);
  13277. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  13278. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  13279. canvas.width = width;
  13280. canvas.height = height;
  13281. var context = canvas.getContext('2d');
  13282. context.drawImage(image, 0, 0, width, height);
  13283. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  13284. return canvas;
  13285. } else {
  13286. if ('data' in image) {
  13287. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  13288. }
  13289. return image;
  13290. }
  13291. }
  13292. return image;
  13293. }
  13294. function isPowerOfTwo(image) {
  13295. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  13296. }
  13297. function textureNeedsPowerOfTwo(texture) {
  13298. if (isWebGL2) return false;
  13299. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13300. }
  13301. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  13302. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13303. }
  13304. function generateMipmap(target, texture, width, height) {
  13305. _gl.generateMipmap(target);
  13306. var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  13307. textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
  13308. }
  13309. function getInternalFormat(internalFormatName, glFormat, glType) {
  13310. if (isWebGL2 === false) return glFormat;
  13311. if (internalFormatName !== null) {
  13312. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  13313. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  13314. }
  13315. var internalFormat = glFormat;
  13316. if (glFormat === 6403) {
  13317. if (glType === 5126) internalFormat = 33326;
  13318. if (glType === 5131) internalFormat = 33325;
  13319. if (glType === 5121) internalFormat = 33321;
  13320. }
  13321. if (glFormat === 6407) {
  13322. if (glType === 5126) internalFormat = 34837;
  13323. if (glType === 5131) internalFormat = 34843;
  13324. if (glType === 5121) internalFormat = 32849;
  13325. }
  13326. if (glFormat === 6408) {
  13327. if (glType === 5126) internalFormat = 34836;
  13328. if (glType === 5131) internalFormat = 34842;
  13329. if (glType === 5121) internalFormat = 32856;
  13330. }
  13331. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  13332. extensions.get('EXT_color_buffer_float');
  13333. }
  13334. return internalFormat;
  13335. } // Fallback filters for non-power-of-2 textures
  13336. function filterFallback(f) {
  13337. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  13338. return 9728;
  13339. }
  13340. return 9729;
  13341. } //
  13342. function onTextureDispose(event) {
  13343. var texture = event.target;
  13344. texture.removeEventListener('dispose', onTextureDispose);
  13345. deallocateTexture(texture);
  13346. if (texture.isVideoTexture) {
  13347. _videoTextures.delete(texture);
  13348. }
  13349. info.memory.textures--;
  13350. }
  13351. function onRenderTargetDispose(event) {
  13352. var renderTarget = event.target;
  13353. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  13354. deallocateRenderTarget(renderTarget);
  13355. info.memory.textures--;
  13356. } //
  13357. function deallocateTexture(texture) {
  13358. var textureProperties = properties.get(texture);
  13359. if (textureProperties.__webglInit === undefined) return;
  13360. _gl.deleteTexture(textureProperties.__webglTexture);
  13361. properties.remove(texture);
  13362. }
  13363. function deallocateRenderTarget(renderTarget) {
  13364. var renderTargetProperties = properties.get(renderTarget);
  13365. var textureProperties = properties.get(renderTarget.texture);
  13366. if (!renderTarget) return;
  13367. if (textureProperties.__webglTexture !== undefined) {
  13368. _gl.deleteTexture(textureProperties.__webglTexture);
  13369. }
  13370. if (renderTarget.depthTexture) {
  13371. renderTarget.depthTexture.dispose();
  13372. }
  13373. if (renderTarget.isWebGLCubeRenderTarget) {
  13374. for (var i = 0; i < 6; i++) {
  13375. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  13376. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  13377. }
  13378. } else {
  13379. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  13380. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  13381. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  13382. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  13383. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  13384. }
  13385. properties.remove(renderTarget.texture);
  13386. properties.remove(renderTarget);
  13387. } //
  13388. var textureUnits = 0;
  13389. function resetTextureUnits() {
  13390. textureUnits = 0;
  13391. }
  13392. function allocateTextureUnit() {
  13393. var textureUnit = textureUnits;
  13394. if (textureUnit >= maxTextures) {
  13395. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  13396. }
  13397. textureUnits += 1;
  13398. return textureUnit;
  13399. } //
  13400. function setTexture2D(texture, slot) {
  13401. var textureProperties = properties.get(texture);
  13402. if (texture.isVideoTexture) updateVideoTexture(texture);
  13403. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13404. var image = texture.image;
  13405. if (image === undefined) {
  13406. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  13407. } else if (image.complete === false) {
  13408. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  13409. } else {
  13410. uploadTexture(textureProperties, texture, slot);
  13411. return;
  13412. }
  13413. }
  13414. state.activeTexture(33984 + slot);
  13415. state.bindTexture(3553, textureProperties.__webglTexture);
  13416. }
  13417. function setTexture2DArray(texture, slot) {
  13418. var textureProperties = properties.get(texture);
  13419. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13420. uploadTexture(textureProperties, texture, slot);
  13421. return;
  13422. }
  13423. state.activeTexture(33984 + slot);
  13424. state.bindTexture(35866, textureProperties.__webglTexture);
  13425. }
  13426. function setTexture3D(texture, slot) {
  13427. var textureProperties = properties.get(texture);
  13428. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13429. uploadTexture(textureProperties, texture, slot);
  13430. return;
  13431. }
  13432. state.activeTexture(33984 + slot);
  13433. state.bindTexture(32879, textureProperties.__webglTexture);
  13434. }
  13435. function setTextureCube(texture, slot) {
  13436. var textureProperties = properties.get(texture);
  13437. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13438. uploadCubeTexture(textureProperties, texture, slot);
  13439. return;
  13440. }
  13441. state.activeTexture(33984 + slot);
  13442. state.bindTexture(34067, textureProperties.__webglTexture);
  13443. }
  13444. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  13445. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  13446. function setTextureParameters(textureType, texture, supportsMips) {
  13447. if (supportsMips) {
  13448. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  13449. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  13450. if (textureType === 32879 || textureType === 35866) {
  13451. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  13452. }
  13453. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  13454. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  13455. } else {
  13456. _gl.texParameteri(textureType, 10242, 33071);
  13457. _gl.texParameteri(textureType, 10243, 33071);
  13458. if (textureType === 32879 || textureType === 35866) {
  13459. _gl.texParameteri(textureType, 32882, 33071);
  13460. }
  13461. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  13462. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  13463. }
  13464. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  13465. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  13466. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  13467. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  13468. }
  13469. }
  13470. if (extensions.has('EXT_texture_filter_anisotropic') === true) {
  13471. var extension = extensions.get('EXT_texture_filter_anisotropic');
  13472. if (texture.type === FloatType && extensions.has('OES_texture_float_linear') === false) return; // verify extension for WebGL 1 and WebGL 2
  13473. if (isWebGL2 === false && texture.type === HalfFloatType && extensions.has('OES_texture_half_float_linear') === false) return; // verify extension for WebGL 1 only
  13474. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  13475. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  13476. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  13477. }
  13478. }
  13479. }
  13480. function initTexture(textureProperties, texture) {
  13481. if (textureProperties.__webglInit === undefined) {
  13482. textureProperties.__webglInit = true;
  13483. texture.addEventListener('dispose', onTextureDispose);
  13484. textureProperties.__webglTexture = _gl.createTexture();
  13485. info.memory.textures++;
  13486. }
  13487. }
  13488. function uploadTexture(textureProperties, texture, slot) {
  13489. var textureType = 3553;
  13490. if (texture.isDataTexture2DArray) textureType = 35866;
  13491. if (texture.isDataTexture3D) textureType = 32879;
  13492. initTexture(textureProperties, texture);
  13493. state.activeTexture(33984 + slot);
  13494. state.bindTexture(textureType, textureProperties.__webglTexture);
  13495. _gl.pixelStorei(37440, texture.flipY);
  13496. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13497. _gl.pixelStorei(3317, texture.unpackAlignment);
  13498. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  13499. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  13500. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  13501. glFormat = utils.convert(texture.format);
  13502. var glType = utils.convert(texture.type),
  13503. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13504. setTextureParameters(textureType, texture, supportsMips);
  13505. var mipmap;
  13506. var mipmaps = texture.mipmaps;
  13507. if (texture.isDepthTexture) {
  13508. // populate depth texture with dummy data
  13509. glInternalFormat = 6402;
  13510. if (isWebGL2) {
  13511. if (texture.type === FloatType) {
  13512. glInternalFormat = 36012;
  13513. } else if (texture.type === UnsignedIntType) {
  13514. glInternalFormat = 33190;
  13515. } else if (texture.type === UnsignedInt248Type) {
  13516. glInternalFormat = 35056;
  13517. } else {
  13518. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  13519. }
  13520. } else {
  13521. if (texture.type === FloatType) {
  13522. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  13523. }
  13524. } // validation checks for WebGL 1
  13525. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  13526. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13527. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  13528. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13529. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  13530. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  13531. texture.type = UnsignedShortType;
  13532. glType = utils.convert(texture.type);
  13533. }
  13534. }
  13535. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  13536. // Depth stencil textures need the DEPTH_STENCIL internal format
  13537. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13538. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13539. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  13540. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13541. if (texture.type !== UnsignedInt248Type) {
  13542. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  13543. texture.type = UnsignedInt248Type;
  13544. glType = utils.convert(texture.type);
  13545. }
  13546. } //
  13547. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  13548. } else if (texture.isDataTexture) {
  13549. // use manually created mipmaps if available
  13550. // if there are no manual mipmaps
  13551. // set 0 level mipmap and then use GL to generate other mipmap levels
  13552. if (mipmaps.length > 0 && supportsMips) {
  13553. for (var i = 0, il = mipmaps.length; i < il; i++) {
  13554. mipmap = mipmaps[i];
  13555. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13556. }
  13557. texture.generateMipmaps = false;
  13558. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13559. } else {
  13560. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  13561. textureProperties.__maxMipLevel = 0;
  13562. }
  13563. } else if (texture.isCompressedTexture) {
  13564. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  13565. mipmap = mipmaps[_i];
  13566. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13567. if (glFormat !== null) {
  13568. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13569. } else {
  13570. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  13571. }
  13572. } else {
  13573. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13574. }
  13575. }
  13576. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13577. } else if (texture.isDataTexture2DArray) {
  13578. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13579. textureProperties.__maxMipLevel = 0;
  13580. } else if (texture.isDataTexture3D) {
  13581. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13582. textureProperties.__maxMipLevel = 0;
  13583. } else {
  13584. // regular Texture (image, video, canvas)
  13585. // use manually created mipmaps if available
  13586. // if there are no manual mipmaps
  13587. // set 0 level mipmap and then use GL to generate other mipmap levels
  13588. if (mipmaps.length > 0 && supportsMips) {
  13589. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  13590. mipmap = mipmaps[_i2];
  13591. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  13592. }
  13593. texture.generateMipmaps = false;
  13594. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13595. } else {
  13596. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  13597. textureProperties.__maxMipLevel = 0;
  13598. }
  13599. }
  13600. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13601. generateMipmap(textureType, texture, image.width, image.height);
  13602. }
  13603. textureProperties.__version = texture.version;
  13604. if (texture.onUpdate) texture.onUpdate(texture);
  13605. }
  13606. function uploadCubeTexture(textureProperties, texture, slot) {
  13607. if (texture.image.length !== 6) return;
  13608. initTexture(textureProperties, texture);
  13609. state.activeTexture(33984 + slot);
  13610. state.bindTexture(34067, textureProperties.__webglTexture);
  13611. _gl.pixelStorei(37440, texture.flipY);
  13612. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13613. _gl.pixelStorei(3317, texture.unpackAlignment);
  13614. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  13615. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  13616. var cubeImage = [];
  13617. for (var i = 0; i < 6; i++) {
  13618. if (!isCompressed && !isDataTexture) {
  13619. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  13620. } else {
  13621. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  13622. }
  13623. }
  13624. var image = cubeImage[0],
  13625. supportsMips = isPowerOfTwo(image) || isWebGL2,
  13626. glFormat = utils.convert(texture.format),
  13627. glType = utils.convert(texture.type),
  13628. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13629. setTextureParameters(34067, texture, supportsMips);
  13630. var mipmaps;
  13631. if (isCompressed) {
  13632. for (var _i3 = 0; _i3 < 6; _i3++) {
  13633. mipmaps = cubeImage[_i3].mipmaps;
  13634. for (var j = 0; j < mipmaps.length; j++) {
  13635. var mipmap = mipmaps[j];
  13636. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13637. if (glFormat !== null) {
  13638. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13639. } else {
  13640. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  13641. }
  13642. } else {
  13643. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13644. }
  13645. }
  13646. }
  13647. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13648. } else {
  13649. mipmaps = texture.mipmaps;
  13650. for (var _i4 = 0; _i4 < 6; _i4++) {
  13651. if (isDataTexture) {
  13652. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  13653. for (var _j = 0; _j < mipmaps.length; _j++) {
  13654. var _mipmap = mipmaps[_j];
  13655. var mipmapImage = _mipmap.image[_i4].image;
  13656. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  13657. }
  13658. } else {
  13659. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  13660. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  13661. var _mipmap2 = mipmaps[_j2];
  13662. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  13663. }
  13664. }
  13665. }
  13666. textureProperties.__maxMipLevel = mipmaps.length;
  13667. }
  13668. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13669. // We assume images for cube map have the same size.
  13670. generateMipmap(34067, texture, image.width, image.height);
  13671. }
  13672. textureProperties.__version = texture.version;
  13673. if (texture.onUpdate) texture.onUpdate(texture);
  13674. } // Render targets
  13675. // Setup storage for target texture and bind it to correct framebuffer
  13676. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  13677. var glFormat = utils.convert(renderTarget.texture.format);
  13678. var glType = utils.convert(renderTarget.texture.type);
  13679. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13680. if (textureTarget === 32879 || textureTarget === 35866) {
  13681. state.texImage3D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, renderTarget.depth, 0, glFormat, glType, null);
  13682. } else {
  13683. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  13684. }
  13685. _gl.bindFramebuffer(36160, framebuffer);
  13686. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(renderTarget.texture).__webglTexture, 0);
  13687. _gl.bindFramebuffer(36160, null);
  13688. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13689. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  13690. _gl.bindRenderbuffer(36161, renderbuffer);
  13691. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  13692. var glInternalFormat = 33189;
  13693. if (isMultisample) {
  13694. var depthTexture = renderTarget.depthTexture;
  13695. if (depthTexture && depthTexture.isDepthTexture) {
  13696. if (depthTexture.type === FloatType) {
  13697. glInternalFormat = 36012;
  13698. } else if (depthTexture.type === UnsignedIntType) {
  13699. glInternalFormat = 33190;
  13700. }
  13701. }
  13702. var samples = getRenderTargetSamples(renderTarget);
  13703. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13704. } else {
  13705. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  13706. }
  13707. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  13708. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  13709. if (isMultisample) {
  13710. var _samples = getRenderTargetSamples(renderTarget);
  13711. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  13712. } else {
  13713. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  13714. }
  13715. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  13716. } else {
  13717. var glFormat = utils.convert(renderTarget.texture.format);
  13718. var glType = utils.convert(renderTarget.texture.type);
  13719. var _glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13720. if (isMultisample) {
  13721. var _samples2 = getRenderTargetSamples(renderTarget);
  13722. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  13723. } else {
  13724. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  13725. }
  13726. }
  13727. _gl.bindRenderbuffer(36161, null);
  13728. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  13729. function setupDepthTexture(framebuffer, renderTarget) {
  13730. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  13731. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  13732. _gl.bindFramebuffer(36160, framebuffer);
  13733. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  13734. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  13735. } // upload an empty depth texture with framebuffer size
  13736. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  13737. renderTarget.depthTexture.image.width = renderTarget.width;
  13738. renderTarget.depthTexture.image.height = renderTarget.height;
  13739. renderTarget.depthTexture.needsUpdate = true;
  13740. }
  13741. setTexture2D(renderTarget.depthTexture, 0);
  13742. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  13743. if (renderTarget.depthTexture.format === DepthFormat) {
  13744. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  13745. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  13746. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  13747. } else {
  13748. throw new Error('Unknown depthTexture format');
  13749. }
  13750. } // Setup GL resources for a non-texture depth buffer
  13751. function setupDepthRenderbuffer(renderTarget) {
  13752. var renderTargetProperties = properties.get(renderTarget);
  13753. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13754. if (renderTarget.depthTexture) {
  13755. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  13756. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  13757. } else {
  13758. if (isCube) {
  13759. renderTargetProperties.__webglDepthbuffer = [];
  13760. for (var i = 0; i < 6; i++) {
  13761. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  13762. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  13763. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  13764. }
  13765. } else {
  13766. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  13767. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13768. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  13769. }
  13770. }
  13771. _gl.bindFramebuffer(36160, null);
  13772. } // Set up GL resources for the render target
  13773. function setupRenderTarget(renderTarget) {
  13774. var texture = renderTarget.texture;
  13775. var renderTargetProperties = properties.get(renderTarget);
  13776. var textureProperties = properties.get(texture);
  13777. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  13778. textureProperties.__webglTexture = _gl.createTexture();
  13779. info.memory.textures++;
  13780. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13781. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  13782. var isRenderTarget3D = texture.isDataTexture3D || texture.isDataTexture2DArray;
  13783. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  13784. if (isWebGL2 && texture.format === RGBFormat && (texture.type === FloatType || texture.type === HalfFloatType)) {
  13785. texture.format = RGBAFormat;
  13786. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  13787. } // Setup framebuffer
  13788. if (isCube) {
  13789. renderTargetProperties.__webglFramebuffer = [];
  13790. for (var i = 0; i < 6; i++) {
  13791. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  13792. }
  13793. } else {
  13794. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13795. if (isMultisample) {
  13796. if (isWebGL2) {
  13797. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13798. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13799. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  13800. var glFormat = utils.convert(texture.format);
  13801. var glType = utils.convert(texture.type);
  13802. var glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13803. var samples = getRenderTargetSamples(renderTarget);
  13804. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13805. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13806. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13807. _gl.bindRenderbuffer(36161, null);
  13808. if (renderTarget.depthBuffer) {
  13809. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13810. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13811. }
  13812. _gl.bindFramebuffer(36160, null);
  13813. } else {
  13814. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13815. }
  13816. }
  13817. } // Setup color buffer
  13818. if (isCube) {
  13819. state.bindTexture(34067, textureProperties.__webglTexture);
  13820. setTextureParameters(34067, texture, supportsMips);
  13821. for (var _i5 = 0; _i5 < 6; _i5++) {
  13822. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13823. }
  13824. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13825. generateMipmap(34067, texture, renderTarget.width, renderTarget.height);
  13826. }
  13827. state.bindTexture(34067, null);
  13828. } else {
  13829. var glTextureType = 3553;
  13830. if (isRenderTarget3D) {
  13831. // Render targets containing layers, i.e: Texture 3D and 2d arrays
  13832. if (isWebGL2) {
  13833. var isTexture3D = texture.isDataTexture3D;
  13834. glTextureType = isTexture3D ? 32879 : 35866;
  13835. } else {
  13836. console.warn('THREE.DataTexture3D and THREE.DataTexture2DArray only supported with WebGL2.');
  13837. }
  13838. }
  13839. state.bindTexture(glTextureType, textureProperties.__webglTexture);
  13840. setTextureParameters(glTextureType, texture, supportsMips);
  13841. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, glTextureType);
  13842. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13843. generateMipmap(3553, texture, renderTarget.width, renderTarget.height);
  13844. }
  13845. state.bindTexture(3553, null);
  13846. } // Setup depth and stencil buffers
  13847. if (renderTarget.depthBuffer) {
  13848. setupDepthRenderbuffer(renderTarget);
  13849. }
  13850. }
  13851. function updateRenderTargetMipmap(renderTarget) {
  13852. var texture = renderTarget.texture;
  13853. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13854. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13855. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13856. var webglTexture = properties.get(texture).__webglTexture;
  13857. state.bindTexture(target, webglTexture);
  13858. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13859. state.bindTexture(target, null);
  13860. }
  13861. }
  13862. function updateMultisampleRenderTarget(renderTarget) {
  13863. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13864. if (isWebGL2) {
  13865. var renderTargetProperties = properties.get(renderTarget);
  13866. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13867. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13868. var width = renderTarget.width;
  13869. var height = renderTarget.height;
  13870. var mask = 16384;
  13871. if (renderTarget.depthBuffer) mask |= 256;
  13872. if (renderTarget.stencilBuffer) mask |= 1024;
  13873. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13874. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13875. } else {
  13876. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13877. }
  13878. }
  13879. }
  13880. function getRenderTargetSamples(renderTarget) {
  13881. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13882. }
  13883. function updateVideoTexture(texture) {
  13884. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13885. if (_videoTextures.get(texture) !== frame) {
  13886. _videoTextures.set(texture, frame);
  13887. texture.update();
  13888. }
  13889. } // backwards compatibility
  13890. var warnedTexture2D = false;
  13891. var warnedTextureCube = false;
  13892. function safeSetTexture2D(texture, slot) {
  13893. if (texture && texture.isWebGLRenderTarget) {
  13894. if (warnedTexture2D === false) {
  13895. console.warn('THREE.WebGLTextures.safeSetTexture2D: don\'t use render targets as textures. Use their .texture property instead.');
  13896. warnedTexture2D = true;
  13897. }
  13898. texture = texture.texture;
  13899. }
  13900. setTexture2D(texture, slot);
  13901. }
  13902. function safeSetTextureCube(texture, slot) {
  13903. if (texture && texture.isWebGLCubeRenderTarget) {
  13904. if (warnedTextureCube === false) {
  13905. console.warn('THREE.WebGLTextures.safeSetTextureCube: don\'t use cube render targets as textures. Use their .texture property instead.');
  13906. warnedTextureCube = true;
  13907. }
  13908. texture = texture.texture;
  13909. }
  13910. setTextureCube(texture, slot);
  13911. } //
  13912. this.allocateTextureUnit = allocateTextureUnit;
  13913. this.resetTextureUnits = resetTextureUnits;
  13914. this.setTexture2D = setTexture2D;
  13915. this.setTexture2DArray = setTexture2DArray;
  13916. this.setTexture3D = setTexture3D;
  13917. this.setTextureCube = setTextureCube;
  13918. this.setupRenderTarget = setupRenderTarget;
  13919. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13920. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13921. this.safeSetTexture2D = safeSetTexture2D;
  13922. this.safeSetTextureCube = safeSetTextureCube;
  13923. }
  13924. function WebGLUtils(gl, extensions, capabilities) {
  13925. var isWebGL2 = capabilities.isWebGL2;
  13926. function convert(p) {
  13927. var extension;
  13928. if (p === UnsignedByteType) return 5121;
  13929. if (p === UnsignedShort4444Type) return 32819;
  13930. if (p === UnsignedShort5551Type) return 32820;
  13931. if (p === UnsignedShort565Type) return 33635;
  13932. if (p === ByteType) return 5120;
  13933. if (p === ShortType) return 5122;
  13934. if (p === UnsignedShortType) return 5123;
  13935. if (p === IntType) return 5124;
  13936. if (p === UnsignedIntType) return 5125;
  13937. if (p === FloatType) return 5126;
  13938. if (p === HalfFloatType) {
  13939. if (isWebGL2) return 5131;
  13940. extension = extensions.get('OES_texture_half_float');
  13941. if (extension !== null) {
  13942. return extension.HALF_FLOAT_OES;
  13943. } else {
  13944. return null;
  13945. }
  13946. }
  13947. if (p === AlphaFormat) return 6406;
  13948. if (p === RGBFormat) return 6407;
  13949. if (p === RGBAFormat) return 6408;
  13950. if (p === LuminanceFormat) return 6409;
  13951. if (p === LuminanceAlphaFormat) return 6410;
  13952. if (p === DepthFormat) return 6402;
  13953. if (p === DepthStencilFormat) return 34041;
  13954. if (p === RedFormat) return 6403; // WebGL2 formats.
  13955. if (p === RedIntegerFormat) return 36244;
  13956. if (p === RGFormat) return 33319;
  13957. if (p === RGIntegerFormat) return 33320;
  13958. if (p === RGBIntegerFormat) return 36248;
  13959. if (p === RGBAIntegerFormat) return 36249;
  13960. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  13961. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  13962. if (extension !== null) {
  13963. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13964. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13965. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13966. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13967. } else {
  13968. return null;
  13969. }
  13970. }
  13971. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  13972. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  13973. if (extension !== null) {
  13974. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13975. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13976. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13977. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13978. } else {
  13979. return null;
  13980. }
  13981. }
  13982. if (p === RGB_ETC1_Format) {
  13983. extension = extensions.get('WEBGL_compressed_texture_etc1');
  13984. if (extension !== null) {
  13985. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13986. } else {
  13987. return null;
  13988. }
  13989. }
  13990. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  13991. extension = extensions.get('WEBGL_compressed_texture_etc');
  13992. if (extension !== null) {
  13993. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  13994. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13995. }
  13996. }
  13997. 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) {
  13998. extension = extensions.get('WEBGL_compressed_texture_astc');
  13999. if (extension !== null) {
  14000. // TODO Complete?
  14001. return p;
  14002. } else {
  14003. return null;
  14004. }
  14005. }
  14006. if (p === RGBA_BPTC_Format) {
  14007. extension = extensions.get('EXT_texture_compression_bptc');
  14008. if (extension !== null) {
  14009. // TODO Complete?
  14010. return p;
  14011. } else {
  14012. return null;
  14013. }
  14014. }
  14015. if (p === UnsignedInt248Type) {
  14016. if (isWebGL2) return 34042;
  14017. extension = extensions.get('WEBGL_depth_texture');
  14018. if (extension !== null) {
  14019. return extension.UNSIGNED_INT_24_8_WEBGL;
  14020. } else {
  14021. return null;
  14022. }
  14023. }
  14024. }
  14025. return {
  14026. convert: convert
  14027. };
  14028. }
  14029. function ArrayCamera(array) {
  14030. if (array === void 0) {
  14031. array = [];
  14032. }
  14033. PerspectiveCamera.call(this);
  14034. this.cameras = array;
  14035. }
  14036. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  14037. constructor: ArrayCamera,
  14038. isArrayCamera: true
  14039. });
  14040. function Group() {
  14041. Object3D.call(this);
  14042. this.type = 'Group';
  14043. }
  14044. Group.prototype = Object.assign(Object.create(Object3D.prototype), {
  14045. constructor: Group,
  14046. isGroup: true
  14047. });
  14048. function WebXRController() {
  14049. this._targetRay = null;
  14050. this._grip = null;
  14051. this._hand = null;
  14052. }
  14053. Object.assign(WebXRController.prototype, {
  14054. constructor: WebXRController,
  14055. getHandSpace: function getHandSpace() {
  14056. if (this._hand === null) {
  14057. this._hand = new Group();
  14058. this._hand.matrixAutoUpdate = false;
  14059. this._hand.visible = false;
  14060. this._hand.joints = {};
  14061. this._hand.inputState = {
  14062. pinching: false
  14063. };
  14064. }
  14065. return this._hand;
  14066. },
  14067. getTargetRaySpace: function getTargetRaySpace() {
  14068. if (this._targetRay === null) {
  14069. this._targetRay = new Group();
  14070. this._targetRay.matrixAutoUpdate = false;
  14071. this._targetRay.visible = false;
  14072. }
  14073. return this._targetRay;
  14074. },
  14075. getGripSpace: function getGripSpace() {
  14076. if (this._grip === null) {
  14077. this._grip = new Group();
  14078. this._grip.matrixAutoUpdate = false;
  14079. this._grip.visible = false;
  14080. }
  14081. return this._grip;
  14082. },
  14083. dispatchEvent: function dispatchEvent(event) {
  14084. if (this._targetRay !== null) {
  14085. this._targetRay.dispatchEvent(event);
  14086. }
  14087. if (this._grip !== null) {
  14088. this._grip.dispatchEvent(event);
  14089. }
  14090. if (this._hand !== null) {
  14091. this._hand.dispatchEvent(event);
  14092. }
  14093. return this;
  14094. },
  14095. disconnect: function disconnect(inputSource) {
  14096. this.dispatchEvent({
  14097. type: 'disconnected',
  14098. data: inputSource
  14099. });
  14100. if (this._targetRay !== null) {
  14101. this._targetRay.visible = false;
  14102. }
  14103. if (this._grip !== null) {
  14104. this._grip.visible = false;
  14105. }
  14106. if (this._hand !== null) {
  14107. this._hand.visible = false;
  14108. }
  14109. return this;
  14110. },
  14111. update: function update(inputSource, frame, referenceSpace) {
  14112. var inputPose = null;
  14113. var gripPose = null;
  14114. var handPose = null;
  14115. var targetRay = this._targetRay;
  14116. var grip = this._grip;
  14117. var hand = this._hand;
  14118. if (inputSource && frame.session.visibilityState !== 'visible-blurred') {
  14119. if (hand && inputSource.hand) {
  14120. handPose = true;
  14121. for (var _iterator = _createForOfIteratorHelperLoose(inputSource.hand.values()), _step; !(_step = _iterator()).done;) {
  14122. var inputjoint = _step.value;
  14123. // Update the joints groups with the XRJoint poses
  14124. var jointPose = frame.getJointPose(inputjoint, referenceSpace);
  14125. if (hand.joints[inputjoint.jointName] === undefined) {
  14126. // The transform of this joint will be updated with the joint pose on each frame
  14127. var _joint = new Group();
  14128. _joint.matrixAutoUpdate = false;
  14129. _joint.visible = false;
  14130. hand.joints[inputjoint.jointName] = _joint; // ??
  14131. hand.add(_joint);
  14132. }
  14133. var joint = hand.joints[inputjoint.jointName];
  14134. if (jointPose !== null) {
  14135. joint.matrix.fromArray(jointPose.transform.matrix);
  14136. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  14137. joint.jointRadius = jointPose.radius;
  14138. }
  14139. joint.visible = jointPose !== null;
  14140. } // Custom events
  14141. // Check pinchz
  14142. var indexTip = hand.joints['index-finger-tip'];
  14143. var thumbTip = hand.joints['thumb-tip'];
  14144. var distance = indexTip.position.distanceTo(thumbTip.position);
  14145. var distanceToPinch = 0.02;
  14146. var threshold = 0.005;
  14147. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  14148. hand.inputState.pinching = false;
  14149. this.dispatchEvent({
  14150. type: 'pinchend',
  14151. handedness: inputSource.handedness,
  14152. target: this
  14153. });
  14154. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  14155. hand.inputState.pinching = true;
  14156. this.dispatchEvent({
  14157. type: 'pinchstart',
  14158. handedness: inputSource.handedness,
  14159. target: this
  14160. });
  14161. }
  14162. } else {
  14163. if (targetRay !== null) {
  14164. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  14165. if (inputPose !== null) {
  14166. targetRay.matrix.fromArray(inputPose.transform.matrix);
  14167. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  14168. }
  14169. }
  14170. if (grip !== null && inputSource.gripSpace) {
  14171. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  14172. if (gripPose !== null) {
  14173. grip.matrix.fromArray(gripPose.transform.matrix);
  14174. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  14175. }
  14176. }
  14177. }
  14178. }
  14179. if (targetRay !== null) {
  14180. targetRay.visible = inputPose !== null;
  14181. }
  14182. if (grip !== null) {
  14183. grip.visible = gripPose !== null;
  14184. }
  14185. if (hand !== null) {
  14186. hand.visible = handPose !== null;
  14187. }
  14188. return this;
  14189. }
  14190. });
  14191. function WebXRManager(renderer, gl) {
  14192. var scope = this;
  14193. var session = null;
  14194. var framebufferScaleFactor = 1.0;
  14195. var referenceSpace = null;
  14196. var referenceSpaceType = 'local-floor';
  14197. var pose = null;
  14198. var controllers = [];
  14199. var inputSourcesMap = new Map(); //
  14200. var cameraL = new PerspectiveCamera();
  14201. cameraL.layers.enable(1);
  14202. cameraL.viewport = new Vector4();
  14203. var cameraR = new PerspectiveCamera();
  14204. cameraR.layers.enable(2);
  14205. cameraR.viewport = new Vector4();
  14206. var cameras = [cameraL, cameraR];
  14207. var cameraVR = new ArrayCamera();
  14208. cameraVR.layers.enable(1);
  14209. cameraVR.layers.enable(2);
  14210. var _currentDepthNear = null;
  14211. var _currentDepthFar = null; //
  14212. this.enabled = false;
  14213. this.isPresenting = false;
  14214. this.getController = function (index) {
  14215. var controller = controllers[index];
  14216. if (controller === undefined) {
  14217. controller = new WebXRController();
  14218. controllers[index] = controller;
  14219. }
  14220. return controller.getTargetRaySpace();
  14221. };
  14222. this.getControllerGrip = function (index) {
  14223. var controller = controllers[index];
  14224. if (controller === undefined) {
  14225. controller = new WebXRController();
  14226. controllers[index] = controller;
  14227. }
  14228. return controller.getGripSpace();
  14229. };
  14230. this.getHand = function (index) {
  14231. var controller = controllers[index];
  14232. if (controller === undefined) {
  14233. controller = new WebXRController();
  14234. controllers[index] = controller;
  14235. }
  14236. return controller.getHandSpace();
  14237. }; //
  14238. function onSessionEvent(event) {
  14239. var controller = inputSourcesMap.get(event.inputSource);
  14240. if (controller) {
  14241. controller.dispatchEvent({
  14242. type: event.type,
  14243. data: event.inputSource
  14244. });
  14245. }
  14246. }
  14247. function onSessionEnd() {
  14248. inputSourcesMap.forEach(function (controller, inputSource) {
  14249. controller.disconnect(inputSource);
  14250. });
  14251. inputSourcesMap.clear();
  14252. _currentDepthNear = null;
  14253. _currentDepthFar = null; //
  14254. renderer.setFramebuffer(null);
  14255. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  14256. animation.stop();
  14257. scope.isPresenting = false;
  14258. scope.dispatchEvent({
  14259. type: 'sessionend'
  14260. });
  14261. }
  14262. this.setFramebufferScaleFactor = function (value) {
  14263. framebufferScaleFactor = value;
  14264. if (scope.isPresenting === true) {
  14265. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  14266. }
  14267. };
  14268. this.setReferenceSpaceType = function (value) {
  14269. referenceSpaceType = value;
  14270. if (scope.isPresenting === true) {
  14271. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  14272. }
  14273. };
  14274. this.getReferenceSpace = function () {
  14275. return referenceSpace;
  14276. };
  14277. this.getSession = function () {
  14278. return session;
  14279. };
  14280. this.setSession = /*#__PURE__*/function () {
  14281. var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(value) {
  14282. var attributes, layerInit, baseLayer;
  14283. return regeneratorRuntime.wrap(function _callee$(_context) {
  14284. while (1) {
  14285. switch (_context.prev = _context.next) {
  14286. case 0:
  14287. session = value;
  14288. if (!(session !== null)) {
  14289. _context.next = 24;
  14290. break;
  14291. }
  14292. session.addEventListener('select', onSessionEvent);
  14293. session.addEventListener('selectstart', onSessionEvent);
  14294. session.addEventListener('selectend', onSessionEvent);
  14295. session.addEventListener('squeeze', onSessionEvent);
  14296. session.addEventListener('squeezestart', onSessionEvent);
  14297. session.addEventListener('squeezeend', onSessionEvent);
  14298. session.addEventListener('end', onSessionEnd);
  14299. session.addEventListener('inputsourceschange', onInputSourcesChange);
  14300. attributes = gl.getContextAttributes();
  14301. if (!(attributes.xrCompatible !== true)) {
  14302. _context.next = 14;
  14303. break;
  14304. }
  14305. _context.next = 14;
  14306. return gl.makeXRCompatible();
  14307. case 14:
  14308. layerInit = {
  14309. antialias: attributes.antialias,
  14310. alpha: attributes.alpha,
  14311. depth: attributes.depth,
  14312. stencil: attributes.stencil,
  14313. framebufferScaleFactor: framebufferScaleFactor
  14314. }; // eslint-disable-next-line no-undef
  14315. baseLayer = new XRWebGLLayer(session, gl, layerInit);
  14316. session.updateRenderState({
  14317. baseLayer: baseLayer
  14318. });
  14319. _context.next = 19;
  14320. return session.requestReferenceSpace(referenceSpaceType);
  14321. case 19:
  14322. referenceSpace = _context.sent;
  14323. animation.setContext(session);
  14324. animation.start();
  14325. scope.isPresenting = true;
  14326. scope.dispatchEvent({
  14327. type: 'sessionstart'
  14328. });
  14329. case 24:
  14330. case "end":
  14331. return _context.stop();
  14332. }
  14333. }
  14334. }, _callee);
  14335. }));
  14336. return function (_x) {
  14337. return _ref.apply(this, arguments);
  14338. };
  14339. }();
  14340. function onInputSourcesChange(event) {
  14341. var inputSources = session.inputSources; // Assign inputSources to available controllers
  14342. for (var i = 0; i < controllers.length; i++) {
  14343. inputSourcesMap.set(inputSources[i], controllers[i]);
  14344. } // Notify disconnected
  14345. for (var _i = 0; _i < event.removed.length; _i++) {
  14346. var inputSource = event.removed[_i];
  14347. var controller = inputSourcesMap.get(inputSource);
  14348. if (controller) {
  14349. controller.dispatchEvent({
  14350. type: 'disconnected',
  14351. data: inputSource
  14352. });
  14353. inputSourcesMap.delete(inputSource);
  14354. }
  14355. } // Notify connected
  14356. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  14357. var _inputSource = event.added[_i2];
  14358. var _controller = inputSourcesMap.get(_inputSource);
  14359. if (_controller) {
  14360. _controller.dispatchEvent({
  14361. type: 'connected',
  14362. data: _inputSource
  14363. });
  14364. }
  14365. }
  14366. } //
  14367. var cameraLPos = new Vector3();
  14368. var cameraRPos = new Vector3();
  14369. /**
  14370. * Assumes 2 cameras that are parallel and share an X-axis, and that
  14371. * the cameras' projection and world matrices have already been set.
  14372. * And that near and far planes are identical for both cameras.
  14373. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  14374. */
  14375. function setProjectionFromUnion(camera, cameraL, cameraR) {
  14376. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  14377. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  14378. var ipd = cameraLPos.distanceTo(cameraRPos);
  14379. var projL = cameraL.projectionMatrix.elements;
  14380. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  14381. // most likely identical top and bottom frustum extents.
  14382. // Use the left camera for these values.
  14383. var near = projL[14] / (projL[10] - 1);
  14384. var far = projL[14] / (projL[10] + 1);
  14385. var topFov = (projL[9] + 1) / projL[5];
  14386. var bottomFov = (projL[9] - 1) / projL[5];
  14387. var leftFov = (projL[8] - 1) / projL[0];
  14388. var rightFov = (projR[8] + 1) / projR[0];
  14389. var left = near * leftFov;
  14390. var right = near * rightFov; // Calculate the new camera's position offset from the
  14391. // left camera. xOffset should be roughly half `ipd`.
  14392. var zOffset = ipd / (-leftFov + rightFov);
  14393. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  14394. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  14395. camera.translateX(xOffset);
  14396. camera.translateZ(zOffset);
  14397. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  14398. camera.matrixWorldInverse.copy(camera.matrixWorld).invert(); // Find the union of the frustum values of the cameras and scale
  14399. // the values so that the near plane's position does not change in world space,
  14400. // although must now be relative to the new union camera.
  14401. var near2 = near + zOffset;
  14402. var far2 = far + zOffset;
  14403. var left2 = left - xOffset;
  14404. var right2 = right + (ipd - xOffset);
  14405. var top2 = topFov * far / far2 * near2;
  14406. var bottom2 = bottomFov * far / far2 * near2;
  14407. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  14408. }
  14409. function updateCamera(camera, parent) {
  14410. if (parent === null) {
  14411. camera.matrixWorld.copy(camera.matrix);
  14412. } else {
  14413. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  14414. }
  14415. camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
  14416. }
  14417. this.getCamera = function (camera) {
  14418. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  14419. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  14420. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  14421. // Note that the new renderState won't apply until the next frame. See #18320
  14422. session.updateRenderState({
  14423. depthNear: cameraVR.near,
  14424. depthFar: cameraVR.far
  14425. });
  14426. _currentDepthNear = cameraVR.near;
  14427. _currentDepthFar = cameraVR.far;
  14428. }
  14429. var parent = camera.parent;
  14430. var cameras = cameraVR.cameras;
  14431. updateCamera(cameraVR, parent);
  14432. for (var i = 0; i < cameras.length; i++) {
  14433. updateCamera(cameras[i], parent);
  14434. } // update camera and its children
  14435. camera.matrixWorld.copy(cameraVR.matrixWorld);
  14436. camera.matrix.copy(cameraVR.matrix);
  14437. camera.matrix.decompose(camera.position, camera.quaternion, camera.scale);
  14438. var children = camera.children;
  14439. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  14440. children[_i3].updateMatrixWorld(true);
  14441. } // update projection matrix for proper view frustum culling
  14442. if (cameras.length === 2) {
  14443. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  14444. } else {
  14445. // assume single camera setup (AR)
  14446. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  14447. }
  14448. return cameraVR;
  14449. }; // Animation Loop
  14450. var onAnimationFrameCallback = null;
  14451. function onAnimationFrame(time, frame) {
  14452. pose = frame.getViewerPose(referenceSpace);
  14453. if (pose !== null) {
  14454. var views = pose.views;
  14455. var baseLayer = session.renderState.baseLayer;
  14456. renderer.setFramebuffer(baseLayer.framebuffer);
  14457. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  14458. if (views.length !== cameraVR.cameras.length) {
  14459. cameraVR.cameras.length = 0;
  14460. cameraVRNeedsUpdate = true;
  14461. }
  14462. for (var i = 0; i < views.length; i++) {
  14463. var view = views[i];
  14464. var viewport = baseLayer.getViewport(view);
  14465. var camera = cameras[i];
  14466. camera.matrix.fromArray(view.transform.matrix);
  14467. camera.projectionMatrix.fromArray(view.projectionMatrix);
  14468. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  14469. if (i === 0) {
  14470. cameraVR.matrix.copy(camera.matrix);
  14471. }
  14472. if (cameraVRNeedsUpdate === true) {
  14473. cameraVR.cameras.push(camera);
  14474. }
  14475. }
  14476. } //
  14477. var inputSources = session.inputSources;
  14478. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  14479. var controller = controllers[_i4];
  14480. var inputSource = inputSources[_i4];
  14481. controller.update(inputSource, frame, referenceSpace);
  14482. }
  14483. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  14484. }
  14485. var animation = new WebGLAnimation();
  14486. animation.setAnimationLoop(onAnimationFrame);
  14487. this.setAnimationLoop = function (callback) {
  14488. onAnimationFrameCallback = callback;
  14489. };
  14490. this.dispose = function () {};
  14491. }
  14492. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  14493. function WebGLMaterials(properties) {
  14494. function refreshFogUniforms(uniforms, fog) {
  14495. uniforms.fogColor.value.copy(fog.color);
  14496. if (fog.isFog) {
  14497. uniforms.fogNear.value = fog.near;
  14498. uniforms.fogFar.value = fog.far;
  14499. } else if (fog.isFogExp2) {
  14500. uniforms.fogDensity.value = fog.density;
  14501. }
  14502. }
  14503. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  14504. if (material.isMeshBasicMaterial) {
  14505. refreshUniformsCommon(uniforms, material);
  14506. } else if (material.isMeshLambertMaterial) {
  14507. refreshUniformsCommon(uniforms, material);
  14508. refreshUniformsLambert(uniforms, material);
  14509. } else if (material.isMeshToonMaterial) {
  14510. refreshUniformsCommon(uniforms, material);
  14511. refreshUniformsToon(uniforms, material);
  14512. } else if (material.isMeshPhongMaterial) {
  14513. refreshUniformsCommon(uniforms, material);
  14514. refreshUniformsPhong(uniforms, material);
  14515. } else if (material.isMeshStandardMaterial) {
  14516. refreshUniformsCommon(uniforms, material);
  14517. if (material.isMeshPhysicalMaterial) {
  14518. refreshUniformsPhysical(uniforms, material);
  14519. } else {
  14520. refreshUniformsStandard(uniforms, material);
  14521. }
  14522. } else if (material.isMeshMatcapMaterial) {
  14523. refreshUniformsCommon(uniforms, material);
  14524. refreshUniformsMatcap(uniforms, material);
  14525. } else if (material.isMeshDepthMaterial) {
  14526. refreshUniformsCommon(uniforms, material);
  14527. refreshUniformsDepth(uniforms, material);
  14528. } else if (material.isMeshDistanceMaterial) {
  14529. refreshUniformsCommon(uniforms, material);
  14530. refreshUniformsDistance(uniforms, material);
  14531. } else if (material.isMeshNormalMaterial) {
  14532. refreshUniformsCommon(uniforms, material);
  14533. refreshUniformsNormal(uniforms, material);
  14534. } else if (material.isLineBasicMaterial) {
  14535. refreshUniformsLine(uniforms, material);
  14536. if (material.isLineDashedMaterial) {
  14537. refreshUniformsDash(uniforms, material);
  14538. }
  14539. } else if (material.isPointsMaterial) {
  14540. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  14541. } else if (material.isSpriteMaterial) {
  14542. refreshUniformsSprites(uniforms, material);
  14543. } else if (material.isShadowMaterial) {
  14544. uniforms.color.value.copy(material.color);
  14545. uniforms.opacity.value = material.opacity;
  14546. } else if (material.isShaderMaterial) {
  14547. material.uniformsNeedUpdate = false; // #15581
  14548. }
  14549. }
  14550. function refreshUniformsCommon(uniforms, material) {
  14551. uniforms.opacity.value = material.opacity;
  14552. if (material.color) {
  14553. uniforms.diffuse.value.copy(material.color);
  14554. }
  14555. if (material.emissive) {
  14556. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  14557. }
  14558. if (material.map) {
  14559. uniforms.map.value = material.map;
  14560. }
  14561. if (material.alphaMap) {
  14562. uniforms.alphaMap.value = material.alphaMap;
  14563. }
  14564. if (material.specularMap) {
  14565. uniforms.specularMap.value = material.specularMap;
  14566. }
  14567. var envMap = properties.get(material).envMap;
  14568. if (envMap) {
  14569. uniforms.envMap.value = envMap;
  14570. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  14571. uniforms.reflectivity.value = material.reflectivity;
  14572. uniforms.refractionRatio.value = material.refractionRatio;
  14573. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  14574. if (maxMipLevel !== undefined) {
  14575. uniforms.maxMipLevel.value = maxMipLevel;
  14576. }
  14577. }
  14578. if (material.lightMap) {
  14579. uniforms.lightMap.value = material.lightMap;
  14580. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14581. }
  14582. if (material.aoMap) {
  14583. uniforms.aoMap.value = material.aoMap;
  14584. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14585. } // uv repeat and offset setting priorities
  14586. // 1. color map
  14587. // 2. specular map
  14588. // 3. displacementMap map
  14589. // 4. normal map
  14590. // 5. bump map
  14591. // 6. roughnessMap map
  14592. // 7. metalnessMap map
  14593. // 8. alphaMap map
  14594. // 9. emissiveMap map
  14595. // 10. clearcoat map
  14596. // 11. clearcoat normal map
  14597. // 12. clearcoat roughnessMap map
  14598. var uvScaleMap;
  14599. if (material.map) {
  14600. uvScaleMap = material.map;
  14601. } else if (material.specularMap) {
  14602. uvScaleMap = material.specularMap;
  14603. } else if (material.displacementMap) {
  14604. uvScaleMap = material.displacementMap;
  14605. } else if (material.normalMap) {
  14606. uvScaleMap = material.normalMap;
  14607. } else if (material.bumpMap) {
  14608. uvScaleMap = material.bumpMap;
  14609. } else if (material.roughnessMap) {
  14610. uvScaleMap = material.roughnessMap;
  14611. } else if (material.metalnessMap) {
  14612. uvScaleMap = material.metalnessMap;
  14613. } else if (material.alphaMap) {
  14614. uvScaleMap = material.alphaMap;
  14615. } else if (material.emissiveMap) {
  14616. uvScaleMap = material.emissiveMap;
  14617. } else if (material.clearcoatMap) {
  14618. uvScaleMap = material.clearcoatMap;
  14619. } else if (material.clearcoatNormalMap) {
  14620. uvScaleMap = material.clearcoatNormalMap;
  14621. } else if (material.clearcoatRoughnessMap) {
  14622. uvScaleMap = material.clearcoatRoughnessMap;
  14623. }
  14624. if (uvScaleMap !== undefined) {
  14625. // backwards compatibility
  14626. if (uvScaleMap.isWebGLRenderTarget) {
  14627. uvScaleMap = uvScaleMap.texture;
  14628. }
  14629. if (uvScaleMap.matrixAutoUpdate === true) {
  14630. uvScaleMap.updateMatrix();
  14631. }
  14632. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14633. } // uv repeat and offset setting priorities for uv2
  14634. // 1. ao map
  14635. // 2. light map
  14636. var uv2ScaleMap;
  14637. if (material.aoMap) {
  14638. uv2ScaleMap = material.aoMap;
  14639. } else if (material.lightMap) {
  14640. uv2ScaleMap = material.lightMap;
  14641. }
  14642. if (uv2ScaleMap !== undefined) {
  14643. // backwards compatibility
  14644. if (uv2ScaleMap.isWebGLRenderTarget) {
  14645. uv2ScaleMap = uv2ScaleMap.texture;
  14646. }
  14647. if (uv2ScaleMap.matrixAutoUpdate === true) {
  14648. uv2ScaleMap.updateMatrix();
  14649. }
  14650. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  14651. }
  14652. }
  14653. function refreshUniformsLine(uniforms, material) {
  14654. uniforms.diffuse.value.copy(material.color);
  14655. uniforms.opacity.value = material.opacity;
  14656. }
  14657. function refreshUniformsDash(uniforms, material) {
  14658. uniforms.dashSize.value = material.dashSize;
  14659. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14660. uniforms.scale.value = material.scale;
  14661. }
  14662. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  14663. uniforms.diffuse.value.copy(material.color);
  14664. uniforms.opacity.value = material.opacity;
  14665. uniforms.size.value = material.size * pixelRatio;
  14666. uniforms.scale.value = height * 0.5;
  14667. if (material.map) {
  14668. uniforms.map.value = material.map;
  14669. }
  14670. if (material.alphaMap) {
  14671. uniforms.alphaMap.value = material.alphaMap;
  14672. } // uv repeat and offset setting priorities
  14673. // 1. color map
  14674. // 2. alpha map
  14675. var uvScaleMap;
  14676. if (material.map) {
  14677. uvScaleMap = material.map;
  14678. } else if (material.alphaMap) {
  14679. uvScaleMap = material.alphaMap;
  14680. }
  14681. if (uvScaleMap !== undefined) {
  14682. if (uvScaleMap.matrixAutoUpdate === true) {
  14683. uvScaleMap.updateMatrix();
  14684. }
  14685. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14686. }
  14687. }
  14688. function refreshUniformsSprites(uniforms, material) {
  14689. uniforms.diffuse.value.copy(material.color);
  14690. uniforms.opacity.value = material.opacity;
  14691. uniforms.rotation.value = material.rotation;
  14692. if (material.map) {
  14693. uniforms.map.value = material.map;
  14694. }
  14695. if (material.alphaMap) {
  14696. uniforms.alphaMap.value = material.alphaMap;
  14697. } // uv repeat and offset setting priorities
  14698. // 1. color map
  14699. // 2. alpha map
  14700. var uvScaleMap;
  14701. if (material.map) {
  14702. uvScaleMap = material.map;
  14703. } else if (material.alphaMap) {
  14704. uvScaleMap = material.alphaMap;
  14705. }
  14706. if (uvScaleMap !== undefined) {
  14707. if (uvScaleMap.matrixAutoUpdate === true) {
  14708. uvScaleMap.updateMatrix();
  14709. }
  14710. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14711. }
  14712. }
  14713. function refreshUniformsLambert(uniforms, material) {
  14714. if (material.emissiveMap) {
  14715. uniforms.emissiveMap.value = material.emissiveMap;
  14716. }
  14717. }
  14718. function refreshUniformsPhong(uniforms, material) {
  14719. uniforms.specular.value.copy(material.specular);
  14720. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  14721. if (material.emissiveMap) {
  14722. uniforms.emissiveMap.value = material.emissiveMap;
  14723. }
  14724. if (material.bumpMap) {
  14725. uniforms.bumpMap.value = material.bumpMap;
  14726. uniforms.bumpScale.value = material.bumpScale;
  14727. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14728. }
  14729. if (material.normalMap) {
  14730. uniforms.normalMap.value = material.normalMap;
  14731. uniforms.normalScale.value.copy(material.normalScale);
  14732. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14733. }
  14734. if (material.displacementMap) {
  14735. uniforms.displacementMap.value = material.displacementMap;
  14736. uniforms.displacementScale.value = material.displacementScale;
  14737. uniforms.displacementBias.value = material.displacementBias;
  14738. }
  14739. }
  14740. function refreshUniformsToon(uniforms, material) {
  14741. if (material.gradientMap) {
  14742. uniforms.gradientMap.value = material.gradientMap;
  14743. }
  14744. if (material.emissiveMap) {
  14745. uniforms.emissiveMap.value = material.emissiveMap;
  14746. }
  14747. if (material.bumpMap) {
  14748. uniforms.bumpMap.value = material.bumpMap;
  14749. uniforms.bumpScale.value = material.bumpScale;
  14750. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14751. }
  14752. if (material.normalMap) {
  14753. uniforms.normalMap.value = material.normalMap;
  14754. uniforms.normalScale.value.copy(material.normalScale);
  14755. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14756. }
  14757. if (material.displacementMap) {
  14758. uniforms.displacementMap.value = material.displacementMap;
  14759. uniforms.displacementScale.value = material.displacementScale;
  14760. uniforms.displacementBias.value = material.displacementBias;
  14761. }
  14762. }
  14763. function refreshUniformsStandard(uniforms, material) {
  14764. uniforms.roughness.value = material.roughness;
  14765. uniforms.metalness.value = material.metalness;
  14766. if (material.roughnessMap) {
  14767. uniforms.roughnessMap.value = material.roughnessMap;
  14768. }
  14769. if (material.metalnessMap) {
  14770. uniforms.metalnessMap.value = material.metalnessMap;
  14771. }
  14772. if (material.emissiveMap) {
  14773. uniforms.emissiveMap.value = material.emissiveMap;
  14774. }
  14775. if (material.bumpMap) {
  14776. uniforms.bumpMap.value = material.bumpMap;
  14777. uniforms.bumpScale.value = material.bumpScale;
  14778. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14779. }
  14780. if (material.normalMap) {
  14781. uniforms.normalMap.value = material.normalMap;
  14782. uniforms.normalScale.value.copy(material.normalScale);
  14783. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14784. }
  14785. if (material.displacementMap) {
  14786. uniforms.displacementMap.value = material.displacementMap;
  14787. uniforms.displacementScale.value = material.displacementScale;
  14788. uniforms.displacementBias.value = material.displacementBias;
  14789. }
  14790. var envMap = properties.get(material).envMap;
  14791. if (envMap) {
  14792. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14793. uniforms.envMapIntensity.value = material.envMapIntensity;
  14794. }
  14795. }
  14796. function refreshUniformsPhysical(uniforms, material) {
  14797. refreshUniformsStandard(uniforms, material);
  14798. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14799. uniforms.clearcoat.value = material.clearcoat;
  14800. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14801. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  14802. if (material.clearcoatMap) {
  14803. uniforms.clearcoatMap.value = material.clearcoatMap;
  14804. }
  14805. if (material.clearcoatRoughnessMap) {
  14806. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14807. }
  14808. if (material.clearcoatNormalMap) {
  14809. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  14810. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14811. if (material.side === BackSide) {
  14812. uniforms.clearcoatNormalScale.value.negate();
  14813. }
  14814. }
  14815. uniforms.transmission.value = material.transmission;
  14816. if (material.transmissionMap) {
  14817. uniforms.transmissionMap.value = material.transmissionMap;
  14818. }
  14819. }
  14820. function refreshUniformsMatcap(uniforms, material) {
  14821. if (material.matcap) {
  14822. uniforms.matcap.value = material.matcap;
  14823. }
  14824. if (material.bumpMap) {
  14825. uniforms.bumpMap.value = material.bumpMap;
  14826. uniforms.bumpScale.value = material.bumpScale;
  14827. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14828. }
  14829. if (material.normalMap) {
  14830. uniforms.normalMap.value = material.normalMap;
  14831. uniforms.normalScale.value.copy(material.normalScale);
  14832. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14833. }
  14834. if (material.displacementMap) {
  14835. uniforms.displacementMap.value = material.displacementMap;
  14836. uniforms.displacementScale.value = material.displacementScale;
  14837. uniforms.displacementBias.value = material.displacementBias;
  14838. }
  14839. }
  14840. function refreshUniformsDepth(uniforms, material) {
  14841. if (material.displacementMap) {
  14842. uniforms.displacementMap.value = material.displacementMap;
  14843. uniforms.displacementScale.value = material.displacementScale;
  14844. uniforms.displacementBias.value = material.displacementBias;
  14845. }
  14846. }
  14847. function refreshUniformsDistance(uniforms, material) {
  14848. if (material.displacementMap) {
  14849. uniforms.displacementMap.value = material.displacementMap;
  14850. uniforms.displacementScale.value = material.displacementScale;
  14851. uniforms.displacementBias.value = material.displacementBias;
  14852. }
  14853. uniforms.referencePosition.value.copy(material.referencePosition);
  14854. uniforms.nearDistance.value = material.nearDistance;
  14855. uniforms.farDistance.value = material.farDistance;
  14856. }
  14857. function refreshUniformsNormal(uniforms, material) {
  14858. if (material.bumpMap) {
  14859. uniforms.bumpMap.value = material.bumpMap;
  14860. uniforms.bumpScale.value = material.bumpScale;
  14861. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14862. }
  14863. if (material.normalMap) {
  14864. uniforms.normalMap.value = material.normalMap;
  14865. uniforms.normalScale.value.copy(material.normalScale);
  14866. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14867. }
  14868. if (material.displacementMap) {
  14869. uniforms.displacementMap.value = material.displacementMap;
  14870. uniforms.displacementScale.value = material.displacementScale;
  14871. uniforms.displacementBias.value = material.displacementBias;
  14872. }
  14873. }
  14874. return {
  14875. refreshFogUniforms: refreshFogUniforms,
  14876. refreshMaterialUniforms: refreshMaterialUniforms
  14877. };
  14878. }
  14879. function createCanvasElement() {
  14880. var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  14881. canvas.style.display = 'block';
  14882. return canvas;
  14883. }
  14884. function WebGLRenderer(parameters) {
  14885. parameters = parameters || {};
  14886. var _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  14887. _context = parameters.context !== undefined ? parameters.context : null,
  14888. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14889. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14890. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14891. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14892. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14893. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14894. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14895. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14896. var currentRenderList = null;
  14897. var currentRenderState = null; // render() can be called from within a callback triggered by another render.
  14898. // We track this so that the nested render call gets its state isolated from the parent render call.
  14899. var renderStateStack = []; // public properties
  14900. this.domElement = _canvas; // Debug configuration container
  14901. this.debug = {
  14902. /**
  14903. * Enables error checking and reporting when shader programs are being compiled
  14904. * @type {boolean}
  14905. */
  14906. checkShaderErrors: true
  14907. }; // clearing
  14908. this.autoClear = true;
  14909. this.autoClearColor = true;
  14910. this.autoClearDepth = true;
  14911. this.autoClearStencil = true; // scene graph
  14912. this.sortObjects = true; // user-defined clipping
  14913. this.clippingPlanes = [];
  14914. this.localClippingEnabled = false; // physically based shading
  14915. this.gammaFactor = 2.0; // for backwards compatibility
  14916. this.outputEncoding = LinearEncoding; // physical lights
  14917. this.physicallyCorrectLights = false; // tone mapping
  14918. this.toneMapping = NoToneMapping;
  14919. this.toneMappingExposure = 1.0; // morphs
  14920. this.maxMorphTargets = 8;
  14921. this.maxMorphNormals = 4; // internal properties
  14922. var _this = this;
  14923. var _isContextLost = false; // internal state cache
  14924. var _framebuffer = null;
  14925. var _currentActiveCubeFace = 0;
  14926. var _currentActiveMipmapLevel = 0;
  14927. var _currentRenderTarget = null;
  14928. var _currentFramebuffer = null;
  14929. var _currentMaterialId = -1;
  14930. var _currentCamera = null;
  14931. var _currentViewport = new Vector4();
  14932. var _currentScissor = new Vector4();
  14933. var _currentScissorTest = null; //
  14934. var _width = _canvas.width;
  14935. var _height = _canvas.height;
  14936. var _pixelRatio = 1;
  14937. var _opaqueSort = null;
  14938. var _transparentSort = null;
  14939. var _viewport = new Vector4(0, 0, _width, _height);
  14940. var _scissor = new Vector4(0, 0, _width, _height);
  14941. var _scissorTest = false; // frustum
  14942. var _frustum = new Frustum(); // clipping
  14943. var _clippingEnabled = false;
  14944. var _localClippingEnabled = false; // camera matrices cache
  14945. var _projScreenMatrix = new Matrix4();
  14946. var _vector3 = new Vector3();
  14947. var _emptyScene = {
  14948. background: null,
  14949. fog: null,
  14950. environment: null,
  14951. overrideMaterial: null,
  14952. isScene: true
  14953. };
  14954. function getTargetPixelRatio() {
  14955. return _currentRenderTarget === null ? _pixelRatio : 1;
  14956. } // initialize
  14957. var _gl = _context;
  14958. function getContext(contextNames, contextAttributes) {
  14959. for (var i = 0; i < contextNames.length; i++) {
  14960. var contextName = contextNames[i];
  14961. var context = _canvas.getContext(contextName, contextAttributes);
  14962. if (context !== null) return context;
  14963. }
  14964. return null;
  14965. }
  14966. try {
  14967. var contextAttributes = {
  14968. alpha: _alpha,
  14969. depth: _depth,
  14970. stencil: _stencil,
  14971. antialias: _antialias,
  14972. premultipliedAlpha: _premultipliedAlpha,
  14973. preserveDrawingBuffer: _preserveDrawingBuffer,
  14974. powerPreference: _powerPreference,
  14975. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  14976. }; // event listeners must be registered before WebGL context is created, see #12753
  14977. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  14978. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  14979. if (_gl === null) {
  14980. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  14981. if (_this.isWebGL1Renderer === true) {
  14982. contextNames.shift();
  14983. }
  14984. _gl = getContext(contextNames, contextAttributes);
  14985. if (_gl === null) {
  14986. if (getContext(contextNames)) {
  14987. throw new Error('Error creating WebGL context with your selected attributes.');
  14988. } else {
  14989. throw new Error('Error creating WebGL context.');
  14990. }
  14991. }
  14992. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14993. if (_gl.getShaderPrecisionFormat === undefined) {
  14994. _gl.getShaderPrecisionFormat = function () {
  14995. return {
  14996. 'rangeMin': 1,
  14997. 'rangeMax': 1,
  14998. 'precision': 1
  14999. };
  15000. };
  15001. }
  15002. } catch (error) {
  15003. console.error('THREE.WebGLRenderer: ' + error.message);
  15004. throw error;
  15005. }
  15006. var extensions, capabilities, state, info;
  15007. var properties, textures, cubemaps, attributes, geometries, objects;
  15008. var programCache, materials, renderLists, renderStates, clipping;
  15009. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  15010. var utils, bindingStates;
  15011. function initGLContext() {
  15012. extensions = new WebGLExtensions(_gl);
  15013. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  15014. extensions.init(capabilities);
  15015. utils = new WebGLUtils(_gl, extensions, capabilities);
  15016. state = new WebGLState(_gl, extensions, capabilities);
  15017. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  15018. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  15019. info = new WebGLInfo(_gl);
  15020. properties = new WebGLProperties();
  15021. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  15022. cubemaps = new WebGLCubeMaps(_this);
  15023. attributes = new WebGLAttributes(_gl, capabilities);
  15024. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  15025. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  15026. objects = new WebGLObjects(_gl, geometries, attributes, info);
  15027. morphtargets = new WebGLMorphtargets(_gl);
  15028. clipping = new WebGLClipping(properties);
  15029. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  15030. materials = new WebGLMaterials(properties);
  15031. renderLists = new WebGLRenderLists(properties);
  15032. renderStates = new WebGLRenderStates(extensions, capabilities);
  15033. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  15034. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  15035. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  15036. info.programs = programCache.programs;
  15037. _this.capabilities = capabilities;
  15038. _this.extensions = extensions;
  15039. _this.properties = properties;
  15040. _this.renderLists = renderLists;
  15041. _this.state = state;
  15042. _this.info = info;
  15043. }
  15044. initGLContext(); // xr
  15045. var xr = new WebXRManager(_this, _gl);
  15046. this.xr = xr; // shadow map
  15047. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  15048. this.shadowMap = shadowMap; // API
  15049. this.getContext = function () {
  15050. return _gl;
  15051. };
  15052. this.getContextAttributes = function () {
  15053. return _gl.getContextAttributes();
  15054. };
  15055. this.forceContextLoss = function () {
  15056. var extension = extensions.get('WEBGL_lose_context');
  15057. if (extension) extension.loseContext();
  15058. };
  15059. this.forceContextRestore = function () {
  15060. var extension = extensions.get('WEBGL_lose_context');
  15061. if (extension) extension.restoreContext();
  15062. };
  15063. this.getPixelRatio = function () {
  15064. return _pixelRatio;
  15065. };
  15066. this.setPixelRatio = function (value) {
  15067. if (value === undefined) return;
  15068. _pixelRatio = value;
  15069. this.setSize(_width, _height, false);
  15070. };
  15071. this.getSize = function (target) {
  15072. if (target === undefined) {
  15073. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  15074. target = new Vector2();
  15075. }
  15076. return target.set(_width, _height);
  15077. };
  15078. this.setSize = function (width, height, updateStyle) {
  15079. if (xr.isPresenting) {
  15080. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  15081. return;
  15082. }
  15083. _width = width;
  15084. _height = height;
  15085. _canvas.width = Math.floor(width * _pixelRatio);
  15086. _canvas.height = Math.floor(height * _pixelRatio);
  15087. if (updateStyle !== false) {
  15088. _canvas.style.width = width + 'px';
  15089. _canvas.style.height = height + 'px';
  15090. }
  15091. this.setViewport(0, 0, width, height);
  15092. };
  15093. this.getDrawingBufferSize = function (target) {
  15094. if (target === undefined) {
  15095. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  15096. target = new Vector2();
  15097. }
  15098. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  15099. };
  15100. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  15101. _width = width;
  15102. _height = height;
  15103. _pixelRatio = pixelRatio;
  15104. _canvas.width = Math.floor(width * pixelRatio);
  15105. _canvas.height = Math.floor(height * pixelRatio);
  15106. this.setViewport(0, 0, width, height);
  15107. };
  15108. this.getCurrentViewport = function (target) {
  15109. if (target === undefined) {
  15110. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  15111. target = new Vector4();
  15112. }
  15113. return target.copy(_currentViewport);
  15114. };
  15115. this.getViewport = function (target) {
  15116. return target.copy(_viewport);
  15117. };
  15118. this.setViewport = function (x, y, width, height) {
  15119. if (x.isVector4) {
  15120. _viewport.set(x.x, x.y, x.z, x.w);
  15121. } else {
  15122. _viewport.set(x, y, width, height);
  15123. }
  15124. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  15125. };
  15126. this.getScissor = function (target) {
  15127. return target.copy(_scissor);
  15128. };
  15129. this.setScissor = function (x, y, width, height) {
  15130. if (x.isVector4) {
  15131. _scissor.set(x.x, x.y, x.z, x.w);
  15132. } else {
  15133. _scissor.set(x, y, width, height);
  15134. }
  15135. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  15136. };
  15137. this.getScissorTest = function () {
  15138. return _scissorTest;
  15139. };
  15140. this.setScissorTest = function (boolean) {
  15141. state.setScissorTest(_scissorTest = boolean);
  15142. };
  15143. this.setOpaqueSort = function (method) {
  15144. _opaqueSort = method;
  15145. };
  15146. this.setTransparentSort = function (method) {
  15147. _transparentSort = method;
  15148. }; // Clearing
  15149. this.getClearColor = function (target) {
  15150. if (target === undefined) {
  15151. console.warn('WebGLRenderer: .getClearColor() now requires a Color as an argument');
  15152. target = new Color();
  15153. }
  15154. return target.copy(background.getClearColor());
  15155. };
  15156. this.setClearColor = function () {
  15157. background.setClearColor.apply(background, arguments);
  15158. };
  15159. this.getClearAlpha = function () {
  15160. return background.getClearAlpha();
  15161. };
  15162. this.setClearAlpha = function () {
  15163. background.setClearAlpha.apply(background, arguments);
  15164. };
  15165. this.clear = function (color, depth, stencil) {
  15166. var bits = 0;
  15167. if (color === undefined || color) bits |= 16384;
  15168. if (depth === undefined || depth) bits |= 256;
  15169. if (stencil === undefined || stencil) bits |= 1024;
  15170. _gl.clear(bits);
  15171. };
  15172. this.clearColor = function () {
  15173. this.clear(true, false, false);
  15174. };
  15175. this.clearDepth = function () {
  15176. this.clear(false, true, false);
  15177. };
  15178. this.clearStencil = function () {
  15179. this.clear(false, false, true);
  15180. }; //
  15181. this.dispose = function () {
  15182. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  15183. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  15184. renderLists.dispose();
  15185. renderStates.dispose();
  15186. properties.dispose();
  15187. cubemaps.dispose();
  15188. objects.dispose();
  15189. bindingStates.dispose();
  15190. xr.dispose();
  15191. animation.stop();
  15192. }; // Events
  15193. function onContextLost(event) {
  15194. event.preventDefault();
  15195. console.log('THREE.WebGLRenderer: Context Lost.');
  15196. _isContextLost = true;
  15197. }
  15198. function onContextRestore()
  15199. /* event */
  15200. {
  15201. console.log('THREE.WebGLRenderer: Context Restored.');
  15202. _isContextLost = false;
  15203. initGLContext();
  15204. }
  15205. function onMaterialDispose(event) {
  15206. var material = event.target;
  15207. material.removeEventListener('dispose', onMaterialDispose);
  15208. deallocateMaterial(material);
  15209. } // Buffer deallocation
  15210. function deallocateMaterial(material) {
  15211. releaseMaterialProgramReference(material);
  15212. properties.remove(material);
  15213. }
  15214. function releaseMaterialProgramReference(material) {
  15215. var programInfo = properties.get(material).program;
  15216. if (programInfo !== undefined) {
  15217. programCache.releaseProgram(programInfo);
  15218. }
  15219. } // Buffer rendering
  15220. function renderObjectImmediate(object, program) {
  15221. object.render(function (object) {
  15222. _this.renderBufferImmediate(object, program);
  15223. });
  15224. }
  15225. this.renderBufferImmediate = function (object, program) {
  15226. bindingStates.initAttributes();
  15227. var buffers = properties.get(object);
  15228. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  15229. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  15230. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  15231. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  15232. var programAttributes = program.getAttributes();
  15233. if (object.hasPositions) {
  15234. _gl.bindBuffer(34962, buffers.position);
  15235. _gl.bufferData(34962, object.positionArray, 35048);
  15236. bindingStates.enableAttribute(programAttributes.position);
  15237. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  15238. }
  15239. if (object.hasNormals) {
  15240. _gl.bindBuffer(34962, buffers.normal);
  15241. _gl.bufferData(34962, object.normalArray, 35048);
  15242. bindingStates.enableAttribute(programAttributes.normal);
  15243. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  15244. }
  15245. if (object.hasUvs) {
  15246. _gl.bindBuffer(34962, buffers.uv);
  15247. _gl.bufferData(34962, object.uvArray, 35048);
  15248. bindingStates.enableAttribute(programAttributes.uv);
  15249. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  15250. }
  15251. if (object.hasColors) {
  15252. _gl.bindBuffer(34962, buffers.color);
  15253. _gl.bufferData(34962, object.colorArray, 35048);
  15254. bindingStates.enableAttribute(programAttributes.color);
  15255. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  15256. }
  15257. bindingStates.disableUnusedAttributes();
  15258. _gl.drawArrays(4, 0, object.count);
  15259. object.count = 0;
  15260. };
  15261. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  15262. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  15263. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  15264. var program = setProgram(camera, scene, material, object);
  15265. state.setMaterial(material, frontFaceCW); //
  15266. var index = geometry.index;
  15267. var position = geometry.attributes.position; //
  15268. if (index === null) {
  15269. if (position === undefined || position.count === 0) return;
  15270. } else if (index.count === 0) {
  15271. return;
  15272. } //
  15273. var rangeFactor = 1;
  15274. if (material.wireframe === true) {
  15275. index = geometries.getWireframeAttribute(geometry);
  15276. rangeFactor = 2;
  15277. }
  15278. if (material.morphTargets || material.morphNormals) {
  15279. morphtargets.update(object, geometry, material, program);
  15280. }
  15281. bindingStates.setup(object, material, program, geometry, index);
  15282. var attribute;
  15283. var renderer = bufferRenderer;
  15284. if (index !== null) {
  15285. attribute = attributes.get(index);
  15286. renderer = indexedBufferRenderer;
  15287. renderer.setIndex(attribute);
  15288. } //
  15289. var dataCount = index !== null ? index.count : position.count;
  15290. var rangeStart = geometry.drawRange.start * rangeFactor;
  15291. var rangeCount = geometry.drawRange.count * rangeFactor;
  15292. var groupStart = group !== null ? group.start * rangeFactor : 0;
  15293. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  15294. var drawStart = Math.max(rangeStart, groupStart);
  15295. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  15296. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  15297. if (drawCount === 0) return; //
  15298. if (object.isMesh) {
  15299. if (material.wireframe === true) {
  15300. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  15301. renderer.setMode(1);
  15302. } else {
  15303. renderer.setMode(4);
  15304. }
  15305. } else if (object.isLine) {
  15306. var lineWidth = material.linewidth;
  15307. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  15308. state.setLineWidth(lineWidth * getTargetPixelRatio());
  15309. if (object.isLineSegments) {
  15310. renderer.setMode(1);
  15311. } else if (object.isLineLoop) {
  15312. renderer.setMode(2);
  15313. } else {
  15314. renderer.setMode(3);
  15315. }
  15316. } else if (object.isPoints) {
  15317. renderer.setMode(0);
  15318. } else if (object.isSprite) {
  15319. renderer.setMode(4);
  15320. }
  15321. if (object.isInstancedMesh) {
  15322. renderer.renderInstances(drawStart, drawCount, object.count);
  15323. } else if (geometry.isInstancedBufferGeometry) {
  15324. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  15325. renderer.renderInstances(drawStart, drawCount, instanceCount);
  15326. } else {
  15327. renderer.render(drawStart, drawCount);
  15328. }
  15329. }; // Compile
  15330. this.compile = function (scene, camera) {
  15331. currentRenderState = renderStates.get(scene);
  15332. currentRenderState.init();
  15333. scene.traverseVisible(function (object) {
  15334. if (object.isLight && object.layers.test(camera.layers)) {
  15335. currentRenderState.pushLight(object);
  15336. if (object.castShadow) {
  15337. currentRenderState.pushShadow(object);
  15338. }
  15339. }
  15340. });
  15341. currentRenderState.setupLights();
  15342. var compiled = new WeakMap();
  15343. scene.traverse(function (object) {
  15344. var material = object.material;
  15345. if (material) {
  15346. if (Array.isArray(material)) {
  15347. for (var i = 0; i < material.length; i++) {
  15348. var material2 = material[i];
  15349. if (compiled.has(material2) === false) {
  15350. initMaterial(material2, scene, object);
  15351. compiled.set(material2);
  15352. }
  15353. }
  15354. } else if (compiled.has(material) === false) {
  15355. initMaterial(material, scene, object);
  15356. compiled.set(material);
  15357. }
  15358. }
  15359. });
  15360. }; // Animation Loop
  15361. var onAnimationFrameCallback = null;
  15362. function onAnimationFrame(time) {
  15363. if (xr.isPresenting) return;
  15364. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  15365. }
  15366. var animation = new WebGLAnimation();
  15367. animation.setAnimationLoop(onAnimationFrame);
  15368. if (typeof window !== 'undefined') animation.setContext(window);
  15369. this.setAnimationLoop = function (callback) {
  15370. onAnimationFrameCallback = callback;
  15371. xr.setAnimationLoop(callback);
  15372. callback === null ? animation.stop() : animation.start();
  15373. }; // Rendering
  15374. this.render = function (scene, camera) {
  15375. var renderTarget, forceClear;
  15376. if (arguments[2] !== undefined) {
  15377. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  15378. renderTarget = arguments[2];
  15379. }
  15380. if (arguments[3] !== undefined) {
  15381. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  15382. forceClear = arguments[3];
  15383. }
  15384. if (camera !== undefined && camera.isCamera !== true) {
  15385. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  15386. return;
  15387. }
  15388. if (_isContextLost === true) return; // reset caching for this frame
  15389. bindingStates.resetDefaultState();
  15390. _currentMaterialId = -1;
  15391. _currentCamera = null; // update scene graph
  15392. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  15393. if (camera.parent === null) camera.updateMatrixWorld();
  15394. if (xr.enabled === true && xr.isPresenting === true) {
  15395. camera = xr.getCamera(camera);
  15396. } //
  15397. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  15398. currentRenderState = renderStates.get(scene, renderStateStack.length);
  15399. currentRenderState.init();
  15400. renderStateStack.push(currentRenderState);
  15401. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  15402. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  15403. _localClippingEnabled = this.localClippingEnabled;
  15404. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  15405. currentRenderList = renderLists.get(scene, camera);
  15406. currentRenderList.init();
  15407. projectObject(scene, camera, 0, _this.sortObjects);
  15408. currentRenderList.finish();
  15409. if (_this.sortObjects === true) {
  15410. currentRenderList.sort(_opaqueSort, _transparentSort);
  15411. } //
  15412. if (_clippingEnabled === true) clipping.beginShadows();
  15413. var shadowsArray = currentRenderState.state.shadowsArray;
  15414. shadowMap.render(shadowsArray, scene, camera);
  15415. currentRenderState.setupLights();
  15416. currentRenderState.setupLightsView(camera);
  15417. if (_clippingEnabled === true) clipping.endShadows(); //
  15418. if (this.info.autoReset === true) this.info.reset();
  15419. if (renderTarget !== undefined) {
  15420. this.setRenderTarget(renderTarget);
  15421. } //
  15422. background.render(currentRenderList, scene, camera, forceClear); // render scene
  15423. var opaqueObjects = currentRenderList.opaque;
  15424. var transparentObjects = currentRenderList.transparent;
  15425. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  15426. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  15427. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  15428. if (_currentRenderTarget !== null) {
  15429. // Generate mipmap if we're using any kind of mipmap filtering
  15430. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  15431. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  15432. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  15433. state.buffers.depth.setTest(true);
  15434. state.buffers.depth.setMask(true);
  15435. state.buffers.color.setMask(true);
  15436. state.setPolygonOffset(false); // _gl.finish();
  15437. renderStateStack.pop();
  15438. if (renderStateStack.length > 0) {
  15439. currentRenderState = renderStateStack[renderStateStack.length - 1];
  15440. } else {
  15441. currentRenderState = null;
  15442. }
  15443. currentRenderList = null;
  15444. };
  15445. function projectObject(object, camera, groupOrder, sortObjects) {
  15446. if (object.visible === false) return;
  15447. var visible = object.layers.test(camera.layers);
  15448. if (visible) {
  15449. if (object.isGroup) {
  15450. groupOrder = object.renderOrder;
  15451. } else if (object.isLOD) {
  15452. if (object.autoUpdate === true) object.update(camera);
  15453. } else if (object.isLight) {
  15454. currentRenderState.pushLight(object);
  15455. if (object.castShadow) {
  15456. currentRenderState.pushShadow(object);
  15457. }
  15458. } else if (object.isSprite) {
  15459. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  15460. if (sortObjects) {
  15461. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15462. }
  15463. var geometry = objects.update(object);
  15464. var material = object.material;
  15465. if (material.visible) {
  15466. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  15467. }
  15468. }
  15469. } else if (object.isImmediateRenderObject) {
  15470. if (sortObjects) {
  15471. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15472. }
  15473. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  15474. } else if (object.isMesh || object.isLine || object.isPoints) {
  15475. if (object.isSkinnedMesh) {
  15476. // update skeleton only once in a frame
  15477. if (object.skeleton.frame !== info.render.frame) {
  15478. object.skeleton.update();
  15479. object.skeleton.frame = info.render.frame;
  15480. }
  15481. }
  15482. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  15483. if (sortObjects) {
  15484. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15485. }
  15486. var _geometry = objects.update(object);
  15487. var _material = object.material;
  15488. if (Array.isArray(_material)) {
  15489. var groups = _geometry.groups;
  15490. for (var i = 0, l = groups.length; i < l; i++) {
  15491. var group = groups[i];
  15492. var groupMaterial = _material[group.materialIndex];
  15493. if (groupMaterial && groupMaterial.visible) {
  15494. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  15495. }
  15496. }
  15497. } else if (_material.visible) {
  15498. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  15499. }
  15500. }
  15501. }
  15502. }
  15503. var children = object.children;
  15504. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  15505. projectObject(children[_i], camera, groupOrder, sortObjects);
  15506. }
  15507. }
  15508. function renderObjects(renderList, scene, camera) {
  15509. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  15510. for (var i = 0, l = renderList.length; i < l; i++) {
  15511. var renderItem = renderList[i];
  15512. var object = renderItem.object;
  15513. var geometry = renderItem.geometry;
  15514. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  15515. var group = renderItem.group;
  15516. if (camera.isArrayCamera) {
  15517. var cameras = camera.cameras;
  15518. for (var j = 0, jl = cameras.length; j < jl; j++) {
  15519. var camera2 = cameras[j];
  15520. if (object.layers.test(camera2.layers)) {
  15521. state.viewport(_currentViewport.copy(camera2.viewport));
  15522. currentRenderState.setupLightsView(camera2);
  15523. renderObject(object, scene, camera2, geometry, material, group);
  15524. }
  15525. }
  15526. } else {
  15527. renderObject(object, scene, camera, geometry, material, group);
  15528. }
  15529. }
  15530. }
  15531. function renderObject(object, scene, camera, geometry, material, group) {
  15532. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  15533. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  15534. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  15535. if (object.isImmediateRenderObject) {
  15536. var program = setProgram(camera, scene, material, object);
  15537. state.setMaterial(material);
  15538. bindingStates.reset();
  15539. renderObjectImmediate(object, program);
  15540. } else {
  15541. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  15542. }
  15543. object.onAfterRender(_this, scene, camera, geometry, material, group);
  15544. }
  15545. function initMaterial(material, scene, object) {
  15546. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15547. var materialProperties = properties.get(material);
  15548. var lights = currentRenderState.state.lights;
  15549. var shadowsArray = currentRenderState.state.shadowsArray;
  15550. var lightsStateVersion = lights.state.version;
  15551. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  15552. var programCacheKey = programCache.getProgramCacheKey(parameters);
  15553. var program = materialProperties.program;
  15554. var programChange = true; // always update environment and fog - changing these trigger an initMaterial call, but it's possible that the program doesn't change
  15555. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  15556. materialProperties.fog = scene.fog;
  15557. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment);
  15558. if (program === undefined) {
  15559. // new material
  15560. material.addEventListener('dispose', onMaterialDispose);
  15561. } else if (program.cacheKey !== programCacheKey) {
  15562. // changed glsl or parameters
  15563. releaseMaterialProgramReference(material);
  15564. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  15565. programChange = false;
  15566. } else if (parameters.shaderID !== undefined) {
  15567. // same glsl and uniform list
  15568. return;
  15569. } else {
  15570. // only rebuild uniform list
  15571. programChange = false;
  15572. }
  15573. if (programChange) {
  15574. parameters.uniforms = programCache.getUniforms(material);
  15575. material.onBeforeCompile(parameters, _this);
  15576. program = programCache.acquireProgram(parameters, programCacheKey);
  15577. materialProperties.program = program;
  15578. materialProperties.uniforms = parameters.uniforms;
  15579. materialProperties.outputEncoding = parameters.outputEncoding;
  15580. }
  15581. var uniforms = materialProperties.uniforms;
  15582. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  15583. materialProperties.numClippingPlanes = clipping.numPlanes;
  15584. materialProperties.numIntersection = clipping.numIntersection;
  15585. uniforms.clippingPlanes = clipping.uniform;
  15586. } // store the light setup it was created for
  15587. materialProperties.needsLights = materialNeedsLights(material);
  15588. materialProperties.lightsStateVersion = lightsStateVersion;
  15589. if (materialProperties.needsLights) {
  15590. // wire up the material to this renderer's lighting state
  15591. uniforms.ambientLightColor.value = lights.state.ambient;
  15592. uniforms.lightProbe.value = lights.state.probe;
  15593. uniforms.directionalLights.value = lights.state.directional;
  15594. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  15595. uniforms.spotLights.value = lights.state.spot;
  15596. uniforms.spotLightShadows.value = lights.state.spotShadow;
  15597. uniforms.rectAreaLights.value = lights.state.rectArea;
  15598. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  15599. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  15600. uniforms.pointLights.value = lights.state.point;
  15601. uniforms.pointLightShadows.value = lights.state.pointShadow;
  15602. uniforms.hemisphereLights.value = lights.state.hemi;
  15603. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  15604. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  15605. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  15606. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  15607. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  15608. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  15609. }
  15610. var progUniforms = materialProperties.program.getUniforms();
  15611. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  15612. materialProperties.uniformsList = uniformsList;
  15613. }
  15614. function setProgram(camera, scene, material, object) {
  15615. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15616. textures.resetTextureUnits();
  15617. var fog = scene.fog;
  15618. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  15619. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  15620. var envMap = cubemaps.get(material.envMap || environment);
  15621. var materialProperties = properties.get(material);
  15622. var lights = currentRenderState.state.lights;
  15623. if (_clippingEnabled === true) {
  15624. if (_localClippingEnabled === true || camera !== _currentCamera) {
  15625. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  15626. // object instead of the material, once it becomes feasible
  15627. // (#8465, #8379)
  15628. clipping.setState(material, camera, useCache);
  15629. }
  15630. }
  15631. if (material.version === materialProperties.__version) {
  15632. if (material.fog && materialProperties.fog !== fog) {
  15633. initMaterial(material, scene, object);
  15634. } else if (materialProperties.environment !== environment) {
  15635. initMaterial(material, scene, object);
  15636. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  15637. initMaterial(material, scene, object);
  15638. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  15639. initMaterial(material, scene, object);
  15640. } else if (materialProperties.outputEncoding !== encoding) {
  15641. initMaterial(material, scene, object);
  15642. } else if (materialProperties.envMap !== envMap) {
  15643. initMaterial(material, scene, object);
  15644. }
  15645. } else {
  15646. initMaterial(material, scene, object);
  15647. materialProperties.__version = material.version;
  15648. }
  15649. var refreshProgram = false;
  15650. var refreshMaterial = false;
  15651. var refreshLights = false;
  15652. var program = materialProperties.program,
  15653. p_uniforms = program.getUniforms(),
  15654. m_uniforms = materialProperties.uniforms;
  15655. if (state.useProgram(program.program)) {
  15656. refreshProgram = true;
  15657. refreshMaterial = true;
  15658. refreshLights = true;
  15659. }
  15660. if (material.id !== _currentMaterialId) {
  15661. _currentMaterialId = material.id;
  15662. refreshMaterial = true;
  15663. }
  15664. if (refreshProgram || _currentCamera !== camera) {
  15665. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  15666. if (capabilities.logarithmicDepthBuffer) {
  15667. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  15668. }
  15669. if (_currentCamera !== camera) {
  15670. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  15671. // now, in case this material supports lights - or later, when
  15672. // the next material that does gets activated:
  15673. refreshMaterial = true; // set to true on material change
  15674. refreshLights = true; // remains set until update done
  15675. } // load material specific uniforms
  15676. // (shader material also gets them for the sake of genericity)
  15677. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  15678. var uCamPos = p_uniforms.map.cameraPosition;
  15679. if (uCamPos !== undefined) {
  15680. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  15681. }
  15682. }
  15683. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  15684. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  15685. }
  15686. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  15687. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  15688. }
  15689. } // skinning uniforms must be set even if material didn't change
  15690. // auto-setting of texture unit for bone texture must go before other textures
  15691. // otherwise textures used for skinning can take over texture units reserved for other material textures
  15692. if (material.skinning) {
  15693. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  15694. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  15695. var skeleton = object.skeleton;
  15696. if (skeleton) {
  15697. var bones = skeleton.bones;
  15698. if (capabilities.floatVertexTextures) {
  15699. if (skeleton.boneTexture === null) {
  15700. // layout (1 matrix = 4 pixels)
  15701. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15702. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15703. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15704. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15705. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15706. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  15707. size = MathUtils.ceilPowerOfTwo(size);
  15708. size = Math.max(size, 4);
  15709. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  15710. boneMatrices.set(skeleton.boneMatrices); // copy current values
  15711. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  15712. skeleton.boneMatrices = boneMatrices;
  15713. skeleton.boneTexture = boneTexture;
  15714. skeleton.boneTextureSize = size;
  15715. }
  15716. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  15717. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  15718. } else {
  15719. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  15720. }
  15721. }
  15722. }
  15723. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  15724. materialProperties.receiveShadow = object.receiveShadow;
  15725. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  15726. }
  15727. if (refreshMaterial) {
  15728. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  15729. if (materialProperties.needsLights) {
  15730. // the current material requires lighting info
  15731. // note: all lighting uniforms are always set correctly
  15732. // they simply reference the renderer's state for their
  15733. // values
  15734. //
  15735. // use the current material's .needsUpdate flags to set
  15736. // the GL state when required
  15737. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  15738. } // refresh uniforms common to several materials
  15739. if (fog && material.fog) {
  15740. materials.refreshFogUniforms(m_uniforms, fog);
  15741. }
  15742. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  15743. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15744. }
  15745. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  15746. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15747. material.uniformsNeedUpdate = false;
  15748. }
  15749. if (material.isSpriteMaterial) {
  15750. p_uniforms.setValue(_gl, 'center', object.center);
  15751. } // common matrices
  15752. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  15753. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  15754. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  15755. return program;
  15756. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15757. function markUniformsLightsNeedsUpdate(uniforms, value) {
  15758. uniforms.ambientLightColor.needsUpdate = value;
  15759. uniforms.lightProbe.needsUpdate = value;
  15760. uniforms.directionalLights.needsUpdate = value;
  15761. uniforms.directionalLightShadows.needsUpdate = value;
  15762. uniforms.pointLights.needsUpdate = value;
  15763. uniforms.pointLightShadows.needsUpdate = value;
  15764. uniforms.spotLights.needsUpdate = value;
  15765. uniforms.spotLightShadows.needsUpdate = value;
  15766. uniforms.rectAreaLights.needsUpdate = value;
  15767. uniforms.hemisphereLights.needsUpdate = value;
  15768. }
  15769. function materialNeedsLights(material) {
  15770. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  15771. } //
  15772. this.setFramebuffer = function (value) {
  15773. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  15774. _framebuffer = value;
  15775. };
  15776. this.getActiveCubeFace = function () {
  15777. return _currentActiveCubeFace;
  15778. };
  15779. this.getActiveMipmapLevel = function () {
  15780. return _currentActiveMipmapLevel;
  15781. };
  15782. this.getRenderList = function () {
  15783. return currentRenderList;
  15784. };
  15785. this.setRenderList = function (renderList) {
  15786. currentRenderList = renderList;
  15787. };
  15788. this.getRenderTarget = function () {
  15789. return _currentRenderTarget;
  15790. };
  15791. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  15792. if (activeCubeFace === void 0) {
  15793. activeCubeFace = 0;
  15794. }
  15795. if (activeMipmapLevel === void 0) {
  15796. activeMipmapLevel = 0;
  15797. }
  15798. _currentRenderTarget = renderTarget;
  15799. _currentActiveCubeFace = activeCubeFace;
  15800. _currentActiveMipmapLevel = activeMipmapLevel;
  15801. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  15802. textures.setupRenderTarget(renderTarget);
  15803. }
  15804. var framebuffer = _framebuffer;
  15805. var isCube = false;
  15806. var isRenderTarget3D = false;
  15807. if (renderTarget) {
  15808. var texture = renderTarget.texture;
  15809. if (texture.isDataTexture3D || texture.isDataTexture2DArray) {
  15810. isRenderTarget3D = true;
  15811. }
  15812. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  15813. if (renderTarget.isWebGLCubeRenderTarget) {
  15814. framebuffer = __webglFramebuffer[activeCubeFace];
  15815. isCube = true;
  15816. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  15817. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  15818. } else {
  15819. framebuffer = __webglFramebuffer;
  15820. }
  15821. _currentViewport.copy(renderTarget.viewport);
  15822. _currentScissor.copy(renderTarget.scissor);
  15823. _currentScissorTest = renderTarget.scissorTest;
  15824. } else {
  15825. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  15826. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  15827. _currentScissorTest = _scissorTest;
  15828. }
  15829. if (_currentFramebuffer !== framebuffer) {
  15830. _gl.bindFramebuffer(36160, framebuffer);
  15831. _currentFramebuffer = framebuffer;
  15832. }
  15833. state.viewport(_currentViewport);
  15834. state.scissor(_currentScissor);
  15835. state.setScissorTest(_currentScissorTest);
  15836. if (isCube) {
  15837. var textureProperties = properties.get(renderTarget.texture);
  15838. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  15839. } else if (isRenderTarget3D) {
  15840. var _textureProperties = properties.get(renderTarget.texture);
  15841. var layer = activeCubeFace || 0;
  15842. _gl.framebufferTextureLayer(36160, 36064, _textureProperties.__webglTexture, activeMipmapLevel || 0, layer);
  15843. }
  15844. };
  15845. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15846. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15847. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15848. return;
  15849. }
  15850. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15851. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15852. framebuffer = framebuffer[activeCubeFaceIndex];
  15853. }
  15854. if (framebuffer) {
  15855. var restore = false;
  15856. if (framebuffer !== _currentFramebuffer) {
  15857. _gl.bindFramebuffer(36160, framebuffer);
  15858. restore = true;
  15859. }
  15860. try {
  15861. var texture = renderTarget.texture;
  15862. var textureFormat = texture.format;
  15863. var textureType = texture.type;
  15864. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15865. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15866. return;
  15867. }
  15868. var halfFloatSupportedByExt = textureType === HalfFloatType && (extensions.has('EXT_color_buffer_half_float') || capabilities.isWebGL2 && extensions.has('EXT_color_buffer_float'));
  15869. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15870. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.has('OES_texture_float') || extensions.has('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15871. !halfFloatSupportedByExt) {
  15872. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15873. return;
  15874. }
  15875. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15876. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15877. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15878. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15879. }
  15880. } else {
  15881. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15882. }
  15883. } finally {
  15884. if (restore) {
  15885. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15886. }
  15887. }
  15888. }
  15889. };
  15890. this.copyFramebufferToTexture = function (position, texture, level) {
  15891. if (level === void 0) {
  15892. level = 0;
  15893. }
  15894. var levelScale = Math.pow(2, -level);
  15895. var width = Math.floor(texture.image.width * levelScale);
  15896. var height = Math.floor(texture.image.height * levelScale);
  15897. var glFormat = utils.convert(texture.format);
  15898. textures.setTexture2D(texture, 0);
  15899. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15900. state.unbindTexture();
  15901. };
  15902. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15903. if (level === void 0) {
  15904. level = 0;
  15905. }
  15906. var width = srcTexture.image.width;
  15907. var height = srcTexture.image.height;
  15908. var glFormat = utils.convert(dstTexture.format);
  15909. var glType = utils.convert(dstTexture.type);
  15910. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  15911. // parameters, make sure they are correct for the dstTexture
  15912. _gl.pixelStorei(37440, dstTexture.flipY);
  15913. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  15914. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  15915. if (srcTexture.isDataTexture) {
  15916. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  15917. } else {
  15918. if (srcTexture.isCompressedTexture) {
  15919. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  15920. } else {
  15921. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  15922. }
  15923. } // Generate mipmaps only when copying level 0
  15924. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  15925. state.unbindTexture();
  15926. };
  15927. this.initTexture = function (texture) {
  15928. textures.setTexture2D(texture, 0);
  15929. state.unbindTexture();
  15930. };
  15931. this.resetState = function () {
  15932. state.reset();
  15933. bindingStates.reset();
  15934. };
  15935. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15936. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15937. detail: this
  15938. })); // eslint-disable-line no-undef
  15939. }
  15940. }
  15941. function WebGL1Renderer(parameters) {
  15942. WebGLRenderer.call(this, parameters);
  15943. }
  15944. WebGL1Renderer.prototype = Object.assign(Object.create(WebGLRenderer.prototype), {
  15945. constructor: WebGL1Renderer,
  15946. isWebGL1Renderer: true
  15947. });
  15948. var FogExp2 = /*#__PURE__*/function () {
  15949. function FogExp2(color, density) {
  15950. Object.defineProperty(this, 'isFogExp2', {
  15951. value: true
  15952. });
  15953. this.name = '';
  15954. this.color = new Color(color);
  15955. this.density = density !== undefined ? density : 0.00025;
  15956. }
  15957. var _proto = FogExp2.prototype;
  15958. _proto.clone = function clone() {
  15959. return new FogExp2(this.color, this.density);
  15960. };
  15961. _proto.toJSON = function toJSON()
  15962. /* meta */
  15963. {
  15964. return {
  15965. type: 'FogExp2',
  15966. color: this.color.getHex(),
  15967. density: this.density
  15968. };
  15969. };
  15970. return FogExp2;
  15971. }();
  15972. var Fog = /*#__PURE__*/function () {
  15973. function Fog(color, near, far) {
  15974. Object.defineProperty(this, 'isFog', {
  15975. value: true
  15976. });
  15977. this.name = '';
  15978. this.color = new Color(color);
  15979. this.near = near !== undefined ? near : 1;
  15980. this.far = far !== undefined ? far : 1000;
  15981. }
  15982. var _proto = Fog.prototype;
  15983. _proto.clone = function clone() {
  15984. return new Fog(this.color, this.near, this.far);
  15985. };
  15986. _proto.toJSON = function toJSON()
  15987. /* meta */
  15988. {
  15989. return {
  15990. type: 'Fog',
  15991. color: this.color.getHex(),
  15992. near: this.near,
  15993. far: this.far
  15994. };
  15995. };
  15996. return Fog;
  15997. }();
  15998. var Scene = /*#__PURE__*/function (_Object3D) {
  15999. _inheritsLoose(Scene, _Object3D);
  16000. function Scene() {
  16001. var _this;
  16002. _this = _Object3D.call(this) || this;
  16003. Object.defineProperty(_assertThisInitialized(_this), 'isScene', {
  16004. value: true
  16005. });
  16006. _this.type = 'Scene';
  16007. _this.background = null;
  16008. _this.environment = null;
  16009. _this.fog = null;
  16010. _this.overrideMaterial = null;
  16011. _this.autoUpdate = true; // checked by the renderer
  16012. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  16013. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  16014. detail: _assertThisInitialized(_this)
  16015. })); // eslint-disable-line no-undef
  16016. }
  16017. return _this;
  16018. }
  16019. var _proto = Scene.prototype;
  16020. _proto.copy = function copy(source, recursive) {
  16021. _Object3D.prototype.copy.call(this, source, recursive);
  16022. if (source.background !== null) this.background = source.background.clone();
  16023. if (source.environment !== null) this.environment = source.environment.clone();
  16024. if (source.fog !== null) this.fog = source.fog.clone();
  16025. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  16026. this.autoUpdate = source.autoUpdate;
  16027. this.matrixAutoUpdate = source.matrixAutoUpdate;
  16028. return this;
  16029. };
  16030. _proto.toJSON = function toJSON(meta) {
  16031. var data = _Object3D.prototype.toJSON.call(this, meta);
  16032. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  16033. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  16034. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  16035. return data;
  16036. };
  16037. return Scene;
  16038. }(Object3D);
  16039. function InterleavedBuffer(array, stride) {
  16040. this.array = array;
  16041. this.stride = stride;
  16042. this.count = array !== undefined ? array.length / stride : 0;
  16043. this.usage = StaticDrawUsage;
  16044. this.updateRange = {
  16045. offset: 0,
  16046. count: -1
  16047. };
  16048. this.version = 0;
  16049. this.uuid = MathUtils.generateUUID();
  16050. }
  16051. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  16052. set: function set(value) {
  16053. if (value === true) this.version++;
  16054. }
  16055. });
  16056. Object.assign(InterleavedBuffer.prototype, {
  16057. isInterleavedBuffer: true,
  16058. onUploadCallback: function onUploadCallback() {},
  16059. setUsage: function setUsage(value) {
  16060. this.usage = value;
  16061. return this;
  16062. },
  16063. copy: function copy(source) {
  16064. this.array = new source.array.constructor(source.array);
  16065. this.count = source.count;
  16066. this.stride = source.stride;
  16067. this.usage = source.usage;
  16068. return this;
  16069. },
  16070. copyAt: function copyAt(index1, attribute, index2) {
  16071. index1 *= this.stride;
  16072. index2 *= attribute.stride;
  16073. for (var i = 0, l = this.stride; i < l; i++) {
  16074. this.array[index1 + i] = attribute.array[index2 + i];
  16075. }
  16076. return this;
  16077. },
  16078. set: function set(value, offset) {
  16079. if (offset === void 0) {
  16080. offset = 0;
  16081. }
  16082. this.array.set(value, offset);
  16083. return this;
  16084. },
  16085. clone: function clone(data) {
  16086. if (data.arrayBuffers === undefined) {
  16087. data.arrayBuffers = {};
  16088. }
  16089. if (this.array.buffer._uuid === undefined) {
  16090. this.array.buffer._uuid = MathUtils.generateUUID();
  16091. }
  16092. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  16093. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  16094. }
  16095. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  16096. var ib = new InterleavedBuffer(array, this.stride);
  16097. ib.setUsage(this.usage);
  16098. return ib;
  16099. },
  16100. onUpload: function onUpload(callback) {
  16101. this.onUploadCallback = callback;
  16102. return this;
  16103. },
  16104. toJSON: function toJSON(data) {
  16105. if (data.arrayBuffers === undefined) {
  16106. data.arrayBuffers = {};
  16107. } // generate UUID for array buffer if necessary
  16108. if (this.array.buffer._uuid === undefined) {
  16109. this.array.buffer._uuid = MathUtils.generateUUID();
  16110. }
  16111. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  16112. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  16113. } //
  16114. return {
  16115. uuid: this.uuid,
  16116. buffer: this.array.buffer._uuid,
  16117. type: this.array.constructor.name,
  16118. stride: this.stride
  16119. };
  16120. }
  16121. });
  16122. var _vector$6 = new Vector3();
  16123. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  16124. this.name = '';
  16125. this.data = interleavedBuffer;
  16126. this.itemSize = itemSize;
  16127. this.offset = offset;
  16128. this.normalized = normalized === true;
  16129. }
  16130. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  16131. count: {
  16132. get: function get() {
  16133. return this.data.count;
  16134. }
  16135. },
  16136. array: {
  16137. get: function get() {
  16138. return this.data.array;
  16139. }
  16140. },
  16141. needsUpdate: {
  16142. set: function set(value) {
  16143. this.data.needsUpdate = value;
  16144. }
  16145. }
  16146. });
  16147. Object.assign(InterleavedBufferAttribute.prototype, {
  16148. isInterleavedBufferAttribute: true,
  16149. applyMatrix4: function applyMatrix4(m) {
  16150. for (var i = 0, l = this.data.count; i < l; i++) {
  16151. _vector$6.x = this.getX(i);
  16152. _vector$6.y = this.getY(i);
  16153. _vector$6.z = this.getZ(i);
  16154. _vector$6.applyMatrix4(m);
  16155. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  16156. }
  16157. return this;
  16158. },
  16159. setX: function setX(index, x) {
  16160. this.data.array[index * this.data.stride + this.offset] = x;
  16161. return this;
  16162. },
  16163. setY: function setY(index, y) {
  16164. this.data.array[index * this.data.stride + this.offset + 1] = y;
  16165. return this;
  16166. },
  16167. setZ: function setZ(index, z) {
  16168. this.data.array[index * this.data.stride + this.offset + 2] = z;
  16169. return this;
  16170. },
  16171. setW: function setW(index, w) {
  16172. this.data.array[index * this.data.stride + this.offset + 3] = w;
  16173. return this;
  16174. },
  16175. getX: function getX(index) {
  16176. return this.data.array[index * this.data.stride + this.offset];
  16177. },
  16178. getY: function getY(index) {
  16179. return this.data.array[index * this.data.stride + this.offset + 1];
  16180. },
  16181. getZ: function getZ(index) {
  16182. return this.data.array[index * this.data.stride + this.offset + 2];
  16183. },
  16184. getW: function getW(index) {
  16185. return this.data.array[index * this.data.stride + this.offset + 3];
  16186. },
  16187. setXY: function setXY(index, x, y) {
  16188. index = index * this.data.stride + this.offset;
  16189. this.data.array[index + 0] = x;
  16190. this.data.array[index + 1] = y;
  16191. return this;
  16192. },
  16193. setXYZ: function setXYZ(index, x, y, z) {
  16194. index = index * this.data.stride + this.offset;
  16195. this.data.array[index + 0] = x;
  16196. this.data.array[index + 1] = y;
  16197. this.data.array[index + 2] = z;
  16198. return this;
  16199. },
  16200. setXYZW: function setXYZW(index, x, y, z, w) {
  16201. index = index * this.data.stride + this.offset;
  16202. this.data.array[index + 0] = x;
  16203. this.data.array[index + 1] = y;
  16204. this.data.array[index + 2] = z;
  16205. this.data.array[index + 3] = w;
  16206. return this;
  16207. },
  16208. clone: function clone(data) {
  16209. if (data === undefined) {
  16210. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  16211. var array = [];
  16212. for (var i = 0; i < this.count; i++) {
  16213. var index = i * this.data.stride + this.offset;
  16214. for (var j = 0; j < this.itemSize; j++) {
  16215. array.push(this.data.array[index + j]);
  16216. }
  16217. }
  16218. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  16219. } else {
  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.clone(data);
  16225. }
  16226. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  16227. }
  16228. },
  16229. toJSON: function toJSON(data) {
  16230. if (data === undefined) {
  16231. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  16232. var array = [];
  16233. for (var i = 0; i < this.count; i++) {
  16234. var index = i * this.data.stride + this.offset;
  16235. for (var j = 0; j < this.itemSize; j++) {
  16236. array.push(this.data.array[index + j]);
  16237. }
  16238. } // deinterleave data and save it as an ordinary buffer attribute for now
  16239. return {
  16240. itemSize: this.itemSize,
  16241. type: this.array.constructor.name,
  16242. array: array,
  16243. normalized: this.normalized
  16244. };
  16245. } else {
  16246. // save as true interlaved attribtue
  16247. if (data.interleavedBuffers === undefined) {
  16248. data.interleavedBuffers = {};
  16249. }
  16250. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  16251. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  16252. }
  16253. return {
  16254. isInterleavedBufferAttribute: true,
  16255. itemSize: this.itemSize,
  16256. data: this.data.uuid,
  16257. offset: this.offset,
  16258. normalized: this.normalized
  16259. };
  16260. }
  16261. }
  16262. });
  16263. /**
  16264. * parameters = {
  16265. * color: <hex>,
  16266. * map: new THREE.Texture( <Image> ),
  16267. * alphaMap: new THREE.Texture( <Image> ),
  16268. * rotation: <float>,
  16269. * sizeAttenuation: <bool>
  16270. * }
  16271. */
  16272. function SpriteMaterial(parameters) {
  16273. Material.call(this);
  16274. this.type = 'SpriteMaterial';
  16275. this.color = new Color(0xffffff);
  16276. this.map = null;
  16277. this.alphaMap = null;
  16278. this.rotation = 0;
  16279. this.sizeAttenuation = true;
  16280. this.transparent = true;
  16281. this.setValues(parameters);
  16282. }
  16283. SpriteMaterial.prototype = Object.create(Material.prototype);
  16284. SpriteMaterial.prototype.constructor = SpriteMaterial;
  16285. SpriteMaterial.prototype.isSpriteMaterial = true;
  16286. SpriteMaterial.prototype.copy = function (source) {
  16287. Material.prototype.copy.call(this, source);
  16288. this.color.copy(source.color);
  16289. this.map = source.map;
  16290. this.alphaMap = source.alphaMap;
  16291. this.rotation = source.rotation;
  16292. this.sizeAttenuation = source.sizeAttenuation;
  16293. return this;
  16294. };
  16295. var _geometry;
  16296. var _intersectPoint = new Vector3();
  16297. var _worldScale = new Vector3();
  16298. var _mvPosition = new Vector3();
  16299. var _alignedPosition = new Vector2();
  16300. var _rotatedPosition = new Vector2();
  16301. var _viewWorldMatrix = new Matrix4();
  16302. var _vA$1 = new Vector3();
  16303. var _vB$1 = new Vector3();
  16304. var _vC$1 = new Vector3();
  16305. var _uvA$1 = new Vector2();
  16306. var _uvB$1 = new Vector2();
  16307. var _uvC$1 = new Vector2();
  16308. function Sprite(material) {
  16309. Object3D.call(this);
  16310. this.type = 'Sprite';
  16311. if (_geometry === undefined) {
  16312. _geometry = new BufferGeometry();
  16313. 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]);
  16314. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  16315. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  16316. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  16317. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  16318. }
  16319. this.geometry = _geometry;
  16320. this.material = material !== undefined ? material : new SpriteMaterial();
  16321. this.center = new Vector2(0.5, 0.5);
  16322. }
  16323. Sprite.prototype = Object.assign(Object.create(Object3D.prototype), {
  16324. constructor: Sprite,
  16325. isSprite: true,
  16326. raycast: function raycast(raycaster, intersects) {
  16327. if (raycaster.camera === null) {
  16328. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  16329. }
  16330. _worldScale.setFromMatrixScale(this.matrixWorld);
  16331. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  16332. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  16333. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  16334. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  16335. _worldScale.multiplyScalar(-_mvPosition.z);
  16336. }
  16337. var rotation = this.material.rotation;
  16338. var sin, cos;
  16339. if (rotation !== 0) {
  16340. cos = Math.cos(rotation);
  16341. sin = Math.sin(rotation);
  16342. }
  16343. var center = this.center;
  16344. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16345. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16346. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16347. _uvA$1.set(0, 0);
  16348. _uvB$1.set(1, 0);
  16349. _uvC$1.set(1, 1); // check first triangle
  16350. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  16351. if (intersect === null) {
  16352. // check second triangle
  16353. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16354. _uvB$1.set(0, 1);
  16355. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  16356. if (intersect === null) {
  16357. return;
  16358. }
  16359. }
  16360. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  16361. if (distance < raycaster.near || distance > raycaster.far) return;
  16362. intersects.push({
  16363. distance: distance,
  16364. point: _intersectPoint.clone(),
  16365. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  16366. face: null,
  16367. object: this
  16368. });
  16369. },
  16370. copy: function copy(source) {
  16371. Object3D.prototype.copy.call(this, source);
  16372. if (source.center !== undefined) this.center.copy(source.center);
  16373. this.material = source.material;
  16374. return this;
  16375. }
  16376. });
  16377. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  16378. // compute position in camera space
  16379. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  16380. if (sin !== undefined) {
  16381. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  16382. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  16383. } else {
  16384. _rotatedPosition.copy(_alignedPosition);
  16385. }
  16386. vertexPosition.copy(mvPosition);
  16387. vertexPosition.x += _rotatedPosition.x;
  16388. vertexPosition.y += _rotatedPosition.y; // transform to world space
  16389. vertexPosition.applyMatrix4(_viewWorldMatrix);
  16390. }
  16391. var _v1$4 = new Vector3();
  16392. var _v2$2 = new Vector3();
  16393. function LOD() {
  16394. Object3D.call(this);
  16395. this._currentLevel = 0;
  16396. this.type = 'LOD';
  16397. Object.defineProperties(this, {
  16398. levels: {
  16399. enumerable: true,
  16400. value: []
  16401. }
  16402. });
  16403. this.autoUpdate = true;
  16404. }
  16405. LOD.prototype = Object.assign(Object.create(Object3D.prototype), {
  16406. constructor: LOD,
  16407. isLOD: true,
  16408. copy: function copy(source) {
  16409. Object3D.prototype.copy.call(this, source, false);
  16410. var levels = source.levels;
  16411. for (var i = 0, l = levels.length; i < l; i++) {
  16412. var level = levels[i];
  16413. this.addLevel(level.object.clone(), level.distance);
  16414. }
  16415. this.autoUpdate = source.autoUpdate;
  16416. return this;
  16417. },
  16418. addLevel: function addLevel(object, distance) {
  16419. if (distance === void 0) {
  16420. distance = 0;
  16421. }
  16422. distance = Math.abs(distance);
  16423. var levels = this.levels;
  16424. var l;
  16425. for (l = 0; l < levels.length; l++) {
  16426. if (distance < levels[l].distance) {
  16427. break;
  16428. }
  16429. }
  16430. levels.splice(l, 0, {
  16431. distance: distance,
  16432. object: object
  16433. });
  16434. this.add(object);
  16435. return this;
  16436. },
  16437. getCurrentLevel: function getCurrentLevel() {
  16438. return this._currentLevel;
  16439. },
  16440. getObjectForDistance: function getObjectForDistance(distance) {
  16441. var levels = this.levels;
  16442. if (levels.length > 0) {
  16443. var i, l;
  16444. for (i = 1, l = levels.length; i < l; i++) {
  16445. if (distance < levels[i].distance) {
  16446. break;
  16447. }
  16448. }
  16449. return levels[i - 1].object;
  16450. }
  16451. return null;
  16452. },
  16453. raycast: function raycast(raycaster, intersects) {
  16454. var levels = this.levels;
  16455. if (levels.length > 0) {
  16456. _v1$4.setFromMatrixPosition(this.matrixWorld);
  16457. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  16458. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  16459. }
  16460. },
  16461. update: function update(camera) {
  16462. var levels = this.levels;
  16463. if (levels.length > 1) {
  16464. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  16465. _v2$2.setFromMatrixPosition(this.matrixWorld);
  16466. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  16467. levels[0].object.visible = true;
  16468. var i, l;
  16469. for (i = 1, l = levels.length; i < l; i++) {
  16470. if (distance >= levels[i].distance) {
  16471. levels[i - 1].object.visible = false;
  16472. levels[i].object.visible = true;
  16473. } else {
  16474. break;
  16475. }
  16476. }
  16477. this._currentLevel = i - 1;
  16478. for (; i < l; i++) {
  16479. levels[i].object.visible = false;
  16480. }
  16481. }
  16482. },
  16483. toJSON: function toJSON(meta) {
  16484. var data = Object3D.prototype.toJSON.call(this, meta);
  16485. if (this.autoUpdate === false) data.object.autoUpdate = false;
  16486. data.object.levels = [];
  16487. var levels = this.levels;
  16488. for (var i = 0, l = levels.length; i < l; i++) {
  16489. var level = levels[i];
  16490. data.object.levels.push({
  16491. object: level.object.uuid,
  16492. distance: level.distance
  16493. });
  16494. }
  16495. return data;
  16496. }
  16497. });
  16498. var _basePosition = new Vector3();
  16499. var _skinIndex = new Vector4();
  16500. var _skinWeight = new Vector4();
  16501. var _vector$7 = new Vector3();
  16502. var _matrix$1 = new Matrix4();
  16503. function SkinnedMesh(geometry, material) {
  16504. Mesh.call(this, geometry, material);
  16505. this.type = 'SkinnedMesh';
  16506. this.bindMode = 'attached';
  16507. this.bindMatrix = new Matrix4();
  16508. this.bindMatrixInverse = new Matrix4();
  16509. }
  16510. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16511. constructor: SkinnedMesh,
  16512. isSkinnedMesh: true,
  16513. copy: function copy(source) {
  16514. Mesh.prototype.copy.call(this, source);
  16515. this.bindMode = source.bindMode;
  16516. this.bindMatrix.copy(source.bindMatrix);
  16517. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  16518. this.skeleton = source.skeleton;
  16519. return this;
  16520. },
  16521. bind: function bind(skeleton, bindMatrix) {
  16522. this.skeleton = skeleton;
  16523. if (bindMatrix === undefined) {
  16524. this.updateMatrixWorld(true);
  16525. this.skeleton.calculateInverses();
  16526. bindMatrix = this.matrixWorld;
  16527. }
  16528. this.bindMatrix.copy(bindMatrix);
  16529. this.bindMatrixInverse.copy(bindMatrix).invert();
  16530. },
  16531. pose: function pose() {
  16532. this.skeleton.pose();
  16533. },
  16534. normalizeSkinWeights: function normalizeSkinWeights() {
  16535. var vector = new Vector4();
  16536. var skinWeight = this.geometry.attributes.skinWeight;
  16537. for (var i = 0, l = skinWeight.count; i < l; i++) {
  16538. vector.x = skinWeight.getX(i);
  16539. vector.y = skinWeight.getY(i);
  16540. vector.z = skinWeight.getZ(i);
  16541. vector.w = skinWeight.getW(i);
  16542. var scale = 1.0 / vector.manhattanLength();
  16543. if (scale !== Infinity) {
  16544. vector.multiplyScalar(scale);
  16545. } else {
  16546. vector.set(1, 0, 0, 0); // do something reasonable
  16547. }
  16548. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  16549. }
  16550. },
  16551. updateMatrixWorld: function updateMatrixWorld(force) {
  16552. Mesh.prototype.updateMatrixWorld.call(this, force);
  16553. if (this.bindMode === 'attached') {
  16554. this.bindMatrixInverse.copy(this.matrixWorld).invert();
  16555. } else if (this.bindMode === 'detached') {
  16556. this.bindMatrixInverse.copy(this.bindMatrix).invert();
  16557. } else {
  16558. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  16559. }
  16560. },
  16561. boneTransform: function boneTransform(index, target) {
  16562. var skeleton = this.skeleton;
  16563. var geometry = this.geometry;
  16564. _skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  16565. _skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  16566. _basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  16567. target.set(0, 0, 0);
  16568. for (var i = 0; i < 4; i++) {
  16569. var weight = _skinWeight.getComponent(i);
  16570. if (weight !== 0) {
  16571. var boneIndex = _skinIndex.getComponent(i);
  16572. _matrix$1.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  16573. target.addScaledVector(_vector$7.copy(_basePosition).applyMatrix4(_matrix$1), weight);
  16574. }
  16575. }
  16576. return target.applyMatrix4(this.bindMatrixInverse);
  16577. }
  16578. });
  16579. function Bone() {
  16580. Object3D.call(this);
  16581. this.type = 'Bone';
  16582. }
  16583. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  16584. constructor: Bone,
  16585. isBone: true
  16586. });
  16587. var _offsetMatrix = new Matrix4();
  16588. var _identityMatrix = new Matrix4();
  16589. function Skeleton(bones, boneInverses) {
  16590. if (bones === void 0) {
  16591. bones = [];
  16592. }
  16593. if (boneInverses === void 0) {
  16594. boneInverses = [];
  16595. }
  16596. this.uuid = MathUtils.generateUUID();
  16597. this.bones = bones.slice(0);
  16598. this.boneInverses = boneInverses;
  16599. this.boneMatrices = null;
  16600. this.boneTexture = null;
  16601. this.boneTextureSize = 0;
  16602. this.frame = -1;
  16603. this.init();
  16604. }
  16605. Object.assign(Skeleton.prototype, {
  16606. init: function init() {
  16607. var bones = this.bones;
  16608. var boneInverses = this.boneInverses;
  16609. this.boneMatrices = new Float32Array(bones.length * 16); // calculate inverse bone matrices if necessary
  16610. if (boneInverses.length === 0) {
  16611. this.calculateInverses();
  16612. } else {
  16613. // handle special case
  16614. if (bones.length !== boneInverses.length) {
  16615. console.warn('THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.');
  16616. this.boneInverses = [];
  16617. for (var i = 0, il = this.bones.length; i < il; i++) {
  16618. this.boneInverses.push(new Matrix4());
  16619. }
  16620. }
  16621. }
  16622. },
  16623. calculateInverses: function calculateInverses() {
  16624. this.boneInverses.length = 0;
  16625. for (var i = 0, il = this.bones.length; i < il; i++) {
  16626. var inverse = new Matrix4();
  16627. if (this.bones[i]) {
  16628. inverse.copy(this.bones[i].matrixWorld).invert();
  16629. }
  16630. this.boneInverses.push(inverse);
  16631. }
  16632. },
  16633. pose: function pose() {
  16634. // recover the bind-time world matrices
  16635. for (var i = 0, il = this.bones.length; i < il; i++) {
  16636. var bone = this.bones[i];
  16637. if (bone) {
  16638. bone.matrixWorld.copy(this.boneInverses[i]).invert();
  16639. }
  16640. } // compute the local matrices, positions, rotations and scales
  16641. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  16642. var _bone = this.bones[_i];
  16643. if (_bone) {
  16644. if (_bone.parent && _bone.parent.isBone) {
  16645. _bone.matrix.copy(_bone.parent.matrixWorld).invert();
  16646. _bone.matrix.multiply(_bone.matrixWorld);
  16647. } else {
  16648. _bone.matrix.copy(_bone.matrixWorld);
  16649. }
  16650. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  16651. }
  16652. }
  16653. },
  16654. update: function update() {
  16655. var bones = this.bones;
  16656. var boneInverses = this.boneInverses;
  16657. var boneMatrices = this.boneMatrices;
  16658. var boneTexture = this.boneTexture; // flatten bone matrices to array
  16659. for (var i = 0, il = bones.length; i < il; i++) {
  16660. // compute the offset between the current and the original transform
  16661. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  16662. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  16663. _offsetMatrix.toArray(boneMatrices, i * 16);
  16664. }
  16665. if (boneTexture !== null) {
  16666. boneTexture.needsUpdate = true;
  16667. }
  16668. },
  16669. clone: function clone() {
  16670. return new Skeleton(this.bones, this.boneInverses);
  16671. },
  16672. getBoneByName: function getBoneByName(name) {
  16673. for (var i = 0, il = this.bones.length; i < il; i++) {
  16674. var bone = this.bones[i];
  16675. if (bone.name === name) {
  16676. return bone;
  16677. }
  16678. }
  16679. return undefined;
  16680. },
  16681. dispose: function dispose() {
  16682. if (this.boneTexture !== null) {
  16683. this.boneTexture.dispose();
  16684. this.boneTexture = null;
  16685. }
  16686. },
  16687. fromJSON: function fromJSON(json, bones) {
  16688. this.uuid = json.uuid;
  16689. for (var i = 0, l = json.bones.length; i < l; i++) {
  16690. var uuid = json.bones[i];
  16691. var bone = bones[uuid];
  16692. if (bone === undefined) {
  16693. console.warn('THREE.Skeleton: No bone found with UUID:', uuid);
  16694. bone = new Bone();
  16695. }
  16696. this.bones.push(bone);
  16697. this.boneInverses.push(new Matrix4().fromArray(json.boneInverses[i]));
  16698. }
  16699. this.init();
  16700. return this;
  16701. },
  16702. toJSON: function toJSON() {
  16703. var data = {
  16704. metadata: {
  16705. version: 4.5,
  16706. type: 'Skeleton',
  16707. generator: 'Skeleton.toJSON'
  16708. },
  16709. bones: [],
  16710. boneInverses: []
  16711. };
  16712. data.uuid = this.uuid;
  16713. var bones = this.bones;
  16714. var boneInverses = this.boneInverses;
  16715. for (var i = 0, l = bones.length; i < l; i++) {
  16716. var bone = bones[i];
  16717. data.bones.push(bone.uuid);
  16718. var boneInverse = boneInverses[i];
  16719. data.boneInverses.push(boneInverse.toArray());
  16720. }
  16721. return data;
  16722. }
  16723. });
  16724. var _instanceLocalMatrix = new Matrix4();
  16725. var _instanceWorldMatrix = new Matrix4();
  16726. var _instanceIntersects = [];
  16727. var _mesh = new Mesh();
  16728. function InstancedMesh(geometry, material, count) {
  16729. Mesh.call(this, geometry, material);
  16730. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  16731. this.instanceColor = null;
  16732. this.count = count;
  16733. this.frustumCulled = false;
  16734. }
  16735. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16736. constructor: InstancedMesh,
  16737. isInstancedMesh: true,
  16738. copy: function copy(source) {
  16739. Mesh.prototype.copy.call(this, source);
  16740. this.instanceMatrix.copy(source.instanceMatrix);
  16741. if (source.instanceColor !== null) this.instanceColor = source.instanceColor.clone();
  16742. this.count = source.count;
  16743. return this;
  16744. },
  16745. getColorAt: function getColorAt(index, color) {
  16746. color.fromArray(this.instanceColor.array, index * 3);
  16747. },
  16748. getMatrixAt: function getMatrixAt(index, matrix) {
  16749. matrix.fromArray(this.instanceMatrix.array, index * 16);
  16750. },
  16751. raycast: function raycast(raycaster, intersects) {
  16752. var matrixWorld = this.matrixWorld;
  16753. var raycastTimes = this.count;
  16754. _mesh.geometry = this.geometry;
  16755. _mesh.material = this.material;
  16756. if (_mesh.material === undefined) return;
  16757. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  16758. // calculate the world matrix for each instance
  16759. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  16760. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  16761. _mesh.matrixWorld = _instanceWorldMatrix;
  16762. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  16763. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  16764. var intersect = _instanceIntersects[i];
  16765. intersect.instanceId = instanceId;
  16766. intersect.object = this;
  16767. intersects.push(intersect);
  16768. }
  16769. _instanceIntersects.length = 0;
  16770. }
  16771. },
  16772. setColorAt: function setColorAt(index, color) {
  16773. if (this.instanceColor === null) {
  16774. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  16775. }
  16776. color.toArray(this.instanceColor.array, index * 3);
  16777. },
  16778. setMatrixAt: function setMatrixAt(index, matrix) {
  16779. matrix.toArray(this.instanceMatrix.array, index * 16);
  16780. },
  16781. updateMorphTargets: function updateMorphTargets() {},
  16782. dispose: function dispose() {
  16783. this.dispatchEvent({
  16784. type: 'dispose'
  16785. });
  16786. }
  16787. });
  16788. /**
  16789. * parameters = {
  16790. * color: <hex>,
  16791. * opacity: <float>,
  16792. *
  16793. * linewidth: <float>,
  16794. * linecap: "round",
  16795. * linejoin: "round"
  16796. * }
  16797. */
  16798. function LineBasicMaterial(parameters) {
  16799. Material.call(this);
  16800. this.type = 'LineBasicMaterial';
  16801. this.color = new Color(0xffffff);
  16802. this.linewidth = 1;
  16803. this.linecap = 'round';
  16804. this.linejoin = 'round';
  16805. this.morphTargets = false;
  16806. this.setValues(parameters);
  16807. }
  16808. LineBasicMaterial.prototype = Object.create(Material.prototype);
  16809. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  16810. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16811. LineBasicMaterial.prototype.copy = function (source) {
  16812. Material.prototype.copy.call(this, source);
  16813. this.color.copy(source.color);
  16814. this.linewidth = source.linewidth;
  16815. this.linecap = source.linecap;
  16816. this.linejoin = source.linejoin;
  16817. this.morphTargets = source.morphTargets;
  16818. return this;
  16819. };
  16820. var _start = new Vector3();
  16821. var _end = new Vector3();
  16822. var _inverseMatrix$1 = new Matrix4();
  16823. var _ray$1 = new Ray();
  16824. var _sphere$2 = new Sphere();
  16825. function Line(geometry, material) {
  16826. if (geometry === void 0) {
  16827. geometry = new BufferGeometry();
  16828. }
  16829. if (material === void 0) {
  16830. material = new LineBasicMaterial();
  16831. }
  16832. Object3D.call(this);
  16833. this.type = 'Line';
  16834. this.geometry = geometry;
  16835. this.material = material;
  16836. this.updateMorphTargets();
  16837. }
  16838. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  16839. constructor: Line,
  16840. isLine: true,
  16841. copy: function copy(source) {
  16842. Object3D.prototype.copy.call(this, source);
  16843. this.material = source.material;
  16844. this.geometry = source.geometry;
  16845. return this;
  16846. },
  16847. computeLineDistances: function computeLineDistances() {
  16848. var geometry = this.geometry;
  16849. if (geometry.isBufferGeometry) {
  16850. // we assume non-indexed geometry
  16851. if (geometry.index === null) {
  16852. var positionAttribute = geometry.attributes.position;
  16853. var lineDistances = [0];
  16854. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  16855. _start.fromBufferAttribute(positionAttribute, i - 1);
  16856. _end.fromBufferAttribute(positionAttribute, i);
  16857. lineDistances[i] = lineDistances[i - 1];
  16858. lineDistances[i] += _start.distanceTo(_end);
  16859. }
  16860. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16861. } else {
  16862. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16863. }
  16864. } else if (geometry.isGeometry) {
  16865. console.error('THREE.Line.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16866. }
  16867. return this;
  16868. },
  16869. raycast: function raycast(raycaster, intersects) {
  16870. var geometry = this.geometry;
  16871. var matrixWorld = this.matrixWorld;
  16872. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  16873. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16874. _sphere$2.copy(geometry.boundingSphere);
  16875. _sphere$2.applyMatrix4(matrixWorld);
  16876. _sphere$2.radius += threshold;
  16877. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  16878. _inverseMatrix$1.copy(matrixWorld).invert();
  16879. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  16880. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16881. var localThresholdSq = localThreshold * localThreshold;
  16882. var vStart = new Vector3();
  16883. var vEnd = new Vector3();
  16884. var interSegment = new Vector3();
  16885. var interRay = new Vector3();
  16886. var step = this.isLineSegments ? 2 : 1;
  16887. if (geometry.isBufferGeometry) {
  16888. var index = geometry.index;
  16889. var attributes = geometry.attributes;
  16890. var positionAttribute = attributes.position;
  16891. if (index !== null) {
  16892. var indices = index.array;
  16893. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  16894. var a = indices[i];
  16895. var b = indices[i + 1];
  16896. vStart.fromBufferAttribute(positionAttribute, a);
  16897. vEnd.fromBufferAttribute(positionAttribute, b);
  16898. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16899. if (distSq > localThresholdSq) continue;
  16900. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16901. var distance = raycaster.ray.origin.distanceTo(interRay);
  16902. if (distance < raycaster.near || distance > raycaster.far) continue;
  16903. intersects.push({
  16904. distance: distance,
  16905. // What do we want? intersection point on the ray or on the segment??
  16906. // point: raycaster.ray.at( distance ),
  16907. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16908. index: i,
  16909. face: null,
  16910. faceIndex: null,
  16911. object: this
  16912. });
  16913. }
  16914. } else {
  16915. for (var _i = 0, _l = positionAttribute.count - 1; _i < _l; _i += step) {
  16916. vStart.fromBufferAttribute(positionAttribute, _i);
  16917. vEnd.fromBufferAttribute(positionAttribute, _i + 1);
  16918. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16919. if (_distSq > localThresholdSq) continue;
  16920. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16921. var _distance = raycaster.ray.origin.distanceTo(interRay);
  16922. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  16923. intersects.push({
  16924. distance: _distance,
  16925. // What do we want? intersection point on the ray or on the segment??
  16926. // point: raycaster.ray.at( distance ),
  16927. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16928. index: _i,
  16929. face: null,
  16930. faceIndex: null,
  16931. object: this
  16932. });
  16933. }
  16934. }
  16935. } else if (geometry.isGeometry) {
  16936. console.error('THREE.Line.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16937. }
  16938. },
  16939. updateMorphTargets: function updateMorphTargets() {
  16940. var geometry = this.geometry;
  16941. if (geometry.isBufferGeometry) {
  16942. var morphAttributes = geometry.morphAttributes;
  16943. var keys = Object.keys(morphAttributes);
  16944. if (keys.length > 0) {
  16945. var morphAttribute = morphAttributes[keys[0]];
  16946. if (morphAttribute !== undefined) {
  16947. this.morphTargetInfluences = [];
  16948. this.morphTargetDictionary = {};
  16949. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16950. var name = morphAttribute[m].name || String(m);
  16951. this.morphTargetInfluences.push(0);
  16952. this.morphTargetDictionary[name] = m;
  16953. }
  16954. }
  16955. }
  16956. } else {
  16957. var morphTargets = geometry.morphTargets;
  16958. if (morphTargets !== undefined && morphTargets.length > 0) {
  16959. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16960. }
  16961. }
  16962. }
  16963. });
  16964. var _start$1 = new Vector3();
  16965. var _end$1 = new Vector3();
  16966. function LineSegments(geometry, material) {
  16967. Line.call(this, geometry, material);
  16968. this.type = 'LineSegments';
  16969. }
  16970. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  16971. constructor: LineSegments,
  16972. isLineSegments: true,
  16973. computeLineDistances: function computeLineDistances() {
  16974. var geometry = this.geometry;
  16975. if (geometry.isBufferGeometry) {
  16976. // we assume non-indexed geometry
  16977. if (geometry.index === null) {
  16978. var positionAttribute = geometry.attributes.position;
  16979. var lineDistances = [];
  16980. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  16981. _start$1.fromBufferAttribute(positionAttribute, i);
  16982. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  16983. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  16984. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  16985. }
  16986. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16987. } else {
  16988. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16989. }
  16990. } else if (geometry.isGeometry) {
  16991. console.error('THREE.LineSegments.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16992. }
  16993. return this;
  16994. }
  16995. });
  16996. function LineLoop(geometry, material) {
  16997. Line.call(this, geometry, material);
  16998. this.type = 'LineLoop';
  16999. }
  17000. LineLoop.prototype = Object.assign(Object.create(Line.prototype), {
  17001. constructor: LineLoop,
  17002. isLineLoop: true
  17003. });
  17004. /**
  17005. * parameters = {
  17006. * color: <hex>,
  17007. * opacity: <float>,
  17008. * map: new THREE.Texture( <Image> ),
  17009. * alphaMap: new THREE.Texture( <Image> ),
  17010. *
  17011. * size: <float>,
  17012. * sizeAttenuation: <bool>
  17013. *
  17014. * morphTargets: <bool>
  17015. * }
  17016. */
  17017. function PointsMaterial(parameters) {
  17018. Material.call(this);
  17019. this.type = 'PointsMaterial';
  17020. this.color = new Color(0xffffff);
  17021. this.map = null;
  17022. this.alphaMap = null;
  17023. this.size = 1;
  17024. this.sizeAttenuation = true;
  17025. this.morphTargets = false;
  17026. this.setValues(parameters);
  17027. }
  17028. PointsMaterial.prototype = Object.create(Material.prototype);
  17029. PointsMaterial.prototype.constructor = PointsMaterial;
  17030. PointsMaterial.prototype.isPointsMaterial = true;
  17031. PointsMaterial.prototype.copy = function (source) {
  17032. Material.prototype.copy.call(this, source);
  17033. this.color.copy(source.color);
  17034. this.map = source.map;
  17035. this.alphaMap = source.alphaMap;
  17036. this.size = source.size;
  17037. this.sizeAttenuation = source.sizeAttenuation;
  17038. this.morphTargets = source.morphTargets;
  17039. return this;
  17040. };
  17041. var _inverseMatrix$2 = new Matrix4();
  17042. var _ray$2 = new Ray();
  17043. var _sphere$3 = new Sphere();
  17044. var _position$1 = new Vector3();
  17045. function Points(geometry, material) {
  17046. if (geometry === void 0) {
  17047. geometry = new BufferGeometry();
  17048. }
  17049. if (material === void 0) {
  17050. material = new PointsMaterial();
  17051. }
  17052. Object3D.call(this);
  17053. this.type = 'Points';
  17054. this.geometry = geometry;
  17055. this.material = material;
  17056. this.updateMorphTargets();
  17057. }
  17058. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  17059. constructor: Points,
  17060. isPoints: true,
  17061. copy: function copy(source) {
  17062. Object3D.prototype.copy.call(this, source);
  17063. this.material = source.material;
  17064. this.geometry = source.geometry;
  17065. return this;
  17066. },
  17067. raycast: function raycast(raycaster, intersects) {
  17068. var geometry = this.geometry;
  17069. var matrixWorld = this.matrixWorld;
  17070. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  17071. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  17072. _sphere$3.copy(geometry.boundingSphere);
  17073. _sphere$3.applyMatrix4(matrixWorld);
  17074. _sphere$3.radius += threshold;
  17075. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  17076. _inverseMatrix$2.copy(matrixWorld).invert();
  17077. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  17078. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  17079. var localThresholdSq = localThreshold * localThreshold;
  17080. if (geometry.isBufferGeometry) {
  17081. var index = geometry.index;
  17082. var attributes = geometry.attributes;
  17083. var positionAttribute = attributes.position;
  17084. if (index !== null) {
  17085. var indices = index.array;
  17086. for (var i = 0, il = indices.length; i < il; i++) {
  17087. var a = indices[i];
  17088. _position$1.fromBufferAttribute(positionAttribute, a);
  17089. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  17090. }
  17091. } else {
  17092. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  17093. _position$1.fromBufferAttribute(positionAttribute, _i);
  17094. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  17095. }
  17096. }
  17097. } else {
  17098. console.error('THREE.Points.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17099. }
  17100. },
  17101. updateMorphTargets: function updateMorphTargets() {
  17102. var geometry = this.geometry;
  17103. if (geometry.isBufferGeometry) {
  17104. var morphAttributes = geometry.morphAttributes;
  17105. var keys = Object.keys(morphAttributes);
  17106. if (keys.length > 0) {
  17107. var morphAttribute = morphAttributes[keys[0]];
  17108. if (morphAttribute !== undefined) {
  17109. this.morphTargetInfluences = [];
  17110. this.morphTargetDictionary = {};
  17111. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  17112. var name = morphAttribute[m].name || String(m);
  17113. this.morphTargetInfluences.push(0);
  17114. this.morphTargetDictionary[name] = m;
  17115. }
  17116. }
  17117. }
  17118. } else {
  17119. var morphTargets = geometry.morphTargets;
  17120. if (morphTargets !== undefined && morphTargets.length > 0) {
  17121. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  17122. }
  17123. }
  17124. }
  17125. });
  17126. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  17127. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  17128. if (rayPointDistanceSq < localThresholdSq) {
  17129. var intersectPoint = new Vector3();
  17130. _ray$2.closestPointToPoint(point, intersectPoint);
  17131. intersectPoint.applyMatrix4(matrixWorld);
  17132. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  17133. if (distance < raycaster.near || distance > raycaster.far) return;
  17134. intersects.push({
  17135. distance: distance,
  17136. distanceToRay: Math.sqrt(rayPointDistanceSq),
  17137. point: intersectPoint,
  17138. index: index,
  17139. face: null,
  17140. object: object
  17141. });
  17142. }
  17143. }
  17144. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  17145. Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17146. this.format = format !== undefined ? format : RGBFormat;
  17147. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  17148. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  17149. this.generateMipmaps = false;
  17150. var scope = this;
  17151. function updateVideo() {
  17152. scope.needsUpdate = true;
  17153. video.requestVideoFrameCallback(updateVideo);
  17154. }
  17155. if ('requestVideoFrameCallback' in video) {
  17156. video.requestVideoFrameCallback(updateVideo);
  17157. }
  17158. }
  17159. VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
  17160. constructor: VideoTexture,
  17161. clone: function clone() {
  17162. return new this.constructor(this.image).copy(this);
  17163. },
  17164. isVideoTexture: true,
  17165. update: function update() {
  17166. var video = this.image;
  17167. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  17168. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  17169. this.needsUpdate = true;
  17170. }
  17171. }
  17172. });
  17173. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  17174. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  17175. this.image = {
  17176. width: width,
  17177. height: height
  17178. };
  17179. this.mipmaps = mipmaps; // no flipping for cube textures
  17180. // (also flipping doesn't work for compressed textures )
  17181. this.flipY = false; // can't generate mipmaps for compressed textures
  17182. // mips must be embedded in DDS files
  17183. this.generateMipmaps = false;
  17184. }
  17185. CompressedTexture.prototype = Object.create(Texture.prototype);
  17186. CompressedTexture.prototype.constructor = CompressedTexture;
  17187. CompressedTexture.prototype.isCompressedTexture = true;
  17188. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  17189. Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17190. this.needsUpdate = true;
  17191. }
  17192. CanvasTexture.prototype = Object.create(Texture.prototype);
  17193. CanvasTexture.prototype.constructor = CanvasTexture;
  17194. CanvasTexture.prototype.isCanvasTexture = true;
  17195. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  17196. format = format !== undefined ? format : DepthFormat;
  17197. if (format !== DepthFormat && format !== DepthStencilFormat) {
  17198. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  17199. }
  17200. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  17201. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  17202. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17203. this.image = {
  17204. width: width,
  17205. height: height
  17206. };
  17207. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  17208. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  17209. this.flipY = false;
  17210. this.generateMipmaps = false;
  17211. }
  17212. DepthTexture.prototype = Object.create(Texture.prototype);
  17213. DepthTexture.prototype.constructor = DepthTexture;
  17214. DepthTexture.prototype.isDepthTexture = true;
  17215. var CircleGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17216. _inheritsLoose(CircleGeometry, _BufferGeometry);
  17217. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  17218. var _this;
  17219. if (radius === void 0) {
  17220. radius = 1;
  17221. }
  17222. if (segments === void 0) {
  17223. segments = 8;
  17224. }
  17225. if (thetaStart === void 0) {
  17226. thetaStart = 0;
  17227. }
  17228. if (thetaLength === void 0) {
  17229. thetaLength = Math.PI * 2;
  17230. }
  17231. _this = _BufferGeometry.call(this) || this;
  17232. _this.type = 'CircleGeometry';
  17233. _this.parameters = {
  17234. radius: radius,
  17235. segments: segments,
  17236. thetaStart: thetaStart,
  17237. thetaLength: thetaLength
  17238. };
  17239. segments = Math.max(3, segments); // buffers
  17240. var indices = [];
  17241. var vertices = [];
  17242. var normals = [];
  17243. var uvs = []; // helper variables
  17244. var vertex = new Vector3();
  17245. var uv = new Vector2(); // center point
  17246. vertices.push(0, 0, 0);
  17247. normals.push(0, 0, 1);
  17248. uvs.push(0.5, 0.5);
  17249. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  17250. var segment = thetaStart + s / segments * thetaLength; // vertex
  17251. vertex.x = radius * Math.cos(segment);
  17252. vertex.y = radius * Math.sin(segment);
  17253. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17254. normals.push(0, 0, 1); // uvs
  17255. uv.x = (vertices[i] / radius + 1) / 2;
  17256. uv.y = (vertices[i + 1] / radius + 1) / 2;
  17257. uvs.push(uv.x, uv.y);
  17258. } // indices
  17259. for (var _i = 1; _i <= segments; _i++) {
  17260. indices.push(_i, _i + 1, 0);
  17261. } // build geometry
  17262. _this.setIndex(indices);
  17263. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17264. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17265. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17266. return _this;
  17267. }
  17268. return CircleGeometry;
  17269. }(BufferGeometry);
  17270. var CylinderGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17271. _inheritsLoose(CylinderGeometry, _BufferGeometry);
  17272. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17273. var _this;
  17274. if (radiusTop === void 0) {
  17275. radiusTop = 1;
  17276. }
  17277. if (radiusBottom === void 0) {
  17278. radiusBottom = 1;
  17279. }
  17280. if (height === void 0) {
  17281. height = 1;
  17282. }
  17283. if (radialSegments === void 0) {
  17284. radialSegments = 8;
  17285. }
  17286. if (heightSegments === void 0) {
  17287. heightSegments = 1;
  17288. }
  17289. if (openEnded === void 0) {
  17290. openEnded = false;
  17291. }
  17292. if (thetaStart === void 0) {
  17293. thetaStart = 0;
  17294. }
  17295. if (thetaLength === void 0) {
  17296. thetaLength = Math.PI * 2;
  17297. }
  17298. _this = _BufferGeometry.call(this) || this;
  17299. _this.type = 'CylinderGeometry';
  17300. _this.parameters = {
  17301. radiusTop: radiusTop,
  17302. radiusBottom: radiusBottom,
  17303. height: height,
  17304. radialSegments: radialSegments,
  17305. heightSegments: heightSegments,
  17306. openEnded: openEnded,
  17307. thetaStart: thetaStart,
  17308. thetaLength: thetaLength
  17309. };
  17310. var scope = _assertThisInitialized(_this);
  17311. radialSegments = Math.floor(radialSegments);
  17312. heightSegments = Math.floor(heightSegments); // buffers
  17313. var indices = [];
  17314. var vertices = [];
  17315. var normals = [];
  17316. var uvs = []; // helper variables
  17317. var index = 0;
  17318. var indexArray = [];
  17319. var halfHeight = height / 2;
  17320. var groupStart = 0; // generate geometry
  17321. generateTorso();
  17322. if (openEnded === false) {
  17323. if (radiusTop > 0) generateCap(true);
  17324. if (radiusBottom > 0) generateCap(false);
  17325. } // build geometry
  17326. _this.setIndex(indices);
  17327. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17328. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17329. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17330. function generateTorso() {
  17331. var normal = new Vector3();
  17332. var vertex = new Vector3();
  17333. var groupCount = 0; // this will be used to calculate the normal
  17334. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  17335. for (var y = 0; y <= heightSegments; y++) {
  17336. var indexRow = [];
  17337. var v = y / heightSegments; // calculate the radius of the current row
  17338. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  17339. for (var x = 0; x <= radialSegments; x++) {
  17340. var u = x / radialSegments;
  17341. var theta = u * thetaLength + thetaStart;
  17342. var sinTheta = Math.sin(theta);
  17343. var cosTheta = Math.cos(theta); // vertex
  17344. vertex.x = radius * sinTheta;
  17345. vertex.y = -v * height + halfHeight;
  17346. vertex.z = radius * cosTheta;
  17347. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17348. normal.set(sinTheta, slope, cosTheta).normalize();
  17349. normals.push(normal.x, normal.y, normal.z); // uv
  17350. uvs.push(u, 1 - v); // save index of vertex in respective row
  17351. indexRow.push(index++);
  17352. } // now save vertices of the row in our index array
  17353. indexArray.push(indexRow);
  17354. } // generate indices
  17355. for (var _x = 0; _x < radialSegments; _x++) {
  17356. for (var _y = 0; _y < heightSegments; _y++) {
  17357. // we use the index array to access the correct indices
  17358. var a = indexArray[_y][_x];
  17359. var b = indexArray[_y + 1][_x];
  17360. var c = indexArray[_y + 1][_x + 1];
  17361. var d = indexArray[_y][_x + 1]; // faces
  17362. indices.push(a, b, d);
  17363. indices.push(b, c, d); // update group counter
  17364. groupCount += 6;
  17365. }
  17366. } // add a group to the geometry. this will ensure multi material support
  17367. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  17368. groupStart += groupCount;
  17369. }
  17370. function generateCap(top) {
  17371. // save the index of the first center vertex
  17372. var centerIndexStart = index;
  17373. var uv = new Vector2();
  17374. var vertex = new Vector3();
  17375. var groupCount = 0;
  17376. var radius = top === true ? radiusTop : radiusBottom;
  17377. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  17378. // because the geometry needs one set of uvs per face,
  17379. // we must generate a center vertex per face/segment
  17380. for (var x = 1; x <= radialSegments; x++) {
  17381. // vertex
  17382. vertices.push(0, halfHeight * sign, 0); // normal
  17383. normals.push(0, sign, 0); // uv
  17384. uvs.push(0.5, 0.5); // increase index
  17385. index++;
  17386. } // save the index of the last center vertex
  17387. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  17388. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  17389. var u = _x2 / radialSegments;
  17390. var theta = u * thetaLength + thetaStart;
  17391. var cosTheta = Math.cos(theta);
  17392. var sinTheta = Math.sin(theta); // vertex
  17393. vertex.x = radius * sinTheta;
  17394. vertex.y = halfHeight * sign;
  17395. vertex.z = radius * cosTheta;
  17396. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17397. normals.push(0, sign, 0); // uv
  17398. uv.x = cosTheta * 0.5 + 0.5;
  17399. uv.y = sinTheta * 0.5 * sign + 0.5;
  17400. uvs.push(uv.x, uv.y); // increase index
  17401. index++;
  17402. } // generate indices
  17403. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  17404. var c = centerIndexStart + _x3;
  17405. var i = centerIndexEnd + _x3;
  17406. if (top === true) {
  17407. // face top
  17408. indices.push(i, i + 1, c);
  17409. } else {
  17410. // face bottom
  17411. indices.push(i + 1, i, c);
  17412. }
  17413. groupCount += 3;
  17414. } // add a group to the geometry. this will ensure multi material support
  17415. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  17416. groupStart += groupCount;
  17417. }
  17418. return _this;
  17419. }
  17420. return CylinderGeometry;
  17421. }(BufferGeometry);
  17422. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  17423. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  17424. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17425. var _this;
  17426. if (radius === void 0) {
  17427. radius = 1;
  17428. }
  17429. if (height === void 0) {
  17430. height = 1;
  17431. }
  17432. if (radialSegments === void 0) {
  17433. radialSegments = 8;
  17434. }
  17435. if (heightSegments === void 0) {
  17436. heightSegments = 1;
  17437. }
  17438. if (openEnded === void 0) {
  17439. openEnded = false;
  17440. }
  17441. if (thetaStart === void 0) {
  17442. thetaStart = 0;
  17443. }
  17444. if (thetaLength === void 0) {
  17445. thetaLength = Math.PI * 2;
  17446. }
  17447. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17448. _this.type = 'ConeGeometry';
  17449. _this.parameters = {
  17450. radius: radius,
  17451. height: height,
  17452. radialSegments: radialSegments,
  17453. heightSegments: heightSegments,
  17454. openEnded: openEnded,
  17455. thetaStart: thetaStart,
  17456. thetaLength: thetaLength
  17457. };
  17458. return _this;
  17459. }
  17460. return ConeGeometry;
  17461. }(CylinderGeometry);
  17462. var PolyhedronGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17463. _inheritsLoose(PolyhedronGeometry, _BufferGeometry);
  17464. function PolyhedronGeometry(vertices, indices, radius, detail) {
  17465. var _this;
  17466. if (radius === void 0) {
  17467. radius = 1;
  17468. }
  17469. if (detail === void 0) {
  17470. detail = 0;
  17471. }
  17472. _this = _BufferGeometry.call(this) || this;
  17473. _this.type = 'PolyhedronGeometry';
  17474. _this.parameters = {
  17475. vertices: vertices,
  17476. indices: indices,
  17477. radius: radius,
  17478. detail: detail
  17479. }; // default buffer data
  17480. var vertexBuffer = [];
  17481. var uvBuffer = []; // the subdivision creates the vertex buffer data
  17482. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  17483. applyRadius(radius); // finally, create the uv data
  17484. generateUVs(); // build non-indexed geometry
  17485. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  17486. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  17487. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  17488. if (detail === 0) {
  17489. _this.computeVertexNormals(); // flat normals
  17490. } else {
  17491. _this.normalizeNormals(); // smooth normals
  17492. } // helper functions
  17493. function subdivide(detail) {
  17494. var a = new Vector3();
  17495. var b = new Vector3();
  17496. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  17497. for (var i = 0; i < indices.length; i += 3) {
  17498. // get the vertices of the face
  17499. getVertexByIndex(indices[i + 0], a);
  17500. getVertexByIndex(indices[i + 1], b);
  17501. getVertexByIndex(indices[i + 2], c); // perform subdivision
  17502. subdivideFace(a, b, c, detail);
  17503. }
  17504. }
  17505. function subdivideFace(a, b, c, detail) {
  17506. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  17507. var v = []; // construct all of the vertices for this subdivision
  17508. for (var i = 0; i <= cols; i++) {
  17509. v[i] = [];
  17510. var aj = a.clone().lerp(c, i / cols);
  17511. var bj = b.clone().lerp(c, i / cols);
  17512. var rows = cols - i;
  17513. for (var j = 0; j <= rows; j++) {
  17514. if (j === 0 && i === cols) {
  17515. v[i][j] = aj;
  17516. } else {
  17517. v[i][j] = aj.clone().lerp(bj, j / rows);
  17518. }
  17519. }
  17520. } // construct all of the faces
  17521. for (var _i = 0; _i < cols; _i++) {
  17522. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  17523. var k = Math.floor(_j / 2);
  17524. if (_j % 2 === 0) {
  17525. pushVertex(v[_i][k + 1]);
  17526. pushVertex(v[_i + 1][k]);
  17527. pushVertex(v[_i][k]);
  17528. } else {
  17529. pushVertex(v[_i][k + 1]);
  17530. pushVertex(v[_i + 1][k + 1]);
  17531. pushVertex(v[_i + 1][k]);
  17532. }
  17533. }
  17534. }
  17535. }
  17536. function applyRadius(radius) {
  17537. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  17538. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17539. vertex.x = vertexBuffer[i + 0];
  17540. vertex.y = vertexBuffer[i + 1];
  17541. vertex.z = vertexBuffer[i + 2];
  17542. vertex.normalize().multiplyScalar(radius);
  17543. vertexBuffer[i + 0] = vertex.x;
  17544. vertexBuffer[i + 1] = vertex.y;
  17545. vertexBuffer[i + 2] = vertex.z;
  17546. }
  17547. }
  17548. function generateUVs() {
  17549. var vertex = new Vector3();
  17550. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17551. vertex.x = vertexBuffer[i + 0];
  17552. vertex.y = vertexBuffer[i + 1];
  17553. vertex.z = vertexBuffer[i + 2];
  17554. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17555. var v = inclination(vertex) / Math.PI + 0.5;
  17556. uvBuffer.push(u, 1 - v);
  17557. }
  17558. correctUVs();
  17559. correctSeam();
  17560. }
  17561. function correctSeam() {
  17562. // handle case when face straddles the seam, see #3269
  17563. for (var i = 0; i < uvBuffer.length; i += 6) {
  17564. // uv data of a single face
  17565. var x0 = uvBuffer[i + 0];
  17566. var x1 = uvBuffer[i + 2];
  17567. var x2 = uvBuffer[i + 4];
  17568. var max = Math.max(x0, x1, x2);
  17569. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17570. if (max > 0.9 && min < 0.1) {
  17571. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17572. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17573. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17574. }
  17575. }
  17576. }
  17577. function pushVertex(vertex) {
  17578. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17579. }
  17580. function getVertexByIndex(index, vertex) {
  17581. var stride = index * 3;
  17582. vertex.x = vertices[stride + 0];
  17583. vertex.y = vertices[stride + 1];
  17584. vertex.z = vertices[stride + 2];
  17585. }
  17586. function correctUVs() {
  17587. var a = new Vector3();
  17588. var b = new Vector3();
  17589. var c = new Vector3();
  17590. var centroid = new Vector3();
  17591. var uvA = new Vector2();
  17592. var uvB = new Vector2();
  17593. var uvC = new Vector2();
  17594. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17595. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17596. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17597. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17598. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17599. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17600. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17601. centroid.copy(a).add(b).add(c).divideScalar(3);
  17602. var azi = azimuth(centroid);
  17603. correctUV(uvA, j + 0, a, azi);
  17604. correctUV(uvB, j + 2, b, azi);
  17605. correctUV(uvC, j + 4, c, azi);
  17606. }
  17607. }
  17608. function correctUV(uv, stride, vector, azimuth) {
  17609. if (azimuth < 0 && uv.x === 1) {
  17610. uvBuffer[stride] = uv.x - 1;
  17611. }
  17612. if (vector.x === 0 && vector.z === 0) {
  17613. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17614. }
  17615. } // Angle around the Y axis, counter-clockwise when looking from above.
  17616. function azimuth(vector) {
  17617. return Math.atan2(vector.z, -vector.x);
  17618. } // Angle above the XZ plane.
  17619. function inclination(vector) {
  17620. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17621. }
  17622. return _this;
  17623. }
  17624. return PolyhedronGeometry;
  17625. }(BufferGeometry);
  17626. var DodecahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  17627. _inheritsLoose(DodecahedronGeometry, _PolyhedronGeometry);
  17628. function DodecahedronGeometry(radius, detail) {
  17629. var _this;
  17630. if (radius === void 0) {
  17631. radius = 1;
  17632. }
  17633. if (detail === void 0) {
  17634. detail = 0;
  17635. }
  17636. var t = (1 + Math.sqrt(5)) / 2;
  17637. var r = 1 / t;
  17638. var vertices = [// (±1, ±1, ±1)
  17639. -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/φ, ±φ)
  17640. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17641. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17642. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17643. 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];
  17644. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  17645. _this.type = 'DodecahedronGeometry';
  17646. _this.parameters = {
  17647. radius: radius,
  17648. detail: detail
  17649. };
  17650. return _this;
  17651. }
  17652. return DodecahedronGeometry;
  17653. }(PolyhedronGeometry);
  17654. var _v0$2 = new Vector3();
  17655. var _v1$5 = new Vector3();
  17656. var _normal$1 = new Vector3();
  17657. var _triangle = new Triangle();
  17658. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17659. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17660. function EdgesGeometry(geometry, thresholdAngle) {
  17661. var _this;
  17662. _this = _BufferGeometry.call(this) || this;
  17663. _this.type = 'EdgesGeometry';
  17664. _this.parameters = {
  17665. thresholdAngle: thresholdAngle
  17666. };
  17667. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  17668. if (geometry.isGeometry === true) {
  17669. console.error('THREE.EdgesGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17670. return _assertThisInitialized(_this);
  17671. }
  17672. var precisionPoints = 4;
  17673. var precision = Math.pow(10, precisionPoints);
  17674. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  17675. var indexAttr = geometry.getIndex();
  17676. var positionAttr = geometry.getAttribute('position');
  17677. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  17678. var indexArr = [0, 0, 0];
  17679. var vertKeys = ['a', 'b', 'c'];
  17680. var hashes = new Array(3);
  17681. var edgeData = {};
  17682. var vertices = [];
  17683. for (var i = 0; i < indexCount; i += 3) {
  17684. if (indexAttr) {
  17685. indexArr[0] = indexAttr.getX(i);
  17686. indexArr[1] = indexAttr.getX(i + 1);
  17687. indexArr[2] = indexAttr.getX(i + 2);
  17688. } else {
  17689. indexArr[0] = i;
  17690. indexArr[1] = i + 1;
  17691. indexArr[2] = i + 2;
  17692. }
  17693. var a = _triangle.a,
  17694. b = _triangle.b,
  17695. c = _triangle.c;
  17696. a.fromBufferAttribute(positionAttr, indexArr[0]);
  17697. b.fromBufferAttribute(positionAttr, indexArr[1]);
  17698. c.fromBufferAttribute(positionAttr, indexArr[2]);
  17699. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  17700. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  17701. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  17702. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  17703. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  17704. continue;
  17705. } // iterate over every edge
  17706. for (var j = 0; j < 3; j++) {
  17707. // get the first and next vertex making up the edge
  17708. var jNext = (j + 1) % 3;
  17709. var vecHash0 = hashes[j];
  17710. var vecHash1 = hashes[jNext];
  17711. var v0 = _triangle[vertKeys[j]];
  17712. var v1 = _triangle[vertKeys[jNext]];
  17713. var hash = vecHash0 + "_" + vecHash1;
  17714. var reverseHash = vecHash1 + "_" + vecHash0;
  17715. if (reverseHash in edgeData && edgeData[reverseHash]) {
  17716. // if we found a sibling edge add it into the vertex array if
  17717. // it meets the angle threshold and delete the edge from the map.
  17718. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  17719. vertices.push(v0.x, v0.y, v0.z);
  17720. vertices.push(v1.x, v1.y, v1.z);
  17721. }
  17722. edgeData[reverseHash] = null;
  17723. } else if (!(hash in edgeData)) {
  17724. // if we've already got an edge here then skip adding a new one
  17725. edgeData[hash] = {
  17726. index0: indexArr[j],
  17727. index1: indexArr[jNext],
  17728. normal: _normal$1.clone()
  17729. };
  17730. }
  17731. }
  17732. } // iterate over all remaining, unmatched edges and add them to the vertex array
  17733. for (var key in edgeData) {
  17734. if (edgeData[key]) {
  17735. var _edgeData$key = edgeData[key],
  17736. index0 = _edgeData$key.index0,
  17737. index1 = _edgeData$key.index1;
  17738. _v0$2.fromBufferAttribute(positionAttr, index0);
  17739. _v1$5.fromBufferAttribute(positionAttr, index1);
  17740. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  17741. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  17742. }
  17743. }
  17744. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17745. return _this;
  17746. }
  17747. return EdgesGeometry;
  17748. }(BufferGeometry);
  17749. /**
  17750. * Port from https://github.com/mapbox/earcut (v2.2.2)
  17751. */
  17752. var Earcut = {
  17753. triangulate: function triangulate(data, holeIndices, dim) {
  17754. dim = dim || 2;
  17755. var hasHoles = holeIndices && holeIndices.length;
  17756. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  17757. var outerNode = linkedList(data, 0, outerLen, dim, true);
  17758. var triangles = [];
  17759. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  17760. var minX, minY, maxX, maxY, x, y, invSize;
  17761. 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
  17762. if (data.length > 80 * dim) {
  17763. minX = maxX = data[0];
  17764. minY = maxY = data[1];
  17765. for (var i = dim; i < outerLen; i += dim) {
  17766. x = data[i];
  17767. y = data[i + 1];
  17768. if (x < minX) minX = x;
  17769. if (y < minY) minY = y;
  17770. if (x > maxX) maxX = x;
  17771. if (y > maxY) maxY = y;
  17772. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17773. invSize = Math.max(maxX - minX, maxY - minY);
  17774. invSize = invSize !== 0 ? 1 / invSize : 0;
  17775. }
  17776. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  17777. return triangles;
  17778. }
  17779. }; // create a circular doubly linked list from polygon points in the specified winding order
  17780. function linkedList(data, start, end, dim, clockwise) {
  17781. var i, last;
  17782. if (clockwise === signedArea(data, start, end, dim) > 0) {
  17783. for (i = start; i < end; i += dim) {
  17784. last = insertNode(i, data[i], data[i + 1], last);
  17785. }
  17786. } else {
  17787. for (i = end - dim; i >= start; i -= dim) {
  17788. last = insertNode(i, data[i], data[i + 1], last);
  17789. }
  17790. }
  17791. if (last && equals(last, last.next)) {
  17792. removeNode(last);
  17793. last = last.next;
  17794. }
  17795. return last;
  17796. } // eliminate colinear or duplicate points
  17797. function filterPoints(start, end) {
  17798. if (!start) return start;
  17799. if (!end) end = start;
  17800. var p = start,
  17801. again;
  17802. do {
  17803. again = false;
  17804. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  17805. removeNode(p);
  17806. p = end = p.prev;
  17807. if (p === p.next) break;
  17808. again = true;
  17809. } else {
  17810. p = p.next;
  17811. }
  17812. } while (again || p !== end);
  17813. return end;
  17814. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  17815. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  17816. if (!ear) return; // interlink polygon nodes in z-order
  17817. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  17818. var stop = ear,
  17819. prev,
  17820. next; // iterate through ears, slicing them one by one
  17821. while (ear.prev !== ear.next) {
  17822. prev = ear.prev;
  17823. next = ear.next;
  17824. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  17825. // cut off the triangle
  17826. triangles.push(prev.i / dim);
  17827. triangles.push(ear.i / dim);
  17828. triangles.push(next.i / dim);
  17829. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  17830. ear = next.next;
  17831. stop = next.next;
  17832. continue;
  17833. }
  17834. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  17835. if (ear === stop) {
  17836. // try filtering points and slicing again
  17837. if (!pass) {
  17838. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  17839. } else if (pass === 1) {
  17840. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  17841. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  17842. } else if (pass === 2) {
  17843. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  17844. }
  17845. break;
  17846. }
  17847. }
  17848. } // check whether a polygon node forms a valid ear with adjacent nodes
  17849. function isEar(ear) {
  17850. var a = ear.prev,
  17851. b = ear,
  17852. c = ear.next;
  17853. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17854. // now make sure we don't have other points inside the potential ear
  17855. var p = ear.next.next;
  17856. while (p !== ear.prev) {
  17857. 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;
  17858. p = p.next;
  17859. }
  17860. return true;
  17861. }
  17862. function isEarHashed(ear, minX, minY, invSize) {
  17863. var a = ear.prev,
  17864. b = ear,
  17865. c = ear.next;
  17866. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17867. // triangle bbox; min & max are calculated like this for speed
  17868. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  17869. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  17870. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  17871. 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;
  17872. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  17873. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  17874. var p = ear.prevZ,
  17875. n = ear.nextZ; // look for points inside the triangle in both directions
  17876. while (p && p.z >= minZ && n && n.z <= maxZ) {
  17877. 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;
  17878. p = p.prevZ;
  17879. 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;
  17880. n = n.nextZ;
  17881. } // look for remaining points in decreasing z-order
  17882. while (p && p.z >= minZ) {
  17883. 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;
  17884. p = p.prevZ;
  17885. } // look for remaining points in increasing z-order
  17886. while (n && n.z <= maxZ) {
  17887. 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;
  17888. n = n.nextZ;
  17889. }
  17890. return true;
  17891. } // go through all polygon nodes and cure small local self-intersections
  17892. function cureLocalIntersections(start, triangles, dim) {
  17893. var p = start;
  17894. do {
  17895. var a = p.prev,
  17896. b = p.next.next;
  17897. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  17898. triangles.push(a.i / dim);
  17899. triangles.push(p.i / dim);
  17900. triangles.push(b.i / dim); // remove two nodes involved
  17901. removeNode(p);
  17902. removeNode(p.next);
  17903. p = start = b;
  17904. }
  17905. p = p.next;
  17906. } while (p !== start);
  17907. return filterPoints(p);
  17908. } // try splitting polygon into two and triangulate them independently
  17909. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  17910. // look for a valid diagonal that divides the polygon into two
  17911. var a = start;
  17912. do {
  17913. var b = a.next.next;
  17914. while (b !== a.prev) {
  17915. if (a.i !== b.i && isValidDiagonal(a, b)) {
  17916. // split the polygon in two by the diagonal
  17917. var c = splitPolygon(a, b); // filter colinear points around the cuts
  17918. a = filterPoints(a, a.next);
  17919. c = filterPoints(c, c.next); // run earcut on each half
  17920. earcutLinked(a, triangles, dim, minX, minY, invSize);
  17921. earcutLinked(c, triangles, dim, minX, minY, invSize);
  17922. return;
  17923. }
  17924. b = b.next;
  17925. }
  17926. a = a.next;
  17927. } while (a !== start);
  17928. } // link every hole into the outer loop, producing a single-ring polygon without holes
  17929. function eliminateHoles(data, holeIndices, outerNode, dim) {
  17930. var queue = [];
  17931. var i, len, start, end, list;
  17932. for (i = 0, len = holeIndices.length; i < len; i++) {
  17933. start = holeIndices[i] * dim;
  17934. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  17935. list = linkedList(data, start, end, dim, false);
  17936. if (list === list.next) list.steiner = true;
  17937. queue.push(getLeftmost(list));
  17938. }
  17939. queue.sort(compareX); // process holes from left to right
  17940. for (i = 0; i < queue.length; i++) {
  17941. eliminateHole(queue[i], outerNode);
  17942. outerNode = filterPoints(outerNode, outerNode.next);
  17943. }
  17944. return outerNode;
  17945. }
  17946. function compareX(a, b) {
  17947. return a.x - b.x;
  17948. } // find a bridge between vertices that connects hole with an outer ring and and link it
  17949. function eliminateHole(hole, outerNode) {
  17950. outerNode = findHoleBridge(hole, outerNode);
  17951. if (outerNode) {
  17952. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  17953. filterPoints(outerNode, outerNode.next);
  17954. filterPoints(b, b.next);
  17955. }
  17956. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17957. function findHoleBridge(hole, outerNode) {
  17958. var p = outerNode;
  17959. var hx = hole.x;
  17960. var hy = hole.y;
  17961. var qx = -Infinity,
  17962. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  17963. // segment's endpoint with lesser x will be potential connection point
  17964. do {
  17965. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  17966. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  17967. if (x <= hx && x > qx) {
  17968. qx = x;
  17969. if (x === hx) {
  17970. if (hy === p.y) return p;
  17971. if (hy === p.next.y) return p.next;
  17972. }
  17973. m = p.x < p.next.x ? p : p.next;
  17974. }
  17975. }
  17976. p = p.next;
  17977. } while (p !== outerNode);
  17978. if (!m) return null;
  17979. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  17980. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17981. // if there are no points found, we have a valid connection;
  17982. // otherwise choose the point of the minimum angle with the ray as connection point
  17983. var stop = m,
  17984. mx = m.x,
  17985. my = m.y;
  17986. var tanMin = Infinity,
  17987. tan;
  17988. p = m;
  17989. do {
  17990. 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)) {
  17991. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  17992. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  17993. m = p;
  17994. tanMin = tan;
  17995. }
  17996. }
  17997. p = p.next;
  17998. } while (p !== stop);
  17999. return m;
  18000. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  18001. function sectorContainsSector(m, p) {
  18002. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  18003. } // interlink polygon nodes in z-order
  18004. function indexCurve(start, minX, minY, invSize) {
  18005. var p = start;
  18006. do {
  18007. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  18008. p.prevZ = p.prev;
  18009. p.nextZ = p.next;
  18010. p = p.next;
  18011. } while (p !== start);
  18012. p.prevZ.nextZ = null;
  18013. p.prevZ = null;
  18014. sortLinked(p);
  18015. } // Simon Tatham's linked list merge sort algorithm
  18016. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  18017. function sortLinked(list) {
  18018. var i,
  18019. p,
  18020. q,
  18021. e,
  18022. tail,
  18023. numMerges,
  18024. pSize,
  18025. qSize,
  18026. inSize = 1;
  18027. do {
  18028. p = list;
  18029. list = null;
  18030. tail = null;
  18031. numMerges = 0;
  18032. while (p) {
  18033. numMerges++;
  18034. q = p;
  18035. pSize = 0;
  18036. for (i = 0; i < inSize; i++) {
  18037. pSize++;
  18038. q = q.nextZ;
  18039. if (!q) break;
  18040. }
  18041. qSize = inSize;
  18042. while (pSize > 0 || qSize > 0 && q) {
  18043. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  18044. e = p;
  18045. p = p.nextZ;
  18046. pSize--;
  18047. } else {
  18048. e = q;
  18049. q = q.nextZ;
  18050. qSize--;
  18051. }
  18052. if (tail) tail.nextZ = e;else list = e;
  18053. e.prevZ = tail;
  18054. tail = e;
  18055. }
  18056. p = q;
  18057. }
  18058. tail.nextZ = null;
  18059. inSize *= 2;
  18060. } while (numMerges > 1);
  18061. return list;
  18062. } // z-order of a point given coords and inverse of the longer side of data bbox
  18063. function zOrder(x, y, minX, minY, invSize) {
  18064. // coords are transformed into non-negative 15-bit integer range
  18065. x = 32767 * (x - minX) * invSize;
  18066. y = 32767 * (y - minY) * invSize;
  18067. x = (x | x << 8) & 0x00FF00FF;
  18068. x = (x | x << 4) & 0x0F0F0F0F;
  18069. x = (x | x << 2) & 0x33333333;
  18070. x = (x | x << 1) & 0x55555555;
  18071. y = (y | y << 8) & 0x00FF00FF;
  18072. y = (y | y << 4) & 0x0F0F0F0F;
  18073. y = (y | y << 2) & 0x33333333;
  18074. y = (y | y << 1) & 0x55555555;
  18075. return x | y << 1;
  18076. } // find the leftmost node of a polygon ring
  18077. function getLeftmost(start) {
  18078. var p = start,
  18079. leftmost = start;
  18080. do {
  18081. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  18082. p = p.next;
  18083. } while (p !== start);
  18084. return leftmost;
  18085. } // check if a point lies within a convex triangle
  18086. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  18087. 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;
  18088. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18089. function isValidDiagonal(a, b) {
  18090. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  18091. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  18092. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  18093. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  18094. } // signed area of a triangle
  18095. function area(p, q, r) {
  18096. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  18097. } // check if two points are equal
  18098. function equals(p1, p2) {
  18099. return p1.x === p2.x && p1.y === p2.y;
  18100. } // check if two segments intersect
  18101. function intersects(p1, q1, p2, q2) {
  18102. var o1 = sign(area(p1, q1, p2));
  18103. var o2 = sign(area(p1, q1, q2));
  18104. var o3 = sign(area(p2, q2, p1));
  18105. var o4 = sign(area(p2, q2, q1));
  18106. if (o1 !== o2 && o3 !== o4) return true; // general case
  18107. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18108. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18109. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18110. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18111. return false;
  18112. } // for collinear points p, q, r, check if point q lies on segment pr
  18113. function onSegment(p, q, r) {
  18114. 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);
  18115. }
  18116. function sign(num) {
  18117. return num > 0 ? 1 : num < 0 ? -1 : 0;
  18118. } // check if a polygon diagonal intersects any polygon segments
  18119. function intersectsPolygon(a, b) {
  18120. var p = a;
  18121. do {
  18122. 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;
  18123. p = p.next;
  18124. } while (p !== a);
  18125. return false;
  18126. } // check if a polygon diagonal is locally inside the polygon
  18127. function locallyInside(a, b) {
  18128. 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;
  18129. } // check if the middle point of a polygon diagonal is inside the polygon
  18130. function middleInside(a, b) {
  18131. var p = a,
  18132. inside = false;
  18133. var px = (a.x + b.x) / 2,
  18134. py = (a.y + b.y) / 2;
  18135. do {
  18136. 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;
  18137. p = p.next;
  18138. } while (p !== a);
  18139. return inside;
  18140. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18141. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18142. function splitPolygon(a, b) {
  18143. var a2 = new Node(a.i, a.x, a.y),
  18144. b2 = new Node(b.i, b.x, b.y),
  18145. an = a.next,
  18146. bp = b.prev;
  18147. a.next = b;
  18148. b.prev = a;
  18149. a2.next = an;
  18150. an.prev = a2;
  18151. b2.next = a2;
  18152. a2.prev = b2;
  18153. bp.next = b2;
  18154. b2.prev = bp;
  18155. return b2;
  18156. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  18157. function insertNode(i, x, y, last) {
  18158. var p = new Node(i, x, y);
  18159. if (!last) {
  18160. p.prev = p;
  18161. p.next = p;
  18162. } else {
  18163. p.next = last.next;
  18164. p.prev = last;
  18165. last.next.prev = p;
  18166. last.next = p;
  18167. }
  18168. return p;
  18169. }
  18170. function removeNode(p) {
  18171. p.next.prev = p.prev;
  18172. p.prev.next = p.next;
  18173. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  18174. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  18175. }
  18176. function Node(i, x, y) {
  18177. // vertex index in coordinates array
  18178. this.i = i; // vertex coordinates
  18179. this.x = x;
  18180. this.y = y; // previous and next vertex nodes in a polygon ring
  18181. this.prev = null;
  18182. this.next = null; // z-order curve value
  18183. this.z = null; // previous and next nodes in z-order
  18184. this.prevZ = null;
  18185. this.nextZ = null; // indicates whether this is a steiner point
  18186. this.steiner = false;
  18187. }
  18188. function signedArea(data, start, end, dim) {
  18189. var sum = 0;
  18190. for (var i = start, j = end - dim; i < end; i += dim) {
  18191. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  18192. j = i;
  18193. }
  18194. return sum;
  18195. }
  18196. var ShapeUtils = {
  18197. // calculate area of the contour polygon
  18198. area: function area(contour) {
  18199. var n = contour.length;
  18200. var a = 0.0;
  18201. for (var p = n - 1, q = 0; q < n; p = q++) {
  18202. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  18203. }
  18204. return a * 0.5;
  18205. },
  18206. isClockWise: function isClockWise(pts) {
  18207. return ShapeUtils.area(pts) < 0;
  18208. },
  18209. triangulateShape: function triangulateShape(contour, holes) {
  18210. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18211. var holeIndices = []; // array of hole indices
  18212. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18213. removeDupEndPts(contour);
  18214. addContour(vertices, contour); //
  18215. var holeIndex = contour.length;
  18216. holes.forEach(removeDupEndPts);
  18217. for (var i = 0; i < holes.length; i++) {
  18218. holeIndices.push(holeIndex);
  18219. holeIndex += holes[i].length;
  18220. addContour(vertices, holes[i]);
  18221. } //
  18222. var triangles = Earcut.triangulate(vertices, holeIndices); //
  18223. for (var _i = 0; _i < triangles.length; _i += 3) {
  18224. faces.push(triangles.slice(_i, _i + 3));
  18225. }
  18226. return faces;
  18227. }
  18228. };
  18229. function removeDupEndPts(points) {
  18230. var l = points.length;
  18231. if (l > 2 && points[l - 1].equals(points[0])) {
  18232. points.pop();
  18233. }
  18234. }
  18235. function addContour(vertices, contour) {
  18236. for (var i = 0; i < contour.length; i++) {
  18237. vertices.push(contour[i].x);
  18238. vertices.push(contour[i].y);
  18239. }
  18240. }
  18241. var ExtrudeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18242. _inheritsLoose(ExtrudeGeometry, _BufferGeometry);
  18243. function ExtrudeGeometry(shapes, options) {
  18244. var _this;
  18245. _this = _BufferGeometry.call(this) || this;
  18246. _this.type = 'ExtrudeGeometry';
  18247. _this.parameters = {
  18248. shapes: shapes,
  18249. options: options
  18250. };
  18251. shapes = Array.isArray(shapes) ? shapes : [shapes];
  18252. var scope = _assertThisInitialized(_this);
  18253. var verticesArray = [];
  18254. var uvArray = [];
  18255. for (var i = 0, l = shapes.length; i < l; i++) {
  18256. var shape = shapes[i];
  18257. addShape(shape);
  18258. } // build geometry
  18259. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  18260. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  18261. _this.computeVertexNormals(); // functions
  18262. function addShape(shape) {
  18263. var placeholder = []; // options
  18264. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18265. var steps = options.steps !== undefined ? options.steps : 1;
  18266. var depth = options.depth !== undefined ? options.depth : 100;
  18267. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18268. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18269. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18270. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18271. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18272. var extrudePath = options.extrudePath;
  18273. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  18274. if (options.amount !== undefined) {
  18275. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  18276. depth = options.amount;
  18277. } //
  18278. var extrudePts,
  18279. extrudeByPath = false;
  18280. var splineTube, binormal, normal, position2;
  18281. if (extrudePath) {
  18282. extrudePts = extrudePath.getSpacedPoints(steps);
  18283. extrudeByPath = true;
  18284. bevelEnabled = false; // bevels not supported for path extrusion
  18285. // SETUP TNB variables
  18286. // TODO1 - have a .isClosed in spline?
  18287. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18288. binormal = new Vector3();
  18289. normal = new Vector3();
  18290. position2 = new Vector3();
  18291. } // Safeguards if bevels are not enabled
  18292. if (!bevelEnabled) {
  18293. bevelSegments = 0;
  18294. bevelThickness = 0;
  18295. bevelSize = 0;
  18296. bevelOffset = 0;
  18297. } // Variables initialization
  18298. var shapePoints = shape.extractPoints(curveSegments);
  18299. var vertices = shapePoints.shape;
  18300. var holes = shapePoints.holes;
  18301. var reverse = !ShapeUtils.isClockWise(vertices);
  18302. if (reverse) {
  18303. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18304. for (var h = 0, hl = holes.length; h < hl; h++) {
  18305. var ahole = holes[h];
  18306. if (ShapeUtils.isClockWise(ahole)) {
  18307. holes[h] = ahole.reverse();
  18308. }
  18309. }
  18310. }
  18311. var faces = ShapeUtils.triangulateShape(vertices, holes);
  18312. /* Vertices */
  18313. var contour = vertices; // vertices has all points but contour has only points of circumference
  18314. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  18315. var _ahole = holes[_h];
  18316. vertices = vertices.concat(_ahole);
  18317. }
  18318. function scalePt2(pt, vec, size) {
  18319. if (!vec) console.error('THREE.ExtrudeGeometry: vec does not exist');
  18320. return vec.clone().multiplyScalar(size).add(pt);
  18321. }
  18322. var vlen = vertices.length,
  18323. flen = faces.length; // Find directions for point movement
  18324. function getBevelVec(inPt, inPrev, inNext) {
  18325. // computes for inPt the corresponding point inPt' on a new contour
  18326. // shifted by 1 unit (length of normalized vector) to the left
  18327. // if we walk along contour clockwise, this new contour is outside the old one
  18328. //
  18329. // inPt' is the intersection of the two lines parallel to the two
  18330. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18331. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18332. // good reading for geometry algorithms (here: line-line intersection)
  18333. // http://geomalgorithms.com/a05-_intersect-1.html
  18334. var v_prev_x = inPt.x - inPrev.x,
  18335. v_prev_y = inPt.y - inPrev.y;
  18336. var v_next_x = inNext.x - inPt.x,
  18337. v_next_y = inNext.y - inPt.y;
  18338. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  18339. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  18340. if (Math.abs(collinear0) > Number.EPSILON) {
  18341. // not collinear
  18342. // length of vectors for normalizing
  18343. var v_prev_len = Math.sqrt(v_prev_lensq);
  18344. 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
  18345. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  18346. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  18347. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  18348. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  18349. 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
  18350. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  18351. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  18352. // but prevent crazy spikes
  18353. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  18354. if (v_trans_lensq <= 2) {
  18355. return new Vector2(v_trans_x, v_trans_y);
  18356. } else {
  18357. shrink_by = Math.sqrt(v_trans_lensq / 2);
  18358. }
  18359. } else {
  18360. // handle special case of collinear edges
  18361. var direction_eq = false; // assumes: opposite
  18362. if (v_prev_x > Number.EPSILON) {
  18363. if (v_next_x > Number.EPSILON) {
  18364. direction_eq = true;
  18365. }
  18366. } else {
  18367. if (v_prev_x < -Number.EPSILON) {
  18368. if (v_next_x < -Number.EPSILON) {
  18369. direction_eq = true;
  18370. }
  18371. } else {
  18372. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  18373. direction_eq = true;
  18374. }
  18375. }
  18376. }
  18377. if (direction_eq) {
  18378. // console.log("Warning: lines are a straight sequence");
  18379. v_trans_x = -v_prev_y;
  18380. v_trans_y = v_prev_x;
  18381. shrink_by = Math.sqrt(v_prev_lensq);
  18382. } else {
  18383. // console.log("Warning: lines are a straight spike");
  18384. v_trans_x = v_prev_x;
  18385. v_trans_y = v_prev_y;
  18386. shrink_by = Math.sqrt(v_prev_lensq / 2);
  18387. }
  18388. }
  18389. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  18390. }
  18391. var contourMovements = [];
  18392. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  18393. if (j === il) j = 0;
  18394. if (k === il) k = 0; // (j)---(i)---(k)
  18395. // console.log('i,j,k', i, j , k)
  18396. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  18397. }
  18398. var holesMovements = [];
  18399. var oneHoleMovements,
  18400. verticesMovements = contourMovements.concat();
  18401. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  18402. var _ahole2 = holes[_h2];
  18403. oneHoleMovements = [];
  18404. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  18405. if (_j === _il) _j = 0;
  18406. if (_k === _il) _k = 0; // (j)---(i)---(k)
  18407. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  18408. }
  18409. holesMovements.push(oneHoleMovements);
  18410. verticesMovements = verticesMovements.concat(oneHoleMovements);
  18411. } // Loop bevelSegments, 1 for the front, 1 for the back
  18412. for (var b = 0; b < bevelSegments; b++) {
  18413. //for ( b = bevelSegments; b > 0; b -- ) {
  18414. var t = b / bevelSegments;
  18415. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  18416. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  18417. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  18418. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  18419. v(vert.x, vert.y, -z);
  18420. } // expand holes
  18421. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  18422. var _ahole3 = holes[_h3];
  18423. oneHoleMovements = holesMovements[_h3];
  18424. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  18425. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  18426. v(_vert.x, _vert.y, -z);
  18427. }
  18428. }
  18429. }
  18430. var bs = bevelSize + bevelOffset; // Back facing vertices
  18431. for (var _i5 = 0; _i5 < vlen; _i5++) {
  18432. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  18433. if (!extrudeByPath) {
  18434. v(_vert2.x, _vert2.y, 0);
  18435. } else {
  18436. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18437. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  18438. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  18439. position2.copy(extrudePts[0]).add(normal).add(binormal);
  18440. v(position2.x, position2.y, position2.z);
  18441. }
  18442. } // Add stepped vertices...
  18443. // Including front facing vertices
  18444. for (var s = 1; s <= steps; s++) {
  18445. for (var _i6 = 0; _i6 < vlen; _i6++) {
  18446. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  18447. if (!extrudeByPath) {
  18448. v(_vert3.x, _vert3.y, depth / steps * s);
  18449. } else {
  18450. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18451. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  18452. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  18453. position2.copy(extrudePts[s]).add(normal).add(binormal);
  18454. v(position2.x, position2.y, position2.z);
  18455. }
  18456. }
  18457. } // Add bevel segments planes
  18458. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18459. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  18460. var _t = _b / bevelSegments;
  18461. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  18462. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  18463. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  18464. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  18465. v(_vert4.x, _vert4.y, depth + _z);
  18466. } // expand holes
  18467. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  18468. var _ahole4 = holes[_h4];
  18469. oneHoleMovements = holesMovements[_h4];
  18470. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  18471. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  18472. if (!extrudeByPath) {
  18473. v(_vert5.x, _vert5.y, depth + _z);
  18474. } else {
  18475. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  18476. }
  18477. }
  18478. }
  18479. }
  18480. /* Faces */
  18481. // Top and bottom faces
  18482. buildLidFaces(); // Sides faces
  18483. buildSideFaces(); ///// Internal functions
  18484. function buildLidFaces() {
  18485. var start = verticesArray.length / 3;
  18486. if (bevelEnabled) {
  18487. var layer = 0; // steps + 1
  18488. var offset = vlen * layer; // Bottom faces
  18489. for (var _i9 = 0; _i9 < flen; _i9++) {
  18490. var face = faces[_i9];
  18491. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  18492. }
  18493. layer = steps + bevelSegments * 2;
  18494. offset = vlen * layer; // Top faces
  18495. for (var _i10 = 0; _i10 < flen; _i10++) {
  18496. var _face = faces[_i10];
  18497. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  18498. }
  18499. } else {
  18500. // Bottom faces
  18501. for (var _i11 = 0; _i11 < flen; _i11++) {
  18502. var _face2 = faces[_i11];
  18503. f3(_face2[2], _face2[1], _face2[0]);
  18504. } // Top faces
  18505. for (var _i12 = 0; _i12 < flen; _i12++) {
  18506. var _face3 = faces[_i12];
  18507. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  18508. }
  18509. }
  18510. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  18511. } // Create faces for the z-sides of the shape
  18512. function buildSideFaces() {
  18513. var start = verticesArray.length / 3;
  18514. var layeroffset = 0;
  18515. sidewalls(contour, layeroffset);
  18516. layeroffset += contour.length;
  18517. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  18518. var _ahole5 = holes[_h5];
  18519. sidewalls(_ahole5, layeroffset); //, true
  18520. layeroffset += _ahole5.length;
  18521. }
  18522. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  18523. }
  18524. function sidewalls(contour, layeroffset) {
  18525. var i = contour.length;
  18526. while (--i >= 0) {
  18527. var _j2 = i;
  18528. var _k2 = i - 1;
  18529. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  18530. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  18531. var slen1 = vlen * _s;
  18532. var slen2 = vlen * (_s + 1);
  18533. var a = layeroffset + _j2 + slen1,
  18534. _b2 = layeroffset + _k2 + slen1,
  18535. c = layeroffset + _k2 + slen2,
  18536. d = layeroffset + _j2 + slen2;
  18537. f4(a, _b2, c, d);
  18538. }
  18539. }
  18540. }
  18541. function v(x, y, z) {
  18542. placeholder.push(x);
  18543. placeholder.push(y);
  18544. placeholder.push(z);
  18545. }
  18546. function f3(a, b, c) {
  18547. addVertex(a);
  18548. addVertex(b);
  18549. addVertex(c);
  18550. var nextIndex = verticesArray.length / 3;
  18551. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18552. addUV(uvs[0]);
  18553. addUV(uvs[1]);
  18554. addUV(uvs[2]);
  18555. }
  18556. function f4(a, b, c, d) {
  18557. addVertex(a);
  18558. addVertex(b);
  18559. addVertex(d);
  18560. addVertex(b);
  18561. addVertex(c);
  18562. addVertex(d);
  18563. var nextIndex = verticesArray.length / 3;
  18564. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18565. addUV(uvs[0]);
  18566. addUV(uvs[1]);
  18567. addUV(uvs[3]);
  18568. addUV(uvs[1]);
  18569. addUV(uvs[2]);
  18570. addUV(uvs[3]);
  18571. }
  18572. function addVertex(index) {
  18573. verticesArray.push(placeholder[index * 3 + 0]);
  18574. verticesArray.push(placeholder[index * 3 + 1]);
  18575. verticesArray.push(placeholder[index * 3 + 2]);
  18576. }
  18577. function addUV(vector2) {
  18578. uvArray.push(vector2.x);
  18579. uvArray.push(vector2.y);
  18580. }
  18581. }
  18582. return _this;
  18583. }
  18584. var _proto = ExtrudeGeometry.prototype;
  18585. _proto.toJSON = function toJSON() {
  18586. var data = BufferGeometry.prototype.toJSON.call(this);
  18587. var shapes = this.parameters.shapes;
  18588. var options = this.parameters.options;
  18589. return _toJSON(shapes, options, data);
  18590. };
  18591. return ExtrudeGeometry;
  18592. }(BufferGeometry);
  18593. var WorldUVGenerator = {
  18594. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18595. var a_x = vertices[indexA * 3];
  18596. var a_y = vertices[indexA * 3 + 1];
  18597. var b_x = vertices[indexB * 3];
  18598. var b_y = vertices[indexB * 3 + 1];
  18599. var c_x = vertices[indexC * 3];
  18600. var c_y = vertices[indexC * 3 + 1];
  18601. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18602. },
  18603. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18604. var a_x = vertices[indexA * 3];
  18605. var a_y = vertices[indexA * 3 + 1];
  18606. var a_z = vertices[indexA * 3 + 2];
  18607. var b_x = vertices[indexB * 3];
  18608. var b_y = vertices[indexB * 3 + 1];
  18609. var b_z = vertices[indexB * 3 + 2];
  18610. var c_x = vertices[indexC * 3];
  18611. var c_y = vertices[indexC * 3 + 1];
  18612. var c_z = vertices[indexC * 3 + 2];
  18613. var d_x = vertices[indexD * 3];
  18614. var d_y = vertices[indexD * 3 + 1];
  18615. var d_z = vertices[indexD * 3 + 2];
  18616. if (Math.abs(a_y - b_y) < 0.01) {
  18617. 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)];
  18618. } else {
  18619. 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)];
  18620. }
  18621. }
  18622. };
  18623. function _toJSON(shapes, options, data) {
  18624. data.shapes = [];
  18625. if (Array.isArray(shapes)) {
  18626. for (var i = 0, l = shapes.length; i < l; i++) {
  18627. var shape = shapes[i];
  18628. data.shapes.push(shape.uuid);
  18629. }
  18630. } else {
  18631. data.shapes.push(shapes.uuid);
  18632. }
  18633. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18634. return data;
  18635. }
  18636. var IcosahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18637. _inheritsLoose(IcosahedronGeometry, _PolyhedronGeometry);
  18638. function IcosahedronGeometry(radius, detail) {
  18639. var _this;
  18640. if (radius === void 0) {
  18641. radius = 1;
  18642. }
  18643. if (detail === void 0) {
  18644. detail = 0;
  18645. }
  18646. var t = (1 + Math.sqrt(5)) / 2;
  18647. 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];
  18648. 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];
  18649. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18650. _this.type = 'IcosahedronGeometry';
  18651. _this.parameters = {
  18652. radius: radius,
  18653. detail: detail
  18654. };
  18655. return _this;
  18656. }
  18657. return IcosahedronGeometry;
  18658. }(PolyhedronGeometry);
  18659. var LatheGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18660. _inheritsLoose(LatheGeometry, _BufferGeometry);
  18661. function LatheGeometry(points, segments, phiStart, phiLength) {
  18662. var _this;
  18663. if (segments === void 0) {
  18664. segments = 12;
  18665. }
  18666. if (phiStart === void 0) {
  18667. phiStart = 0;
  18668. }
  18669. if (phiLength === void 0) {
  18670. phiLength = Math.PI * 2;
  18671. }
  18672. _this = _BufferGeometry.call(this) || this;
  18673. _this.type = 'LatheGeometry';
  18674. _this.parameters = {
  18675. points: points,
  18676. segments: segments,
  18677. phiStart: phiStart,
  18678. phiLength: phiLength
  18679. };
  18680. segments = Math.floor(segments); // clamp phiLength so it's in range of [ 0, 2PI ]
  18681. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  18682. var indices = [];
  18683. var vertices = [];
  18684. var uvs = []; // helper variables
  18685. var inverseSegments = 1.0 / segments;
  18686. var vertex = new Vector3();
  18687. var uv = new Vector2(); // generate vertices and uvs
  18688. for (var i = 0; i <= segments; i++) {
  18689. var phi = phiStart + i * inverseSegments * phiLength;
  18690. var sin = Math.sin(phi);
  18691. var cos = Math.cos(phi);
  18692. for (var j = 0; j <= points.length - 1; j++) {
  18693. // vertex
  18694. vertex.x = points[j].x * sin;
  18695. vertex.y = points[j].y;
  18696. vertex.z = points[j].x * cos;
  18697. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  18698. uv.x = i / segments;
  18699. uv.y = j / (points.length - 1);
  18700. uvs.push(uv.x, uv.y);
  18701. }
  18702. } // indices
  18703. for (var _i = 0; _i < segments; _i++) {
  18704. for (var _j = 0; _j < points.length - 1; _j++) {
  18705. var base = _j + _i * points.length;
  18706. var a = base;
  18707. var b = base + points.length;
  18708. var c = base + points.length + 1;
  18709. var d = base + 1; // faces
  18710. indices.push(a, b, d);
  18711. indices.push(b, c, d);
  18712. }
  18713. } // build geometry
  18714. _this.setIndex(indices);
  18715. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18716. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  18717. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  18718. // because the corresponding vertices are identical (but still have different UVs).
  18719. if (phiLength === Math.PI * 2) {
  18720. var normals = _this.attributes.normal.array;
  18721. var n1 = new Vector3();
  18722. var n2 = new Vector3();
  18723. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  18724. var _base = segments * points.length * 3;
  18725. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  18726. // select the normal of the vertex in the first line
  18727. n1.x = normals[_j2 + 0];
  18728. n1.y = normals[_j2 + 1];
  18729. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  18730. n2.x = normals[_base + _j2 + 0];
  18731. n2.y = normals[_base + _j2 + 1];
  18732. n2.z = normals[_base + _j2 + 2]; // average normals
  18733. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  18734. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  18735. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  18736. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  18737. }
  18738. }
  18739. return _this;
  18740. }
  18741. return LatheGeometry;
  18742. }(BufferGeometry);
  18743. var OctahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18744. _inheritsLoose(OctahedronGeometry, _PolyhedronGeometry);
  18745. function OctahedronGeometry(radius, detail) {
  18746. var _this;
  18747. if (radius === void 0) {
  18748. radius = 1;
  18749. }
  18750. if (detail === void 0) {
  18751. detail = 0;
  18752. }
  18753. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  18754. 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];
  18755. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18756. _this.type = 'OctahedronGeometry';
  18757. _this.parameters = {
  18758. radius: radius,
  18759. detail: detail
  18760. };
  18761. return _this;
  18762. }
  18763. return OctahedronGeometry;
  18764. }(PolyhedronGeometry);
  18765. /**
  18766. * Parametric Surfaces Geometry
  18767. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18768. */
  18769. function ParametricGeometry(func, slices, stacks) {
  18770. BufferGeometry.call(this);
  18771. this.type = 'ParametricGeometry';
  18772. this.parameters = {
  18773. func: func,
  18774. slices: slices,
  18775. stacks: stacks
  18776. }; // buffers
  18777. var indices = [];
  18778. var vertices = [];
  18779. var normals = [];
  18780. var uvs = [];
  18781. var EPS = 0.00001;
  18782. var normal = new Vector3();
  18783. var p0 = new Vector3(),
  18784. p1 = new Vector3();
  18785. var pu = new Vector3(),
  18786. pv = new Vector3();
  18787. if (func.length < 3) {
  18788. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  18789. } // generate vertices, normals and uvs
  18790. var sliceCount = slices + 1;
  18791. for (var i = 0; i <= stacks; i++) {
  18792. var v = i / stacks;
  18793. for (var j = 0; j <= slices; j++) {
  18794. var u = j / slices; // vertex
  18795. func(u, v, p0);
  18796. vertices.push(p0.x, p0.y, p0.z); // normal
  18797. // approximate tangent vectors via finite differences
  18798. if (u - EPS >= 0) {
  18799. func(u - EPS, v, p1);
  18800. pu.subVectors(p0, p1);
  18801. } else {
  18802. func(u + EPS, v, p1);
  18803. pu.subVectors(p1, p0);
  18804. }
  18805. if (v - EPS >= 0) {
  18806. func(u, v - EPS, p1);
  18807. pv.subVectors(p0, p1);
  18808. } else {
  18809. func(u, v + EPS, p1);
  18810. pv.subVectors(p1, p0);
  18811. } // cross product of tangent vectors returns surface normal
  18812. normal.crossVectors(pu, pv).normalize();
  18813. normals.push(normal.x, normal.y, normal.z); // uv
  18814. uvs.push(u, v);
  18815. }
  18816. } // generate indices
  18817. for (var _i = 0; _i < stacks; _i++) {
  18818. for (var _j = 0; _j < slices; _j++) {
  18819. var a = _i * sliceCount + _j;
  18820. var b = _i * sliceCount + _j + 1;
  18821. var c = (_i + 1) * sliceCount + _j + 1;
  18822. var d = (_i + 1) * sliceCount + _j; // faces one and two
  18823. indices.push(a, b, d);
  18824. indices.push(b, c, d);
  18825. }
  18826. } // build geometry
  18827. this.setIndex(indices);
  18828. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18829. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18830. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18831. }
  18832. ParametricGeometry.prototype = Object.create(BufferGeometry.prototype);
  18833. ParametricGeometry.prototype.constructor = ParametricGeometry;
  18834. var RingGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18835. _inheritsLoose(RingGeometry, _BufferGeometry);
  18836. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  18837. var _this;
  18838. if (innerRadius === void 0) {
  18839. innerRadius = 0.5;
  18840. }
  18841. if (outerRadius === void 0) {
  18842. outerRadius = 1;
  18843. }
  18844. if (thetaSegments === void 0) {
  18845. thetaSegments = 8;
  18846. }
  18847. if (phiSegments === void 0) {
  18848. phiSegments = 1;
  18849. }
  18850. if (thetaStart === void 0) {
  18851. thetaStart = 0;
  18852. }
  18853. if (thetaLength === void 0) {
  18854. thetaLength = Math.PI * 2;
  18855. }
  18856. _this = _BufferGeometry.call(this) || this;
  18857. _this.type = 'RingGeometry';
  18858. _this.parameters = {
  18859. innerRadius: innerRadius,
  18860. outerRadius: outerRadius,
  18861. thetaSegments: thetaSegments,
  18862. phiSegments: phiSegments,
  18863. thetaStart: thetaStart,
  18864. thetaLength: thetaLength
  18865. };
  18866. thetaSegments = Math.max(3, thetaSegments);
  18867. phiSegments = Math.max(1, phiSegments); // buffers
  18868. var indices = [];
  18869. var vertices = [];
  18870. var normals = [];
  18871. var uvs = []; // some helper variables
  18872. var radius = innerRadius;
  18873. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  18874. var vertex = new Vector3();
  18875. var uv = new Vector2(); // generate vertices, normals and uvs
  18876. for (var j = 0; j <= phiSegments; j++) {
  18877. for (var i = 0; i <= thetaSegments; i++) {
  18878. // values are generate from the inside of the ring to the outside
  18879. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  18880. vertex.x = radius * Math.cos(segment);
  18881. vertex.y = radius * Math.sin(segment);
  18882. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  18883. normals.push(0, 0, 1); // uv
  18884. uv.x = (vertex.x / outerRadius + 1) / 2;
  18885. uv.y = (vertex.y / outerRadius + 1) / 2;
  18886. uvs.push(uv.x, uv.y);
  18887. } // increase the radius for next row of vertices
  18888. radius += radiusStep;
  18889. } // indices
  18890. for (var _j = 0; _j < phiSegments; _j++) {
  18891. var thetaSegmentLevel = _j * (thetaSegments + 1);
  18892. for (var _i = 0; _i < thetaSegments; _i++) {
  18893. var _segment = _i + thetaSegmentLevel;
  18894. var a = _segment;
  18895. var b = _segment + thetaSegments + 1;
  18896. var c = _segment + thetaSegments + 2;
  18897. var d = _segment + 1; // faces
  18898. indices.push(a, b, d);
  18899. indices.push(b, c, d);
  18900. }
  18901. } // build geometry
  18902. _this.setIndex(indices);
  18903. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18904. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18905. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18906. return _this;
  18907. }
  18908. return RingGeometry;
  18909. }(BufferGeometry);
  18910. var ShapeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18911. _inheritsLoose(ShapeGeometry, _BufferGeometry);
  18912. function ShapeGeometry(shapes, curveSegments) {
  18913. var _this;
  18914. if (curveSegments === void 0) {
  18915. curveSegments = 12;
  18916. }
  18917. _this = _BufferGeometry.call(this) || this;
  18918. _this.type = 'ShapeGeometry';
  18919. _this.parameters = {
  18920. shapes: shapes,
  18921. curveSegments: curveSegments
  18922. }; // buffers
  18923. var indices = [];
  18924. var vertices = [];
  18925. var normals = [];
  18926. var uvs = []; // helper variables
  18927. var groupStart = 0;
  18928. var groupCount = 0; // allow single and array values for "shapes" parameter
  18929. if (Array.isArray(shapes) === false) {
  18930. addShape(shapes);
  18931. } else {
  18932. for (var i = 0; i < shapes.length; i++) {
  18933. addShape(shapes[i]);
  18934. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  18935. groupStart += groupCount;
  18936. groupCount = 0;
  18937. }
  18938. } // build geometry
  18939. _this.setIndex(indices);
  18940. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18941. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18942. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  18943. function addShape(shape) {
  18944. var indexOffset = vertices.length / 3;
  18945. var points = shape.extractPoints(curveSegments);
  18946. var shapeVertices = points.shape;
  18947. var shapeHoles = points.holes; // check direction of vertices
  18948. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  18949. shapeVertices = shapeVertices.reverse();
  18950. }
  18951. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  18952. var shapeHole = shapeHoles[_i];
  18953. if (ShapeUtils.isClockWise(shapeHole) === true) {
  18954. shapeHoles[_i] = shapeHole.reverse();
  18955. }
  18956. }
  18957. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  18958. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  18959. var _shapeHole = shapeHoles[_i2];
  18960. shapeVertices = shapeVertices.concat(_shapeHole);
  18961. } // vertices, normals, uvs
  18962. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  18963. var vertex = shapeVertices[_i3];
  18964. vertices.push(vertex.x, vertex.y, 0);
  18965. normals.push(0, 0, 1);
  18966. uvs.push(vertex.x, vertex.y); // world uvs
  18967. } // incides
  18968. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  18969. var face = faces[_i4];
  18970. var a = face[0] + indexOffset;
  18971. var b = face[1] + indexOffset;
  18972. var c = face[2] + indexOffset;
  18973. indices.push(a, b, c);
  18974. groupCount += 3;
  18975. }
  18976. }
  18977. return _this;
  18978. }
  18979. var _proto = ShapeGeometry.prototype;
  18980. _proto.toJSON = function toJSON() {
  18981. var data = BufferGeometry.prototype.toJSON.call(this);
  18982. var shapes = this.parameters.shapes;
  18983. return _toJSON$1(shapes, data);
  18984. };
  18985. return ShapeGeometry;
  18986. }(BufferGeometry);
  18987. function _toJSON$1(shapes, data) {
  18988. data.shapes = [];
  18989. if (Array.isArray(shapes)) {
  18990. for (var i = 0, l = shapes.length; i < l; i++) {
  18991. var shape = shapes[i];
  18992. data.shapes.push(shape.uuid);
  18993. }
  18994. } else {
  18995. data.shapes.push(shapes.uuid);
  18996. }
  18997. return data;
  18998. }
  18999. var SphereGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19000. _inheritsLoose(SphereGeometry, _BufferGeometry);
  19001. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19002. var _this;
  19003. if (radius === void 0) {
  19004. radius = 1;
  19005. }
  19006. if (widthSegments === void 0) {
  19007. widthSegments = 8;
  19008. }
  19009. if (heightSegments === void 0) {
  19010. heightSegments = 6;
  19011. }
  19012. if (phiStart === void 0) {
  19013. phiStart = 0;
  19014. }
  19015. if (phiLength === void 0) {
  19016. phiLength = Math.PI * 2;
  19017. }
  19018. if (thetaStart === void 0) {
  19019. thetaStart = 0;
  19020. }
  19021. if (thetaLength === void 0) {
  19022. thetaLength = Math.PI;
  19023. }
  19024. _this = _BufferGeometry.call(this) || this;
  19025. _this.type = 'SphereGeometry';
  19026. _this.parameters = {
  19027. radius: radius,
  19028. widthSegments: widthSegments,
  19029. heightSegments: heightSegments,
  19030. phiStart: phiStart,
  19031. phiLength: phiLength,
  19032. thetaStart: thetaStart,
  19033. thetaLength: thetaLength
  19034. };
  19035. widthSegments = Math.max(3, Math.floor(widthSegments));
  19036. heightSegments = Math.max(2, Math.floor(heightSegments));
  19037. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  19038. var index = 0;
  19039. var grid = [];
  19040. var vertex = new Vector3();
  19041. var normal = new Vector3(); // buffers
  19042. var indices = [];
  19043. var vertices = [];
  19044. var normals = [];
  19045. var uvs = []; // generate vertices, normals and uvs
  19046. for (var iy = 0; iy <= heightSegments; iy++) {
  19047. var verticesRow = [];
  19048. var v = iy / heightSegments; // special case for the poles
  19049. var uOffset = 0;
  19050. if (iy == 0 && thetaStart == 0) {
  19051. uOffset = 0.5 / widthSegments;
  19052. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  19053. uOffset = -0.5 / widthSegments;
  19054. }
  19055. for (var ix = 0; ix <= widthSegments; ix++) {
  19056. var u = ix / widthSegments; // vertex
  19057. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19058. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  19059. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19060. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19061. normal.copy(vertex).normalize();
  19062. normals.push(normal.x, normal.y, normal.z); // uv
  19063. uvs.push(u + uOffset, 1 - v);
  19064. verticesRow.push(index++);
  19065. }
  19066. grid.push(verticesRow);
  19067. } // indices
  19068. for (var _iy = 0; _iy < heightSegments; _iy++) {
  19069. for (var _ix = 0; _ix < widthSegments; _ix++) {
  19070. var a = grid[_iy][_ix + 1];
  19071. var b = grid[_iy][_ix];
  19072. var c = grid[_iy + 1][_ix];
  19073. var d = grid[_iy + 1][_ix + 1];
  19074. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  19075. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  19076. }
  19077. } // build geometry
  19078. _this.setIndex(indices);
  19079. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19080. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19081. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19082. return _this;
  19083. }
  19084. return SphereGeometry;
  19085. }(BufferGeometry);
  19086. var TetrahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  19087. _inheritsLoose(TetrahedronGeometry, _PolyhedronGeometry);
  19088. function TetrahedronGeometry(radius, detail) {
  19089. var _this;
  19090. if (radius === void 0) {
  19091. radius = 1;
  19092. }
  19093. if (detail === void 0) {
  19094. detail = 0;
  19095. }
  19096. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  19097. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  19098. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  19099. _this.type = 'TetrahedronGeometry';
  19100. _this.parameters = {
  19101. radius: radius,
  19102. detail: detail
  19103. };
  19104. return _this;
  19105. }
  19106. return TetrahedronGeometry;
  19107. }(PolyhedronGeometry);
  19108. var TextGeometry = /*#__PURE__*/function (_ExtrudeGeometry) {
  19109. _inheritsLoose(TextGeometry, _ExtrudeGeometry);
  19110. function TextGeometry(text, parameters) {
  19111. var _this;
  19112. if (parameters === void 0) {
  19113. parameters = {};
  19114. }
  19115. var font = parameters.font;
  19116. if (!(font && font.isFont)) {
  19117. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  19118. return new BufferGeometry() || _assertThisInitialized(_this);
  19119. }
  19120. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  19121. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  19122. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  19123. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  19124. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  19125. _this = _ExtrudeGeometry.call(this, shapes, parameters) || this;
  19126. _this.type = 'TextGeometry';
  19127. return _this;
  19128. }
  19129. return TextGeometry;
  19130. }(ExtrudeGeometry);
  19131. var TorusGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19132. _inheritsLoose(TorusGeometry, _BufferGeometry);
  19133. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19134. var _this;
  19135. if (radius === void 0) {
  19136. radius = 1;
  19137. }
  19138. if (tube === void 0) {
  19139. tube = 0.4;
  19140. }
  19141. if (radialSegments === void 0) {
  19142. radialSegments = 8;
  19143. }
  19144. if (tubularSegments === void 0) {
  19145. tubularSegments = 6;
  19146. }
  19147. if (arc === void 0) {
  19148. arc = Math.PI * 2;
  19149. }
  19150. _this = _BufferGeometry.call(this) || this;
  19151. _this.type = 'TorusGeometry';
  19152. _this.parameters = {
  19153. radius: radius,
  19154. tube: tube,
  19155. radialSegments: radialSegments,
  19156. tubularSegments: tubularSegments,
  19157. arc: arc
  19158. };
  19159. radialSegments = Math.floor(radialSegments);
  19160. tubularSegments = Math.floor(tubularSegments); // buffers
  19161. var indices = [];
  19162. var vertices = [];
  19163. var normals = [];
  19164. var uvs = []; // helper variables
  19165. var center = new Vector3();
  19166. var vertex = new Vector3();
  19167. var normal = new Vector3(); // generate vertices, normals and uvs
  19168. for (var j = 0; j <= radialSegments; j++) {
  19169. for (var i = 0; i <= tubularSegments; i++) {
  19170. var u = i / tubularSegments * arc;
  19171. var v = j / radialSegments * Math.PI * 2; // vertex
  19172. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  19173. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  19174. vertex.z = tube * Math.sin(v);
  19175. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19176. center.x = radius * Math.cos(u);
  19177. center.y = radius * Math.sin(u);
  19178. normal.subVectors(vertex, center).normalize();
  19179. normals.push(normal.x, normal.y, normal.z); // uv
  19180. uvs.push(i / tubularSegments);
  19181. uvs.push(j / radialSegments);
  19182. }
  19183. } // generate indices
  19184. for (var _j = 1; _j <= radialSegments; _j++) {
  19185. for (var _i = 1; _i <= tubularSegments; _i++) {
  19186. // indices
  19187. var a = (tubularSegments + 1) * _j + _i - 1;
  19188. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  19189. var c = (tubularSegments + 1) * (_j - 1) + _i;
  19190. var d = (tubularSegments + 1) * _j + _i; // faces
  19191. indices.push(a, b, d);
  19192. indices.push(b, c, d);
  19193. }
  19194. } // build geometry
  19195. _this.setIndex(indices);
  19196. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19197. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19198. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19199. return _this;
  19200. }
  19201. return TorusGeometry;
  19202. }(BufferGeometry);
  19203. var TorusKnotGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19204. _inheritsLoose(TorusKnotGeometry, _BufferGeometry);
  19205. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  19206. var _this;
  19207. if (radius === void 0) {
  19208. radius = 1;
  19209. }
  19210. if (tube === void 0) {
  19211. tube = 0.4;
  19212. }
  19213. if (tubularSegments === void 0) {
  19214. tubularSegments = 64;
  19215. }
  19216. if (radialSegments === void 0) {
  19217. radialSegments = 8;
  19218. }
  19219. if (p === void 0) {
  19220. p = 2;
  19221. }
  19222. if (q === void 0) {
  19223. q = 3;
  19224. }
  19225. _this = _BufferGeometry.call(this) || this;
  19226. _this.type = 'TorusKnotGeometry';
  19227. _this.parameters = {
  19228. radius: radius,
  19229. tube: tube,
  19230. tubularSegments: tubularSegments,
  19231. radialSegments: radialSegments,
  19232. p: p,
  19233. q: q
  19234. };
  19235. tubularSegments = Math.floor(tubularSegments);
  19236. radialSegments = Math.floor(radialSegments); // buffers
  19237. var indices = [];
  19238. var vertices = [];
  19239. var normals = [];
  19240. var uvs = []; // helper variables
  19241. var vertex = new Vector3();
  19242. var normal = new Vector3();
  19243. var P1 = new Vector3();
  19244. var P2 = new Vector3();
  19245. var B = new Vector3();
  19246. var T = new Vector3();
  19247. var N = new Vector3(); // generate vertices, normals and uvs
  19248. for (var i = 0; i <= tubularSegments; ++i) {
  19249. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19250. 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.
  19251. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19252. calculatePositionOnCurve(u, p, q, radius, P1);
  19253. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  19254. T.subVectors(P2, P1);
  19255. N.addVectors(P2, P1);
  19256. B.crossVectors(T, N);
  19257. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  19258. B.normalize();
  19259. N.normalize();
  19260. for (var j = 0; j <= radialSegments; ++j) {
  19261. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19262. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19263. var v = j / radialSegments * Math.PI * 2;
  19264. var cx = -tube * Math.cos(v);
  19265. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  19266. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19267. vertex.x = P1.x + (cx * N.x + cy * B.x);
  19268. vertex.y = P1.y + (cx * N.y + cy * B.y);
  19269. vertex.z = P1.z + (cx * N.z + cy * B.z);
  19270. 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)
  19271. normal.subVectors(vertex, P1).normalize();
  19272. normals.push(normal.x, normal.y, normal.z); // uv
  19273. uvs.push(i / tubularSegments);
  19274. uvs.push(j / radialSegments);
  19275. }
  19276. } // generate indices
  19277. for (var _j = 1; _j <= tubularSegments; _j++) {
  19278. for (var _i = 1; _i <= radialSegments; _i++) {
  19279. // indices
  19280. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  19281. var b = (radialSegments + 1) * _j + (_i - 1);
  19282. var c = (radialSegments + 1) * _j + _i;
  19283. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  19284. indices.push(a, b, d);
  19285. indices.push(b, c, d);
  19286. }
  19287. } // build geometry
  19288. _this.setIndex(indices);
  19289. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19290. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19291. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  19292. function calculatePositionOnCurve(u, p, q, radius, position) {
  19293. var cu = Math.cos(u);
  19294. var su = Math.sin(u);
  19295. var quOverP = q / p * u;
  19296. var cs = Math.cos(quOverP);
  19297. position.x = radius * (2 + cs) * 0.5 * cu;
  19298. position.y = radius * (2 + cs) * su * 0.5;
  19299. position.z = radius * Math.sin(quOverP) * 0.5;
  19300. }
  19301. return _this;
  19302. }
  19303. return TorusKnotGeometry;
  19304. }(BufferGeometry);
  19305. var TubeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19306. _inheritsLoose(TubeGeometry, _BufferGeometry);
  19307. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed) {
  19308. var _this;
  19309. if (tubularSegments === void 0) {
  19310. tubularSegments = 64;
  19311. }
  19312. if (radius === void 0) {
  19313. radius = 1;
  19314. }
  19315. if (radialSegments === void 0) {
  19316. radialSegments = 8;
  19317. }
  19318. if (closed === void 0) {
  19319. closed = false;
  19320. }
  19321. _this = _BufferGeometry.call(this) || this;
  19322. _this.type = 'TubeGeometry';
  19323. _this.parameters = {
  19324. path: path,
  19325. tubularSegments: tubularSegments,
  19326. radius: radius,
  19327. radialSegments: radialSegments,
  19328. closed: closed
  19329. };
  19330. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  19331. _this.tangents = frames.tangents;
  19332. _this.normals = frames.normals;
  19333. _this.binormals = frames.binormals; // helper variables
  19334. var vertex = new Vector3();
  19335. var normal = new Vector3();
  19336. var uv = new Vector2();
  19337. var P = new Vector3(); // buffer
  19338. var vertices = [];
  19339. var normals = [];
  19340. var uvs = [];
  19341. var indices = []; // create buffer data
  19342. generateBufferData(); // build geometry
  19343. _this.setIndex(indices);
  19344. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19345. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19346. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  19347. function generateBufferData() {
  19348. for (var i = 0; i < tubularSegments; i++) {
  19349. generateSegment(i);
  19350. } // if the geometry is not closed, generate the last row of vertices and normals
  19351. // at the regular position on the given path
  19352. //
  19353. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19354. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  19355. // this makes it easy compute correct values for closed geometries
  19356. generateUVs(); // finally create faces
  19357. generateIndices();
  19358. }
  19359. function generateSegment(i) {
  19360. // we use getPointAt to sample evenly distributed points from the given path
  19361. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  19362. var N = frames.normals[i];
  19363. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  19364. for (var j = 0; j <= radialSegments; j++) {
  19365. var v = j / radialSegments * Math.PI * 2;
  19366. var sin = Math.sin(v);
  19367. var cos = -Math.cos(v); // normal
  19368. normal.x = cos * N.x + sin * B.x;
  19369. normal.y = cos * N.y + sin * B.y;
  19370. normal.z = cos * N.z + sin * B.z;
  19371. normal.normalize();
  19372. normals.push(normal.x, normal.y, normal.z); // vertex
  19373. vertex.x = P.x + radius * normal.x;
  19374. vertex.y = P.y + radius * normal.y;
  19375. vertex.z = P.z + radius * normal.z;
  19376. vertices.push(vertex.x, vertex.y, vertex.z);
  19377. }
  19378. }
  19379. function generateIndices() {
  19380. for (var j = 1; j <= tubularSegments; j++) {
  19381. for (var i = 1; i <= radialSegments; i++) {
  19382. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  19383. var b = (radialSegments + 1) * j + (i - 1);
  19384. var c = (radialSegments + 1) * j + i;
  19385. var d = (radialSegments + 1) * (j - 1) + i; // faces
  19386. indices.push(a, b, d);
  19387. indices.push(b, c, d);
  19388. }
  19389. }
  19390. }
  19391. function generateUVs() {
  19392. for (var i = 0; i <= tubularSegments; i++) {
  19393. for (var j = 0; j <= radialSegments; j++) {
  19394. uv.x = i / tubularSegments;
  19395. uv.y = j / radialSegments;
  19396. uvs.push(uv.x, uv.y);
  19397. }
  19398. }
  19399. }
  19400. return _this;
  19401. }
  19402. var _proto = TubeGeometry.prototype;
  19403. _proto.toJSON = function toJSON() {
  19404. var data = BufferGeometry.prototype.toJSON.call(this);
  19405. data.path = this.parameters.path.toJSON();
  19406. return data;
  19407. };
  19408. return TubeGeometry;
  19409. }(BufferGeometry);
  19410. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19411. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  19412. function WireframeGeometry(geometry) {
  19413. var _this;
  19414. _this = _BufferGeometry.call(this) || this;
  19415. _this.type = 'WireframeGeometry';
  19416. if (geometry.isGeometry === true) {
  19417. console.error('THREE.WireframeGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  19418. return _assertThisInitialized(_this);
  19419. } // buffer
  19420. var vertices = []; // helper variables
  19421. var edge = [0, 0],
  19422. edges = {};
  19423. var vertex = new Vector3();
  19424. if (geometry.index !== null) {
  19425. // indexed BufferGeometry
  19426. var position = geometry.attributes.position;
  19427. var indices = geometry.index;
  19428. var groups = geometry.groups;
  19429. if (groups.length === 0) {
  19430. groups = [{
  19431. start: 0,
  19432. count: indices.count,
  19433. materialIndex: 0
  19434. }];
  19435. } // create a data structure that contains all eges without duplicates
  19436. for (var o = 0, ol = groups.length; o < ol; ++o) {
  19437. var group = groups[o];
  19438. var start = group.start;
  19439. var count = group.count;
  19440. for (var i = start, l = start + count; i < l; i += 3) {
  19441. for (var j = 0; j < 3; j++) {
  19442. var edge1 = indices.getX(i + j);
  19443. var edge2 = indices.getX(i + (j + 1) % 3);
  19444. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  19445. edge[1] = Math.max(edge1, edge2);
  19446. var key = edge[0] + ',' + edge[1];
  19447. if (edges[key] === undefined) {
  19448. edges[key] = {
  19449. index1: edge[0],
  19450. index2: edge[1]
  19451. };
  19452. }
  19453. }
  19454. }
  19455. } // generate vertices
  19456. for (var _key in edges) {
  19457. var e = edges[_key];
  19458. vertex.fromBufferAttribute(position, e.index1);
  19459. vertices.push(vertex.x, vertex.y, vertex.z);
  19460. vertex.fromBufferAttribute(position, e.index2);
  19461. vertices.push(vertex.x, vertex.y, vertex.z);
  19462. }
  19463. } else {
  19464. // non-indexed BufferGeometry
  19465. var _position = geometry.attributes.position;
  19466. for (var _i = 0, _l = _position.count / 3; _i < _l; _i++) {
  19467. for (var _j = 0; _j < 3; _j++) {
  19468. // three edges per triangle, an edge is represented as (index1, index2)
  19469. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  19470. var index1 = 3 * _i + _j;
  19471. vertex.fromBufferAttribute(_position, index1);
  19472. vertices.push(vertex.x, vertex.y, vertex.z);
  19473. var index2 = 3 * _i + (_j + 1) % 3;
  19474. vertex.fromBufferAttribute(_position, index2);
  19475. vertices.push(vertex.x, vertex.y, vertex.z);
  19476. }
  19477. }
  19478. } // build geometry
  19479. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19480. return _this;
  19481. }
  19482. return WireframeGeometry;
  19483. }(BufferGeometry);
  19484. var Geometries = /*#__PURE__*/Object.freeze({
  19485. __proto__: null,
  19486. BoxGeometry: BoxGeometry,
  19487. BoxBufferGeometry: BoxGeometry,
  19488. CircleGeometry: CircleGeometry,
  19489. CircleBufferGeometry: CircleGeometry,
  19490. ConeGeometry: ConeGeometry,
  19491. ConeBufferGeometry: ConeGeometry,
  19492. CylinderGeometry: CylinderGeometry,
  19493. CylinderBufferGeometry: CylinderGeometry,
  19494. DodecahedronGeometry: DodecahedronGeometry,
  19495. DodecahedronBufferGeometry: DodecahedronGeometry,
  19496. EdgesGeometry: EdgesGeometry,
  19497. ExtrudeGeometry: ExtrudeGeometry,
  19498. ExtrudeBufferGeometry: ExtrudeGeometry,
  19499. IcosahedronGeometry: IcosahedronGeometry,
  19500. IcosahedronBufferGeometry: IcosahedronGeometry,
  19501. LatheGeometry: LatheGeometry,
  19502. LatheBufferGeometry: LatheGeometry,
  19503. OctahedronGeometry: OctahedronGeometry,
  19504. OctahedronBufferGeometry: OctahedronGeometry,
  19505. ParametricGeometry: ParametricGeometry,
  19506. ParametricBufferGeometry: ParametricGeometry,
  19507. PlaneGeometry: PlaneGeometry,
  19508. PlaneBufferGeometry: PlaneGeometry,
  19509. PolyhedronGeometry: PolyhedronGeometry,
  19510. PolyhedronBufferGeometry: PolyhedronGeometry,
  19511. RingGeometry: RingGeometry,
  19512. RingBufferGeometry: RingGeometry,
  19513. ShapeGeometry: ShapeGeometry,
  19514. ShapeBufferGeometry: ShapeGeometry,
  19515. SphereGeometry: SphereGeometry,
  19516. SphereBufferGeometry: SphereGeometry,
  19517. TetrahedronGeometry: TetrahedronGeometry,
  19518. TetrahedronBufferGeometry: TetrahedronGeometry,
  19519. TextGeometry: TextGeometry,
  19520. TextBufferGeometry: TextGeometry,
  19521. TorusGeometry: TorusGeometry,
  19522. TorusBufferGeometry: TorusGeometry,
  19523. TorusKnotGeometry: TorusKnotGeometry,
  19524. TorusKnotBufferGeometry: TorusKnotGeometry,
  19525. TubeGeometry: TubeGeometry,
  19526. TubeBufferGeometry: TubeGeometry,
  19527. WireframeGeometry: WireframeGeometry
  19528. });
  19529. /**
  19530. * parameters = {
  19531. * color: <THREE.Color>
  19532. * }
  19533. */
  19534. function ShadowMaterial(parameters) {
  19535. Material.call(this);
  19536. this.type = 'ShadowMaterial';
  19537. this.color = new Color(0x000000);
  19538. this.transparent = true;
  19539. this.setValues(parameters);
  19540. }
  19541. ShadowMaterial.prototype = Object.create(Material.prototype);
  19542. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19543. ShadowMaterial.prototype.isShadowMaterial = true;
  19544. ShadowMaterial.prototype.copy = function (source) {
  19545. Material.prototype.copy.call(this, source);
  19546. this.color.copy(source.color);
  19547. return this;
  19548. };
  19549. function RawShaderMaterial(parameters) {
  19550. ShaderMaterial.call(this, parameters);
  19551. this.type = 'RawShaderMaterial';
  19552. }
  19553. RawShaderMaterial.prototype = Object.create(ShaderMaterial.prototype);
  19554. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19555. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19556. /**
  19557. * parameters = {
  19558. * color: <hex>,
  19559. * roughness: <float>,
  19560. * metalness: <float>,
  19561. * opacity: <float>,
  19562. *
  19563. * map: new THREE.Texture( <Image> ),
  19564. *
  19565. * lightMap: new THREE.Texture( <Image> ),
  19566. * lightMapIntensity: <float>
  19567. *
  19568. * aoMap: new THREE.Texture( <Image> ),
  19569. * aoMapIntensity: <float>
  19570. *
  19571. * emissive: <hex>,
  19572. * emissiveIntensity: <float>
  19573. * emissiveMap: new THREE.Texture( <Image> ),
  19574. *
  19575. * bumpMap: new THREE.Texture( <Image> ),
  19576. * bumpScale: <float>,
  19577. *
  19578. * normalMap: new THREE.Texture( <Image> ),
  19579. * normalMapType: THREE.TangentSpaceNormalMap,
  19580. * normalScale: <Vector2>,
  19581. *
  19582. * displacementMap: new THREE.Texture( <Image> ),
  19583. * displacementScale: <float>,
  19584. * displacementBias: <float>,
  19585. *
  19586. * roughnessMap: new THREE.Texture( <Image> ),
  19587. *
  19588. * metalnessMap: new THREE.Texture( <Image> ),
  19589. *
  19590. * alphaMap: new THREE.Texture( <Image> ),
  19591. *
  19592. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19593. * envMapIntensity: <float>
  19594. *
  19595. * refractionRatio: <float>,
  19596. *
  19597. * wireframe: <boolean>,
  19598. * wireframeLinewidth: <float>,
  19599. *
  19600. * skinning: <bool>,
  19601. * morphTargets: <bool>,
  19602. * morphNormals: <bool>,
  19603. *
  19604. * flatShading: <bool>
  19605. * }
  19606. */
  19607. function MeshStandardMaterial(parameters) {
  19608. Material.call(this);
  19609. this.defines = {
  19610. 'STANDARD': ''
  19611. };
  19612. this.type = 'MeshStandardMaterial';
  19613. this.color = new Color(0xffffff); // diffuse
  19614. this.roughness = 1.0;
  19615. this.metalness = 0.0;
  19616. this.map = null;
  19617. this.lightMap = null;
  19618. this.lightMapIntensity = 1.0;
  19619. this.aoMap = null;
  19620. this.aoMapIntensity = 1.0;
  19621. this.emissive = new Color(0x000000);
  19622. this.emissiveIntensity = 1.0;
  19623. this.emissiveMap = null;
  19624. this.bumpMap = null;
  19625. this.bumpScale = 1;
  19626. this.normalMap = null;
  19627. this.normalMapType = TangentSpaceNormalMap;
  19628. this.normalScale = new Vector2(1, 1);
  19629. this.displacementMap = null;
  19630. this.displacementScale = 1;
  19631. this.displacementBias = 0;
  19632. this.roughnessMap = null;
  19633. this.metalnessMap = null;
  19634. this.alphaMap = null;
  19635. this.envMap = null;
  19636. this.envMapIntensity = 1.0;
  19637. this.refractionRatio = 0.98;
  19638. this.wireframe = false;
  19639. this.wireframeLinewidth = 1;
  19640. this.wireframeLinecap = 'round';
  19641. this.wireframeLinejoin = 'round';
  19642. this.skinning = false;
  19643. this.morphTargets = false;
  19644. this.morphNormals = false;
  19645. this.flatShading = false;
  19646. this.vertexTangents = false;
  19647. this.setValues(parameters);
  19648. }
  19649. MeshStandardMaterial.prototype = Object.create(Material.prototype);
  19650. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19651. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19652. MeshStandardMaterial.prototype.copy = function (source) {
  19653. Material.prototype.copy.call(this, source);
  19654. this.defines = {
  19655. 'STANDARD': ''
  19656. };
  19657. this.color.copy(source.color);
  19658. this.roughness = source.roughness;
  19659. this.metalness = source.metalness;
  19660. this.map = source.map;
  19661. this.lightMap = source.lightMap;
  19662. this.lightMapIntensity = source.lightMapIntensity;
  19663. this.aoMap = source.aoMap;
  19664. this.aoMapIntensity = source.aoMapIntensity;
  19665. this.emissive.copy(source.emissive);
  19666. this.emissiveMap = source.emissiveMap;
  19667. this.emissiveIntensity = source.emissiveIntensity;
  19668. this.bumpMap = source.bumpMap;
  19669. this.bumpScale = source.bumpScale;
  19670. this.normalMap = source.normalMap;
  19671. this.normalMapType = source.normalMapType;
  19672. this.normalScale.copy(source.normalScale);
  19673. this.displacementMap = source.displacementMap;
  19674. this.displacementScale = source.displacementScale;
  19675. this.displacementBias = source.displacementBias;
  19676. this.roughnessMap = source.roughnessMap;
  19677. this.metalnessMap = source.metalnessMap;
  19678. this.alphaMap = source.alphaMap;
  19679. this.envMap = source.envMap;
  19680. this.envMapIntensity = source.envMapIntensity;
  19681. this.refractionRatio = source.refractionRatio;
  19682. this.wireframe = source.wireframe;
  19683. this.wireframeLinewidth = source.wireframeLinewidth;
  19684. this.wireframeLinecap = source.wireframeLinecap;
  19685. this.wireframeLinejoin = source.wireframeLinejoin;
  19686. this.skinning = source.skinning;
  19687. this.morphTargets = source.morphTargets;
  19688. this.morphNormals = source.morphNormals;
  19689. this.flatShading = source.flatShading;
  19690. this.vertexTangents = source.vertexTangents;
  19691. return this;
  19692. };
  19693. /**
  19694. * parameters = {
  19695. * clearcoat: <float>,
  19696. * clearcoatMap: new THREE.Texture( <Image> ),
  19697. * clearcoatRoughness: <float>,
  19698. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  19699. * clearcoatNormalScale: <Vector2>,
  19700. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  19701. *
  19702. * reflectivity: <float>,
  19703. * ior: <float>,
  19704. *
  19705. * sheen: <Color>,
  19706. *
  19707. * transmission: <float>,
  19708. * transmissionMap: new THREE.Texture( <Image> )
  19709. * }
  19710. */
  19711. function MeshPhysicalMaterial(parameters) {
  19712. MeshStandardMaterial.call(this);
  19713. this.defines = {
  19714. 'STANDARD': '',
  19715. 'PHYSICAL': ''
  19716. };
  19717. this.type = 'MeshPhysicalMaterial';
  19718. this.clearcoat = 0.0;
  19719. this.clearcoatMap = null;
  19720. this.clearcoatRoughness = 0.0;
  19721. this.clearcoatRoughnessMap = null;
  19722. this.clearcoatNormalScale = new Vector2(1, 1);
  19723. this.clearcoatNormalMap = null;
  19724. this.reflectivity = 0.5; // maps to F0 = 0.04
  19725. Object.defineProperty(this, 'ior', {
  19726. get: function get() {
  19727. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  19728. },
  19729. set: function set(ior) {
  19730. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  19731. }
  19732. });
  19733. this.sheen = null; // null will disable sheen bsdf
  19734. this.transmission = 0.0;
  19735. this.transmissionMap = null;
  19736. this.setValues(parameters);
  19737. }
  19738. MeshPhysicalMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
  19739. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  19740. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19741. MeshPhysicalMaterial.prototype.copy = function (source) {
  19742. MeshStandardMaterial.prototype.copy.call(this, source);
  19743. this.defines = {
  19744. 'STANDARD': '',
  19745. 'PHYSICAL': ''
  19746. };
  19747. this.clearcoat = source.clearcoat;
  19748. this.clearcoatMap = source.clearcoatMap;
  19749. this.clearcoatRoughness = source.clearcoatRoughness;
  19750. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  19751. this.clearcoatNormalMap = source.clearcoatNormalMap;
  19752. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  19753. this.reflectivity = source.reflectivity;
  19754. if (source.sheen) {
  19755. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  19756. } else {
  19757. this.sheen = null;
  19758. }
  19759. this.transmission = source.transmission;
  19760. this.transmissionMap = source.transmissionMap;
  19761. return this;
  19762. };
  19763. /**
  19764. * parameters = {
  19765. * color: <hex>,
  19766. * specular: <hex>,
  19767. * shininess: <float>,
  19768. * opacity: <float>,
  19769. *
  19770. * map: new THREE.Texture( <Image> ),
  19771. *
  19772. * lightMap: new THREE.Texture( <Image> ),
  19773. * lightMapIntensity: <float>
  19774. *
  19775. * aoMap: new THREE.Texture( <Image> ),
  19776. * aoMapIntensity: <float>
  19777. *
  19778. * emissive: <hex>,
  19779. * emissiveIntensity: <float>
  19780. * emissiveMap: new THREE.Texture( <Image> ),
  19781. *
  19782. * bumpMap: new THREE.Texture( <Image> ),
  19783. * bumpScale: <float>,
  19784. *
  19785. * normalMap: new THREE.Texture( <Image> ),
  19786. * normalMapType: THREE.TangentSpaceNormalMap,
  19787. * normalScale: <Vector2>,
  19788. *
  19789. * displacementMap: new THREE.Texture( <Image> ),
  19790. * displacementScale: <float>,
  19791. * displacementBias: <float>,
  19792. *
  19793. * specularMap: new THREE.Texture( <Image> ),
  19794. *
  19795. * alphaMap: new THREE.Texture( <Image> ),
  19796. *
  19797. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19798. * combine: THREE.MultiplyOperation,
  19799. * reflectivity: <float>,
  19800. * refractionRatio: <float>,
  19801. *
  19802. * wireframe: <boolean>,
  19803. * wireframeLinewidth: <float>,
  19804. *
  19805. * skinning: <bool>,
  19806. * morphTargets: <bool>,
  19807. * morphNormals: <bool>,
  19808. *
  19809. * flatShading: <bool>
  19810. * }
  19811. */
  19812. function MeshPhongMaterial(parameters) {
  19813. Material.call(this);
  19814. this.type = 'MeshPhongMaterial';
  19815. this.color = new Color(0xffffff); // diffuse
  19816. this.specular = new Color(0x111111);
  19817. this.shininess = 30;
  19818. this.map = null;
  19819. this.lightMap = null;
  19820. this.lightMapIntensity = 1.0;
  19821. this.aoMap = null;
  19822. this.aoMapIntensity = 1.0;
  19823. this.emissive = new Color(0x000000);
  19824. this.emissiveIntensity = 1.0;
  19825. this.emissiveMap = null;
  19826. this.bumpMap = null;
  19827. this.bumpScale = 1;
  19828. this.normalMap = null;
  19829. this.normalMapType = TangentSpaceNormalMap;
  19830. this.normalScale = new Vector2(1, 1);
  19831. this.displacementMap = null;
  19832. this.displacementScale = 1;
  19833. this.displacementBias = 0;
  19834. this.specularMap = null;
  19835. this.alphaMap = null;
  19836. this.envMap = null;
  19837. this.combine = MultiplyOperation;
  19838. this.reflectivity = 1;
  19839. this.refractionRatio = 0.98;
  19840. this.wireframe = false;
  19841. this.wireframeLinewidth = 1;
  19842. this.wireframeLinecap = 'round';
  19843. this.wireframeLinejoin = 'round';
  19844. this.skinning = false;
  19845. this.morphTargets = false;
  19846. this.morphNormals = false;
  19847. this.flatShading = false;
  19848. this.setValues(parameters);
  19849. }
  19850. MeshPhongMaterial.prototype = Object.create(Material.prototype);
  19851. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  19852. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  19853. MeshPhongMaterial.prototype.copy = function (source) {
  19854. Material.prototype.copy.call(this, source);
  19855. this.color.copy(source.color);
  19856. this.specular.copy(source.specular);
  19857. this.shininess = source.shininess;
  19858. this.map = source.map;
  19859. this.lightMap = source.lightMap;
  19860. this.lightMapIntensity = source.lightMapIntensity;
  19861. this.aoMap = source.aoMap;
  19862. this.aoMapIntensity = source.aoMapIntensity;
  19863. this.emissive.copy(source.emissive);
  19864. this.emissiveMap = source.emissiveMap;
  19865. this.emissiveIntensity = source.emissiveIntensity;
  19866. this.bumpMap = source.bumpMap;
  19867. this.bumpScale = source.bumpScale;
  19868. this.normalMap = source.normalMap;
  19869. this.normalMapType = source.normalMapType;
  19870. this.normalScale.copy(source.normalScale);
  19871. this.displacementMap = source.displacementMap;
  19872. this.displacementScale = source.displacementScale;
  19873. this.displacementBias = source.displacementBias;
  19874. this.specularMap = source.specularMap;
  19875. this.alphaMap = source.alphaMap;
  19876. this.envMap = source.envMap;
  19877. this.combine = source.combine;
  19878. this.reflectivity = source.reflectivity;
  19879. this.refractionRatio = source.refractionRatio;
  19880. this.wireframe = source.wireframe;
  19881. this.wireframeLinewidth = source.wireframeLinewidth;
  19882. this.wireframeLinecap = source.wireframeLinecap;
  19883. this.wireframeLinejoin = source.wireframeLinejoin;
  19884. this.skinning = source.skinning;
  19885. this.morphTargets = source.morphTargets;
  19886. this.morphNormals = source.morphNormals;
  19887. this.flatShading = source.flatShading;
  19888. return this;
  19889. };
  19890. /**
  19891. * parameters = {
  19892. * color: <hex>,
  19893. *
  19894. * map: new THREE.Texture( <Image> ),
  19895. * gradientMap: new THREE.Texture( <Image> ),
  19896. *
  19897. * lightMap: new THREE.Texture( <Image> ),
  19898. * lightMapIntensity: <float>
  19899. *
  19900. * aoMap: new THREE.Texture( <Image> ),
  19901. * aoMapIntensity: <float>
  19902. *
  19903. * emissive: <hex>,
  19904. * emissiveIntensity: <float>
  19905. * emissiveMap: new THREE.Texture( <Image> ),
  19906. *
  19907. * bumpMap: new THREE.Texture( <Image> ),
  19908. * bumpScale: <float>,
  19909. *
  19910. * normalMap: new THREE.Texture( <Image> ),
  19911. * normalMapType: THREE.TangentSpaceNormalMap,
  19912. * normalScale: <Vector2>,
  19913. *
  19914. * displacementMap: new THREE.Texture( <Image> ),
  19915. * displacementScale: <float>,
  19916. * displacementBias: <float>,
  19917. *
  19918. * alphaMap: new THREE.Texture( <Image> ),
  19919. *
  19920. * wireframe: <boolean>,
  19921. * wireframeLinewidth: <float>,
  19922. *
  19923. * skinning: <bool>,
  19924. * morphTargets: <bool>,
  19925. * morphNormals: <bool>
  19926. * }
  19927. */
  19928. function MeshToonMaterial(parameters) {
  19929. Material.call(this);
  19930. this.defines = {
  19931. 'TOON': ''
  19932. };
  19933. this.type = 'MeshToonMaterial';
  19934. this.color = new Color(0xffffff);
  19935. this.map = null;
  19936. this.gradientMap = null;
  19937. this.lightMap = null;
  19938. this.lightMapIntensity = 1.0;
  19939. this.aoMap = null;
  19940. this.aoMapIntensity = 1.0;
  19941. this.emissive = new Color(0x000000);
  19942. this.emissiveIntensity = 1.0;
  19943. this.emissiveMap = null;
  19944. this.bumpMap = null;
  19945. this.bumpScale = 1;
  19946. this.normalMap = null;
  19947. this.normalMapType = TangentSpaceNormalMap;
  19948. this.normalScale = new Vector2(1, 1);
  19949. this.displacementMap = null;
  19950. this.displacementScale = 1;
  19951. this.displacementBias = 0;
  19952. this.alphaMap = null;
  19953. this.wireframe = false;
  19954. this.wireframeLinewidth = 1;
  19955. this.wireframeLinecap = 'round';
  19956. this.wireframeLinejoin = 'round';
  19957. this.skinning = false;
  19958. this.morphTargets = false;
  19959. this.morphNormals = false;
  19960. this.setValues(parameters);
  19961. }
  19962. MeshToonMaterial.prototype = Object.create(Material.prototype);
  19963. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  19964. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  19965. MeshToonMaterial.prototype.copy = function (source) {
  19966. Material.prototype.copy.call(this, source);
  19967. this.color.copy(source.color);
  19968. this.map = source.map;
  19969. this.gradientMap = source.gradientMap;
  19970. this.lightMap = source.lightMap;
  19971. this.lightMapIntensity = source.lightMapIntensity;
  19972. this.aoMap = source.aoMap;
  19973. this.aoMapIntensity = source.aoMapIntensity;
  19974. this.emissive.copy(source.emissive);
  19975. this.emissiveMap = source.emissiveMap;
  19976. this.emissiveIntensity = source.emissiveIntensity;
  19977. this.bumpMap = source.bumpMap;
  19978. this.bumpScale = source.bumpScale;
  19979. this.normalMap = source.normalMap;
  19980. this.normalMapType = source.normalMapType;
  19981. this.normalScale.copy(source.normalScale);
  19982. this.displacementMap = source.displacementMap;
  19983. this.displacementScale = source.displacementScale;
  19984. this.displacementBias = source.displacementBias;
  19985. this.alphaMap = source.alphaMap;
  19986. this.wireframe = source.wireframe;
  19987. this.wireframeLinewidth = source.wireframeLinewidth;
  19988. this.wireframeLinecap = source.wireframeLinecap;
  19989. this.wireframeLinejoin = source.wireframeLinejoin;
  19990. this.skinning = source.skinning;
  19991. this.morphTargets = source.morphTargets;
  19992. this.morphNormals = source.morphNormals;
  19993. return this;
  19994. };
  19995. /**
  19996. * parameters = {
  19997. * opacity: <float>,
  19998. *
  19999. * bumpMap: new THREE.Texture( <Image> ),
  20000. * bumpScale: <float>,
  20001. *
  20002. * normalMap: new THREE.Texture( <Image> ),
  20003. * normalMapType: THREE.TangentSpaceNormalMap,
  20004. * normalScale: <Vector2>,
  20005. *
  20006. * displacementMap: new THREE.Texture( <Image> ),
  20007. * displacementScale: <float>,
  20008. * displacementBias: <float>,
  20009. *
  20010. * wireframe: <boolean>,
  20011. * wireframeLinewidth: <float>
  20012. *
  20013. * skinning: <bool>,
  20014. * morphTargets: <bool>,
  20015. * morphNormals: <bool>,
  20016. *
  20017. * flatShading: <bool>
  20018. * }
  20019. */
  20020. function MeshNormalMaterial(parameters) {
  20021. Material.call(this);
  20022. this.type = 'MeshNormalMaterial';
  20023. this.bumpMap = null;
  20024. this.bumpScale = 1;
  20025. this.normalMap = null;
  20026. this.normalMapType = TangentSpaceNormalMap;
  20027. this.normalScale = new Vector2(1, 1);
  20028. this.displacementMap = null;
  20029. this.displacementScale = 1;
  20030. this.displacementBias = 0;
  20031. this.wireframe = false;
  20032. this.wireframeLinewidth = 1;
  20033. this.fog = false;
  20034. this.skinning = false;
  20035. this.morphTargets = false;
  20036. this.morphNormals = false;
  20037. this.flatShading = false;
  20038. this.setValues(parameters);
  20039. }
  20040. MeshNormalMaterial.prototype = Object.create(Material.prototype);
  20041. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  20042. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20043. MeshNormalMaterial.prototype.copy = function (source) {
  20044. Material.prototype.copy.call(this, source);
  20045. this.bumpMap = source.bumpMap;
  20046. this.bumpScale = source.bumpScale;
  20047. this.normalMap = source.normalMap;
  20048. this.normalMapType = source.normalMapType;
  20049. this.normalScale.copy(source.normalScale);
  20050. this.displacementMap = source.displacementMap;
  20051. this.displacementScale = source.displacementScale;
  20052. this.displacementBias = source.displacementBias;
  20053. this.wireframe = source.wireframe;
  20054. this.wireframeLinewidth = source.wireframeLinewidth;
  20055. this.skinning = source.skinning;
  20056. this.morphTargets = source.morphTargets;
  20057. this.morphNormals = source.morphNormals;
  20058. this.flatShading = source.flatShading;
  20059. return this;
  20060. };
  20061. /**
  20062. * parameters = {
  20063. * color: <hex>,
  20064. * opacity: <float>,
  20065. *
  20066. * map: new THREE.Texture( <Image> ),
  20067. *
  20068. * lightMap: new THREE.Texture( <Image> ),
  20069. * lightMapIntensity: <float>
  20070. *
  20071. * aoMap: new THREE.Texture( <Image> ),
  20072. * aoMapIntensity: <float>
  20073. *
  20074. * emissive: <hex>,
  20075. * emissiveIntensity: <float>
  20076. * emissiveMap: new THREE.Texture( <Image> ),
  20077. *
  20078. * specularMap: new THREE.Texture( <Image> ),
  20079. *
  20080. * alphaMap: new THREE.Texture( <Image> ),
  20081. *
  20082. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20083. * combine: THREE.Multiply,
  20084. * reflectivity: <float>,
  20085. * refractionRatio: <float>,
  20086. *
  20087. * wireframe: <boolean>,
  20088. * wireframeLinewidth: <float>,
  20089. *
  20090. * skinning: <bool>,
  20091. * morphTargets: <bool>,
  20092. * morphNormals: <bool>
  20093. * }
  20094. */
  20095. function MeshLambertMaterial(parameters) {
  20096. Material.call(this);
  20097. this.type = 'MeshLambertMaterial';
  20098. this.color = new Color(0xffffff); // diffuse
  20099. this.map = null;
  20100. this.lightMap = null;
  20101. this.lightMapIntensity = 1.0;
  20102. this.aoMap = null;
  20103. this.aoMapIntensity = 1.0;
  20104. this.emissive = new Color(0x000000);
  20105. this.emissiveIntensity = 1.0;
  20106. this.emissiveMap = null;
  20107. this.specularMap = null;
  20108. this.alphaMap = null;
  20109. this.envMap = null;
  20110. this.combine = MultiplyOperation;
  20111. this.reflectivity = 1;
  20112. this.refractionRatio = 0.98;
  20113. this.wireframe = false;
  20114. this.wireframeLinewidth = 1;
  20115. this.wireframeLinecap = 'round';
  20116. this.wireframeLinejoin = 'round';
  20117. this.skinning = false;
  20118. this.morphTargets = false;
  20119. this.morphNormals = false;
  20120. this.setValues(parameters);
  20121. }
  20122. MeshLambertMaterial.prototype = Object.create(Material.prototype);
  20123. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20124. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20125. MeshLambertMaterial.prototype.copy = function (source) {
  20126. Material.prototype.copy.call(this, source);
  20127. this.color.copy(source.color);
  20128. this.map = source.map;
  20129. this.lightMap = source.lightMap;
  20130. this.lightMapIntensity = source.lightMapIntensity;
  20131. this.aoMap = source.aoMap;
  20132. this.aoMapIntensity = source.aoMapIntensity;
  20133. this.emissive.copy(source.emissive);
  20134. this.emissiveMap = source.emissiveMap;
  20135. this.emissiveIntensity = source.emissiveIntensity;
  20136. this.specularMap = source.specularMap;
  20137. this.alphaMap = source.alphaMap;
  20138. this.envMap = source.envMap;
  20139. this.combine = source.combine;
  20140. this.reflectivity = source.reflectivity;
  20141. this.refractionRatio = source.refractionRatio;
  20142. this.wireframe = source.wireframe;
  20143. this.wireframeLinewidth = source.wireframeLinewidth;
  20144. this.wireframeLinecap = source.wireframeLinecap;
  20145. this.wireframeLinejoin = source.wireframeLinejoin;
  20146. this.skinning = source.skinning;
  20147. this.morphTargets = source.morphTargets;
  20148. this.morphNormals = source.morphNormals;
  20149. return this;
  20150. };
  20151. /**
  20152. * parameters = {
  20153. * color: <hex>,
  20154. * opacity: <float>,
  20155. *
  20156. * matcap: new THREE.Texture( <Image> ),
  20157. *
  20158. * map: new THREE.Texture( <Image> ),
  20159. *
  20160. * bumpMap: new THREE.Texture( <Image> ),
  20161. * bumpScale: <float>,
  20162. *
  20163. * normalMap: new THREE.Texture( <Image> ),
  20164. * normalMapType: THREE.TangentSpaceNormalMap,
  20165. * normalScale: <Vector2>,
  20166. *
  20167. * displacementMap: new THREE.Texture( <Image> ),
  20168. * displacementScale: <float>,
  20169. * displacementBias: <float>,
  20170. *
  20171. * alphaMap: new THREE.Texture( <Image> ),
  20172. *
  20173. * skinning: <bool>,
  20174. * morphTargets: <bool>,
  20175. * morphNormals: <bool>
  20176. *
  20177. * flatShading: <bool>
  20178. * }
  20179. */
  20180. function MeshMatcapMaterial(parameters) {
  20181. Material.call(this);
  20182. this.defines = {
  20183. 'MATCAP': ''
  20184. };
  20185. this.type = 'MeshMatcapMaterial';
  20186. this.color = new Color(0xffffff); // diffuse
  20187. this.matcap = null;
  20188. this.map = null;
  20189. this.bumpMap = null;
  20190. this.bumpScale = 1;
  20191. this.normalMap = null;
  20192. this.normalMapType = TangentSpaceNormalMap;
  20193. this.normalScale = new Vector2(1, 1);
  20194. this.displacementMap = null;
  20195. this.displacementScale = 1;
  20196. this.displacementBias = 0;
  20197. this.alphaMap = null;
  20198. this.skinning = false;
  20199. this.morphTargets = false;
  20200. this.morphNormals = false;
  20201. this.flatShading = false;
  20202. this.setValues(parameters);
  20203. }
  20204. MeshMatcapMaterial.prototype = Object.create(Material.prototype);
  20205. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20206. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20207. MeshMatcapMaterial.prototype.copy = function (source) {
  20208. Material.prototype.copy.call(this, source);
  20209. this.defines = {
  20210. 'MATCAP': ''
  20211. };
  20212. this.color.copy(source.color);
  20213. this.matcap = source.matcap;
  20214. this.map = source.map;
  20215. this.bumpMap = source.bumpMap;
  20216. this.bumpScale = source.bumpScale;
  20217. this.normalMap = source.normalMap;
  20218. this.normalMapType = source.normalMapType;
  20219. this.normalScale.copy(source.normalScale);
  20220. this.displacementMap = source.displacementMap;
  20221. this.displacementScale = source.displacementScale;
  20222. this.displacementBias = source.displacementBias;
  20223. this.alphaMap = source.alphaMap;
  20224. this.skinning = source.skinning;
  20225. this.morphTargets = source.morphTargets;
  20226. this.morphNormals = source.morphNormals;
  20227. this.flatShading = source.flatShading;
  20228. return this;
  20229. };
  20230. /**
  20231. * parameters = {
  20232. * color: <hex>,
  20233. * opacity: <float>,
  20234. *
  20235. * linewidth: <float>,
  20236. *
  20237. * scale: <float>,
  20238. * dashSize: <float>,
  20239. * gapSize: <float>
  20240. * }
  20241. */
  20242. function LineDashedMaterial(parameters) {
  20243. LineBasicMaterial.call(this);
  20244. this.type = 'LineDashedMaterial';
  20245. this.scale = 1;
  20246. this.dashSize = 3;
  20247. this.gapSize = 1;
  20248. this.setValues(parameters);
  20249. }
  20250. LineDashedMaterial.prototype = Object.create(LineBasicMaterial.prototype);
  20251. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20252. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20253. LineDashedMaterial.prototype.copy = function (source) {
  20254. LineBasicMaterial.prototype.copy.call(this, source);
  20255. this.scale = source.scale;
  20256. this.dashSize = source.dashSize;
  20257. this.gapSize = source.gapSize;
  20258. return this;
  20259. };
  20260. var Materials = /*#__PURE__*/Object.freeze({
  20261. __proto__: null,
  20262. ShadowMaterial: ShadowMaterial,
  20263. SpriteMaterial: SpriteMaterial,
  20264. RawShaderMaterial: RawShaderMaterial,
  20265. ShaderMaterial: ShaderMaterial,
  20266. PointsMaterial: PointsMaterial,
  20267. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20268. MeshStandardMaterial: MeshStandardMaterial,
  20269. MeshPhongMaterial: MeshPhongMaterial,
  20270. MeshToonMaterial: MeshToonMaterial,
  20271. MeshNormalMaterial: MeshNormalMaterial,
  20272. MeshLambertMaterial: MeshLambertMaterial,
  20273. MeshDepthMaterial: MeshDepthMaterial,
  20274. MeshDistanceMaterial: MeshDistanceMaterial,
  20275. MeshBasicMaterial: MeshBasicMaterial,
  20276. MeshMatcapMaterial: MeshMatcapMaterial,
  20277. LineDashedMaterial: LineDashedMaterial,
  20278. LineBasicMaterial: LineBasicMaterial,
  20279. Material: Material
  20280. });
  20281. var AnimationUtils = {
  20282. // same as Array.prototype.slice, but also works on typed arrays
  20283. arraySlice: function arraySlice(array, from, to) {
  20284. if (AnimationUtils.isTypedArray(array)) {
  20285. // in ios9 array.subarray(from, undefined) will return empty array
  20286. // but array.subarray(from) or array.subarray(from, len) is correct
  20287. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  20288. }
  20289. return array.slice(from, to);
  20290. },
  20291. // converts an array to a specific type
  20292. convertArray: function convertArray(array, type, forceClone) {
  20293. if (!array || // let 'undefined' and 'null' pass
  20294. !forceClone && array.constructor === type) return array;
  20295. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  20296. return new type(array); // create typed array
  20297. }
  20298. return Array.prototype.slice.call(array); // create Array
  20299. },
  20300. isTypedArray: function isTypedArray(object) {
  20301. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  20302. },
  20303. // returns an array by which times and values can be sorted
  20304. getKeyframeOrder: function getKeyframeOrder(times) {
  20305. function compareTime(i, j) {
  20306. return times[i] - times[j];
  20307. }
  20308. var n = times.length;
  20309. var result = new Array(n);
  20310. for (var i = 0; i !== n; ++i) {
  20311. result[i] = i;
  20312. }
  20313. result.sort(compareTime);
  20314. return result;
  20315. },
  20316. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20317. sortedArray: function sortedArray(values, stride, order) {
  20318. var nValues = values.length;
  20319. var result = new values.constructor(nValues);
  20320. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  20321. var srcOffset = order[i] * stride;
  20322. for (var j = 0; j !== stride; ++j) {
  20323. result[dstOffset++] = values[srcOffset + j];
  20324. }
  20325. }
  20326. return result;
  20327. },
  20328. // function for parsing AOS keyframe formats
  20329. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  20330. var i = 1,
  20331. key = jsonKeys[0];
  20332. while (key !== undefined && key[valuePropertyName] === undefined) {
  20333. key = jsonKeys[i++];
  20334. }
  20335. if (key === undefined) return; // no data
  20336. var value = key[valuePropertyName];
  20337. if (value === undefined) return; // no data
  20338. if (Array.isArray(value)) {
  20339. do {
  20340. value = key[valuePropertyName];
  20341. if (value !== undefined) {
  20342. times.push(key.time);
  20343. values.push.apply(values, value); // push all elements
  20344. }
  20345. key = jsonKeys[i++];
  20346. } while (key !== undefined);
  20347. } else if (value.toArray !== undefined) {
  20348. // ...assume THREE.Math-ish
  20349. do {
  20350. value = key[valuePropertyName];
  20351. if (value !== undefined) {
  20352. times.push(key.time);
  20353. value.toArray(values, values.length);
  20354. }
  20355. key = jsonKeys[i++];
  20356. } while (key !== undefined);
  20357. } else {
  20358. // otherwise push as-is
  20359. do {
  20360. value = key[valuePropertyName];
  20361. if (value !== undefined) {
  20362. times.push(key.time);
  20363. values.push(value);
  20364. }
  20365. key = jsonKeys[i++];
  20366. } while (key !== undefined);
  20367. }
  20368. },
  20369. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  20370. if (fps === void 0) {
  20371. fps = 30;
  20372. }
  20373. var clip = sourceClip.clone();
  20374. clip.name = name;
  20375. var tracks = [];
  20376. for (var i = 0; i < clip.tracks.length; ++i) {
  20377. var track = clip.tracks[i];
  20378. var valueSize = track.getValueSize();
  20379. var times = [];
  20380. var values = [];
  20381. for (var j = 0; j < track.times.length; ++j) {
  20382. var frame = track.times[j] * fps;
  20383. if (frame < startFrame || frame >= endFrame) continue;
  20384. times.push(track.times[j]);
  20385. for (var k = 0; k < valueSize; ++k) {
  20386. values.push(track.values[j * valueSize + k]);
  20387. }
  20388. }
  20389. if (times.length === 0) continue;
  20390. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  20391. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  20392. tracks.push(track);
  20393. }
  20394. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  20395. var minStartTime = Infinity;
  20396. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  20397. if (minStartTime > clip.tracks[_i].times[0]) {
  20398. minStartTime = clip.tracks[_i].times[0];
  20399. }
  20400. } // shift all tracks such that clip begins at t=0
  20401. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  20402. clip.tracks[_i2].shift(-1 * minStartTime);
  20403. }
  20404. clip.resetDuration();
  20405. return clip;
  20406. },
  20407. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  20408. if (referenceFrame === void 0) {
  20409. referenceFrame = 0;
  20410. }
  20411. if (referenceClip === void 0) {
  20412. referenceClip = targetClip;
  20413. }
  20414. if (fps === void 0) {
  20415. fps = 30;
  20416. }
  20417. if (fps <= 0) fps = 30;
  20418. var numTracks = referenceClip.tracks.length;
  20419. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  20420. var _loop = function _loop(i) {
  20421. var referenceTrack = referenceClip.tracks[i];
  20422. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  20423. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  20424. var targetTrack = targetClip.tracks.find(function (track) {
  20425. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  20426. });
  20427. if (targetTrack === undefined) return "continue";
  20428. var referenceOffset = 0;
  20429. var referenceValueSize = referenceTrack.getValueSize();
  20430. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20431. referenceOffset = referenceValueSize / 3;
  20432. }
  20433. var targetOffset = 0;
  20434. var targetValueSize = targetTrack.getValueSize();
  20435. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20436. targetOffset = targetValueSize / 3;
  20437. }
  20438. var lastIndex = referenceTrack.times.length - 1;
  20439. var referenceValue = void 0; // Find the value to subtract out of the track
  20440. if (referenceTime <= referenceTrack.times[0]) {
  20441. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  20442. var startIndex = referenceOffset;
  20443. var endIndex = referenceValueSize - referenceOffset;
  20444. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  20445. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  20446. // Reference frame is after the last keyframe, so just use the last keyframe
  20447. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  20448. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  20449. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  20450. } else {
  20451. // Interpolate to the reference value
  20452. var interpolant = referenceTrack.createInterpolant();
  20453. var _startIndex2 = referenceOffset;
  20454. var _endIndex2 = referenceValueSize - referenceOffset;
  20455. interpolant.evaluate(referenceTime);
  20456. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  20457. } // Conjugate the quaternion
  20458. if (referenceTrackType === 'quaternion') {
  20459. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  20460. referenceQuat.toArray(referenceValue);
  20461. } // Subtract the reference value from all of the track values
  20462. var numTimes = targetTrack.times.length;
  20463. for (var j = 0; j < numTimes; ++j) {
  20464. var valueStart = j * targetValueSize + targetOffset;
  20465. if (referenceTrackType === 'quaternion') {
  20466. // Multiply the conjugate for quaternion track types
  20467. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  20468. } else {
  20469. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  20470. for (var k = 0; k < valueEnd; ++k) {
  20471. targetTrack.values[valueStart + k] -= referenceValue[k];
  20472. }
  20473. }
  20474. }
  20475. };
  20476. for (var i = 0; i < numTracks; ++i) {
  20477. var _ret = _loop(i);
  20478. if (_ret === "continue") continue;
  20479. }
  20480. targetClip.blendMode = AdditiveAnimationBlendMode;
  20481. return targetClip;
  20482. }
  20483. };
  20484. /**
  20485. * Abstract base class of interpolants over parametric samples.
  20486. *
  20487. * The parameter domain is one dimensional, typically the time or a path
  20488. * along a curve defined by the data.
  20489. *
  20490. * The sample values can have any dimensionality and derived classes may
  20491. * apply special interpretations to the data.
  20492. *
  20493. * This class provides the interval seek in a Template Method, deferring
  20494. * the actual interpolation to derived classes.
  20495. *
  20496. * Time complexity is O(1) for linear access crossing at most two points
  20497. * and O(log N) for random access, where N is the number of positions.
  20498. *
  20499. * References:
  20500. *
  20501. * http://www.oodesign.com/template-method-pattern.html
  20502. *
  20503. */
  20504. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20505. this.parameterPositions = parameterPositions;
  20506. this._cachedIndex = 0;
  20507. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  20508. this.sampleValues = sampleValues;
  20509. this.valueSize = sampleSize;
  20510. }
  20511. Object.assign(Interpolant.prototype, {
  20512. evaluate: function evaluate(t) {
  20513. var pp = this.parameterPositions;
  20514. var i1 = this._cachedIndex,
  20515. t1 = pp[i1],
  20516. t0 = pp[i1 - 1];
  20517. validate_interval: {
  20518. seek: {
  20519. var right;
  20520. linear_scan: {
  20521. //- See http://jsperf.com/comparison-to-undefined/3
  20522. //- slower code:
  20523. //-
  20524. //- if ( t >= t1 || t1 === undefined ) {
  20525. forward_scan: if (!(t < t1)) {
  20526. for (var giveUpAt = i1 + 2;;) {
  20527. if (t1 === undefined) {
  20528. if (t < t0) break forward_scan; // after end
  20529. i1 = pp.length;
  20530. this._cachedIndex = i1;
  20531. return this.afterEnd_(i1 - 1, t, t0);
  20532. }
  20533. if (i1 === giveUpAt) break; // this loop
  20534. t0 = t1;
  20535. t1 = pp[++i1];
  20536. if (t < t1) {
  20537. // we have arrived at the sought interval
  20538. break seek;
  20539. }
  20540. } // prepare binary search on the right side of the index
  20541. right = pp.length;
  20542. break linear_scan;
  20543. } //- slower code:
  20544. //- if ( t < t0 || t0 === undefined ) {
  20545. if (!(t >= t0)) {
  20546. // looping?
  20547. var t1global = pp[1];
  20548. if (t < t1global) {
  20549. i1 = 2; // + 1, using the scan for the details
  20550. t0 = t1global;
  20551. } // linear reverse scan
  20552. for (var _giveUpAt = i1 - 2;;) {
  20553. if (t0 === undefined) {
  20554. // before start
  20555. this._cachedIndex = 0;
  20556. return this.beforeStart_(0, t, t1);
  20557. }
  20558. if (i1 === _giveUpAt) break; // this loop
  20559. t1 = t0;
  20560. t0 = pp[--i1 - 1];
  20561. if (t >= t0) {
  20562. // we have arrived at the sought interval
  20563. break seek;
  20564. }
  20565. } // prepare binary search on the left side of the index
  20566. right = i1;
  20567. i1 = 0;
  20568. break linear_scan;
  20569. } // the interval is valid
  20570. break validate_interval;
  20571. } // linear scan
  20572. // binary search
  20573. while (i1 < right) {
  20574. var mid = i1 + right >>> 1;
  20575. if (t < pp[mid]) {
  20576. right = mid;
  20577. } else {
  20578. i1 = mid + 1;
  20579. }
  20580. }
  20581. t1 = pp[i1];
  20582. t0 = pp[i1 - 1]; // check boundary cases, again
  20583. if (t0 === undefined) {
  20584. this._cachedIndex = 0;
  20585. return this.beforeStart_(0, t, t1);
  20586. }
  20587. if (t1 === undefined) {
  20588. i1 = pp.length;
  20589. this._cachedIndex = i1;
  20590. return this.afterEnd_(i1 - 1, t0, t);
  20591. }
  20592. } // seek
  20593. this._cachedIndex = i1;
  20594. this.intervalChanged_(i1, t0, t1);
  20595. } // validate_interval
  20596. return this.interpolate_(i1, t0, t, t1);
  20597. },
  20598. settings: null,
  20599. // optional, subclass-specific settings structure
  20600. // Note: The indirection allows central control of many interpolants.
  20601. // --- Protected interface
  20602. DefaultSettings_: {},
  20603. getSettings_: function getSettings_() {
  20604. return this.settings || this.DefaultSettings_;
  20605. },
  20606. copySampleValue_: function copySampleValue_(index) {
  20607. // copies a sample value to the result buffer
  20608. var result = this.resultBuffer,
  20609. values = this.sampleValues,
  20610. stride = this.valueSize,
  20611. offset = index * stride;
  20612. for (var i = 0; i !== stride; ++i) {
  20613. result[i] = values[offset + i];
  20614. }
  20615. return result;
  20616. },
  20617. // Template methods for derived classes:
  20618. interpolate_: function interpolate_()
  20619. /* i1, t0, t, t1 */
  20620. {
  20621. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  20622. },
  20623. intervalChanged_: function intervalChanged_()
  20624. /* i1, t0, t1 */
  20625. {// empty
  20626. }
  20627. }); // DECLARE ALIAS AFTER assign prototype
  20628. Object.assign(Interpolant.prototype, {
  20629. //( 0, t, t0 ), returns this.resultBuffer
  20630. beforeStart_: Interpolant.prototype.copySampleValue_,
  20631. //( N-1, tN-1, t ), returns this.resultBuffer
  20632. afterEnd_: Interpolant.prototype.copySampleValue_
  20633. });
  20634. /**
  20635. * Fast and simple cubic spline interpolant.
  20636. *
  20637. * It was derived from a Hermitian construction setting the first derivative
  20638. * at each sample position to the linear slope between neighboring positions
  20639. * over their parameter interval.
  20640. */
  20641. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20642. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20643. this._weightPrev = -0;
  20644. this._offsetPrev = -0;
  20645. this._weightNext = -0;
  20646. this._offsetNext = -0;
  20647. }
  20648. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20649. constructor: CubicInterpolant,
  20650. DefaultSettings_: {
  20651. endingStart: ZeroCurvatureEnding,
  20652. endingEnd: ZeroCurvatureEnding
  20653. },
  20654. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  20655. var pp = this.parameterPositions;
  20656. var iPrev = i1 - 2,
  20657. iNext = i1 + 1,
  20658. tPrev = pp[iPrev],
  20659. tNext = pp[iNext];
  20660. if (tPrev === undefined) {
  20661. switch (this.getSettings_().endingStart) {
  20662. case ZeroSlopeEnding:
  20663. // f'(t0) = 0
  20664. iPrev = i1;
  20665. tPrev = 2 * t0 - t1;
  20666. break;
  20667. case WrapAroundEnding:
  20668. // use the other end of the curve
  20669. iPrev = pp.length - 2;
  20670. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  20671. break;
  20672. default:
  20673. // ZeroCurvatureEnding
  20674. // f''(t0) = 0 a.k.a. Natural Spline
  20675. iPrev = i1;
  20676. tPrev = t1;
  20677. }
  20678. }
  20679. if (tNext === undefined) {
  20680. switch (this.getSettings_().endingEnd) {
  20681. case ZeroSlopeEnding:
  20682. // f'(tN) = 0
  20683. iNext = i1;
  20684. tNext = 2 * t1 - t0;
  20685. break;
  20686. case WrapAroundEnding:
  20687. // use the other end of the curve
  20688. iNext = 1;
  20689. tNext = t1 + pp[1] - pp[0];
  20690. break;
  20691. default:
  20692. // ZeroCurvatureEnding
  20693. // f''(tN) = 0, a.k.a. Natural Spline
  20694. iNext = i1 - 1;
  20695. tNext = t0;
  20696. }
  20697. }
  20698. var halfDt = (t1 - t0) * 0.5,
  20699. stride = this.valueSize;
  20700. this._weightPrev = halfDt / (t0 - tPrev);
  20701. this._weightNext = halfDt / (tNext - t1);
  20702. this._offsetPrev = iPrev * stride;
  20703. this._offsetNext = iNext * stride;
  20704. },
  20705. interpolate_: function interpolate_(i1, t0, t, t1) {
  20706. var result = this.resultBuffer,
  20707. values = this.sampleValues,
  20708. stride = this.valueSize,
  20709. o1 = i1 * stride,
  20710. o0 = o1 - stride,
  20711. oP = this._offsetPrev,
  20712. oN = this._offsetNext,
  20713. wP = this._weightPrev,
  20714. wN = this._weightNext,
  20715. p = (t - t0) / (t1 - t0),
  20716. pp = p * p,
  20717. ppp = pp * p; // evaluate polynomials
  20718. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  20719. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  20720. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  20721. var sN = wN * ppp - wN * pp; // combine data linearly
  20722. for (var i = 0; i !== stride; ++i) {
  20723. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  20724. }
  20725. return result;
  20726. }
  20727. });
  20728. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20729. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20730. }
  20731. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20732. constructor: LinearInterpolant,
  20733. interpolate_: function interpolate_(i1, t0, t, t1) {
  20734. var result = this.resultBuffer,
  20735. values = this.sampleValues,
  20736. stride = this.valueSize,
  20737. offset1 = i1 * stride,
  20738. offset0 = offset1 - stride,
  20739. weight1 = (t - t0) / (t1 - t0),
  20740. weight0 = 1 - weight1;
  20741. for (var i = 0; i !== stride; ++i) {
  20742. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  20743. }
  20744. return result;
  20745. }
  20746. });
  20747. /**
  20748. *
  20749. * Interpolant that evaluates to the sample value at the position preceeding
  20750. * the parameter.
  20751. */
  20752. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20753. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20754. }
  20755. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20756. constructor: DiscreteInterpolant,
  20757. interpolate_: function interpolate_(i1
  20758. /*, t0, t, t1 */
  20759. ) {
  20760. return this.copySampleValue_(i1 - 1);
  20761. }
  20762. });
  20763. function KeyframeTrack(name, times, values, interpolation) {
  20764. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  20765. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  20766. this.name = name;
  20767. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  20768. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  20769. this.setInterpolation(interpolation || this.DefaultInterpolation);
  20770. } // Static methods
  20771. Object.assign(KeyframeTrack, {
  20772. // Serialization (in static context, because of constructor invocation
  20773. // and automatic invocation of .toJSON):
  20774. toJSON: function toJSON(track) {
  20775. var trackType = track.constructor;
  20776. var json; // derived classes can define a static toJSON method
  20777. if (trackType.toJSON !== undefined) {
  20778. json = trackType.toJSON(track);
  20779. } else {
  20780. // by default, we assume the data can be serialized as-is
  20781. json = {
  20782. 'name': track.name,
  20783. 'times': AnimationUtils.convertArray(track.times, Array),
  20784. 'values': AnimationUtils.convertArray(track.values, Array)
  20785. };
  20786. var interpolation = track.getInterpolation();
  20787. if (interpolation !== track.DefaultInterpolation) {
  20788. json.interpolation = interpolation;
  20789. }
  20790. }
  20791. json.type = track.ValueTypeName; // mandatory
  20792. return json;
  20793. }
  20794. });
  20795. Object.assign(KeyframeTrack.prototype, {
  20796. constructor: KeyframeTrack,
  20797. TimeBufferType: Float32Array,
  20798. ValueBufferType: Float32Array,
  20799. DefaultInterpolation: InterpolateLinear,
  20800. InterpolantFactoryMethodDiscrete: function InterpolantFactoryMethodDiscrete(result) {
  20801. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  20802. },
  20803. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  20804. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  20805. },
  20806. InterpolantFactoryMethodSmooth: function InterpolantFactoryMethodSmooth(result) {
  20807. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  20808. },
  20809. setInterpolation: function setInterpolation(interpolation) {
  20810. var factoryMethod;
  20811. switch (interpolation) {
  20812. case InterpolateDiscrete:
  20813. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  20814. break;
  20815. case InterpolateLinear:
  20816. factoryMethod = this.InterpolantFactoryMethodLinear;
  20817. break;
  20818. case InterpolateSmooth:
  20819. factoryMethod = this.InterpolantFactoryMethodSmooth;
  20820. break;
  20821. }
  20822. if (factoryMethod === undefined) {
  20823. var message = 'unsupported interpolation for ' + this.ValueTypeName + ' keyframe track named ' + this.name;
  20824. if (this.createInterpolant === undefined) {
  20825. // fall back to default, unless the default itself is messed up
  20826. if (interpolation !== this.DefaultInterpolation) {
  20827. this.setInterpolation(this.DefaultInterpolation);
  20828. } else {
  20829. throw new Error(message); // fatal, in this case
  20830. }
  20831. }
  20832. console.warn('THREE.KeyframeTrack:', message);
  20833. return this;
  20834. }
  20835. this.createInterpolant = factoryMethod;
  20836. return this;
  20837. },
  20838. getInterpolation: function getInterpolation() {
  20839. switch (this.createInterpolant) {
  20840. case this.InterpolantFactoryMethodDiscrete:
  20841. return InterpolateDiscrete;
  20842. case this.InterpolantFactoryMethodLinear:
  20843. return InterpolateLinear;
  20844. case this.InterpolantFactoryMethodSmooth:
  20845. return InterpolateSmooth;
  20846. }
  20847. },
  20848. getValueSize: function getValueSize() {
  20849. return this.values.length / this.times.length;
  20850. },
  20851. // move all keyframes either forwards or backwards in time
  20852. shift: function shift(timeOffset) {
  20853. if (timeOffset !== 0.0) {
  20854. var times = this.times;
  20855. for (var i = 0, n = times.length; i !== n; ++i) {
  20856. times[i] += timeOffset;
  20857. }
  20858. }
  20859. return this;
  20860. },
  20861. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  20862. scale: function scale(timeScale) {
  20863. if (timeScale !== 1.0) {
  20864. var times = this.times;
  20865. for (var i = 0, n = times.length; i !== n; ++i) {
  20866. times[i] *= timeScale;
  20867. }
  20868. }
  20869. return this;
  20870. },
  20871. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  20872. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  20873. trim: function trim(startTime, endTime) {
  20874. var times = this.times,
  20875. nKeys = times.length;
  20876. var from = 0,
  20877. to = nKeys - 1;
  20878. while (from !== nKeys && times[from] < startTime) {
  20879. ++from;
  20880. }
  20881. while (to !== -1 && times[to] > endTime) {
  20882. --to;
  20883. }
  20884. ++to; // inclusive -> exclusive bound
  20885. if (from !== 0 || to !== nKeys) {
  20886. // empty tracks are forbidden, so keep at least one keyframe
  20887. if (from >= to) {
  20888. to = Math.max(to, 1);
  20889. from = to - 1;
  20890. }
  20891. var stride = this.getValueSize();
  20892. this.times = AnimationUtils.arraySlice(times, from, to);
  20893. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  20894. }
  20895. return this;
  20896. },
  20897. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  20898. validate: function validate() {
  20899. var valid = true;
  20900. var valueSize = this.getValueSize();
  20901. if (valueSize - Math.floor(valueSize) !== 0) {
  20902. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  20903. valid = false;
  20904. }
  20905. var times = this.times,
  20906. values = this.values,
  20907. nKeys = times.length;
  20908. if (nKeys === 0) {
  20909. console.error('THREE.KeyframeTrack: Track is empty.', this);
  20910. valid = false;
  20911. }
  20912. var prevTime = null;
  20913. for (var i = 0; i !== nKeys; i++) {
  20914. var currTime = times[i];
  20915. if (typeof currTime === 'number' && isNaN(currTime)) {
  20916. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  20917. valid = false;
  20918. break;
  20919. }
  20920. if (prevTime !== null && prevTime > currTime) {
  20921. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  20922. valid = false;
  20923. break;
  20924. }
  20925. prevTime = currTime;
  20926. }
  20927. if (values !== undefined) {
  20928. if (AnimationUtils.isTypedArray(values)) {
  20929. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  20930. var value = values[_i];
  20931. if (isNaN(value)) {
  20932. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  20933. valid = false;
  20934. break;
  20935. }
  20936. }
  20937. }
  20938. }
  20939. return valid;
  20940. },
  20941. // removes equivalent sequential keys as common in morph target sequences
  20942. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  20943. optimize: function optimize() {
  20944. // times or values may be shared with other tracks, so overwriting is unsafe
  20945. var times = AnimationUtils.arraySlice(this.times),
  20946. values = AnimationUtils.arraySlice(this.values),
  20947. stride = this.getValueSize(),
  20948. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  20949. lastIndex = times.length - 1;
  20950. var writeIndex = 1;
  20951. for (var i = 1; i < lastIndex; ++i) {
  20952. var keep = false;
  20953. var time = times[i];
  20954. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  20955. if (time !== timeNext && (i !== 1 || time !== times[0])) {
  20956. if (!smoothInterpolation) {
  20957. // remove unnecessary keyframes same as their neighbors
  20958. var offset = i * stride,
  20959. offsetP = offset - stride,
  20960. offsetN = offset + stride;
  20961. for (var j = 0; j !== stride; ++j) {
  20962. var value = values[offset + j];
  20963. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  20964. keep = true;
  20965. break;
  20966. }
  20967. }
  20968. } else {
  20969. keep = true;
  20970. }
  20971. } // in-place compaction
  20972. if (keep) {
  20973. if (i !== writeIndex) {
  20974. times[writeIndex] = times[i];
  20975. var readOffset = i * stride,
  20976. writeOffset = writeIndex * stride;
  20977. for (var _j = 0; _j !== stride; ++_j) {
  20978. values[writeOffset + _j] = values[readOffset + _j];
  20979. }
  20980. }
  20981. ++writeIndex;
  20982. }
  20983. } // flush last keyframe (compaction looks ahead)
  20984. if (lastIndex > 0) {
  20985. times[writeIndex] = times[lastIndex];
  20986. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  20987. values[_writeOffset + _j2] = values[_readOffset + _j2];
  20988. }
  20989. ++writeIndex;
  20990. }
  20991. if (writeIndex !== times.length) {
  20992. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  20993. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  20994. } else {
  20995. this.times = times;
  20996. this.values = values;
  20997. }
  20998. return this;
  20999. },
  21000. clone: function clone() {
  21001. var times = AnimationUtils.arraySlice(this.times, 0);
  21002. var values = AnimationUtils.arraySlice(this.values, 0);
  21003. var TypedKeyframeTrack = this.constructor;
  21004. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21005. track.createInterpolant = this.createInterpolant;
  21006. return track;
  21007. }
  21008. });
  21009. /**
  21010. * A Track of Boolean keyframe values.
  21011. */
  21012. function BooleanKeyframeTrack(name, times, values) {
  21013. KeyframeTrack.call(this, name, times, values);
  21014. }
  21015. BooleanKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21016. constructor: BooleanKeyframeTrack,
  21017. ValueTypeName: 'bool',
  21018. ValueBufferType: Array,
  21019. DefaultInterpolation: InterpolateDiscrete,
  21020. InterpolantFactoryMethodLinear: undefined,
  21021. InterpolantFactoryMethodSmooth: undefined // Note: Actually this track could have a optimized / compressed
  21022. // representation of a single value and a custom interpolant that
  21023. // computes "firstValue ^ isOdd( index )".
  21024. });
  21025. /**
  21026. * A Track of keyframe values that represent color.
  21027. */
  21028. function ColorKeyframeTrack(name, times, values, interpolation) {
  21029. KeyframeTrack.call(this, name, times, values, interpolation);
  21030. }
  21031. ColorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21032. constructor: ColorKeyframeTrack,
  21033. ValueTypeName: 'color' // ValueBufferType is inherited
  21034. // DefaultInterpolation is inherited
  21035. // Note: Very basic implementation and nothing special yet.
  21036. // However, this is the place for color space parameterization.
  21037. });
  21038. /**
  21039. * A Track of numeric keyframe values.
  21040. */
  21041. function NumberKeyframeTrack(name, times, values, interpolation) {
  21042. KeyframeTrack.call(this, name, times, values, interpolation);
  21043. }
  21044. NumberKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21045. constructor: NumberKeyframeTrack,
  21046. ValueTypeName: 'number' // ValueBufferType is inherited
  21047. // DefaultInterpolation is inherited
  21048. });
  21049. /**
  21050. * Spherical linear unit quaternion interpolant.
  21051. */
  21052. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21053. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21054. }
  21055. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21056. constructor: QuaternionLinearInterpolant,
  21057. interpolate_: function interpolate_(i1, t0, t, t1) {
  21058. var result = this.resultBuffer,
  21059. values = this.sampleValues,
  21060. stride = this.valueSize,
  21061. alpha = (t - t0) / (t1 - t0);
  21062. var offset = i1 * stride;
  21063. for (var end = offset + stride; offset !== end; offset += 4) {
  21064. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  21065. }
  21066. return result;
  21067. }
  21068. });
  21069. /**
  21070. * A Track of quaternion keyframe values.
  21071. */
  21072. function QuaternionKeyframeTrack(name, times, values, interpolation) {
  21073. KeyframeTrack.call(this, name, times, values, interpolation);
  21074. }
  21075. QuaternionKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21076. constructor: QuaternionKeyframeTrack,
  21077. ValueTypeName: 'quaternion',
  21078. // ValueBufferType is inherited
  21079. DefaultInterpolation: InterpolateLinear,
  21080. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21081. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21082. },
  21083. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21084. });
  21085. /**
  21086. * A Track that interpolates Strings
  21087. */
  21088. function StringKeyframeTrack(name, times, values, interpolation) {
  21089. KeyframeTrack.call(this, name, times, values, interpolation);
  21090. }
  21091. StringKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21092. constructor: StringKeyframeTrack,
  21093. ValueTypeName: 'string',
  21094. ValueBufferType: Array,
  21095. DefaultInterpolation: InterpolateDiscrete,
  21096. InterpolantFactoryMethodLinear: undefined,
  21097. InterpolantFactoryMethodSmooth: undefined
  21098. });
  21099. /**
  21100. * A Track of vectored keyframe values.
  21101. */
  21102. function VectorKeyframeTrack(name, times, values, interpolation) {
  21103. KeyframeTrack.call(this, name, times, values, interpolation);
  21104. }
  21105. VectorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21106. constructor: VectorKeyframeTrack,
  21107. ValueTypeName: 'vector' // ValueBufferType is inherited
  21108. // DefaultInterpolation is inherited
  21109. });
  21110. function AnimationClip(name, duration, tracks, blendMode) {
  21111. if (duration === void 0) {
  21112. duration = -1;
  21113. }
  21114. if (blendMode === void 0) {
  21115. blendMode = NormalAnimationBlendMode;
  21116. }
  21117. this.name = name;
  21118. this.tracks = tracks;
  21119. this.duration = duration;
  21120. this.blendMode = blendMode;
  21121. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  21122. if (this.duration < 0) {
  21123. this.resetDuration();
  21124. }
  21125. }
  21126. function getTrackTypeForValueTypeName(typeName) {
  21127. switch (typeName.toLowerCase()) {
  21128. case 'scalar':
  21129. case 'double':
  21130. case 'float':
  21131. case 'number':
  21132. case 'integer':
  21133. return NumberKeyframeTrack;
  21134. case 'vector':
  21135. case 'vector2':
  21136. case 'vector3':
  21137. case 'vector4':
  21138. return VectorKeyframeTrack;
  21139. case 'color':
  21140. return ColorKeyframeTrack;
  21141. case 'quaternion':
  21142. return QuaternionKeyframeTrack;
  21143. case 'bool':
  21144. case 'boolean':
  21145. return BooleanKeyframeTrack;
  21146. case 'string':
  21147. return StringKeyframeTrack;
  21148. }
  21149. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  21150. }
  21151. function parseKeyframeTrack(json) {
  21152. if (json.type === undefined) {
  21153. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  21154. }
  21155. var trackType = getTrackTypeForValueTypeName(json.type);
  21156. if (json.times === undefined) {
  21157. var times = [],
  21158. values = [];
  21159. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  21160. json.times = times;
  21161. json.values = values;
  21162. } // derived classes can define a static parse method
  21163. if (trackType.parse !== undefined) {
  21164. return trackType.parse(json);
  21165. } else {
  21166. // by default, we assume a constructor compatible with the base
  21167. return new trackType(json.name, json.times, json.values, json.interpolation);
  21168. }
  21169. }
  21170. Object.assign(AnimationClip, {
  21171. parse: function parse(json) {
  21172. var tracks = [],
  21173. jsonTracks = json.tracks,
  21174. frameTime = 1.0 / (json.fps || 1.0);
  21175. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  21176. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  21177. }
  21178. var clip = new AnimationClip(json.name, json.duration, tracks, json.blendMode);
  21179. clip.uuid = json.uuid;
  21180. return clip;
  21181. },
  21182. toJSON: function toJSON(clip) {
  21183. var tracks = [],
  21184. clipTracks = clip.tracks;
  21185. var json = {
  21186. 'name': clip.name,
  21187. 'duration': clip.duration,
  21188. 'tracks': tracks,
  21189. 'uuid': clip.uuid,
  21190. 'blendMode': clip.blendMode
  21191. };
  21192. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  21193. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  21194. }
  21195. return json;
  21196. },
  21197. CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  21198. var numMorphTargets = morphTargetSequence.length;
  21199. var tracks = [];
  21200. for (var i = 0; i < numMorphTargets; i++) {
  21201. var times = [];
  21202. var values = [];
  21203. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  21204. values.push(0, 1, 0);
  21205. var order = AnimationUtils.getKeyframeOrder(times);
  21206. times = AnimationUtils.sortedArray(times, 1, order);
  21207. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  21208. // last frame as well for perfect loop.
  21209. if (!noLoop && times[0] === 0) {
  21210. times.push(numMorphTargets);
  21211. values.push(values[0]);
  21212. }
  21213. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  21214. }
  21215. return new AnimationClip(name, -1, tracks);
  21216. },
  21217. findByName: function findByName(objectOrClipArray, name) {
  21218. var clipArray = objectOrClipArray;
  21219. if (!Array.isArray(objectOrClipArray)) {
  21220. var o = objectOrClipArray;
  21221. clipArray = o.geometry && o.geometry.animations || o.animations;
  21222. }
  21223. for (var i = 0; i < clipArray.length; i++) {
  21224. if (clipArray[i].name === name) {
  21225. return clipArray[i];
  21226. }
  21227. }
  21228. return null;
  21229. },
  21230. CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  21231. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  21232. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21233. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  21234. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21235. for (var i = 0, il = morphTargets.length; i < il; i++) {
  21236. var morphTarget = morphTargets[i];
  21237. var parts = morphTarget.name.match(pattern);
  21238. if (parts && parts.length > 1) {
  21239. var name = parts[1];
  21240. var animationMorphTargets = animationToMorphTargets[name];
  21241. if (!animationMorphTargets) {
  21242. animationToMorphTargets[name] = animationMorphTargets = [];
  21243. }
  21244. animationMorphTargets.push(morphTarget);
  21245. }
  21246. }
  21247. var clips = [];
  21248. for (var _name in animationToMorphTargets) {
  21249. clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  21250. }
  21251. return clips;
  21252. },
  21253. // parse the animation.hierarchy format
  21254. parseAnimation: function parseAnimation(animation, bones) {
  21255. if (!animation) {
  21256. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  21257. return null;
  21258. }
  21259. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  21260. // only return track if there are actually keys.
  21261. if (animationKeys.length !== 0) {
  21262. var times = [];
  21263. var values = [];
  21264. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  21265. if (times.length !== 0) {
  21266. destTracks.push(new trackType(trackName, times, values));
  21267. }
  21268. }
  21269. };
  21270. var tracks = [];
  21271. var clipName = animation.name || 'default';
  21272. var fps = animation.fps || 30;
  21273. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  21274. var duration = animation.length || -1;
  21275. var hierarchyTracks = animation.hierarchy || [];
  21276. for (var h = 0; h < hierarchyTracks.length; h++) {
  21277. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  21278. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  21279. if (animationKeys[0].morphTargets) {
  21280. // figure out all morph targets used in this track
  21281. var morphTargetNames = {};
  21282. var k = void 0;
  21283. for (k = 0; k < animationKeys.length; k++) {
  21284. if (animationKeys[k].morphTargets) {
  21285. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  21286. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  21287. }
  21288. }
  21289. } // create a track for each morph target with all zero
  21290. // morphTargetInfluences except for the keys in which
  21291. // the morphTarget is named.
  21292. for (var morphTargetName in morphTargetNames) {
  21293. var times = [];
  21294. var values = [];
  21295. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  21296. var animationKey = animationKeys[k];
  21297. times.push(animationKey.time);
  21298. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  21299. }
  21300. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  21301. }
  21302. duration = morphTargetNames.length * (fps || 1.0);
  21303. } else {
  21304. // ...assume skeletal animation
  21305. var boneName = '.bones[' + bones[h].name + ']';
  21306. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  21307. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  21308. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  21309. }
  21310. }
  21311. if (tracks.length === 0) {
  21312. return null;
  21313. }
  21314. var clip = new AnimationClip(clipName, duration, tracks, blendMode);
  21315. return clip;
  21316. }
  21317. });
  21318. Object.assign(AnimationClip.prototype, {
  21319. resetDuration: function resetDuration() {
  21320. var tracks = this.tracks;
  21321. var duration = 0;
  21322. for (var i = 0, n = tracks.length; i !== n; ++i) {
  21323. var track = this.tracks[i];
  21324. duration = Math.max(duration, track.times[track.times.length - 1]);
  21325. }
  21326. this.duration = duration;
  21327. return this;
  21328. },
  21329. trim: function trim() {
  21330. for (var i = 0; i < this.tracks.length; i++) {
  21331. this.tracks[i].trim(0, this.duration);
  21332. }
  21333. return this;
  21334. },
  21335. validate: function validate() {
  21336. var valid = true;
  21337. for (var i = 0; i < this.tracks.length; i++) {
  21338. valid = valid && this.tracks[i].validate();
  21339. }
  21340. return valid;
  21341. },
  21342. optimize: function optimize() {
  21343. for (var i = 0; i < this.tracks.length; i++) {
  21344. this.tracks[i].optimize();
  21345. }
  21346. return this;
  21347. },
  21348. clone: function clone() {
  21349. var tracks = [];
  21350. for (var i = 0; i < this.tracks.length; i++) {
  21351. tracks.push(this.tracks[i].clone());
  21352. }
  21353. return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
  21354. },
  21355. toJSON: function toJSON() {
  21356. return AnimationClip.toJSON(this);
  21357. }
  21358. });
  21359. var Cache = {
  21360. enabled: false,
  21361. files: {},
  21362. add: function add(key, file) {
  21363. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  21364. this.files[key] = file;
  21365. },
  21366. get: function get(key) {
  21367. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  21368. return this.files[key];
  21369. },
  21370. remove: function remove(key) {
  21371. delete this.files[key];
  21372. },
  21373. clear: function clear() {
  21374. this.files = {};
  21375. }
  21376. };
  21377. function LoadingManager(onLoad, onProgress, onError) {
  21378. var scope = this;
  21379. var isLoading = false;
  21380. var itemsLoaded = 0;
  21381. var itemsTotal = 0;
  21382. var urlModifier = undefined;
  21383. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  21384. // in the constructor
  21385. this.onStart = undefined;
  21386. this.onLoad = onLoad;
  21387. this.onProgress = onProgress;
  21388. this.onError = onError;
  21389. this.itemStart = function (url) {
  21390. itemsTotal++;
  21391. if (isLoading === false) {
  21392. if (scope.onStart !== undefined) {
  21393. scope.onStart(url, itemsLoaded, itemsTotal);
  21394. }
  21395. }
  21396. isLoading = true;
  21397. };
  21398. this.itemEnd = function (url) {
  21399. itemsLoaded++;
  21400. if (scope.onProgress !== undefined) {
  21401. scope.onProgress(url, itemsLoaded, itemsTotal);
  21402. }
  21403. if (itemsLoaded === itemsTotal) {
  21404. isLoading = false;
  21405. if (scope.onLoad !== undefined) {
  21406. scope.onLoad();
  21407. }
  21408. }
  21409. };
  21410. this.itemError = function (url) {
  21411. if (scope.onError !== undefined) {
  21412. scope.onError(url);
  21413. }
  21414. };
  21415. this.resolveURL = function (url) {
  21416. if (urlModifier) {
  21417. return urlModifier(url);
  21418. }
  21419. return url;
  21420. };
  21421. this.setURLModifier = function (transform) {
  21422. urlModifier = transform;
  21423. return this;
  21424. };
  21425. this.addHandler = function (regex, loader) {
  21426. handlers.push(regex, loader);
  21427. return this;
  21428. };
  21429. this.removeHandler = function (regex) {
  21430. var index = handlers.indexOf(regex);
  21431. if (index !== -1) {
  21432. handlers.splice(index, 2);
  21433. }
  21434. return this;
  21435. };
  21436. this.getHandler = function (file) {
  21437. for (var i = 0, l = handlers.length; i < l; i += 2) {
  21438. var regex = handlers[i];
  21439. var loader = handlers[i + 1];
  21440. if (regex.global) regex.lastIndex = 0; // see #17920
  21441. if (regex.test(file)) {
  21442. return loader;
  21443. }
  21444. }
  21445. return null;
  21446. };
  21447. }
  21448. var DefaultLoadingManager = new LoadingManager();
  21449. function Loader(manager) {
  21450. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  21451. this.crossOrigin = 'anonymous';
  21452. this.withCredentials = false;
  21453. this.path = '';
  21454. this.resourcePath = '';
  21455. this.requestHeader = {};
  21456. }
  21457. Object.assign(Loader.prototype, {
  21458. load: function load()
  21459. /* url, onLoad, onProgress, onError */
  21460. {},
  21461. loadAsync: function loadAsync(url, onProgress) {
  21462. var scope = this;
  21463. return new Promise(function (resolve, reject) {
  21464. scope.load(url, resolve, onProgress, reject);
  21465. });
  21466. },
  21467. parse: function parse()
  21468. /* data */
  21469. {},
  21470. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  21471. this.crossOrigin = crossOrigin;
  21472. return this;
  21473. },
  21474. setWithCredentials: function setWithCredentials(value) {
  21475. this.withCredentials = value;
  21476. return this;
  21477. },
  21478. setPath: function setPath(path) {
  21479. this.path = path;
  21480. return this;
  21481. },
  21482. setResourcePath: function setResourcePath(resourcePath) {
  21483. this.resourcePath = resourcePath;
  21484. return this;
  21485. },
  21486. setRequestHeader: function setRequestHeader(requestHeader) {
  21487. this.requestHeader = requestHeader;
  21488. return this;
  21489. }
  21490. });
  21491. var loading = {};
  21492. function FileLoader(manager) {
  21493. Loader.call(this, manager);
  21494. }
  21495. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21496. constructor: FileLoader,
  21497. load: function load(url, onLoad, onProgress, onError) {
  21498. if (url === undefined) url = '';
  21499. if (this.path !== undefined) url = this.path + url;
  21500. url = this.manager.resolveURL(url);
  21501. var scope = this;
  21502. var cached = Cache.get(url);
  21503. if (cached !== undefined) {
  21504. scope.manager.itemStart(url);
  21505. setTimeout(function () {
  21506. if (onLoad) onLoad(cached);
  21507. scope.manager.itemEnd(url);
  21508. }, 0);
  21509. return cached;
  21510. } // Check if request is duplicate
  21511. if (loading[url] !== undefined) {
  21512. loading[url].push({
  21513. onLoad: onLoad,
  21514. onProgress: onProgress,
  21515. onError: onError
  21516. });
  21517. return;
  21518. } // Check for data: URI
  21519. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  21520. var dataUriRegexResult = url.match(dataUriRegex);
  21521. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  21522. if (dataUriRegexResult) {
  21523. var mimeType = dataUriRegexResult[1];
  21524. var isBase64 = !!dataUriRegexResult[2];
  21525. var data = dataUriRegexResult[3];
  21526. data = decodeURIComponent(data);
  21527. if (isBase64) data = atob(data);
  21528. try {
  21529. var response;
  21530. var responseType = (this.responseType || '').toLowerCase();
  21531. switch (responseType) {
  21532. case 'arraybuffer':
  21533. case 'blob':
  21534. var view = new Uint8Array(data.length);
  21535. for (var i = 0; i < data.length; i++) {
  21536. view[i] = data.charCodeAt(i);
  21537. }
  21538. if (responseType === 'blob') {
  21539. response = new Blob([view.buffer], {
  21540. type: mimeType
  21541. });
  21542. } else {
  21543. response = view.buffer;
  21544. }
  21545. break;
  21546. case 'document':
  21547. var parser = new DOMParser();
  21548. response = parser.parseFromString(data, mimeType);
  21549. break;
  21550. case 'json':
  21551. response = JSON.parse(data);
  21552. break;
  21553. default:
  21554. // 'text' or other
  21555. response = data;
  21556. break;
  21557. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21558. setTimeout(function () {
  21559. if (onLoad) onLoad(response);
  21560. scope.manager.itemEnd(url);
  21561. }, 0);
  21562. } catch (error) {
  21563. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21564. setTimeout(function () {
  21565. if (onError) onError(error);
  21566. scope.manager.itemError(url);
  21567. scope.manager.itemEnd(url);
  21568. }, 0);
  21569. }
  21570. } else {
  21571. // Initialise array for duplicate requests
  21572. loading[url] = [];
  21573. loading[url].push({
  21574. onLoad: onLoad,
  21575. onProgress: onProgress,
  21576. onError: onError
  21577. });
  21578. request = new XMLHttpRequest();
  21579. request.open('GET', url, true);
  21580. request.addEventListener('load', function (event) {
  21581. var response = this.response;
  21582. var callbacks = loading[url];
  21583. delete loading[url];
  21584. if (this.status === 200 || this.status === 0) {
  21585. // Some browsers return HTTP Status 0 when using non-http protocol
  21586. // e.g. 'file://' or 'data://'. Handle as success.
  21587. 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
  21588. // error response bodies as proper responses to requests.
  21589. Cache.add(url, response);
  21590. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  21591. var callback = callbacks[_i];
  21592. if (callback.onLoad) callback.onLoad(response);
  21593. }
  21594. scope.manager.itemEnd(url);
  21595. } else {
  21596. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  21597. var _callback = callbacks[_i2];
  21598. if (_callback.onError) _callback.onError(event);
  21599. }
  21600. scope.manager.itemError(url);
  21601. scope.manager.itemEnd(url);
  21602. }
  21603. }, false);
  21604. request.addEventListener('progress', function (event) {
  21605. var callbacks = loading[url];
  21606. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  21607. var callback = callbacks[_i3];
  21608. if (callback.onProgress) callback.onProgress(event);
  21609. }
  21610. }, false);
  21611. request.addEventListener('error', function (event) {
  21612. var callbacks = loading[url];
  21613. delete loading[url];
  21614. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  21615. var callback = callbacks[_i4];
  21616. if (callback.onError) callback.onError(event);
  21617. }
  21618. scope.manager.itemError(url);
  21619. scope.manager.itemEnd(url);
  21620. }, false);
  21621. request.addEventListener('abort', function (event) {
  21622. var callbacks = loading[url];
  21623. delete loading[url];
  21624. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  21625. var callback = callbacks[_i5];
  21626. if (callback.onError) callback.onError(event);
  21627. }
  21628. scope.manager.itemError(url);
  21629. scope.manager.itemEnd(url);
  21630. }, false);
  21631. if (this.responseType !== undefined) request.responseType = this.responseType;
  21632. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  21633. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  21634. for (var header in this.requestHeader) {
  21635. request.setRequestHeader(header, this.requestHeader[header]);
  21636. }
  21637. request.send(null);
  21638. }
  21639. scope.manager.itemStart(url);
  21640. return request;
  21641. },
  21642. setResponseType: function setResponseType(value) {
  21643. this.responseType = value;
  21644. return this;
  21645. },
  21646. setMimeType: function setMimeType(value) {
  21647. this.mimeType = value;
  21648. return this;
  21649. }
  21650. });
  21651. function AnimationLoader(manager) {
  21652. Loader.call(this, manager);
  21653. }
  21654. AnimationLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21655. constructor: AnimationLoader,
  21656. load: function load(url, onLoad, onProgress, onError) {
  21657. var scope = this;
  21658. var loader = new FileLoader(scope.manager);
  21659. loader.setPath(scope.path);
  21660. loader.setRequestHeader(scope.requestHeader);
  21661. loader.setWithCredentials(scope.withCredentials);
  21662. loader.load(url, function (text) {
  21663. try {
  21664. onLoad(scope.parse(JSON.parse(text)));
  21665. } catch (e) {
  21666. if (onError) {
  21667. onError(e);
  21668. } else {
  21669. console.error(e);
  21670. }
  21671. scope.manager.itemError(url);
  21672. }
  21673. }, onProgress, onError);
  21674. },
  21675. parse: function parse(json) {
  21676. var animations = [];
  21677. for (var i = 0; i < json.length; i++) {
  21678. var clip = AnimationClip.parse(json[i]);
  21679. animations.push(clip);
  21680. }
  21681. return animations;
  21682. }
  21683. });
  21684. /**
  21685. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21686. *
  21687. * Sub classes have to implement the parse() method which will be used in load().
  21688. */
  21689. function CompressedTextureLoader(manager) {
  21690. Loader.call(this, manager);
  21691. }
  21692. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21693. constructor: CompressedTextureLoader,
  21694. load: function load(url, onLoad, onProgress, onError) {
  21695. var scope = this;
  21696. var images = [];
  21697. var texture = new CompressedTexture();
  21698. var loader = new FileLoader(this.manager);
  21699. loader.setPath(this.path);
  21700. loader.setResponseType('arraybuffer');
  21701. loader.setRequestHeader(this.requestHeader);
  21702. loader.setWithCredentials(scope.withCredentials);
  21703. var loaded = 0;
  21704. function loadTexture(i) {
  21705. loader.load(url[i], function (buffer) {
  21706. var texDatas = scope.parse(buffer, true);
  21707. images[i] = {
  21708. width: texDatas.width,
  21709. height: texDatas.height,
  21710. format: texDatas.format,
  21711. mipmaps: texDatas.mipmaps
  21712. };
  21713. loaded += 1;
  21714. if (loaded === 6) {
  21715. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  21716. texture.image = images;
  21717. texture.format = texDatas.format;
  21718. texture.needsUpdate = true;
  21719. if (onLoad) onLoad(texture);
  21720. }
  21721. }, onProgress, onError);
  21722. }
  21723. if (Array.isArray(url)) {
  21724. for (var i = 0, il = url.length; i < il; ++i) {
  21725. loadTexture(i);
  21726. }
  21727. } else {
  21728. // compressed cubemap texture stored in a single DDS file
  21729. loader.load(url, function (buffer) {
  21730. var texDatas = scope.parse(buffer, true);
  21731. if (texDatas.isCubemap) {
  21732. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21733. for (var f = 0; f < faces; f++) {
  21734. images[f] = {
  21735. mipmaps: []
  21736. };
  21737. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  21738. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  21739. images[f].format = texDatas.format;
  21740. images[f].width = texDatas.width;
  21741. images[f].height = texDatas.height;
  21742. }
  21743. }
  21744. texture.image = images;
  21745. } else {
  21746. texture.image.width = texDatas.width;
  21747. texture.image.height = texDatas.height;
  21748. texture.mipmaps = texDatas.mipmaps;
  21749. }
  21750. if (texDatas.mipmapCount === 1) {
  21751. texture.minFilter = LinearFilter;
  21752. }
  21753. texture.format = texDatas.format;
  21754. texture.needsUpdate = true;
  21755. if (onLoad) onLoad(texture);
  21756. }, onProgress, onError);
  21757. }
  21758. return texture;
  21759. }
  21760. });
  21761. function ImageLoader(manager) {
  21762. Loader.call(this, manager);
  21763. }
  21764. ImageLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21765. constructor: ImageLoader,
  21766. load: function load(url, onLoad, onProgress, onError) {
  21767. if (this.path !== undefined) url = this.path + url;
  21768. url = this.manager.resolveURL(url);
  21769. var scope = this;
  21770. var cached = Cache.get(url);
  21771. if (cached !== undefined) {
  21772. scope.manager.itemStart(url);
  21773. setTimeout(function () {
  21774. if (onLoad) onLoad(cached);
  21775. scope.manager.itemEnd(url);
  21776. }, 0);
  21777. return cached;
  21778. }
  21779. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  21780. function onImageLoad() {
  21781. image.removeEventListener('load', onImageLoad, false);
  21782. image.removeEventListener('error', onImageError, false);
  21783. Cache.add(url, this);
  21784. if (onLoad) onLoad(this);
  21785. scope.manager.itemEnd(url);
  21786. }
  21787. function onImageError(event) {
  21788. image.removeEventListener('load', onImageLoad, false);
  21789. image.removeEventListener('error', onImageError, false);
  21790. if (onError) onError(event);
  21791. scope.manager.itemError(url);
  21792. scope.manager.itemEnd(url);
  21793. }
  21794. image.addEventListener('load', onImageLoad, false);
  21795. image.addEventListener('error', onImageError, false);
  21796. if (url.substr(0, 5) !== 'data:') {
  21797. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  21798. }
  21799. scope.manager.itemStart(url);
  21800. image.src = url;
  21801. return image;
  21802. }
  21803. });
  21804. function CubeTextureLoader(manager) {
  21805. Loader.call(this, manager);
  21806. }
  21807. CubeTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21808. constructor: CubeTextureLoader,
  21809. load: function load(urls, onLoad, onProgress, onError) {
  21810. var texture = new CubeTexture();
  21811. var loader = new ImageLoader(this.manager);
  21812. loader.setCrossOrigin(this.crossOrigin);
  21813. loader.setPath(this.path);
  21814. var loaded = 0;
  21815. function loadTexture(i) {
  21816. loader.load(urls[i], function (image) {
  21817. texture.images[i] = image;
  21818. loaded++;
  21819. if (loaded === 6) {
  21820. texture.needsUpdate = true;
  21821. if (onLoad) onLoad(texture);
  21822. }
  21823. }, undefined, onError);
  21824. }
  21825. for (var i = 0; i < urls.length; ++i) {
  21826. loadTexture(i);
  21827. }
  21828. return texture;
  21829. }
  21830. });
  21831. /**
  21832. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  21833. *
  21834. * Sub classes have to implement the parse() method which will be used in load().
  21835. */
  21836. function DataTextureLoader(manager) {
  21837. Loader.call(this, manager);
  21838. }
  21839. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21840. constructor: DataTextureLoader,
  21841. load: function load(url, onLoad, onProgress, onError) {
  21842. var scope = this;
  21843. var texture = new DataTexture();
  21844. var loader = new FileLoader(this.manager);
  21845. loader.setResponseType('arraybuffer');
  21846. loader.setRequestHeader(this.requestHeader);
  21847. loader.setPath(this.path);
  21848. loader.setWithCredentials(scope.withCredentials);
  21849. loader.load(url, function (buffer) {
  21850. var texData = scope.parse(buffer);
  21851. if (!texData) return;
  21852. if (texData.image !== undefined) {
  21853. texture.image = texData.image;
  21854. } else if (texData.data !== undefined) {
  21855. texture.image.width = texData.width;
  21856. texture.image.height = texData.height;
  21857. texture.image.data = texData.data;
  21858. }
  21859. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  21860. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  21861. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  21862. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  21863. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  21864. if (texData.encoding !== undefined) {
  21865. texture.encoding = texData.encoding;
  21866. }
  21867. if (texData.flipY !== undefined) {
  21868. texture.flipY = texData.flipY;
  21869. }
  21870. if (texData.format !== undefined) {
  21871. texture.format = texData.format;
  21872. }
  21873. if (texData.type !== undefined) {
  21874. texture.type = texData.type;
  21875. }
  21876. if (texData.mipmaps !== undefined) {
  21877. texture.mipmaps = texData.mipmaps;
  21878. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  21879. }
  21880. if (texData.mipmapCount === 1) {
  21881. texture.minFilter = LinearFilter;
  21882. }
  21883. texture.needsUpdate = true;
  21884. if (onLoad) onLoad(texture, texData);
  21885. }, onProgress, onError);
  21886. return texture;
  21887. }
  21888. });
  21889. function TextureLoader(manager) {
  21890. Loader.call(this, manager);
  21891. }
  21892. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21893. constructor: TextureLoader,
  21894. load: function load(url, onLoad, onProgress, onError) {
  21895. var texture = new Texture();
  21896. var loader = new ImageLoader(this.manager);
  21897. loader.setCrossOrigin(this.crossOrigin);
  21898. loader.setPath(this.path);
  21899. loader.load(url, function (image) {
  21900. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  21901. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  21902. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  21903. texture.needsUpdate = true;
  21904. if (onLoad !== undefined) {
  21905. onLoad(texture);
  21906. }
  21907. }, onProgress, onError);
  21908. return texture;
  21909. }
  21910. });
  21911. /**
  21912. * Extensible curve object.
  21913. *
  21914. * Some common of curve methods:
  21915. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  21916. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  21917. * .getPoints(), .getSpacedPoints()
  21918. * .getLength()
  21919. * .updateArcLengths()
  21920. *
  21921. * This following curves inherit from THREE.Curve:
  21922. *
  21923. * -- 2D curves --
  21924. * THREE.ArcCurve
  21925. * THREE.CubicBezierCurve
  21926. * THREE.EllipseCurve
  21927. * THREE.LineCurve
  21928. * THREE.QuadraticBezierCurve
  21929. * THREE.SplineCurve
  21930. *
  21931. * -- 3D curves --
  21932. * THREE.CatmullRomCurve3
  21933. * THREE.CubicBezierCurve3
  21934. * THREE.LineCurve3
  21935. * THREE.QuadraticBezierCurve3
  21936. *
  21937. * A series of curves can be represented as a THREE.CurvePath.
  21938. *
  21939. **/
  21940. function Curve() {
  21941. this.type = 'Curve';
  21942. this.arcLengthDivisions = 200;
  21943. }
  21944. Object.assign(Curve.prototype, {
  21945. // Virtual base class method to overwrite and implement in subclasses
  21946. // - t [0 .. 1]
  21947. getPoint: function getPoint()
  21948. /* t, optionalTarget */
  21949. {
  21950. console.warn('THREE.Curve: .getPoint() not implemented.');
  21951. return null;
  21952. },
  21953. // Get point at relative position in curve according to arc length
  21954. // - u [0 .. 1]
  21955. getPointAt: function getPointAt(u, optionalTarget) {
  21956. var t = this.getUtoTmapping(u);
  21957. return this.getPoint(t, optionalTarget);
  21958. },
  21959. // Get sequence of points using getPoint( t )
  21960. getPoints: function getPoints(divisions) {
  21961. if (divisions === void 0) {
  21962. divisions = 5;
  21963. }
  21964. var points = [];
  21965. for (var d = 0; d <= divisions; d++) {
  21966. points.push(this.getPoint(d / divisions));
  21967. }
  21968. return points;
  21969. },
  21970. // Get sequence of points using getPointAt( u )
  21971. getSpacedPoints: function getSpacedPoints(divisions) {
  21972. if (divisions === void 0) {
  21973. divisions = 5;
  21974. }
  21975. var points = [];
  21976. for (var d = 0; d <= divisions; d++) {
  21977. points.push(this.getPointAt(d / divisions));
  21978. }
  21979. return points;
  21980. },
  21981. // Get total curve arc length
  21982. getLength: function getLength() {
  21983. var lengths = this.getLengths();
  21984. return lengths[lengths.length - 1];
  21985. },
  21986. // Get list of cumulative segment lengths
  21987. getLengths: function getLengths(divisions) {
  21988. if (divisions === undefined) divisions = this.arcLengthDivisions;
  21989. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  21990. return this.cacheArcLengths;
  21991. }
  21992. this.needsUpdate = false;
  21993. var cache = [];
  21994. var current,
  21995. last = this.getPoint(0);
  21996. var sum = 0;
  21997. cache.push(0);
  21998. for (var p = 1; p <= divisions; p++) {
  21999. current = this.getPoint(p / divisions);
  22000. sum += current.distanceTo(last);
  22001. cache.push(sum);
  22002. last = current;
  22003. }
  22004. this.cacheArcLengths = cache;
  22005. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22006. },
  22007. updateArcLengths: function updateArcLengths() {
  22008. this.needsUpdate = true;
  22009. this.getLengths();
  22010. },
  22011. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22012. getUtoTmapping: function getUtoTmapping(u, distance) {
  22013. var arcLengths = this.getLengths();
  22014. var i = 0;
  22015. var il = arcLengths.length;
  22016. var targetArcLength; // The targeted u distance value to get
  22017. if (distance) {
  22018. targetArcLength = distance;
  22019. } else {
  22020. targetArcLength = u * arcLengths[il - 1];
  22021. } // binary search for the index with largest value smaller than target u distance
  22022. var low = 0,
  22023. high = il - 1,
  22024. comparison;
  22025. while (low <= high) {
  22026. 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
  22027. comparison = arcLengths[i] - targetArcLength;
  22028. if (comparison < 0) {
  22029. low = i + 1;
  22030. } else if (comparison > 0) {
  22031. high = i - 1;
  22032. } else {
  22033. high = i;
  22034. break; // DONE
  22035. }
  22036. }
  22037. i = high;
  22038. if (arcLengths[i] === targetArcLength) {
  22039. return i / (il - 1);
  22040. } // we could get finer grain at lengths, or use simple interpolation between two points
  22041. var lengthBefore = arcLengths[i];
  22042. var lengthAfter = arcLengths[i + 1];
  22043. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  22044. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  22045. var t = (i + segmentFraction) / (il - 1);
  22046. return t;
  22047. },
  22048. // Returns a unit vector tangent at t
  22049. // In case any sub curve does not implement its tangent derivation,
  22050. // 2 points a small delta apart will be used to find its gradient
  22051. // which seems to give a reasonable approximation
  22052. getTangent: function getTangent(t, optionalTarget) {
  22053. var delta = 0.0001;
  22054. var t1 = t - delta;
  22055. var t2 = t + delta; // Capping in case of danger
  22056. if (t1 < 0) t1 = 0;
  22057. if (t2 > 1) t2 = 1;
  22058. var pt1 = this.getPoint(t1);
  22059. var pt2 = this.getPoint(t2);
  22060. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  22061. tangent.copy(pt2).sub(pt1).normalize();
  22062. return tangent;
  22063. },
  22064. getTangentAt: function getTangentAt(u, optionalTarget) {
  22065. var t = this.getUtoTmapping(u);
  22066. return this.getTangent(t, optionalTarget);
  22067. },
  22068. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  22069. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22070. var normal = new Vector3();
  22071. var tangents = [];
  22072. var normals = [];
  22073. var binormals = [];
  22074. var vec = new Vector3();
  22075. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  22076. for (var i = 0; i <= segments; i++) {
  22077. var u = i / segments;
  22078. tangents[i] = this.getTangentAt(u, new Vector3());
  22079. tangents[i].normalize();
  22080. } // select an initial normal vector perpendicular to the first tangent vector,
  22081. // and in the direction of the minimum tangent xyz component
  22082. normals[0] = new Vector3();
  22083. binormals[0] = new Vector3();
  22084. var min = Number.MAX_VALUE;
  22085. var tx = Math.abs(tangents[0].x);
  22086. var ty = Math.abs(tangents[0].y);
  22087. var tz = Math.abs(tangents[0].z);
  22088. if (tx <= min) {
  22089. min = tx;
  22090. normal.set(1, 0, 0);
  22091. }
  22092. if (ty <= min) {
  22093. min = ty;
  22094. normal.set(0, 1, 0);
  22095. }
  22096. if (tz <= min) {
  22097. normal.set(0, 0, 1);
  22098. }
  22099. vec.crossVectors(tangents[0], normal).normalize();
  22100. normals[0].crossVectors(tangents[0], vec);
  22101. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22102. for (var _i = 1; _i <= segments; _i++) {
  22103. normals[_i] = normals[_i - 1].clone();
  22104. binormals[_i] = binormals[_i - 1].clone();
  22105. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  22106. if (vec.length() > Number.EPSILON) {
  22107. vec.normalize();
  22108. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  22109. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  22110. }
  22111. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  22112. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22113. if (closed === true) {
  22114. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  22115. _theta /= segments;
  22116. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  22117. _theta = -_theta;
  22118. }
  22119. for (var _i2 = 1; _i2 <= segments; _i2++) {
  22120. // twist a little...
  22121. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  22122. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  22123. }
  22124. }
  22125. return {
  22126. tangents: tangents,
  22127. normals: normals,
  22128. binormals: binormals
  22129. };
  22130. },
  22131. clone: function clone() {
  22132. return new this.constructor().copy(this);
  22133. },
  22134. copy: function copy(source) {
  22135. this.arcLengthDivisions = source.arcLengthDivisions;
  22136. return this;
  22137. },
  22138. toJSON: function toJSON() {
  22139. var data = {
  22140. metadata: {
  22141. version: 4.5,
  22142. type: 'Curve',
  22143. generator: 'Curve.toJSON'
  22144. }
  22145. };
  22146. data.arcLengthDivisions = this.arcLengthDivisions;
  22147. data.type = this.type;
  22148. return data;
  22149. },
  22150. fromJSON: function fromJSON(json) {
  22151. this.arcLengthDivisions = json.arcLengthDivisions;
  22152. return this;
  22153. }
  22154. });
  22155. var EllipseCurve = /*#__PURE__*/function (_Curve) {
  22156. _inheritsLoose(EllipseCurve, _Curve);
  22157. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22158. var _this;
  22159. _this = _Curve.call(this) || this;
  22160. _this.type = 'EllipseCurve';
  22161. Object.defineProperty(_assertThisInitialized(_this), 'isEllipseCurve', {
  22162. value: true
  22163. });
  22164. _this.aX = aX || 0;
  22165. _this.aY = aY || 0;
  22166. _this.xRadius = xRadius || 1;
  22167. _this.yRadius = yRadius || 1;
  22168. _this.aStartAngle = aStartAngle || 0;
  22169. _this.aEndAngle = aEndAngle || 2 * Math.PI;
  22170. _this.aClockwise = aClockwise || false;
  22171. _this.aRotation = aRotation || 0;
  22172. return _this;
  22173. }
  22174. var _proto = EllipseCurve.prototype;
  22175. _proto.getPoint = function getPoint(t, optionalTarget) {
  22176. var point = optionalTarget || new Vector2();
  22177. var twoPi = Math.PI * 2;
  22178. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22179. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  22180. while (deltaAngle < 0) {
  22181. deltaAngle += twoPi;
  22182. }
  22183. while (deltaAngle > twoPi) {
  22184. deltaAngle -= twoPi;
  22185. }
  22186. if (deltaAngle < Number.EPSILON) {
  22187. if (samePoints) {
  22188. deltaAngle = 0;
  22189. } else {
  22190. deltaAngle = twoPi;
  22191. }
  22192. }
  22193. if (this.aClockwise === true && !samePoints) {
  22194. if (deltaAngle === twoPi) {
  22195. deltaAngle = -twoPi;
  22196. } else {
  22197. deltaAngle = deltaAngle - twoPi;
  22198. }
  22199. }
  22200. var angle = this.aStartAngle + t * deltaAngle;
  22201. var x = this.aX + this.xRadius * Math.cos(angle);
  22202. var y = this.aY + this.yRadius * Math.sin(angle);
  22203. if (this.aRotation !== 0) {
  22204. var cos = Math.cos(this.aRotation);
  22205. var sin = Math.sin(this.aRotation);
  22206. var tx = x - this.aX;
  22207. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  22208. x = tx * cos - ty * sin + this.aX;
  22209. y = tx * sin + ty * cos + this.aY;
  22210. }
  22211. return point.set(x, y);
  22212. };
  22213. _proto.copy = function copy(source) {
  22214. _Curve.prototype.copy.call(this, source);
  22215. this.aX = source.aX;
  22216. this.aY = source.aY;
  22217. this.xRadius = source.xRadius;
  22218. this.yRadius = source.yRadius;
  22219. this.aStartAngle = source.aStartAngle;
  22220. this.aEndAngle = source.aEndAngle;
  22221. this.aClockwise = source.aClockwise;
  22222. this.aRotation = source.aRotation;
  22223. return this;
  22224. };
  22225. _proto.toJSON = function toJSON() {
  22226. var data = _Curve.prototype.toJSON.call(this);
  22227. data.aX = this.aX;
  22228. data.aY = this.aY;
  22229. data.xRadius = this.xRadius;
  22230. data.yRadius = this.yRadius;
  22231. data.aStartAngle = this.aStartAngle;
  22232. data.aEndAngle = this.aEndAngle;
  22233. data.aClockwise = this.aClockwise;
  22234. data.aRotation = this.aRotation;
  22235. return data;
  22236. };
  22237. _proto.fromJSON = function fromJSON(json) {
  22238. _Curve.prototype.fromJSON.call(this, json);
  22239. this.aX = json.aX;
  22240. this.aY = json.aY;
  22241. this.xRadius = json.xRadius;
  22242. this.yRadius = json.yRadius;
  22243. this.aStartAngle = json.aStartAngle;
  22244. this.aEndAngle = json.aEndAngle;
  22245. this.aClockwise = json.aClockwise;
  22246. this.aRotation = json.aRotation;
  22247. return this;
  22248. };
  22249. return EllipseCurve;
  22250. }(Curve);
  22251. var ArcCurve = /*#__PURE__*/function (_EllipseCurve) {
  22252. _inheritsLoose(ArcCurve, _EllipseCurve);
  22253. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22254. var _this;
  22255. _this = _EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise) || this;
  22256. _this.type = 'ArcCurve';
  22257. Object.defineProperty(_assertThisInitialized(_this), 'isArcCurve', {
  22258. value: true
  22259. });
  22260. return _this;
  22261. }
  22262. return ArcCurve;
  22263. }(EllipseCurve);
  22264. /**
  22265. * Centripetal CatmullRom Curve - which is useful for avoiding
  22266. * cusps and self-intersections in non-uniform catmull rom curves.
  22267. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22268. *
  22269. * curve.type accepts centripetal(default), chordal and catmullrom
  22270. * curve.tension is used for catmullrom which defaults to 0.5
  22271. */
  22272. /*
  22273. Based on an optimized c++ solution in
  22274. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22275. - http://ideone.com/NoEbVM
  22276. This CubicPoly class could be used for reusing some variables and calculations,
  22277. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22278. which can be placed in CurveUtils.
  22279. */
  22280. function CubicPoly() {
  22281. var c0 = 0,
  22282. c1 = 0,
  22283. c2 = 0,
  22284. c3 = 0;
  22285. /*
  22286. * Compute coefficients for a cubic polynomial
  22287. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22288. * such that
  22289. * p(0) = x0, p(1) = x1
  22290. * and
  22291. * p'(0) = t0, p'(1) = t1.
  22292. */
  22293. function init(x0, x1, t0, t1) {
  22294. c0 = x0;
  22295. c1 = t0;
  22296. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  22297. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22298. }
  22299. return {
  22300. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  22301. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  22302. },
  22303. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  22304. // compute tangents when parameterized in [t1,t2]
  22305. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  22306. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  22307. t1 *= dt1;
  22308. t2 *= dt1;
  22309. init(x1, x2, t1, t2);
  22310. },
  22311. calc: function calc(t) {
  22312. var t2 = t * t;
  22313. var t3 = t2 * t;
  22314. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22315. }
  22316. };
  22317. } //
  22318. var tmp = new Vector3();
  22319. var px = new CubicPoly(),
  22320. py = new CubicPoly(),
  22321. pz = new CubicPoly();
  22322. var CatmullRomCurve3 = /*#__PURE__*/function (_Curve) {
  22323. _inheritsLoose(CatmullRomCurve3, _Curve);
  22324. function CatmullRomCurve3(points, closed, curveType, tension) {
  22325. var _this;
  22326. if (points === void 0) {
  22327. points = [];
  22328. }
  22329. if (closed === void 0) {
  22330. closed = false;
  22331. }
  22332. if (curveType === void 0) {
  22333. curveType = 'centripetal';
  22334. }
  22335. if (tension === void 0) {
  22336. tension = 0.5;
  22337. }
  22338. _this = _Curve.call(this) || this;
  22339. _this.type = 'CatmullRomCurve3';
  22340. Object.defineProperty(_assertThisInitialized(_this), 'isCatmullRomCurve3', {
  22341. value: true
  22342. });
  22343. _this.points = points;
  22344. _this.closed = closed;
  22345. _this.curveType = curveType;
  22346. _this.tension = tension;
  22347. return _this;
  22348. }
  22349. var _proto = CatmullRomCurve3.prototype;
  22350. _proto.getPoint = function getPoint(t, optionalTarget) {
  22351. if (optionalTarget === void 0) {
  22352. optionalTarget = new Vector3();
  22353. }
  22354. var point = optionalTarget;
  22355. var points = this.points;
  22356. var l = points.length;
  22357. var p = (l - (this.closed ? 0 : 1)) * t;
  22358. var intPoint = Math.floor(p);
  22359. var weight = p - intPoint;
  22360. if (this.closed) {
  22361. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  22362. } else if (weight === 0 && intPoint === l - 1) {
  22363. intPoint = l - 2;
  22364. weight = 1;
  22365. }
  22366. var p0, p3; // 4 points (p1 & p2 defined below)
  22367. if (this.closed || intPoint > 0) {
  22368. p0 = points[(intPoint - 1) % l];
  22369. } else {
  22370. // extrapolate first point
  22371. tmp.subVectors(points[0], points[1]).add(points[0]);
  22372. p0 = tmp;
  22373. }
  22374. var p1 = points[intPoint % l];
  22375. var p2 = points[(intPoint + 1) % l];
  22376. if (this.closed || intPoint + 2 < l) {
  22377. p3 = points[(intPoint + 2) % l];
  22378. } else {
  22379. // extrapolate last point
  22380. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  22381. p3 = tmp;
  22382. }
  22383. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  22384. // init Centripetal / Chordal Catmull-Rom
  22385. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22386. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  22387. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  22388. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  22389. if (dt1 < 1e-4) dt1 = 1.0;
  22390. if (dt0 < 1e-4) dt0 = dt1;
  22391. if (dt2 < 1e-4) dt2 = dt1;
  22392. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  22393. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  22394. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  22395. } else if (this.curveType === 'catmullrom') {
  22396. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  22397. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  22398. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  22399. }
  22400. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  22401. return point;
  22402. };
  22403. _proto.copy = function copy(source) {
  22404. _Curve.prototype.copy.call(this, source);
  22405. this.points = [];
  22406. for (var i = 0, l = source.points.length; i < l; i++) {
  22407. var point = source.points[i];
  22408. this.points.push(point.clone());
  22409. }
  22410. this.closed = source.closed;
  22411. this.curveType = source.curveType;
  22412. this.tension = source.tension;
  22413. return this;
  22414. };
  22415. _proto.toJSON = function toJSON() {
  22416. var data = _Curve.prototype.toJSON.call(this);
  22417. data.points = [];
  22418. for (var i = 0, l = this.points.length; i < l; i++) {
  22419. var point = this.points[i];
  22420. data.points.push(point.toArray());
  22421. }
  22422. data.closed = this.closed;
  22423. data.curveType = this.curveType;
  22424. data.tension = this.tension;
  22425. return data;
  22426. };
  22427. _proto.fromJSON = function fromJSON(json) {
  22428. _Curve.prototype.fromJSON.call(this, json);
  22429. this.points = [];
  22430. for (var i = 0, l = json.points.length; i < l; i++) {
  22431. var point = json.points[i];
  22432. this.points.push(new Vector3().fromArray(point));
  22433. }
  22434. this.closed = json.closed;
  22435. this.curveType = json.curveType;
  22436. this.tension = json.tension;
  22437. return this;
  22438. };
  22439. return CatmullRomCurve3;
  22440. }(Curve);
  22441. /**
  22442. * Bezier Curves formulas obtained from
  22443. * http://en.wikipedia.org/wiki/Bézier_curve
  22444. */
  22445. function CatmullRom(t, p0, p1, p2, p3) {
  22446. var v0 = (p2 - p0) * 0.5;
  22447. var v1 = (p3 - p1) * 0.5;
  22448. var t2 = t * t;
  22449. var t3 = t * t2;
  22450. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  22451. } //
  22452. function QuadraticBezierP0(t, p) {
  22453. var k = 1 - t;
  22454. return k * k * p;
  22455. }
  22456. function QuadraticBezierP1(t, p) {
  22457. return 2 * (1 - t) * t * p;
  22458. }
  22459. function QuadraticBezierP2(t, p) {
  22460. return t * t * p;
  22461. }
  22462. function QuadraticBezier(t, p0, p1, p2) {
  22463. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  22464. } //
  22465. function CubicBezierP0(t, p) {
  22466. var k = 1 - t;
  22467. return k * k * k * p;
  22468. }
  22469. function CubicBezierP1(t, p) {
  22470. var k = 1 - t;
  22471. return 3 * k * k * t * p;
  22472. }
  22473. function CubicBezierP2(t, p) {
  22474. return 3 * (1 - t) * t * t * p;
  22475. }
  22476. function CubicBezierP3(t, p) {
  22477. return t * t * t * p;
  22478. }
  22479. function CubicBezier(t, p0, p1, p2, p3) {
  22480. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  22481. }
  22482. var CubicBezierCurve = /*#__PURE__*/function (_Curve) {
  22483. _inheritsLoose(CubicBezierCurve, _Curve);
  22484. function CubicBezierCurve(v0, v1, v2, v3) {
  22485. var _this;
  22486. if (v0 === void 0) {
  22487. v0 = new Vector2();
  22488. }
  22489. if (v1 === void 0) {
  22490. v1 = new Vector2();
  22491. }
  22492. if (v2 === void 0) {
  22493. v2 = new Vector2();
  22494. }
  22495. if (v3 === void 0) {
  22496. v3 = new Vector2();
  22497. }
  22498. _this = _Curve.call(this) || this;
  22499. _this.type = 'CubicBezierCurve';
  22500. Object.defineProperty(_assertThisInitialized(_this), 'isCubicBezierCurve', {
  22501. value: true
  22502. });
  22503. _this.v0 = v0;
  22504. _this.v1 = v1;
  22505. _this.v2 = v2;
  22506. _this.v3 = v3;
  22507. return _this;
  22508. }
  22509. var _proto = CubicBezierCurve.prototype;
  22510. _proto.getPoint = function getPoint(t, optionalTarget) {
  22511. if (optionalTarget === void 0) {
  22512. optionalTarget = new Vector2();
  22513. }
  22514. var point = optionalTarget;
  22515. var v0 = this.v0,
  22516. v1 = this.v1,
  22517. v2 = this.v2,
  22518. v3 = this.v3;
  22519. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  22520. return point;
  22521. };
  22522. _proto.copy = function copy(source) {
  22523. _Curve.prototype.copy.call(this, source);
  22524. this.v0.copy(source.v0);
  22525. this.v1.copy(source.v1);
  22526. this.v2.copy(source.v2);
  22527. this.v3.copy(source.v3);
  22528. return this;
  22529. };
  22530. _proto.toJSON = function toJSON() {
  22531. var data = _Curve.prototype.toJSON.call(this);
  22532. data.v0 = this.v0.toArray();
  22533. data.v1 = this.v1.toArray();
  22534. data.v2 = this.v2.toArray();
  22535. data.v3 = this.v3.toArray();
  22536. return data;
  22537. };
  22538. _proto.fromJSON = function fromJSON(json) {
  22539. _Curve.prototype.fromJSON.call(this, json);
  22540. this.v0.fromArray(json.v0);
  22541. this.v1.fromArray(json.v1);
  22542. this.v2.fromArray(json.v2);
  22543. this.v3.fromArray(json.v3);
  22544. return this;
  22545. };
  22546. return CubicBezierCurve;
  22547. }(Curve);
  22548. var CubicBezierCurve3 = /*#__PURE__*/function (_Curve) {
  22549. _inheritsLoose(CubicBezierCurve3, _Curve);
  22550. function CubicBezierCurve3(v0, v1, v2, v3) {
  22551. var _this;
  22552. if (v0 === void 0) {
  22553. v0 = new Vector3();
  22554. }
  22555. if (v1 === void 0) {
  22556. v1 = new Vector3();
  22557. }
  22558. if (v2 === void 0) {
  22559. v2 = new Vector3();
  22560. }
  22561. if (v3 === void 0) {
  22562. v3 = new Vector3();
  22563. }
  22564. _this = _Curve.call(this) || this;
  22565. _this.type = 'CubicBezierCurve3';
  22566. Object.defineProperty(_assertThisInitialized(_this), 'isCubicBezierCurve3', {
  22567. value: true
  22568. });
  22569. _this.v0 = v0;
  22570. _this.v1 = v1;
  22571. _this.v2 = v2;
  22572. _this.v3 = v3;
  22573. return _this;
  22574. }
  22575. var _proto = CubicBezierCurve3.prototype;
  22576. _proto.getPoint = function getPoint(t, optionalTarget) {
  22577. if (optionalTarget === void 0) {
  22578. optionalTarget = new Vector3();
  22579. }
  22580. var point = optionalTarget;
  22581. var v0 = this.v0,
  22582. v1 = this.v1,
  22583. v2 = this.v2,
  22584. v3 = this.v3;
  22585. 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));
  22586. return point;
  22587. };
  22588. _proto.copy = function copy(source) {
  22589. _Curve.prototype.copy.call(this, source);
  22590. this.v0.copy(source.v0);
  22591. this.v1.copy(source.v1);
  22592. this.v2.copy(source.v2);
  22593. this.v3.copy(source.v3);
  22594. return this;
  22595. };
  22596. _proto.toJSON = function toJSON() {
  22597. var data = _Curve.prototype.toJSON.call(this);
  22598. data.v0 = this.v0.toArray();
  22599. data.v1 = this.v1.toArray();
  22600. data.v2 = this.v2.toArray();
  22601. data.v3 = this.v3.toArray();
  22602. return data;
  22603. };
  22604. _proto.fromJSON = function fromJSON(json) {
  22605. _Curve.prototype.fromJSON.call(this, json);
  22606. this.v0.fromArray(json.v0);
  22607. this.v1.fromArray(json.v1);
  22608. this.v2.fromArray(json.v2);
  22609. this.v3.fromArray(json.v3);
  22610. return this;
  22611. };
  22612. return CubicBezierCurve3;
  22613. }(Curve);
  22614. var LineCurve = /*#__PURE__*/function (_Curve) {
  22615. _inheritsLoose(LineCurve, _Curve);
  22616. function LineCurve(v1, v2) {
  22617. var _this;
  22618. if (v1 === void 0) {
  22619. v1 = new Vector2();
  22620. }
  22621. if (v2 === void 0) {
  22622. v2 = new Vector2();
  22623. }
  22624. _this = _Curve.call(this) || this;
  22625. _this.type = 'LineCurve';
  22626. Object.defineProperty(_assertThisInitialized(_this), 'isLineCurve', {
  22627. value: true
  22628. });
  22629. _this.v1 = v1;
  22630. _this.v2 = v2;
  22631. return _this;
  22632. }
  22633. var _proto = LineCurve.prototype;
  22634. _proto.getPoint = function getPoint(t, optionalTarget) {
  22635. if (optionalTarget === void 0) {
  22636. optionalTarget = new Vector2();
  22637. }
  22638. var point = optionalTarget;
  22639. if (t === 1) {
  22640. point.copy(this.v2);
  22641. } else {
  22642. point.copy(this.v2).sub(this.v1);
  22643. point.multiplyScalar(t).add(this.v1);
  22644. }
  22645. return point;
  22646. } // Line curve is linear, so we can overwrite default getPointAt
  22647. ;
  22648. _proto.getPointAt = function getPointAt(u, optionalTarget) {
  22649. return this.getPoint(u, optionalTarget);
  22650. };
  22651. _proto.getTangent = function getTangent(t, optionalTarget) {
  22652. var tangent = optionalTarget || new Vector2();
  22653. tangent.copy(this.v2).sub(this.v1).normalize();
  22654. return tangent;
  22655. };
  22656. _proto.copy = function copy(source) {
  22657. _Curve.prototype.copy.call(this, source);
  22658. this.v1.copy(source.v1);
  22659. this.v2.copy(source.v2);
  22660. return this;
  22661. };
  22662. _proto.toJSON = function toJSON() {
  22663. var data = _Curve.prototype.toJSON.call(this);
  22664. data.v1 = this.v1.toArray();
  22665. data.v2 = this.v2.toArray();
  22666. return data;
  22667. };
  22668. _proto.fromJSON = function fromJSON(json) {
  22669. _Curve.prototype.fromJSON.call(this, json);
  22670. this.v1.fromArray(json.v1);
  22671. this.v2.fromArray(json.v2);
  22672. return this;
  22673. };
  22674. return LineCurve;
  22675. }(Curve);
  22676. var LineCurve3 = /*#__PURE__*/function (_Curve) {
  22677. _inheritsLoose(LineCurve3, _Curve);
  22678. function LineCurve3(v1, v2) {
  22679. var _this;
  22680. if (v1 === void 0) {
  22681. v1 = new Vector3();
  22682. }
  22683. if (v2 === void 0) {
  22684. v2 = new Vector3();
  22685. }
  22686. _this = _Curve.call(this) || this;
  22687. _this.type = 'LineCurve3';
  22688. Object.defineProperty(_assertThisInitialized(_this), 'isLineCurve3', {
  22689. value: true
  22690. });
  22691. _this.v1 = v1;
  22692. _this.v2 = v2;
  22693. return _this;
  22694. }
  22695. var _proto = LineCurve3.prototype;
  22696. _proto.getPoint = function getPoint(t, optionalTarget) {
  22697. if (optionalTarget === void 0) {
  22698. optionalTarget = new Vector3();
  22699. }
  22700. var point = optionalTarget;
  22701. if (t === 1) {
  22702. point.copy(this.v2);
  22703. } else {
  22704. point.copy(this.v2).sub(this.v1);
  22705. point.multiplyScalar(t).add(this.v1);
  22706. }
  22707. return point;
  22708. } // Line curve is linear, so we can overwrite default getPointAt
  22709. ;
  22710. _proto.getPointAt = function getPointAt(u, optionalTarget) {
  22711. return this.getPoint(u, optionalTarget);
  22712. };
  22713. _proto.copy = function copy(source) {
  22714. _Curve.prototype.copy.call(this, source);
  22715. this.v1.copy(source.v1);
  22716. this.v2.copy(source.v2);
  22717. return this;
  22718. };
  22719. _proto.toJSON = function toJSON() {
  22720. var data = _Curve.prototype.toJSON.call(this);
  22721. data.v1 = this.v1.toArray();
  22722. data.v2 = this.v2.toArray();
  22723. return data;
  22724. };
  22725. _proto.fromJSON = function fromJSON(json) {
  22726. _Curve.prototype.fromJSON.call(this, json);
  22727. this.v1.fromArray(json.v1);
  22728. this.v2.fromArray(json.v2);
  22729. return this;
  22730. };
  22731. return LineCurve3;
  22732. }(Curve);
  22733. var QuadraticBezierCurve = /*#__PURE__*/function (_Curve) {
  22734. _inheritsLoose(QuadraticBezierCurve, _Curve);
  22735. function QuadraticBezierCurve(v0, v1, v2) {
  22736. var _this;
  22737. if (v0 === void 0) {
  22738. v0 = new Vector2();
  22739. }
  22740. if (v1 === void 0) {
  22741. v1 = new Vector2();
  22742. }
  22743. if (v2 === void 0) {
  22744. v2 = new Vector2();
  22745. }
  22746. _this = _Curve.call(this) || this;
  22747. _this.type = 'QuadraticBezierCurve';
  22748. Object.defineProperty(_assertThisInitialized(_this), 'isQuadraticBezierCurve', {
  22749. value: true
  22750. });
  22751. _this.v0 = v0;
  22752. _this.v1 = v1;
  22753. _this.v2 = v2;
  22754. return _this;
  22755. }
  22756. var _proto = QuadraticBezierCurve.prototype;
  22757. _proto.getPoint = function getPoint(t, optionalTarget) {
  22758. if (optionalTarget === void 0) {
  22759. optionalTarget = new Vector2();
  22760. }
  22761. var point = optionalTarget;
  22762. var v0 = this.v0,
  22763. v1 = this.v1,
  22764. v2 = this.v2;
  22765. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  22766. return point;
  22767. };
  22768. _proto.copy = function copy(source) {
  22769. _Curve.prototype.copy.call(this, source);
  22770. this.v0.copy(source.v0);
  22771. this.v1.copy(source.v1);
  22772. this.v2.copy(source.v2);
  22773. return this;
  22774. };
  22775. _proto.toJSON = function toJSON() {
  22776. var data = _Curve.prototype.toJSON.call(this);
  22777. data.v0 = this.v0.toArray();
  22778. data.v1 = this.v1.toArray();
  22779. data.v2 = this.v2.toArray();
  22780. return data;
  22781. };
  22782. _proto.fromJSON = function fromJSON(json) {
  22783. _Curve.prototype.fromJSON.call(this, json);
  22784. this.v0.fromArray(json.v0);
  22785. this.v1.fromArray(json.v1);
  22786. this.v2.fromArray(json.v2);
  22787. return this;
  22788. };
  22789. return QuadraticBezierCurve;
  22790. }(Curve);
  22791. var QuadraticBezierCurve3 = /*#__PURE__*/function (_Curve) {
  22792. _inheritsLoose(QuadraticBezierCurve3, _Curve);
  22793. function QuadraticBezierCurve3(v0, v1, v2) {
  22794. var _this;
  22795. if (v0 === void 0) {
  22796. v0 = new Vector3();
  22797. }
  22798. if (v1 === void 0) {
  22799. v1 = new Vector3();
  22800. }
  22801. if (v2 === void 0) {
  22802. v2 = new Vector3();
  22803. }
  22804. _this = _Curve.call(this) || this;
  22805. _this.type = 'QuadraticBezierCurve3';
  22806. Object.defineProperty(_assertThisInitialized(_this), 'isQuadraticBezierCurve3', {
  22807. value: true
  22808. });
  22809. _this.v0 = v0;
  22810. _this.v1 = v1;
  22811. _this.v2 = v2;
  22812. return _this;
  22813. }
  22814. var _proto = QuadraticBezierCurve3.prototype;
  22815. _proto.getPoint = function getPoint(t, optionalTarget) {
  22816. if (optionalTarget === void 0) {
  22817. optionalTarget = new Vector3();
  22818. }
  22819. var point = optionalTarget;
  22820. var v0 = this.v0,
  22821. v1 = this.v1,
  22822. v2 = this.v2;
  22823. 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));
  22824. return point;
  22825. };
  22826. _proto.copy = function copy(source) {
  22827. _Curve.prototype.copy.call(this, source);
  22828. this.v0.copy(source.v0);
  22829. this.v1.copy(source.v1);
  22830. this.v2.copy(source.v2);
  22831. return this;
  22832. };
  22833. _proto.toJSON = function toJSON() {
  22834. var data = _Curve.prototype.toJSON.call(this);
  22835. data.v0 = this.v0.toArray();
  22836. data.v1 = this.v1.toArray();
  22837. data.v2 = this.v2.toArray();
  22838. return data;
  22839. };
  22840. _proto.fromJSON = function fromJSON(json) {
  22841. _Curve.prototype.fromJSON.call(this, json);
  22842. this.v0.fromArray(json.v0);
  22843. this.v1.fromArray(json.v1);
  22844. this.v2.fromArray(json.v2);
  22845. return this;
  22846. };
  22847. return QuadraticBezierCurve3;
  22848. }(Curve);
  22849. var SplineCurve = /*#__PURE__*/function (_Curve) {
  22850. _inheritsLoose(SplineCurve, _Curve);
  22851. function SplineCurve(points) {
  22852. var _this;
  22853. if (points === void 0) {
  22854. points = [];
  22855. }
  22856. _this = _Curve.call(this) || this;
  22857. _this.type = 'SplineCurve';
  22858. Object.defineProperty(_assertThisInitialized(_this), 'isSplineCurve', {
  22859. value: true
  22860. });
  22861. _this.points = points;
  22862. return _this;
  22863. }
  22864. var _proto = SplineCurve.prototype;
  22865. _proto.getPoint = function getPoint(t, optionalTarget) {
  22866. if (optionalTarget === void 0) {
  22867. optionalTarget = new Vector2();
  22868. }
  22869. var point = optionalTarget;
  22870. var points = this.points;
  22871. var p = (points.length - 1) * t;
  22872. var intPoint = Math.floor(p);
  22873. var weight = p - intPoint;
  22874. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  22875. var p1 = points[intPoint];
  22876. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  22877. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  22878. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  22879. return point;
  22880. };
  22881. _proto.copy = function copy(source) {
  22882. Curve.prototype.copy.call(this, source);
  22883. this.points = [];
  22884. for (var i = 0, l = source.points.length; i < l; i++) {
  22885. var point = source.points[i];
  22886. this.points.push(point.clone());
  22887. }
  22888. return this;
  22889. };
  22890. _proto.toJSON = function toJSON() {
  22891. var data = Curve.prototype.toJSON.call(this);
  22892. data.points = [];
  22893. for (var i = 0, l = this.points.length; i < l; i++) {
  22894. var point = this.points[i];
  22895. data.points.push(point.toArray());
  22896. }
  22897. return data;
  22898. };
  22899. _proto.fromJSON = function fromJSON(json) {
  22900. Curve.prototype.fromJSON.call(this, json);
  22901. this.points = [];
  22902. for (var i = 0, l = json.points.length; i < l; i++) {
  22903. var point = json.points[i];
  22904. this.points.push(new Vector2().fromArray(point));
  22905. }
  22906. return this;
  22907. };
  22908. return SplineCurve;
  22909. }(Curve);
  22910. var Curves = /*#__PURE__*/Object.freeze({
  22911. __proto__: null,
  22912. ArcCurve: ArcCurve,
  22913. CatmullRomCurve3: CatmullRomCurve3,
  22914. CubicBezierCurve: CubicBezierCurve,
  22915. CubicBezierCurve3: CubicBezierCurve3,
  22916. EllipseCurve: EllipseCurve,
  22917. LineCurve: LineCurve,
  22918. LineCurve3: LineCurve3,
  22919. QuadraticBezierCurve: QuadraticBezierCurve,
  22920. QuadraticBezierCurve3: QuadraticBezierCurve3,
  22921. SplineCurve: SplineCurve
  22922. });
  22923. /**************************************************************
  22924. * Curved Path - a curve path is simply a array of connected
  22925. * curves, but retains the api of a curve
  22926. **************************************************************/
  22927. var CurvePath = /*#__PURE__*/function (_Curve) {
  22928. _inheritsLoose(CurvePath, _Curve);
  22929. function CurvePath() {
  22930. var _this;
  22931. _this = _Curve.call(this) || this;
  22932. _this.type = 'CurvePath';
  22933. _this.curves = [];
  22934. _this.autoClose = false; // Automatically closes the path
  22935. return _this;
  22936. }
  22937. var _proto = CurvePath.prototype;
  22938. _proto.add = function add(curve) {
  22939. this.curves.push(curve);
  22940. };
  22941. _proto.closePath = function closePath() {
  22942. // Add a line curve if start and end of lines are not connected
  22943. var startPoint = this.curves[0].getPoint(0);
  22944. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  22945. if (!startPoint.equals(endPoint)) {
  22946. this.curves.push(new LineCurve(endPoint, startPoint));
  22947. }
  22948. } // To get accurate point with reference to
  22949. // entire path distance at time t,
  22950. // following has to be done:
  22951. // 1. Length of each sub path have to be known
  22952. // 2. Locate and identify type of curve
  22953. // 3. Get t for the curve
  22954. // 4. Return curve.getPointAt(t')
  22955. ;
  22956. _proto.getPoint = function getPoint(t) {
  22957. var d = t * this.getLength();
  22958. var curveLengths = this.getCurveLengths();
  22959. var i = 0; // To think about boundaries points.
  22960. while (i < curveLengths.length) {
  22961. if (curveLengths[i] >= d) {
  22962. var diff = curveLengths[i] - d;
  22963. var curve = this.curves[i];
  22964. var segmentLength = curve.getLength();
  22965. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  22966. return curve.getPointAt(u);
  22967. }
  22968. i++;
  22969. }
  22970. return null; // loop where sum != 0, sum > d , sum+1 <d
  22971. } // We cannot use the default THREE.Curve getPoint() with getLength() because in
  22972. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  22973. // getPoint() depends on getLength
  22974. ;
  22975. _proto.getLength = function getLength() {
  22976. var lens = this.getCurveLengths();
  22977. return lens[lens.length - 1];
  22978. } // cacheLengths must be recalculated.
  22979. ;
  22980. _proto.updateArcLengths = function updateArcLengths() {
  22981. this.needsUpdate = true;
  22982. this.cacheLengths = null;
  22983. this.getCurveLengths();
  22984. } // Compute lengths and cache them
  22985. // We cannot overwrite getLengths() because UtoT mapping uses it.
  22986. ;
  22987. _proto.getCurveLengths = function getCurveLengths() {
  22988. // We use cache values if curves and cache array are same length
  22989. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  22990. return this.cacheLengths;
  22991. } // Get length of sub-curve
  22992. // Push sums into cached array
  22993. var lengths = [];
  22994. var sums = 0;
  22995. for (var i = 0, l = this.curves.length; i < l; i++) {
  22996. sums += this.curves[i].getLength();
  22997. lengths.push(sums);
  22998. }
  22999. this.cacheLengths = lengths;
  23000. return lengths;
  23001. };
  23002. _proto.getSpacedPoints = function getSpacedPoints(divisions) {
  23003. if (divisions === void 0) {
  23004. divisions = 40;
  23005. }
  23006. var points = [];
  23007. for (var i = 0; i <= divisions; i++) {
  23008. points.push(this.getPoint(i / divisions));
  23009. }
  23010. if (this.autoClose) {
  23011. points.push(points[0]);
  23012. }
  23013. return points;
  23014. };
  23015. _proto.getPoints = function getPoints(divisions) {
  23016. if (divisions === void 0) {
  23017. divisions = 12;
  23018. }
  23019. var points = [];
  23020. var last;
  23021. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  23022. var curve = curves[i];
  23023. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  23024. var pts = curve.getPoints(resolution);
  23025. for (var j = 0; j < pts.length; j++) {
  23026. var point = pts[j];
  23027. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  23028. points.push(point);
  23029. last = point;
  23030. }
  23031. }
  23032. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  23033. points.push(points[0]);
  23034. }
  23035. return points;
  23036. };
  23037. _proto.copy = function copy(source) {
  23038. _Curve.prototype.copy.call(this, source);
  23039. this.curves = [];
  23040. for (var i = 0, l = source.curves.length; i < l; i++) {
  23041. var curve = source.curves[i];
  23042. this.curves.push(curve.clone());
  23043. }
  23044. this.autoClose = source.autoClose;
  23045. return this;
  23046. };
  23047. _proto.toJSON = function toJSON() {
  23048. var data = _Curve.prototype.toJSON.call(this);
  23049. data.autoClose = this.autoClose;
  23050. data.curves = [];
  23051. for (var i = 0, l = this.curves.length; i < l; i++) {
  23052. var curve = this.curves[i];
  23053. data.curves.push(curve.toJSON());
  23054. }
  23055. return data;
  23056. };
  23057. _proto.fromJSON = function fromJSON(json) {
  23058. _Curve.prototype.fromJSON.call(this, json);
  23059. this.autoClose = json.autoClose;
  23060. this.curves = [];
  23061. for (var i = 0, l = json.curves.length; i < l; i++) {
  23062. var curve = json.curves[i];
  23063. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  23064. }
  23065. return this;
  23066. };
  23067. return CurvePath;
  23068. }(Curve);
  23069. var Path = /*#__PURE__*/function (_CurvePath) {
  23070. _inheritsLoose(Path, _CurvePath);
  23071. function Path(points) {
  23072. var _this;
  23073. _this = _CurvePath.call(this) || this;
  23074. _this.type = 'Path';
  23075. _this.currentPoint = new Vector2();
  23076. if (points) {
  23077. _this.setFromPoints(points);
  23078. }
  23079. return _this;
  23080. }
  23081. var _proto = Path.prototype;
  23082. _proto.setFromPoints = function setFromPoints(points) {
  23083. this.moveTo(points[0].x, points[0].y);
  23084. for (var i = 1, l = points.length; i < l; i++) {
  23085. this.lineTo(points[i].x, points[i].y);
  23086. }
  23087. return this;
  23088. };
  23089. _proto.moveTo = function moveTo(x, y) {
  23090. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  23091. return this;
  23092. };
  23093. _proto.lineTo = function lineTo(x, y) {
  23094. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  23095. this.curves.push(curve);
  23096. this.currentPoint.set(x, y);
  23097. return this;
  23098. };
  23099. _proto.quadraticCurveTo = function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  23100. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  23101. this.curves.push(curve);
  23102. this.currentPoint.set(aX, aY);
  23103. return this;
  23104. };
  23105. _proto.bezierCurveTo = function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  23106. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  23107. this.curves.push(curve);
  23108. this.currentPoint.set(aX, aY);
  23109. return this;
  23110. };
  23111. _proto.splineThru = function splineThru(pts
  23112. /*Array of Vector*/
  23113. ) {
  23114. var npts = [this.currentPoint.clone()].concat(pts);
  23115. var curve = new SplineCurve(npts);
  23116. this.curves.push(curve);
  23117. this.currentPoint.copy(pts[pts.length - 1]);
  23118. return this;
  23119. };
  23120. _proto.arc = function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23121. var x0 = this.currentPoint.x;
  23122. var y0 = this.currentPoint.y;
  23123. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  23124. return this;
  23125. };
  23126. _proto.absarc = function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23127. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  23128. return this;
  23129. };
  23130. _proto.ellipse = function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23131. var x0 = this.currentPoint.x;
  23132. var y0 = this.currentPoint.y;
  23133. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23134. return this;
  23135. };
  23136. _proto.absellipse = function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23137. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23138. if (this.curves.length > 0) {
  23139. // if a previous curve is present, attempt to join
  23140. var firstPoint = curve.getPoint(0);
  23141. if (!firstPoint.equals(this.currentPoint)) {
  23142. this.lineTo(firstPoint.x, firstPoint.y);
  23143. }
  23144. }
  23145. this.curves.push(curve);
  23146. var lastPoint = curve.getPoint(1);
  23147. this.currentPoint.copy(lastPoint);
  23148. return this;
  23149. };
  23150. _proto.copy = function copy(source) {
  23151. _CurvePath.prototype.copy.call(this, source);
  23152. this.currentPoint.copy(source.currentPoint);
  23153. return this;
  23154. };
  23155. _proto.toJSON = function toJSON() {
  23156. var data = _CurvePath.prototype.toJSON.call(this);
  23157. data.currentPoint = this.currentPoint.toArray();
  23158. return data;
  23159. };
  23160. _proto.fromJSON = function fromJSON(json) {
  23161. _CurvePath.prototype.fromJSON.call(this, json);
  23162. this.currentPoint.fromArray(json.currentPoint);
  23163. return this;
  23164. };
  23165. return Path;
  23166. }(CurvePath);
  23167. var Shape = /*#__PURE__*/function (_Path) {
  23168. _inheritsLoose(Shape, _Path);
  23169. function Shape(points) {
  23170. var _this;
  23171. _this = _Path.call(this, points) || this;
  23172. _this.uuid = MathUtils.generateUUID();
  23173. _this.type = 'Shape';
  23174. _this.holes = [];
  23175. return _this;
  23176. }
  23177. var _proto = Shape.prototype;
  23178. _proto.getPointsHoles = function getPointsHoles(divisions) {
  23179. var holesPts = [];
  23180. for (var i = 0, l = this.holes.length; i < l; i++) {
  23181. holesPts[i] = this.holes[i].getPoints(divisions);
  23182. }
  23183. return holesPts;
  23184. } // get points of shape and holes (keypoints based on segments parameter)
  23185. ;
  23186. _proto.extractPoints = function extractPoints(divisions) {
  23187. return {
  23188. shape: this.getPoints(divisions),
  23189. holes: this.getPointsHoles(divisions)
  23190. };
  23191. };
  23192. _proto.copy = function copy(source) {
  23193. _Path.prototype.copy.call(this, source);
  23194. this.holes = [];
  23195. for (var i = 0, l = source.holes.length; i < l; i++) {
  23196. var hole = source.holes[i];
  23197. this.holes.push(hole.clone());
  23198. }
  23199. return this;
  23200. };
  23201. _proto.toJSON = function toJSON() {
  23202. var data = _Path.prototype.toJSON.call(this);
  23203. data.uuid = this.uuid;
  23204. data.holes = [];
  23205. for (var i = 0, l = this.holes.length; i < l; i++) {
  23206. var hole = this.holes[i];
  23207. data.holes.push(hole.toJSON());
  23208. }
  23209. return data;
  23210. };
  23211. _proto.fromJSON = function fromJSON(json) {
  23212. _Path.prototype.fromJSON.call(this, json);
  23213. this.uuid = json.uuid;
  23214. this.holes = [];
  23215. for (var i = 0, l = json.holes.length; i < l; i++) {
  23216. var hole = json.holes[i];
  23217. this.holes.push(new Path().fromJSON(hole));
  23218. }
  23219. return this;
  23220. };
  23221. return Shape;
  23222. }(Path);
  23223. function Light(color, intensity) {
  23224. if (intensity === void 0) {
  23225. intensity = 1;
  23226. }
  23227. Object3D.call(this);
  23228. this.type = 'Light';
  23229. this.color = new Color(color);
  23230. this.intensity = intensity;
  23231. }
  23232. Light.prototype = Object.assign(Object.create(Object3D.prototype), {
  23233. constructor: Light,
  23234. isLight: true,
  23235. copy: function copy(source) {
  23236. Object3D.prototype.copy.call(this, source);
  23237. this.color.copy(source.color);
  23238. this.intensity = source.intensity;
  23239. return this;
  23240. },
  23241. toJSON: function toJSON(meta) {
  23242. var data = Object3D.prototype.toJSON.call(this, meta);
  23243. data.object.color = this.color.getHex();
  23244. data.object.intensity = this.intensity;
  23245. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  23246. if (this.distance !== undefined) data.object.distance = this.distance;
  23247. if (this.angle !== undefined) data.object.angle = this.angle;
  23248. if (this.decay !== undefined) data.object.decay = this.decay;
  23249. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  23250. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  23251. return data;
  23252. }
  23253. });
  23254. function HemisphereLight(skyColor, groundColor, intensity) {
  23255. Light.call(this, skyColor, intensity);
  23256. this.type = 'HemisphereLight';
  23257. this.position.copy(Object3D.DefaultUp);
  23258. this.updateMatrix();
  23259. this.groundColor = new Color(groundColor);
  23260. }
  23261. HemisphereLight.prototype = Object.assign(Object.create(Light.prototype), {
  23262. constructor: HemisphereLight,
  23263. isHemisphereLight: true,
  23264. copy: function copy(source) {
  23265. Light.prototype.copy.call(this, source);
  23266. this.groundColor.copy(source.groundColor);
  23267. return this;
  23268. }
  23269. });
  23270. function LightShadow(camera) {
  23271. this.camera = camera;
  23272. this.bias = 0;
  23273. this.normalBias = 0;
  23274. this.radius = 1;
  23275. this.mapSize = new Vector2(512, 512);
  23276. this.map = null;
  23277. this.mapPass = null;
  23278. this.matrix = new Matrix4();
  23279. this.autoUpdate = true;
  23280. this.needsUpdate = false;
  23281. this._frustum = new Frustum();
  23282. this._frameExtents = new Vector2(1, 1);
  23283. this._viewportCount = 1;
  23284. this._viewports = [new Vector4(0, 0, 1, 1)];
  23285. }
  23286. Object.assign(LightShadow.prototype, {
  23287. _projScreenMatrix: new Matrix4(),
  23288. _lightPositionWorld: new Vector3(),
  23289. _lookTarget: new Vector3(),
  23290. getViewportCount: function getViewportCount() {
  23291. return this._viewportCount;
  23292. },
  23293. getFrustum: function getFrustum() {
  23294. return this._frustum;
  23295. },
  23296. updateMatrices: function updateMatrices(light) {
  23297. var shadowCamera = this.camera,
  23298. shadowMatrix = this.matrix,
  23299. projScreenMatrix = this._projScreenMatrix,
  23300. lookTarget = this._lookTarget,
  23301. lightPositionWorld = this._lightPositionWorld;
  23302. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23303. shadowCamera.position.copy(lightPositionWorld);
  23304. lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  23305. shadowCamera.lookAt(lookTarget);
  23306. shadowCamera.updateMatrixWorld();
  23307. projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  23308. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23309. 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);
  23310. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  23311. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  23312. },
  23313. getViewport: function getViewport(viewportIndex) {
  23314. return this._viewports[viewportIndex];
  23315. },
  23316. getFrameExtents: function getFrameExtents() {
  23317. return this._frameExtents;
  23318. },
  23319. copy: function copy(source) {
  23320. this.camera = source.camera.clone();
  23321. this.bias = source.bias;
  23322. this.radius = source.radius;
  23323. this.mapSize.copy(source.mapSize);
  23324. return this;
  23325. },
  23326. clone: function clone() {
  23327. return new this.constructor().copy(this);
  23328. },
  23329. toJSON: function toJSON() {
  23330. var object = {};
  23331. if (this.bias !== 0) object.bias = this.bias;
  23332. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  23333. if (this.radius !== 1) object.radius = this.radius;
  23334. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  23335. object.camera = this.camera.toJSON(false).object;
  23336. delete object.camera.matrix;
  23337. return object;
  23338. }
  23339. });
  23340. function SpotLightShadow() {
  23341. LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500));
  23342. this.focus = 1;
  23343. }
  23344. SpotLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23345. constructor: SpotLightShadow,
  23346. isSpotLightShadow: true,
  23347. updateMatrices: function updateMatrices(light) {
  23348. var camera = this.camera;
  23349. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23350. var aspect = this.mapSize.width / this.mapSize.height;
  23351. var far = light.distance || camera.far;
  23352. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  23353. camera.fov = fov;
  23354. camera.aspect = aspect;
  23355. camera.far = far;
  23356. camera.updateProjectionMatrix();
  23357. }
  23358. LightShadow.prototype.updateMatrices.call(this, light);
  23359. }
  23360. });
  23361. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  23362. Light.call(this, color, intensity);
  23363. this.type = 'SpotLight';
  23364. this.position.copy(Object3D.DefaultUp);
  23365. this.updateMatrix();
  23366. this.target = new Object3D();
  23367. Object.defineProperty(this, 'power', {
  23368. get: function get() {
  23369. // intensity = power per solid angle.
  23370. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23371. return this.intensity * Math.PI;
  23372. },
  23373. set: function set(power) {
  23374. // intensity = power per solid angle.
  23375. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23376. this.intensity = power / Math.PI;
  23377. }
  23378. });
  23379. this.distance = distance !== undefined ? distance : 0;
  23380. this.angle = angle !== undefined ? angle : Math.PI / 3;
  23381. this.penumbra = penumbra !== undefined ? penumbra : 0;
  23382. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23383. this.shadow = new SpotLightShadow();
  23384. }
  23385. SpotLight.prototype = Object.assign(Object.create(Light.prototype), {
  23386. constructor: SpotLight,
  23387. isSpotLight: true,
  23388. copy: function copy(source) {
  23389. Light.prototype.copy.call(this, source);
  23390. this.distance = source.distance;
  23391. this.angle = source.angle;
  23392. this.penumbra = source.penumbra;
  23393. this.decay = source.decay;
  23394. this.target = source.target.clone();
  23395. this.shadow = source.shadow.clone();
  23396. return this;
  23397. }
  23398. });
  23399. function PointLightShadow() {
  23400. LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500));
  23401. this._frameExtents = new Vector2(4, 2);
  23402. this._viewportCount = 6;
  23403. this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  23404. // following orientation:
  23405. //
  23406. // xzXZ
  23407. // y Y
  23408. //
  23409. // X - Positive x direction
  23410. // x - Negative x direction
  23411. // Y - Positive y direction
  23412. // y - Negative y direction
  23413. // Z - Positive z direction
  23414. // z - Negative z direction
  23415. // positive X
  23416. new Vector4(2, 1, 1, 1), // negative X
  23417. new Vector4(0, 1, 1, 1), // positive Z
  23418. new Vector4(3, 1, 1, 1), // negative Z
  23419. new Vector4(1, 1, 1, 1), // positive Y
  23420. new Vector4(3, 0, 1, 1), // negative Y
  23421. new Vector4(1, 0, 1, 1)];
  23422. 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)];
  23423. 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)];
  23424. }
  23425. PointLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23426. constructor: PointLightShadow,
  23427. isPointLightShadow: true,
  23428. updateMatrices: function updateMatrices(light, viewportIndex) {
  23429. if (viewportIndex === void 0) {
  23430. viewportIndex = 0;
  23431. }
  23432. var camera = this.camera,
  23433. shadowMatrix = this.matrix,
  23434. lightPositionWorld = this._lightPositionWorld,
  23435. lookTarget = this._lookTarget,
  23436. projScreenMatrix = this._projScreenMatrix;
  23437. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23438. camera.position.copy(lightPositionWorld);
  23439. lookTarget.copy(camera.position);
  23440. lookTarget.add(this._cubeDirections[viewportIndex]);
  23441. camera.up.copy(this._cubeUps[viewportIndex]);
  23442. camera.lookAt(lookTarget);
  23443. camera.updateMatrixWorld();
  23444. shadowMatrix.makeTranslation(-lightPositionWorld.x, -lightPositionWorld.y, -lightPositionWorld.z);
  23445. projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  23446. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23447. }
  23448. });
  23449. function PointLight(color, intensity, distance, decay) {
  23450. Light.call(this, color, intensity);
  23451. this.type = 'PointLight';
  23452. Object.defineProperty(this, 'power', {
  23453. get: function get() {
  23454. // intensity = power per solid angle.
  23455. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23456. return this.intensity * 4 * Math.PI;
  23457. },
  23458. set: function set(power) {
  23459. // intensity = power per solid angle.
  23460. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23461. this.intensity = power / (4 * Math.PI);
  23462. }
  23463. });
  23464. this.distance = distance !== undefined ? distance : 0;
  23465. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23466. this.shadow = new PointLightShadow();
  23467. }
  23468. PointLight.prototype = Object.assign(Object.create(Light.prototype), {
  23469. constructor: PointLight,
  23470. isPointLight: true,
  23471. copy: function copy(source) {
  23472. Light.prototype.copy.call(this, source);
  23473. this.distance = source.distance;
  23474. this.decay = source.decay;
  23475. this.shadow = source.shadow.clone();
  23476. return this;
  23477. }
  23478. });
  23479. function OrthographicCamera(left, right, top, bottom, near, far) {
  23480. if (left === void 0) {
  23481. left = -1;
  23482. }
  23483. if (right === void 0) {
  23484. right = 1;
  23485. }
  23486. if (top === void 0) {
  23487. top = 1;
  23488. }
  23489. if (bottom === void 0) {
  23490. bottom = -1;
  23491. }
  23492. if (near === void 0) {
  23493. near = 0.1;
  23494. }
  23495. if (far === void 0) {
  23496. far = 2000;
  23497. }
  23498. Camera.call(this);
  23499. this.type = 'OrthographicCamera';
  23500. this.zoom = 1;
  23501. this.view = null;
  23502. this.left = left;
  23503. this.right = right;
  23504. this.top = top;
  23505. this.bottom = bottom;
  23506. this.near = near;
  23507. this.far = far;
  23508. this.updateProjectionMatrix();
  23509. }
  23510. OrthographicCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  23511. constructor: OrthographicCamera,
  23512. isOrthographicCamera: true,
  23513. copy: function copy(source, recursive) {
  23514. Camera.prototype.copy.call(this, source, recursive);
  23515. this.left = source.left;
  23516. this.right = source.right;
  23517. this.top = source.top;
  23518. this.bottom = source.bottom;
  23519. this.near = source.near;
  23520. this.far = source.far;
  23521. this.zoom = source.zoom;
  23522. this.view = source.view === null ? null : Object.assign({}, source.view);
  23523. return this;
  23524. },
  23525. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  23526. if (this.view === null) {
  23527. this.view = {
  23528. enabled: true,
  23529. fullWidth: 1,
  23530. fullHeight: 1,
  23531. offsetX: 0,
  23532. offsetY: 0,
  23533. width: 1,
  23534. height: 1
  23535. };
  23536. }
  23537. this.view.enabled = true;
  23538. this.view.fullWidth = fullWidth;
  23539. this.view.fullHeight = fullHeight;
  23540. this.view.offsetX = x;
  23541. this.view.offsetY = y;
  23542. this.view.width = width;
  23543. this.view.height = height;
  23544. this.updateProjectionMatrix();
  23545. },
  23546. clearViewOffset: function clearViewOffset() {
  23547. if (this.view !== null) {
  23548. this.view.enabled = false;
  23549. }
  23550. this.updateProjectionMatrix();
  23551. },
  23552. updateProjectionMatrix: function updateProjectionMatrix() {
  23553. var dx = (this.right - this.left) / (2 * this.zoom);
  23554. var dy = (this.top - this.bottom) / (2 * this.zoom);
  23555. var cx = (this.right + this.left) / 2;
  23556. var cy = (this.top + this.bottom) / 2;
  23557. var left = cx - dx;
  23558. var right = cx + dx;
  23559. var top = cy + dy;
  23560. var bottom = cy - dy;
  23561. if (this.view !== null && this.view.enabled) {
  23562. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  23563. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  23564. left += scaleW * this.view.offsetX;
  23565. right = left + scaleW * this.view.width;
  23566. top -= scaleH * this.view.offsetY;
  23567. bottom = top - scaleH * this.view.height;
  23568. }
  23569. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  23570. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  23571. },
  23572. toJSON: function toJSON(meta) {
  23573. var data = Object3D.prototype.toJSON.call(this, meta);
  23574. data.object.zoom = this.zoom;
  23575. data.object.left = this.left;
  23576. data.object.right = this.right;
  23577. data.object.top = this.top;
  23578. data.object.bottom = this.bottom;
  23579. data.object.near = this.near;
  23580. data.object.far = this.far;
  23581. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  23582. return data;
  23583. }
  23584. });
  23585. function DirectionalLightShadow() {
  23586. LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500));
  23587. }
  23588. DirectionalLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23589. constructor: DirectionalLightShadow,
  23590. isDirectionalLightShadow: true,
  23591. updateMatrices: function updateMatrices(light) {
  23592. LightShadow.prototype.updateMatrices.call(this, light);
  23593. }
  23594. });
  23595. function DirectionalLight(color, intensity) {
  23596. Light.call(this, color, intensity);
  23597. this.type = 'DirectionalLight';
  23598. this.position.copy(Object3D.DefaultUp);
  23599. this.updateMatrix();
  23600. this.target = new Object3D();
  23601. this.shadow = new DirectionalLightShadow();
  23602. }
  23603. DirectionalLight.prototype = Object.assign(Object.create(Light.prototype), {
  23604. constructor: DirectionalLight,
  23605. isDirectionalLight: true,
  23606. copy: function copy(source) {
  23607. Light.prototype.copy.call(this, source);
  23608. this.target = source.target.clone();
  23609. this.shadow = source.shadow.clone();
  23610. return this;
  23611. }
  23612. });
  23613. function AmbientLight(color, intensity) {
  23614. Light.call(this, color, intensity);
  23615. this.type = 'AmbientLight';
  23616. }
  23617. AmbientLight.prototype = Object.assign(Object.create(Light.prototype), {
  23618. constructor: AmbientLight,
  23619. isAmbientLight: true
  23620. });
  23621. function RectAreaLight(color, intensity, width, height) {
  23622. Light.call(this, color, intensity);
  23623. this.type = 'RectAreaLight';
  23624. this.width = width !== undefined ? width : 10;
  23625. this.height = height !== undefined ? height : 10;
  23626. }
  23627. RectAreaLight.prototype = Object.assign(Object.create(Light.prototype), {
  23628. constructor: RectAreaLight,
  23629. isRectAreaLight: true,
  23630. copy: function copy(source) {
  23631. Light.prototype.copy.call(this, source);
  23632. this.width = source.width;
  23633. this.height = source.height;
  23634. return this;
  23635. },
  23636. toJSON: function toJSON(meta) {
  23637. var data = Light.prototype.toJSON.call(this, meta);
  23638. data.object.width = this.width;
  23639. data.object.height = this.height;
  23640. return data;
  23641. }
  23642. });
  23643. /**
  23644. * Primary reference:
  23645. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23646. *
  23647. * Secondary reference:
  23648. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23649. */
  23650. // 3-band SH defined by 9 coefficients
  23651. var SphericalHarmonics3 = /*#__PURE__*/function () {
  23652. function SphericalHarmonics3() {
  23653. Object.defineProperty(this, 'isSphericalHarmonics3', {
  23654. value: true
  23655. });
  23656. this.coefficients = [];
  23657. for (var i = 0; i < 9; i++) {
  23658. this.coefficients.push(new Vector3());
  23659. }
  23660. }
  23661. var _proto = SphericalHarmonics3.prototype;
  23662. _proto.set = function set(coefficients) {
  23663. for (var i = 0; i < 9; i++) {
  23664. this.coefficients[i].copy(coefficients[i]);
  23665. }
  23666. return this;
  23667. };
  23668. _proto.zero = function zero() {
  23669. for (var i = 0; i < 9; i++) {
  23670. this.coefficients[i].set(0, 0, 0);
  23671. }
  23672. return this;
  23673. } // get the radiance in the direction of the normal
  23674. // target is a Vector3
  23675. ;
  23676. _proto.getAt = function getAt(normal, target) {
  23677. // normal is assumed to be unit length
  23678. var x = normal.x,
  23679. y = normal.y,
  23680. z = normal.z;
  23681. var coeff = this.coefficients; // band 0
  23682. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  23683. target.addScaledVector(coeff[1], 0.488603 * y);
  23684. target.addScaledVector(coeff[2], 0.488603 * z);
  23685. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  23686. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  23687. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  23688. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  23689. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  23690. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  23691. return target;
  23692. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23693. // target is a Vector3
  23694. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23695. ;
  23696. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  23697. // normal is assumed to be unit length
  23698. var x = normal.x,
  23699. y = normal.y,
  23700. z = normal.z;
  23701. var coeff = this.coefficients; // band 0
  23702. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  23703. // band 1
  23704. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  23705. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  23706. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  23707. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  23708. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  23709. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  23710. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  23711. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  23712. return target;
  23713. };
  23714. _proto.add = function add(sh) {
  23715. for (var i = 0; i < 9; i++) {
  23716. this.coefficients[i].add(sh.coefficients[i]);
  23717. }
  23718. return this;
  23719. };
  23720. _proto.addScaledSH = function addScaledSH(sh, s) {
  23721. for (var i = 0; i < 9; i++) {
  23722. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  23723. }
  23724. return this;
  23725. };
  23726. _proto.scale = function scale(s) {
  23727. for (var i = 0; i < 9; i++) {
  23728. this.coefficients[i].multiplyScalar(s);
  23729. }
  23730. return this;
  23731. };
  23732. _proto.lerp = function lerp(sh, alpha) {
  23733. for (var i = 0; i < 9; i++) {
  23734. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  23735. }
  23736. return this;
  23737. };
  23738. _proto.equals = function equals(sh) {
  23739. for (var i = 0; i < 9; i++) {
  23740. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  23741. return false;
  23742. }
  23743. }
  23744. return true;
  23745. };
  23746. _proto.copy = function copy(sh) {
  23747. return this.set(sh.coefficients);
  23748. };
  23749. _proto.clone = function clone() {
  23750. return new this.constructor().copy(this);
  23751. };
  23752. _proto.fromArray = function fromArray(array, offset) {
  23753. if (offset === void 0) {
  23754. offset = 0;
  23755. }
  23756. var coefficients = this.coefficients;
  23757. for (var i = 0; i < 9; i++) {
  23758. coefficients[i].fromArray(array, offset + i * 3);
  23759. }
  23760. return this;
  23761. };
  23762. _proto.toArray = function toArray(array, offset) {
  23763. if (array === void 0) {
  23764. array = [];
  23765. }
  23766. if (offset === void 0) {
  23767. offset = 0;
  23768. }
  23769. var coefficients = this.coefficients;
  23770. for (var i = 0; i < 9; i++) {
  23771. coefficients[i].toArray(array, offset + i * 3);
  23772. }
  23773. return array;
  23774. } // evaluate the basis functions
  23775. // shBasis is an Array[ 9 ]
  23776. ;
  23777. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  23778. // normal is assumed to be unit length
  23779. var x = normal.x,
  23780. y = normal.y,
  23781. z = normal.z; // band 0
  23782. shBasis[0] = 0.282095; // band 1
  23783. shBasis[1] = 0.488603 * y;
  23784. shBasis[2] = 0.488603 * z;
  23785. shBasis[3] = 0.488603 * x; // band 2
  23786. shBasis[4] = 1.092548 * x * y;
  23787. shBasis[5] = 1.092548 * y * z;
  23788. shBasis[6] = 0.315392 * (3 * z * z - 1);
  23789. shBasis[7] = 1.092548 * x * z;
  23790. shBasis[8] = 0.546274 * (x * x - y * y);
  23791. };
  23792. return SphericalHarmonics3;
  23793. }();
  23794. function LightProbe(sh, intensity) {
  23795. Light.call(this, undefined, intensity);
  23796. this.type = 'LightProbe';
  23797. this.sh = sh !== undefined ? sh : new SphericalHarmonics3();
  23798. }
  23799. LightProbe.prototype = Object.assign(Object.create(Light.prototype), {
  23800. constructor: LightProbe,
  23801. isLightProbe: true,
  23802. copy: function copy(source) {
  23803. Light.prototype.copy.call(this, source);
  23804. this.sh.copy(source.sh);
  23805. return this;
  23806. },
  23807. fromJSON: function fromJSON(json) {
  23808. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  23809. this.sh.fromArray(json.sh);
  23810. return this;
  23811. },
  23812. toJSON: function toJSON(meta) {
  23813. var data = Light.prototype.toJSON.call(this, meta);
  23814. data.object.sh = this.sh.toArray();
  23815. return data;
  23816. }
  23817. });
  23818. function MaterialLoader(manager) {
  23819. Loader.call(this, manager);
  23820. this.textures = {};
  23821. }
  23822. MaterialLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  23823. constructor: MaterialLoader,
  23824. load: function load(url, onLoad, onProgress, onError) {
  23825. var scope = this;
  23826. var loader = new FileLoader(scope.manager);
  23827. loader.setPath(scope.path);
  23828. loader.setRequestHeader(scope.requestHeader);
  23829. loader.setWithCredentials(scope.withCredentials);
  23830. loader.load(url, function (text) {
  23831. try {
  23832. onLoad(scope.parse(JSON.parse(text)));
  23833. } catch (e) {
  23834. if (onError) {
  23835. onError(e);
  23836. } else {
  23837. console.error(e);
  23838. }
  23839. scope.manager.itemError(url);
  23840. }
  23841. }, onProgress, onError);
  23842. },
  23843. parse: function parse(json) {
  23844. var textures = this.textures;
  23845. function getTexture(name) {
  23846. if (textures[name] === undefined) {
  23847. console.warn('THREE.MaterialLoader: Undefined texture', name);
  23848. }
  23849. return textures[name];
  23850. }
  23851. var material = new Materials[json.type]();
  23852. if (json.uuid !== undefined) material.uuid = json.uuid;
  23853. if (json.name !== undefined) material.name = json.name;
  23854. if (json.color !== undefined && material.color !== undefined) material.color.setHex(json.color);
  23855. if (json.roughness !== undefined) material.roughness = json.roughness;
  23856. if (json.metalness !== undefined) material.metalness = json.metalness;
  23857. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  23858. if (json.emissive !== undefined && material.emissive !== undefined) material.emissive.setHex(json.emissive);
  23859. if (json.specular !== undefined && material.specular !== undefined) material.specular.setHex(json.specular);
  23860. if (json.shininess !== undefined) material.shininess = json.shininess;
  23861. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  23862. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  23863. if (json.fog !== undefined) material.fog = json.fog;
  23864. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  23865. if (json.blending !== undefined) material.blending = json.blending;
  23866. if (json.combine !== undefined) material.combine = json.combine;
  23867. if (json.side !== undefined) material.side = json.side;
  23868. if (json.opacity !== undefined) material.opacity = json.opacity;
  23869. if (json.transparent !== undefined) material.transparent = json.transparent;
  23870. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  23871. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  23872. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  23873. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  23874. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  23875. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  23876. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  23877. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  23878. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  23879. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  23880. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  23881. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  23882. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  23883. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  23884. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  23885. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  23886. if (json.rotation !== undefined) material.rotation = json.rotation;
  23887. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  23888. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  23889. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  23890. if (json.scale !== undefined) material.scale = json.scale;
  23891. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  23892. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  23893. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  23894. if (json.skinning !== undefined) material.skinning = json.skinning;
  23895. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  23896. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  23897. if (json.dithering !== undefined) material.dithering = json.dithering;
  23898. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  23899. if (json.visible !== undefined) material.visible = json.visible;
  23900. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  23901. if (json.userData !== undefined) material.userData = json.userData;
  23902. if (json.vertexColors !== undefined) {
  23903. if (typeof json.vertexColors === 'number') {
  23904. material.vertexColors = json.vertexColors > 0 ? true : false;
  23905. } else {
  23906. material.vertexColors = json.vertexColors;
  23907. }
  23908. } // Shader Material
  23909. if (json.uniforms !== undefined) {
  23910. for (var name in json.uniforms) {
  23911. var uniform = json.uniforms[name];
  23912. material.uniforms[name] = {};
  23913. switch (uniform.type) {
  23914. case 't':
  23915. material.uniforms[name].value = getTexture(uniform.value);
  23916. break;
  23917. case 'c':
  23918. material.uniforms[name].value = new Color().setHex(uniform.value);
  23919. break;
  23920. case 'v2':
  23921. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  23922. break;
  23923. case 'v3':
  23924. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  23925. break;
  23926. case 'v4':
  23927. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  23928. break;
  23929. case 'm3':
  23930. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  23931. break;
  23932. case 'm4':
  23933. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  23934. break;
  23935. default:
  23936. material.uniforms[name].value = uniform.value;
  23937. }
  23938. }
  23939. }
  23940. if (json.defines !== undefined) material.defines = json.defines;
  23941. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  23942. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  23943. if (json.extensions !== undefined) {
  23944. for (var key in json.extensions) {
  23945. material.extensions[key] = json.extensions[key];
  23946. }
  23947. } // Deprecated
  23948. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  23949. // for PointsMaterial
  23950. if (json.size !== undefined) material.size = json.size;
  23951. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  23952. if (json.map !== undefined) material.map = getTexture(json.map);
  23953. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  23954. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  23955. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  23956. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  23957. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  23958. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  23959. if (json.normalScale !== undefined) {
  23960. var normalScale = json.normalScale;
  23961. if (Array.isArray(normalScale) === false) {
  23962. // Blender exporter used to export a scalar. See #7459
  23963. normalScale = [normalScale, normalScale];
  23964. }
  23965. material.normalScale = new Vector2().fromArray(normalScale);
  23966. }
  23967. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  23968. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  23969. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  23970. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  23971. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  23972. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  23973. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  23974. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  23975. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  23976. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  23977. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  23978. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  23979. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  23980. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  23981. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  23982. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  23983. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  23984. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  23985. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  23986. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  23987. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  23988. if (json.transmission !== undefined) material.transmission = json.transmission;
  23989. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  23990. return material;
  23991. },
  23992. setTextures: function setTextures(value) {
  23993. this.textures = value;
  23994. return this;
  23995. }
  23996. });
  23997. var LoaderUtils = {
  23998. decodeText: function decodeText(array) {
  23999. if (typeof TextDecoder !== 'undefined') {
  24000. return new TextDecoder().decode(array);
  24001. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  24002. // throws a "maximum call stack size exceeded" error for large arrays.
  24003. var s = '';
  24004. for (var i = 0, il = array.length; i < il; i++) {
  24005. // Implicitly assumes little-endian.
  24006. s += String.fromCharCode(array[i]);
  24007. }
  24008. try {
  24009. // merges multi-byte utf-8 characters.
  24010. return decodeURIComponent(escape(s));
  24011. } catch (e) {
  24012. // see #16358
  24013. return s;
  24014. }
  24015. },
  24016. extractUrlBase: function extractUrlBase(url) {
  24017. var index = url.lastIndexOf('/');
  24018. if (index === -1) return './';
  24019. return url.substr(0, index + 1);
  24020. }
  24021. };
  24022. function InstancedBufferGeometry() {
  24023. BufferGeometry.call(this);
  24024. this.type = 'InstancedBufferGeometry';
  24025. this.instanceCount = Infinity;
  24026. }
  24027. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  24028. constructor: InstancedBufferGeometry,
  24029. isInstancedBufferGeometry: true,
  24030. copy: function copy(source) {
  24031. BufferGeometry.prototype.copy.call(this, source);
  24032. this.instanceCount = source.instanceCount;
  24033. return this;
  24034. },
  24035. clone: function clone() {
  24036. return new this.constructor().copy(this);
  24037. },
  24038. toJSON: function toJSON() {
  24039. var data = BufferGeometry.prototype.toJSON.call(this);
  24040. data.instanceCount = this.instanceCount;
  24041. data.isInstancedBufferGeometry = true;
  24042. return data;
  24043. }
  24044. });
  24045. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  24046. if (typeof normalized === 'number') {
  24047. meshPerAttribute = normalized;
  24048. normalized = false;
  24049. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  24050. }
  24051. BufferAttribute.call(this, array, itemSize, normalized);
  24052. this.meshPerAttribute = meshPerAttribute || 1;
  24053. }
  24054. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  24055. constructor: InstancedBufferAttribute,
  24056. isInstancedBufferAttribute: true,
  24057. copy: function copy(source) {
  24058. BufferAttribute.prototype.copy.call(this, source);
  24059. this.meshPerAttribute = source.meshPerAttribute;
  24060. return this;
  24061. },
  24062. toJSON: function toJSON() {
  24063. var data = BufferAttribute.prototype.toJSON.call(this);
  24064. data.meshPerAttribute = this.meshPerAttribute;
  24065. data.isInstancedBufferAttribute = true;
  24066. return data;
  24067. }
  24068. });
  24069. function BufferGeometryLoader(manager) {
  24070. Loader.call(this, manager);
  24071. }
  24072. BufferGeometryLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24073. constructor: BufferGeometryLoader,
  24074. load: function load(url, onLoad, onProgress, onError) {
  24075. var scope = this;
  24076. var loader = new FileLoader(scope.manager);
  24077. loader.setPath(scope.path);
  24078. loader.setRequestHeader(scope.requestHeader);
  24079. loader.setWithCredentials(scope.withCredentials);
  24080. loader.load(url, function (text) {
  24081. try {
  24082. onLoad(scope.parse(JSON.parse(text)));
  24083. } catch (e) {
  24084. if (onError) {
  24085. onError(e);
  24086. } else {
  24087. console.error(e);
  24088. }
  24089. scope.manager.itemError(url);
  24090. }
  24091. }, onProgress, onError);
  24092. },
  24093. parse: function parse(json) {
  24094. var interleavedBufferMap = {};
  24095. var arrayBufferMap = {};
  24096. function getInterleavedBuffer(json, uuid) {
  24097. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  24098. var interleavedBuffers = json.interleavedBuffers;
  24099. var interleavedBuffer = interleavedBuffers[uuid];
  24100. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  24101. var array = getTypedArray(interleavedBuffer.type, buffer);
  24102. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  24103. ib.uuid = interleavedBuffer.uuid;
  24104. interleavedBufferMap[uuid] = ib;
  24105. return ib;
  24106. }
  24107. function getArrayBuffer(json, uuid) {
  24108. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  24109. var arrayBuffers = json.arrayBuffers;
  24110. var arrayBuffer = arrayBuffers[uuid];
  24111. var ab = new Uint32Array(arrayBuffer).buffer;
  24112. arrayBufferMap[uuid] = ab;
  24113. return ab;
  24114. }
  24115. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24116. var index = json.data.index;
  24117. if (index !== undefined) {
  24118. var typedArray = getTypedArray(index.type, index.array);
  24119. geometry.setIndex(new BufferAttribute(typedArray, 1));
  24120. }
  24121. var attributes = json.data.attributes;
  24122. for (var key in attributes) {
  24123. var attribute = attributes[key];
  24124. var bufferAttribute = void 0;
  24125. if (attribute.isInterleavedBufferAttribute) {
  24126. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  24127. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  24128. } else {
  24129. var _typedArray = getTypedArray(attribute.type, attribute.array);
  24130. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24131. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  24132. }
  24133. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  24134. geometry.setAttribute(key, bufferAttribute);
  24135. }
  24136. var morphAttributes = json.data.morphAttributes;
  24137. if (morphAttributes) {
  24138. for (var _key in morphAttributes) {
  24139. var attributeArray = morphAttributes[_key];
  24140. var array = [];
  24141. for (var i = 0, il = attributeArray.length; i < il; i++) {
  24142. var _attribute = attributeArray[i];
  24143. var _bufferAttribute = void 0;
  24144. if (_attribute.isInterleavedBufferAttribute) {
  24145. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  24146. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  24147. } else {
  24148. var _typedArray2 = getTypedArray(_attribute.type, _attribute.array);
  24149. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  24150. }
  24151. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  24152. array.push(_bufferAttribute);
  24153. }
  24154. geometry.morphAttributes[_key] = array;
  24155. }
  24156. }
  24157. var morphTargetsRelative = json.data.morphTargetsRelative;
  24158. if (morphTargetsRelative) {
  24159. geometry.morphTargetsRelative = true;
  24160. }
  24161. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24162. if (groups !== undefined) {
  24163. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  24164. var group = groups[_i];
  24165. geometry.addGroup(group.start, group.count, group.materialIndex);
  24166. }
  24167. }
  24168. var boundingSphere = json.data.boundingSphere;
  24169. if (boundingSphere !== undefined) {
  24170. var center = new Vector3();
  24171. if (boundingSphere.center !== undefined) {
  24172. center.fromArray(boundingSphere.center);
  24173. }
  24174. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  24175. }
  24176. if (json.name) geometry.name = json.name;
  24177. if (json.userData) geometry.userData = json.userData;
  24178. return geometry;
  24179. }
  24180. });
  24181. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  24182. _inheritsLoose(ObjectLoader, _Loader);
  24183. function ObjectLoader(manager) {
  24184. return _Loader.call(this, manager) || this;
  24185. }
  24186. var _proto = ObjectLoader.prototype;
  24187. _proto.load = function load(url, onLoad, onProgress, onError) {
  24188. var scope = this;
  24189. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  24190. this.resourcePath = this.resourcePath || path;
  24191. var loader = new FileLoader(this.manager);
  24192. loader.setPath(this.path);
  24193. loader.setRequestHeader(this.requestHeader);
  24194. loader.setWithCredentials(this.withCredentials);
  24195. loader.load(url, function (text) {
  24196. var json = null;
  24197. try {
  24198. json = JSON.parse(text);
  24199. } catch (error) {
  24200. if (onError !== undefined) onError(error);
  24201. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  24202. return;
  24203. }
  24204. var metadata = json.metadata;
  24205. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  24206. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  24207. return;
  24208. }
  24209. scope.parse(json, onLoad);
  24210. }, onProgress, onError);
  24211. };
  24212. _proto.parse = function parse(json, onLoad) {
  24213. var animations = this.parseAnimations(json.animations);
  24214. var shapes = this.parseShapes(json.shapes);
  24215. var geometries = this.parseGeometries(json.geometries, shapes);
  24216. var images = this.parseImages(json.images, function () {
  24217. if (onLoad !== undefined) onLoad(object);
  24218. });
  24219. var textures = this.parseTextures(json.textures, images);
  24220. var materials = this.parseMaterials(json.materials, textures);
  24221. var object = this.parseObject(json.object, geometries, materials, animations);
  24222. var skeletons = this.parseSkeletons(json.skeletons, object);
  24223. this.bindSkeletons(object, skeletons); //
  24224. if (onLoad !== undefined) {
  24225. var hasImages = false;
  24226. for (var uuid in images) {
  24227. if (images[uuid] instanceof HTMLImageElement) {
  24228. hasImages = true;
  24229. break;
  24230. }
  24231. }
  24232. if (hasImages === false) onLoad(object);
  24233. }
  24234. return object;
  24235. };
  24236. _proto.parseShapes = function parseShapes(json) {
  24237. var shapes = {};
  24238. if (json !== undefined) {
  24239. for (var i = 0, l = json.length; i < l; i++) {
  24240. var shape = new Shape().fromJSON(json[i]);
  24241. shapes[shape.uuid] = shape;
  24242. }
  24243. }
  24244. return shapes;
  24245. };
  24246. _proto.parseSkeletons = function parseSkeletons(json, object) {
  24247. var skeletons = {};
  24248. var bones = {}; // generate bone lookup table
  24249. object.traverse(function (child) {
  24250. if (child.isBone) bones[child.uuid] = child;
  24251. }); // create skeletons
  24252. if (json !== undefined) {
  24253. for (var i = 0, l = json.length; i < l; i++) {
  24254. var skeleton = new Skeleton().fromJSON(json[i], bones);
  24255. skeletons[skeleton.uuid] = skeleton;
  24256. }
  24257. }
  24258. return skeletons;
  24259. };
  24260. _proto.parseGeometries = function parseGeometries(json, shapes) {
  24261. var geometries = {};
  24262. var geometryShapes;
  24263. if (json !== undefined) {
  24264. var bufferGeometryLoader = new BufferGeometryLoader();
  24265. for (var i = 0, l = json.length; i < l; i++) {
  24266. var geometry = void 0;
  24267. var data = json[i];
  24268. switch (data.type) {
  24269. case 'PlaneGeometry':
  24270. case 'PlaneBufferGeometry':
  24271. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  24272. break;
  24273. case 'BoxGeometry':
  24274. case 'BoxBufferGeometry':
  24275. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  24276. break;
  24277. case 'CircleGeometry':
  24278. case 'CircleBufferGeometry':
  24279. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  24280. break;
  24281. case 'CylinderGeometry':
  24282. case 'CylinderBufferGeometry':
  24283. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24284. break;
  24285. case 'ConeGeometry':
  24286. case 'ConeBufferGeometry':
  24287. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24288. break;
  24289. case 'SphereGeometry':
  24290. case 'SphereBufferGeometry':
  24291. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  24292. break;
  24293. case 'DodecahedronGeometry':
  24294. case 'DodecahedronBufferGeometry':
  24295. case 'IcosahedronGeometry':
  24296. case 'IcosahedronBufferGeometry':
  24297. case 'OctahedronGeometry':
  24298. case 'OctahedronBufferGeometry':
  24299. case 'TetrahedronGeometry':
  24300. case 'TetrahedronBufferGeometry':
  24301. geometry = new Geometries[data.type](data.radius, data.detail);
  24302. break;
  24303. case 'RingGeometry':
  24304. case 'RingBufferGeometry':
  24305. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  24306. break;
  24307. case 'TorusGeometry':
  24308. case 'TorusBufferGeometry':
  24309. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  24310. break;
  24311. case 'TorusKnotGeometry':
  24312. case 'TorusKnotBufferGeometry':
  24313. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  24314. break;
  24315. case 'TubeGeometry':
  24316. case 'TubeBufferGeometry':
  24317. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24318. // User defined curves or instances of CurvePath will not be deserialized.
  24319. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  24320. break;
  24321. case 'LatheGeometry':
  24322. case 'LatheBufferGeometry':
  24323. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  24324. break;
  24325. case 'PolyhedronGeometry':
  24326. case 'PolyhedronBufferGeometry':
  24327. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  24328. break;
  24329. case 'ShapeGeometry':
  24330. case 'ShapeBufferGeometry':
  24331. geometryShapes = [];
  24332. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  24333. var shape = shapes[data.shapes[j]];
  24334. geometryShapes.push(shape);
  24335. }
  24336. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  24337. break;
  24338. case 'ExtrudeGeometry':
  24339. case 'ExtrudeBufferGeometry':
  24340. geometryShapes = [];
  24341. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  24342. var _shape = shapes[data.shapes[_j]];
  24343. geometryShapes.push(_shape);
  24344. }
  24345. var extrudePath = data.options.extrudePath;
  24346. if (extrudePath !== undefined) {
  24347. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  24348. }
  24349. geometry = new Geometries[data.type](geometryShapes, data.options);
  24350. break;
  24351. case 'BufferGeometry':
  24352. case 'InstancedBufferGeometry':
  24353. geometry = bufferGeometryLoader.parse(data);
  24354. break;
  24355. case 'Geometry':
  24356. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  24357. break;
  24358. default:
  24359. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  24360. continue;
  24361. }
  24362. geometry.uuid = data.uuid;
  24363. if (data.name !== undefined) geometry.name = data.name;
  24364. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  24365. geometries[data.uuid] = geometry;
  24366. }
  24367. }
  24368. return geometries;
  24369. };
  24370. _proto.parseMaterials = function parseMaterials(json, textures) {
  24371. var cache = {}; // MultiMaterial
  24372. var materials = {};
  24373. if (json !== undefined) {
  24374. var loader = new MaterialLoader();
  24375. loader.setTextures(textures);
  24376. for (var i = 0, l = json.length; i < l; i++) {
  24377. var data = json[i];
  24378. if (data.type === 'MultiMaterial') {
  24379. // Deprecated
  24380. var array = [];
  24381. for (var j = 0; j < data.materials.length; j++) {
  24382. var material = data.materials[j];
  24383. if (cache[material.uuid] === undefined) {
  24384. cache[material.uuid] = loader.parse(material);
  24385. }
  24386. array.push(cache[material.uuid]);
  24387. }
  24388. materials[data.uuid] = array;
  24389. } else {
  24390. if (cache[data.uuid] === undefined) {
  24391. cache[data.uuid] = loader.parse(data);
  24392. }
  24393. materials[data.uuid] = cache[data.uuid];
  24394. }
  24395. }
  24396. }
  24397. return materials;
  24398. };
  24399. _proto.parseAnimations = function parseAnimations(json) {
  24400. var animations = {};
  24401. if (json !== undefined) {
  24402. for (var i = 0; i < json.length; i++) {
  24403. var data = json[i];
  24404. var clip = AnimationClip.parse(data);
  24405. animations[clip.uuid] = clip;
  24406. }
  24407. }
  24408. return animations;
  24409. };
  24410. _proto.parseImages = function parseImages(json, onLoad) {
  24411. var scope = this;
  24412. var images = {};
  24413. var loader;
  24414. function loadImage(url) {
  24415. scope.manager.itemStart(url);
  24416. return loader.load(url, function () {
  24417. scope.manager.itemEnd(url);
  24418. }, undefined, function () {
  24419. scope.manager.itemError(url);
  24420. scope.manager.itemEnd(url);
  24421. });
  24422. }
  24423. function deserializeImage(image) {
  24424. if (typeof image === 'string') {
  24425. var url = image;
  24426. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(url) ? url : scope.resourcePath + url;
  24427. return loadImage(path);
  24428. } else {
  24429. if (image.data) {
  24430. return {
  24431. data: getTypedArray(image.type, image.data),
  24432. width: image.width,
  24433. height: image.height
  24434. };
  24435. } else {
  24436. return null;
  24437. }
  24438. }
  24439. }
  24440. if (json !== undefined && json.length > 0) {
  24441. var manager = new LoadingManager(onLoad);
  24442. loader = new ImageLoader(manager);
  24443. loader.setCrossOrigin(this.crossOrigin);
  24444. for (var i = 0, il = json.length; i < il; i++) {
  24445. var image = json[i];
  24446. var url = image.url;
  24447. if (Array.isArray(url)) {
  24448. // load array of images e.g CubeTexture
  24449. images[image.uuid] = [];
  24450. for (var j = 0, jl = url.length; j < jl; j++) {
  24451. var currentUrl = url[j];
  24452. var deserializedImage = deserializeImage(currentUrl);
  24453. if (deserializedImage !== null) {
  24454. if (deserializedImage instanceof HTMLImageElement) {
  24455. images[image.uuid].push(deserializedImage);
  24456. } else {
  24457. // special case: handle array of data textures for cube textures
  24458. images[image.uuid].push(new DataTexture(deserializedImage.data, deserializedImage.width, deserializedImage.height));
  24459. }
  24460. }
  24461. }
  24462. } else {
  24463. // load single image
  24464. var _deserializedImage = deserializeImage(image.url);
  24465. if (_deserializedImage !== null) {
  24466. images[image.uuid] = _deserializedImage;
  24467. }
  24468. }
  24469. }
  24470. }
  24471. return images;
  24472. };
  24473. _proto.parseTextures = function parseTextures(json, images) {
  24474. function parseConstant(value, type) {
  24475. if (typeof value === 'number') return value;
  24476. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  24477. return type[value];
  24478. }
  24479. var textures = {};
  24480. if (json !== undefined) {
  24481. for (var i = 0, l = json.length; i < l; i++) {
  24482. var data = json[i];
  24483. if (data.image === undefined) {
  24484. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  24485. }
  24486. if (images[data.image] === undefined) {
  24487. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  24488. }
  24489. var texture = void 0;
  24490. var image = images[data.image];
  24491. if (Array.isArray(image)) {
  24492. texture = new CubeTexture(image);
  24493. if (image.length === 6) texture.needsUpdate = true;
  24494. } else {
  24495. if (image && image.data) {
  24496. texture = new DataTexture(image.data, image.width, image.height);
  24497. } else {
  24498. texture = new Texture(image);
  24499. }
  24500. if (image) texture.needsUpdate = true; // textures can have undefined image data
  24501. }
  24502. texture.uuid = data.uuid;
  24503. if (data.name !== undefined) texture.name = data.name;
  24504. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  24505. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  24506. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  24507. if (data.center !== undefined) texture.center.fromArray(data.center);
  24508. if (data.rotation !== undefined) texture.rotation = data.rotation;
  24509. if (data.wrap !== undefined) {
  24510. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  24511. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  24512. }
  24513. if (data.format !== undefined) texture.format = data.format;
  24514. if (data.type !== undefined) texture.type = data.type;
  24515. if (data.encoding !== undefined) texture.encoding = data.encoding;
  24516. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  24517. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  24518. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  24519. if (data.flipY !== undefined) texture.flipY = data.flipY;
  24520. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  24521. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  24522. textures[data.uuid] = texture;
  24523. }
  24524. }
  24525. return textures;
  24526. };
  24527. _proto.parseObject = function parseObject(data, geometries, materials, animations) {
  24528. var object;
  24529. function getGeometry(name) {
  24530. if (geometries[name] === undefined) {
  24531. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  24532. }
  24533. return geometries[name];
  24534. }
  24535. function getMaterial(name) {
  24536. if (name === undefined) return undefined;
  24537. if (Array.isArray(name)) {
  24538. var array = [];
  24539. for (var i = 0, l = name.length; i < l; i++) {
  24540. var uuid = name[i];
  24541. if (materials[uuid] === undefined) {
  24542. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  24543. }
  24544. array.push(materials[uuid]);
  24545. }
  24546. return array;
  24547. }
  24548. if (materials[name] === undefined) {
  24549. console.warn('THREE.ObjectLoader: Undefined material', name);
  24550. }
  24551. return materials[name];
  24552. }
  24553. var geometry, material;
  24554. switch (data.type) {
  24555. case 'Scene':
  24556. object = new Scene();
  24557. if (data.background !== undefined) {
  24558. if (Number.isInteger(data.background)) {
  24559. object.background = new Color(data.background);
  24560. }
  24561. }
  24562. if (data.fog !== undefined) {
  24563. if (data.fog.type === 'Fog') {
  24564. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  24565. } else if (data.fog.type === 'FogExp2') {
  24566. object.fog = new FogExp2(data.fog.color, data.fog.density);
  24567. }
  24568. }
  24569. break;
  24570. case 'PerspectiveCamera':
  24571. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  24572. if (data.focus !== undefined) object.focus = data.focus;
  24573. if (data.zoom !== undefined) object.zoom = data.zoom;
  24574. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  24575. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  24576. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24577. break;
  24578. case 'OrthographicCamera':
  24579. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  24580. if (data.zoom !== undefined) object.zoom = data.zoom;
  24581. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24582. break;
  24583. case 'AmbientLight':
  24584. object = new AmbientLight(data.color, data.intensity);
  24585. break;
  24586. case 'DirectionalLight':
  24587. object = new DirectionalLight(data.color, data.intensity);
  24588. break;
  24589. case 'PointLight':
  24590. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  24591. break;
  24592. case 'RectAreaLight':
  24593. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  24594. break;
  24595. case 'SpotLight':
  24596. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  24597. break;
  24598. case 'HemisphereLight':
  24599. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  24600. break;
  24601. case 'LightProbe':
  24602. object = new LightProbe().fromJSON(data);
  24603. break;
  24604. case 'SkinnedMesh':
  24605. geometry = getGeometry(data.geometry);
  24606. material = getMaterial(data.material);
  24607. object = new SkinnedMesh(geometry, material);
  24608. if (data.bindMode !== undefined) object.bindMode = data.bindMode;
  24609. if (data.bindMatrix !== undefined) object.bindMatrix.fromArray(data.bindMatrix);
  24610. if (data.skeleton !== undefined) object.skeleton = data.skeleton;
  24611. break;
  24612. case 'Mesh':
  24613. geometry = getGeometry(data.geometry);
  24614. material = getMaterial(data.material);
  24615. object = new Mesh(geometry, material);
  24616. break;
  24617. case 'InstancedMesh':
  24618. geometry = getGeometry(data.geometry);
  24619. material = getMaterial(data.material);
  24620. var count = data.count;
  24621. var instanceMatrix = data.instanceMatrix;
  24622. object = new InstancedMesh(geometry, material, count);
  24623. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  24624. break;
  24625. case 'LOD':
  24626. object = new LOD();
  24627. break;
  24628. case 'Line':
  24629. object = new Line(getGeometry(data.geometry), getMaterial(data.material));
  24630. break;
  24631. case 'LineLoop':
  24632. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  24633. break;
  24634. case 'LineSegments':
  24635. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  24636. break;
  24637. case 'PointCloud':
  24638. case 'Points':
  24639. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  24640. break;
  24641. case 'Sprite':
  24642. object = new Sprite(getMaterial(data.material));
  24643. break;
  24644. case 'Group':
  24645. object = new Group();
  24646. break;
  24647. case 'Bone':
  24648. object = new Bone();
  24649. break;
  24650. default:
  24651. object = new Object3D();
  24652. }
  24653. object.uuid = data.uuid;
  24654. if (data.name !== undefined) object.name = data.name;
  24655. if (data.matrix !== undefined) {
  24656. object.matrix.fromArray(data.matrix);
  24657. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24658. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  24659. } else {
  24660. if (data.position !== undefined) object.position.fromArray(data.position);
  24661. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  24662. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  24663. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  24664. }
  24665. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  24666. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  24667. if (data.shadow) {
  24668. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  24669. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  24670. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  24671. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  24672. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  24673. }
  24674. if (data.visible !== undefined) object.visible = data.visible;
  24675. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  24676. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  24677. if (data.userData !== undefined) object.userData = data.userData;
  24678. if (data.layers !== undefined) object.layers.mask = data.layers;
  24679. if (data.children !== undefined) {
  24680. var children = data.children;
  24681. for (var i = 0; i < children.length; i++) {
  24682. object.add(this.parseObject(children[i], geometries, materials, animations));
  24683. }
  24684. }
  24685. if (data.animations !== undefined) {
  24686. var objectAnimations = data.animations;
  24687. for (var _i = 0; _i < objectAnimations.length; _i++) {
  24688. var uuid = objectAnimations[_i];
  24689. object.animations.push(animations[uuid]);
  24690. }
  24691. }
  24692. if (data.type === 'LOD') {
  24693. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  24694. var levels = data.levels;
  24695. for (var l = 0; l < levels.length; l++) {
  24696. var level = levels[l];
  24697. var child = object.getObjectByProperty('uuid', level.object);
  24698. if (child !== undefined) {
  24699. object.addLevel(child, level.distance);
  24700. }
  24701. }
  24702. }
  24703. return object;
  24704. };
  24705. _proto.bindSkeletons = function bindSkeletons(object, skeletons) {
  24706. if (Object.keys(skeletons).length === 0) return;
  24707. object.traverse(function (child) {
  24708. if (child.isSkinnedMesh === true && child.skeleton !== undefined) {
  24709. var skeleton = skeletons[child.skeleton];
  24710. if (skeleton === undefined) {
  24711. console.warn('THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton);
  24712. } else {
  24713. child.bind(skeleton, child.bindMatrix);
  24714. }
  24715. }
  24716. });
  24717. }
  24718. /* DEPRECATED */
  24719. ;
  24720. _proto.setTexturePath = function setTexturePath(value) {
  24721. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  24722. return this.setResourcePath(value);
  24723. };
  24724. return ObjectLoader;
  24725. }(Loader);
  24726. var TEXTURE_MAPPING = {
  24727. UVMapping: UVMapping,
  24728. CubeReflectionMapping: CubeReflectionMapping,
  24729. CubeRefractionMapping: CubeRefractionMapping,
  24730. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  24731. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  24732. CubeUVReflectionMapping: CubeUVReflectionMapping,
  24733. CubeUVRefractionMapping: CubeUVRefractionMapping
  24734. };
  24735. var TEXTURE_WRAPPING = {
  24736. RepeatWrapping: RepeatWrapping,
  24737. ClampToEdgeWrapping: ClampToEdgeWrapping,
  24738. MirroredRepeatWrapping: MirroredRepeatWrapping
  24739. };
  24740. var TEXTURE_FILTER = {
  24741. NearestFilter: NearestFilter,
  24742. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  24743. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  24744. LinearFilter: LinearFilter,
  24745. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  24746. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  24747. };
  24748. function ImageBitmapLoader(manager) {
  24749. if (typeof createImageBitmap === 'undefined') {
  24750. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  24751. }
  24752. if (typeof fetch === 'undefined') {
  24753. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  24754. }
  24755. Loader.call(this, manager);
  24756. this.options = {
  24757. premultiplyAlpha: 'none'
  24758. };
  24759. }
  24760. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24761. constructor: ImageBitmapLoader,
  24762. isImageBitmapLoader: true,
  24763. setOptions: function setOptions(options) {
  24764. this.options = options;
  24765. return this;
  24766. },
  24767. load: function load(url, onLoad, onProgress, onError) {
  24768. if (url === undefined) url = '';
  24769. if (this.path !== undefined) url = this.path + url;
  24770. url = this.manager.resolveURL(url);
  24771. var scope = this;
  24772. var cached = Cache.get(url);
  24773. if (cached !== undefined) {
  24774. scope.manager.itemStart(url);
  24775. setTimeout(function () {
  24776. if (onLoad) onLoad(cached);
  24777. scope.manager.itemEnd(url);
  24778. }, 0);
  24779. return cached;
  24780. }
  24781. var fetchOptions = {};
  24782. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  24783. fetch(url, fetchOptions).then(function (res) {
  24784. return res.blob();
  24785. }).then(function (blob) {
  24786. return createImageBitmap(blob, scope.options);
  24787. }).then(function (imageBitmap) {
  24788. Cache.add(url, imageBitmap);
  24789. if (onLoad) onLoad(imageBitmap);
  24790. scope.manager.itemEnd(url);
  24791. }).catch(function (e) {
  24792. if (onError) onError(e);
  24793. scope.manager.itemError(url);
  24794. scope.manager.itemEnd(url);
  24795. });
  24796. scope.manager.itemStart(url);
  24797. }
  24798. });
  24799. var ShapePath = /*#__PURE__*/function () {
  24800. function ShapePath() {
  24801. this.type = 'ShapePath';
  24802. this.color = new Color();
  24803. this.subPaths = [];
  24804. this.currentPath = null;
  24805. }
  24806. var _proto = ShapePath.prototype;
  24807. _proto.moveTo = function moveTo(x, y) {
  24808. this.currentPath = new Path();
  24809. this.subPaths.push(this.currentPath);
  24810. this.currentPath.moveTo(x, y);
  24811. return this;
  24812. };
  24813. _proto.lineTo = function lineTo(x, y) {
  24814. this.currentPath.lineTo(x, y);
  24815. return this;
  24816. };
  24817. _proto.quadraticCurveTo = function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  24818. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  24819. return this;
  24820. };
  24821. _proto.bezierCurveTo = function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  24822. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  24823. return this;
  24824. };
  24825. _proto.splineThru = function splineThru(pts) {
  24826. this.currentPath.splineThru(pts);
  24827. return this;
  24828. };
  24829. _proto.toShapes = function toShapes(isCCW, noHoles) {
  24830. function toShapesNoHoles(inSubpaths) {
  24831. var shapes = [];
  24832. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  24833. var _tmpPath = inSubpaths[i];
  24834. var _tmpShape = new Shape();
  24835. _tmpShape.curves = _tmpPath.curves;
  24836. shapes.push(_tmpShape);
  24837. }
  24838. return shapes;
  24839. }
  24840. function isPointInsidePolygon(inPt, inPolygon) {
  24841. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  24842. // toggling of inside/outside at every single! intersection point of an edge
  24843. // with the horizontal line through inPt, left of inPt
  24844. // not counting lowerY endpoints of edges and whole edges on that line
  24845. var inside = false;
  24846. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  24847. var edgeLowPt = inPolygon[p];
  24848. var edgeHighPt = inPolygon[q];
  24849. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  24850. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  24851. if (Math.abs(edgeDy) > Number.EPSILON) {
  24852. // not parallel
  24853. if (edgeDy < 0) {
  24854. edgeLowPt = inPolygon[q];
  24855. edgeDx = -edgeDx;
  24856. edgeHighPt = inPolygon[p];
  24857. edgeDy = -edgeDy;
  24858. }
  24859. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  24860. if (inPt.y === edgeLowPt.y) {
  24861. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  24862. // continue; // no intersection or edgeLowPt => doesn't count !!!
  24863. } else {
  24864. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  24865. if (perpEdge === 0) return true; // inPt is on contour ?
  24866. if (perpEdge < 0) continue;
  24867. inside = !inside; // true intersection left of inPt
  24868. }
  24869. } else {
  24870. // parallel or collinear
  24871. if (inPt.y !== edgeLowPt.y) continue; // parallel
  24872. // edge lies on the same horizontal line as inPt
  24873. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  24874. // continue;
  24875. }
  24876. }
  24877. return inside;
  24878. }
  24879. var isClockWise = ShapeUtils.isClockWise;
  24880. var subPaths = this.subPaths;
  24881. if (subPaths.length === 0) return [];
  24882. if (noHoles === true) return toShapesNoHoles(subPaths);
  24883. var solid, tmpPath, tmpShape;
  24884. var shapes = [];
  24885. if (subPaths.length === 1) {
  24886. tmpPath = subPaths[0];
  24887. tmpShape = new Shape();
  24888. tmpShape.curves = tmpPath.curves;
  24889. shapes.push(tmpShape);
  24890. return shapes;
  24891. }
  24892. var holesFirst = !isClockWise(subPaths[0].getPoints());
  24893. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  24894. var betterShapeHoles = [];
  24895. var newShapes = [];
  24896. var newShapeHoles = [];
  24897. var mainIdx = 0;
  24898. var tmpPoints;
  24899. newShapes[mainIdx] = undefined;
  24900. newShapeHoles[mainIdx] = [];
  24901. for (var i = 0, l = subPaths.length; i < l; i++) {
  24902. tmpPath = subPaths[i];
  24903. tmpPoints = tmpPath.getPoints();
  24904. solid = isClockWise(tmpPoints);
  24905. solid = isCCW ? !solid : solid;
  24906. if (solid) {
  24907. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  24908. newShapes[mainIdx] = {
  24909. s: new Shape(),
  24910. p: tmpPoints
  24911. };
  24912. newShapes[mainIdx].s.curves = tmpPath.curves;
  24913. if (holesFirst) mainIdx++;
  24914. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  24915. } else {
  24916. newShapeHoles[mainIdx].push({
  24917. h: tmpPath,
  24918. p: tmpPoints[0]
  24919. }); //console.log('ccw', i);
  24920. }
  24921. } // only Holes? -> probably all Shapes with wrong orientation
  24922. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  24923. if (newShapes.length > 1) {
  24924. var ambiguous = false;
  24925. var toChange = [];
  24926. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  24927. betterShapeHoles[sIdx] = [];
  24928. }
  24929. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  24930. var sho = newShapeHoles[_sIdx];
  24931. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  24932. var ho = sho[hIdx];
  24933. var hole_unassigned = true;
  24934. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  24935. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  24936. if (_sIdx !== s2Idx) toChange.push({
  24937. froms: _sIdx,
  24938. tos: s2Idx,
  24939. hole: hIdx
  24940. });
  24941. if (hole_unassigned) {
  24942. hole_unassigned = false;
  24943. betterShapeHoles[s2Idx].push(ho);
  24944. } else {
  24945. ambiguous = true;
  24946. }
  24947. }
  24948. }
  24949. if (hole_unassigned) {
  24950. betterShapeHoles[_sIdx].push(ho);
  24951. }
  24952. }
  24953. } // console.log("ambiguous: ", ambiguous);
  24954. if (toChange.length > 0) {
  24955. // console.log("to change: ", toChange);
  24956. if (!ambiguous) newShapeHoles = betterShapeHoles;
  24957. }
  24958. }
  24959. var tmpHoles;
  24960. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  24961. tmpShape = newShapes[_i].s;
  24962. shapes.push(tmpShape);
  24963. tmpHoles = newShapeHoles[_i];
  24964. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  24965. tmpShape.holes.push(tmpHoles[j].h);
  24966. }
  24967. } //console.log("shape", shapes);
  24968. return shapes;
  24969. };
  24970. return ShapePath;
  24971. }();
  24972. var Font = /*#__PURE__*/function () {
  24973. function Font(data) {
  24974. Object.defineProperty(this, 'isFont', {
  24975. value: true
  24976. });
  24977. this.type = 'Font';
  24978. this.data = data;
  24979. }
  24980. var _proto = Font.prototype;
  24981. _proto.generateShapes = function generateShapes(text, size) {
  24982. if (size === void 0) {
  24983. size = 100;
  24984. }
  24985. var shapes = [];
  24986. var paths = createPaths(text, size, this.data);
  24987. for (var p = 0, pl = paths.length; p < pl; p++) {
  24988. Array.prototype.push.apply(shapes, paths[p].toShapes());
  24989. }
  24990. return shapes;
  24991. };
  24992. return Font;
  24993. }();
  24994. function createPaths(text, size, data) {
  24995. var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
  24996. var scale = size / data.resolution;
  24997. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  24998. var paths = [];
  24999. var offsetX = 0,
  25000. offsetY = 0;
  25001. for (var i = 0; i < chars.length; i++) {
  25002. var char = chars[i];
  25003. if (char === '\n') {
  25004. offsetX = 0;
  25005. offsetY -= line_height;
  25006. } else {
  25007. var ret = createPath(char, scale, offsetX, offsetY, data);
  25008. offsetX += ret.offsetX;
  25009. paths.push(ret.path);
  25010. }
  25011. }
  25012. return paths;
  25013. }
  25014. function createPath(char, scale, offsetX, offsetY, data) {
  25015. var glyph = data.glyphs[char] || data.glyphs['?'];
  25016. if (!glyph) {
  25017. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  25018. return;
  25019. }
  25020. var path = new ShapePath();
  25021. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  25022. if (glyph.o) {
  25023. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  25024. for (var i = 0, l = outline.length; i < l;) {
  25025. var action = outline[i++];
  25026. switch (action) {
  25027. case 'm':
  25028. // moveTo
  25029. x = outline[i++] * scale + offsetX;
  25030. y = outline[i++] * scale + offsetY;
  25031. path.moveTo(x, y);
  25032. break;
  25033. case 'l':
  25034. // lineTo
  25035. x = outline[i++] * scale + offsetX;
  25036. y = outline[i++] * scale + offsetY;
  25037. path.lineTo(x, y);
  25038. break;
  25039. case 'q':
  25040. // quadraticCurveTo
  25041. cpx = outline[i++] * scale + offsetX;
  25042. cpy = outline[i++] * scale + offsetY;
  25043. cpx1 = outline[i++] * scale + offsetX;
  25044. cpy1 = outline[i++] * scale + offsetY;
  25045. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  25046. break;
  25047. case 'b':
  25048. // bezierCurveTo
  25049. cpx = outline[i++] * scale + offsetX;
  25050. cpy = outline[i++] * scale + offsetY;
  25051. cpx1 = outline[i++] * scale + offsetX;
  25052. cpy1 = outline[i++] * scale + offsetY;
  25053. cpx2 = outline[i++] * scale + offsetX;
  25054. cpy2 = outline[i++] * scale + offsetY;
  25055. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  25056. break;
  25057. }
  25058. }
  25059. }
  25060. return {
  25061. offsetX: glyph.ha * scale,
  25062. path: path
  25063. };
  25064. }
  25065. function FontLoader(manager) {
  25066. Loader.call(this, manager);
  25067. }
  25068. FontLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25069. constructor: FontLoader,
  25070. load: function load(url, onLoad, onProgress, onError) {
  25071. var scope = this;
  25072. var loader = new FileLoader(this.manager);
  25073. loader.setPath(this.path);
  25074. loader.setRequestHeader(this.requestHeader);
  25075. loader.setWithCredentials(scope.withCredentials);
  25076. loader.load(url, function (text) {
  25077. var json;
  25078. try {
  25079. json = JSON.parse(text);
  25080. } catch (e) {
  25081. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  25082. json = JSON.parse(text.substring(65, text.length - 2));
  25083. }
  25084. var font = scope.parse(json);
  25085. if (onLoad) onLoad(font);
  25086. }, onProgress, onError);
  25087. },
  25088. parse: function parse(json) {
  25089. return new Font(json);
  25090. }
  25091. });
  25092. var _context;
  25093. var AudioContext = {
  25094. getContext: function getContext() {
  25095. if (_context === undefined) {
  25096. _context = new (window.AudioContext || window.webkitAudioContext)();
  25097. }
  25098. return _context;
  25099. },
  25100. setContext: function setContext(value) {
  25101. _context = value;
  25102. }
  25103. };
  25104. function AudioLoader(manager) {
  25105. Loader.call(this, manager);
  25106. }
  25107. AudioLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25108. constructor: AudioLoader,
  25109. load: function load(url, onLoad, onProgress, onError) {
  25110. var scope = this;
  25111. var loader = new FileLoader(scope.manager);
  25112. loader.setResponseType('arraybuffer');
  25113. loader.setPath(scope.path);
  25114. loader.setRequestHeader(scope.requestHeader);
  25115. loader.setWithCredentials(scope.withCredentials);
  25116. loader.load(url, function (buffer) {
  25117. try {
  25118. // Create a copy of the buffer. The `decodeAudioData` method
  25119. // detaches the buffer when complete, preventing reuse.
  25120. var bufferCopy = buffer.slice(0);
  25121. var context = AudioContext.getContext();
  25122. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  25123. onLoad(audioBuffer);
  25124. });
  25125. } catch (e) {
  25126. if (onError) {
  25127. onError(e);
  25128. } else {
  25129. console.error(e);
  25130. }
  25131. scope.manager.itemError(url);
  25132. }
  25133. }, onProgress, onError);
  25134. }
  25135. });
  25136. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  25137. LightProbe.call(this, undefined, intensity);
  25138. var color1 = new Color().set(skyColor);
  25139. var color2 = new Color().set(groundColor);
  25140. var sky = new Vector3(color1.r, color1.g, color1.b);
  25141. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25142. var c0 = Math.sqrt(Math.PI);
  25143. var c1 = c0 * Math.sqrt(0.75);
  25144. this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  25145. this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  25146. }
  25147. HemisphereLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25148. constructor: HemisphereLightProbe,
  25149. isHemisphereLightProbe: true,
  25150. copy: function copy(source) {
  25151. // modifying colors not currently supported
  25152. LightProbe.prototype.copy.call(this, source);
  25153. return this;
  25154. },
  25155. toJSON: function toJSON(meta) {
  25156. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25157. return data;
  25158. }
  25159. });
  25160. function AmbientLightProbe(color, intensity) {
  25161. LightProbe.call(this, undefined, intensity);
  25162. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25163. this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  25164. }
  25165. AmbientLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25166. constructor: AmbientLightProbe,
  25167. isAmbientLightProbe: true,
  25168. copy: function copy(source) {
  25169. // modifying color not currently supported
  25170. LightProbe.prototype.copy.call(this, source);
  25171. return this;
  25172. },
  25173. toJSON: function toJSON(meta) {
  25174. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25175. return data;
  25176. }
  25177. });
  25178. var _eyeRight = new Matrix4();
  25179. var _eyeLeft = new Matrix4();
  25180. function StereoCamera() {
  25181. this.type = 'StereoCamera';
  25182. this.aspect = 1;
  25183. this.eyeSep = 0.064;
  25184. this.cameraL = new PerspectiveCamera();
  25185. this.cameraL.layers.enable(1);
  25186. this.cameraL.matrixAutoUpdate = false;
  25187. this.cameraR = new PerspectiveCamera();
  25188. this.cameraR.layers.enable(2);
  25189. this.cameraR.matrixAutoUpdate = false;
  25190. this._cache = {
  25191. focus: null,
  25192. fov: null,
  25193. aspect: null,
  25194. near: null,
  25195. far: null,
  25196. zoom: null,
  25197. eyeSep: null
  25198. };
  25199. }
  25200. Object.assign(StereoCamera.prototype, {
  25201. update: function update(camera) {
  25202. var cache = this._cache;
  25203. 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;
  25204. if (needsUpdate) {
  25205. cache.focus = camera.focus;
  25206. cache.fov = camera.fov;
  25207. cache.aspect = camera.aspect * this.aspect;
  25208. cache.near = camera.near;
  25209. cache.far = camera.far;
  25210. cache.zoom = camera.zoom;
  25211. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  25212. // http://paulbourke.net/stereographics/stereorender/
  25213. var projectionMatrix = camera.projectionMatrix.clone();
  25214. var eyeSepHalf = cache.eyeSep / 2;
  25215. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25216. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  25217. var xmin, xmax; // translate xOffset
  25218. _eyeLeft.elements[12] = -eyeSepHalf;
  25219. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  25220. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  25221. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25222. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25223. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25224. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  25225. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  25226. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25227. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25228. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25229. this.cameraR.projectionMatrix.copy(projectionMatrix);
  25230. }
  25231. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  25232. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  25233. }
  25234. });
  25235. var Clock = /*#__PURE__*/function () {
  25236. function Clock(autoStart) {
  25237. this.autoStart = autoStart !== undefined ? autoStart : true;
  25238. this.startTime = 0;
  25239. this.oldTime = 0;
  25240. this.elapsedTime = 0;
  25241. this.running = false;
  25242. }
  25243. var _proto = Clock.prototype;
  25244. _proto.start = function start() {
  25245. this.startTime = now();
  25246. this.oldTime = this.startTime;
  25247. this.elapsedTime = 0;
  25248. this.running = true;
  25249. };
  25250. _proto.stop = function stop() {
  25251. this.getElapsedTime();
  25252. this.running = false;
  25253. this.autoStart = false;
  25254. };
  25255. _proto.getElapsedTime = function getElapsedTime() {
  25256. this.getDelta();
  25257. return this.elapsedTime;
  25258. };
  25259. _proto.getDelta = function getDelta() {
  25260. var diff = 0;
  25261. if (this.autoStart && !this.running) {
  25262. this.start();
  25263. return 0;
  25264. }
  25265. if (this.running) {
  25266. var newTime = now();
  25267. diff = (newTime - this.oldTime) / 1000;
  25268. this.oldTime = newTime;
  25269. this.elapsedTime += diff;
  25270. }
  25271. return diff;
  25272. };
  25273. return Clock;
  25274. }();
  25275. function now() {
  25276. return (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  25277. }
  25278. var _position$2 = /*@__PURE__*/new Vector3();
  25279. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  25280. var _scale$1 = /*@__PURE__*/new Vector3();
  25281. var _orientation = /*@__PURE__*/new Vector3();
  25282. var AudioListener = /*#__PURE__*/function (_Object3D) {
  25283. _inheritsLoose(AudioListener, _Object3D);
  25284. function AudioListener() {
  25285. var _this;
  25286. _this = _Object3D.call(this) || this;
  25287. _this.type = 'AudioListener';
  25288. _this.context = AudioContext.getContext();
  25289. _this.gain = _this.context.createGain();
  25290. _this.gain.connect(_this.context.destination);
  25291. _this.filter = null;
  25292. _this.timeDelta = 0; // private
  25293. _this._clock = new Clock();
  25294. return _this;
  25295. }
  25296. var _proto = AudioListener.prototype;
  25297. _proto.getInput = function getInput() {
  25298. return this.gain;
  25299. };
  25300. _proto.removeFilter = function removeFilter() {
  25301. if (this.filter !== null) {
  25302. this.gain.disconnect(this.filter);
  25303. this.filter.disconnect(this.context.destination);
  25304. this.gain.connect(this.context.destination);
  25305. this.filter = null;
  25306. }
  25307. return this;
  25308. };
  25309. _proto.getFilter = function getFilter() {
  25310. return this.filter;
  25311. };
  25312. _proto.setFilter = function setFilter(value) {
  25313. if (this.filter !== null) {
  25314. this.gain.disconnect(this.filter);
  25315. this.filter.disconnect(this.context.destination);
  25316. } else {
  25317. this.gain.disconnect(this.context.destination);
  25318. }
  25319. this.filter = value;
  25320. this.gain.connect(this.filter);
  25321. this.filter.connect(this.context.destination);
  25322. return this;
  25323. };
  25324. _proto.getMasterVolume = function getMasterVolume() {
  25325. return this.gain.gain.value;
  25326. };
  25327. _proto.setMasterVolume = function setMasterVolume(value) {
  25328. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25329. return this;
  25330. };
  25331. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25332. _Object3D.prototype.updateMatrixWorld.call(this, force);
  25333. var listener = this.context.listener;
  25334. var up = this.up;
  25335. this.timeDelta = this._clock.getDelta();
  25336. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  25337. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  25338. if (listener.positionX) {
  25339. // code path for Chrome (see #14393)
  25340. var endTime = this.context.currentTime + this.timeDelta;
  25341. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  25342. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  25343. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  25344. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  25345. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  25346. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  25347. listener.upX.linearRampToValueAtTime(up.x, endTime);
  25348. listener.upY.linearRampToValueAtTime(up.y, endTime);
  25349. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  25350. } else {
  25351. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  25352. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  25353. }
  25354. };
  25355. return AudioListener;
  25356. }(Object3D);
  25357. var Audio = /*#__PURE__*/function (_Object3D) {
  25358. _inheritsLoose(Audio, _Object3D);
  25359. function Audio(listener) {
  25360. var _this;
  25361. _this = _Object3D.call(this) || this;
  25362. _this.type = 'Audio';
  25363. _this.listener = listener;
  25364. _this.context = listener.context;
  25365. _this.gain = _this.context.createGain();
  25366. _this.gain.connect(listener.getInput());
  25367. _this.autoplay = false;
  25368. _this.buffer = null;
  25369. _this.detune = 0;
  25370. _this.loop = false;
  25371. _this.loopStart = 0;
  25372. _this.loopEnd = 0;
  25373. _this.offset = 0;
  25374. _this.duration = undefined;
  25375. _this.playbackRate = 1;
  25376. _this.isPlaying = false;
  25377. _this.hasPlaybackControl = true;
  25378. _this.source = null;
  25379. _this.sourceType = 'empty';
  25380. _this._startedAt = 0;
  25381. _this._progress = 0;
  25382. _this._connected = false;
  25383. _this.filters = [];
  25384. return _this;
  25385. }
  25386. var _proto = Audio.prototype;
  25387. _proto.getOutput = function getOutput() {
  25388. return this.gain;
  25389. };
  25390. _proto.setNodeSource = function setNodeSource(audioNode) {
  25391. this.hasPlaybackControl = false;
  25392. this.sourceType = 'audioNode';
  25393. this.source = audioNode;
  25394. this.connect();
  25395. return this;
  25396. };
  25397. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  25398. this.hasPlaybackControl = false;
  25399. this.sourceType = 'mediaNode';
  25400. this.source = this.context.createMediaElementSource(mediaElement);
  25401. this.connect();
  25402. return this;
  25403. };
  25404. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  25405. this.hasPlaybackControl = false;
  25406. this.sourceType = 'mediaStreamNode';
  25407. this.source = this.context.createMediaStreamSource(mediaStream);
  25408. this.connect();
  25409. return this;
  25410. };
  25411. _proto.setBuffer = function setBuffer(audioBuffer) {
  25412. this.buffer = audioBuffer;
  25413. this.sourceType = 'buffer';
  25414. if (this.autoplay) this.play();
  25415. return this;
  25416. };
  25417. _proto.play = function play(delay) {
  25418. if (delay === void 0) {
  25419. delay = 0;
  25420. }
  25421. if (this.isPlaying === true) {
  25422. console.warn('THREE.Audio: Audio is already playing.');
  25423. return;
  25424. }
  25425. if (this.hasPlaybackControl === false) {
  25426. console.warn('THREE.Audio: this Audio has no playback control.');
  25427. return;
  25428. }
  25429. this._startedAt = this.context.currentTime + delay;
  25430. var source = this.context.createBufferSource();
  25431. source.buffer = this.buffer;
  25432. source.loop = this.loop;
  25433. source.loopStart = this.loopStart;
  25434. source.loopEnd = this.loopEnd;
  25435. source.onended = this.onEnded.bind(this);
  25436. source.start(this._startedAt, this._progress + this.offset, this.duration);
  25437. this.isPlaying = true;
  25438. this.source = source;
  25439. this.setDetune(this.detune);
  25440. this.setPlaybackRate(this.playbackRate);
  25441. return this.connect();
  25442. };
  25443. _proto.pause = function pause() {
  25444. if (this.hasPlaybackControl === false) {
  25445. console.warn('THREE.Audio: this Audio has no playback control.');
  25446. return;
  25447. }
  25448. if (this.isPlaying === true) {
  25449. // update current progress
  25450. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  25451. if (this.loop === true) {
  25452. // ensure _progress does not exceed duration with looped audios
  25453. this._progress = this._progress % (this.duration || this.buffer.duration);
  25454. }
  25455. this.source.stop();
  25456. this.source.onended = null;
  25457. this.isPlaying = false;
  25458. }
  25459. return this;
  25460. };
  25461. _proto.stop = function stop() {
  25462. if (this.hasPlaybackControl === false) {
  25463. console.warn('THREE.Audio: this Audio has no playback control.');
  25464. return;
  25465. }
  25466. this._progress = 0;
  25467. this.source.stop();
  25468. this.source.onended = null;
  25469. this.isPlaying = false;
  25470. return this;
  25471. };
  25472. _proto.connect = function connect() {
  25473. if (this.filters.length > 0) {
  25474. this.source.connect(this.filters[0]);
  25475. for (var i = 1, l = this.filters.length; i < l; i++) {
  25476. this.filters[i - 1].connect(this.filters[i]);
  25477. }
  25478. this.filters[this.filters.length - 1].connect(this.getOutput());
  25479. } else {
  25480. this.source.connect(this.getOutput());
  25481. }
  25482. this._connected = true;
  25483. return this;
  25484. };
  25485. _proto.disconnect = function disconnect() {
  25486. if (this.filters.length > 0) {
  25487. this.source.disconnect(this.filters[0]);
  25488. for (var i = 1, l = this.filters.length; i < l; i++) {
  25489. this.filters[i - 1].disconnect(this.filters[i]);
  25490. }
  25491. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  25492. } else {
  25493. this.source.disconnect(this.getOutput());
  25494. }
  25495. this._connected = false;
  25496. return this;
  25497. };
  25498. _proto.getFilters = function getFilters() {
  25499. return this.filters;
  25500. };
  25501. _proto.setFilters = function setFilters(value) {
  25502. if (!value) value = [];
  25503. if (this._connected === true) {
  25504. this.disconnect();
  25505. this.filters = value.slice();
  25506. this.connect();
  25507. } else {
  25508. this.filters = value.slice();
  25509. }
  25510. return this;
  25511. };
  25512. _proto.setDetune = function setDetune(value) {
  25513. this.detune = value;
  25514. if (this.source.detune === undefined) return; // only set detune when available
  25515. if (this.isPlaying === true) {
  25516. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  25517. }
  25518. return this;
  25519. };
  25520. _proto.getDetune = function getDetune() {
  25521. return this.detune;
  25522. };
  25523. _proto.getFilter = function getFilter() {
  25524. return this.getFilters()[0];
  25525. };
  25526. _proto.setFilter = function setFilter(filter) {
  25527. return this.setFilters(filter ? [filter] : []);
  25528. };
  25529. _proto.setPlaybackRate = function setPlaybackRate(value) {
  25530. if (this.hasPlaybackControl === false) {
  25531. console.warn('THREE.Audio: this Audio has no playback control.');
  25532. return;
  25533. }
  25534. this.playbackRate = value;
  25535. if (this.isPlaying === true) {
  25536. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  25537. }
  25538. return this;
  25539. };
  25540. _proto.getPlaybackRate = function getPlaybackRate() {
  25541. return this.playbackRate;
  25542. };
  25543. _proto.onEnded = function onEnded() {
  25544. this.isPlaying = false;
  25545. };
  25546. _proto.getLoop = function getLoop() {
  25547. if (this.hasPlaybackControl === false) {
  25548. console.warn('THREE.Audio: this Audio has no playback control.');
  25549. return false;
  25550. }
  25551. return this.loop;
  25552. };
  25553. _proto.setLoop = function setLoop(value) {
  25554. if (this.hasPlaybackControl === false) {
  25555. console.warn('THREE.Audio: this Audio has no playback control.');
  25556. return;
  25557. }
  25558. this.loop = value;
  25559. if (this.isPlaying === true) {
  25560. this.source.loop = this.loop;
  25561. }
  25562. return this;
  25563. };
  25564. _proto.setLoopStart = function setLoopStart(value) {
  25565. this.loopStart = value;
  25566. return this;
  25567. };
  25568. _proto.setLoopEnd = function setLoopEnd(value) {
  25569. this.loopEnd = value;
  25570. return this;
  25571. };
  25572. _proto.getVolume = function getVolume() {
  25573. return this.gain.gain.value;
  25574. };
  25575. _proto.setVolume = function setVolume(value) {
  25576. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25577. return this;
  25578. };
  25579. return Audio;
  25580. }(Object3D);
  25581. var _position$3 = /*@__PURE__*/new Vector3();
  25582. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  25583. var _scale$2 = /*@__PURE__*/new Vector3();
  25584. var _orientation$1 = /*@__PURE__*/new Vector3();
  25585. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  25586. _inheritsLoose(PositionalAudio, _Audio);
  25587. function PositionalAudio(listener) {
  25588. var _this;
  25589. _this = _Audio.call(this, listener) || this;
  25590. _this.panner = _this.context.createPanner();
  25591. _this.panner.panningModel = 'HRTF';
  25592. _this.panner.connect(_this.gain);
  25593. return _this;
  25594. }
  25595. var _proto = PositionalAudio.prototype;
  25596. _proto.getOutput = function getOutput() {
  25597. return this.panner;
  25598. };
  25599. _proto.getRefDistance = function getRefDistance() {
  25600. return this.panner.refDistance;
  25601. };
  25602. _proto.setRefDistance = function setRefDistance(value) {
  25603. this.panner.refDistance = value;
  25604. return this;
  25605. };
  25606. _proto.getRolloffFactor = function getRolloffFactor() {
  25607. return this.panner.rolloffFactor;
  25608. };
  25609. _proto.setRolloffFactor = function setRolloffFactor(value) {
  25610. this.panner.rolloffFactor = value;
  25611. return this;
  25612. };
  25613. _proto.getDistanceModel = function getDistanceModel() {
  25614. return this.panner.distanceModel;
  25615. };
  25616. _proto.setDistanceModel = function setDistanceModel(value) {
  25617. this.panner.distanceModel = value;
  25618. return this;
  25619. };
  25620. _proto.getMaxDistance = function getMaxDistance() {
  25621. return this.panner.maxDistance;
  25622. };
  25623. _proto.setMaxDistance = function setMaxDistance(value) {
  25624. this.panner.maxDistance = value;
  25625. return this;
  25626. };
  25627. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  25628. this.panner.coneInnerAngle = coneInnerAngle;
  25629. this.panner.coneOuterAngle = coneOuterAngle;
  25630. this.panner.coneOuterGain = coneOuterGain;
  25631. return this;
  25632. };
  25633. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25634. _Audio.prototype.updateMatrixWorld.call(this, force);
  25635. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  25636. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  25637. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  25638. var panner = this.panner;
  25639. if (panner.positionX) {
  25640. // code path for Chrome and Firefox (see #14393)
  25641. var endTime = this.context.currentTime + this.listener.timeDelta;
  25642. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  25643. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  25644. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  25645. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  25646. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  25647. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  25648. } else {
  25649. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  25650. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  25651. }
  25652. };
  25653. return PositionalAudio;
  25654. }(Audio);
  25655. var AudioAnalyser = /*#__PURE__*/function () {
  25656. function AudioAnalyser(audio, fftSize) {
  25657. if (fftSize === void 0) {
  25658. fftSize = 2048;
  25659. }
  25660. this.analyser = audio.context.createAnalyser();
  25661. this.analyser.fftSize = fftSize;
  25662. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  25663. audio.getOutput().connect(this.analyser);
  25664. }
  25665. var _proto = AudioAnalyser.prototype;
  25666. _proto.getFrequencyData = function getFrequencyData() {
  25667. this.analyser.getByteFrequencyData(this.data);
  25668. return this.data;
  25669. };
  25670. _proto.getAverageFrequency = function getAverageFrequency() {
  25671. var value = 0;
  25672. var data = this.getFrequencyData();
  25673. for (var i = 0; i < data.length; i++) {
  25674. value += data[i];
  25675. }
  25676. return value / data.length;
  25677. };
  25678. return AudioAnalyser;
  25679. }();
  25680. function PropertyMixer(binding, typeName, valueSize) {
  25681. this.binding = binding;
  25682. this.valueSize = valueSize;
  25683. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  25684. //
  25685. // interpolators can use .buffer as their .result
  25686. // the data then goes to 'incoming'
  25687. //
  25688. // 'accu0' and 'accu1' are used frame-interleaved for
  25689. // the cumulative result and are compared to detect
  25690. // changes
  25691. //
  25692. // 'orig' stores the original state of the property
  25693. //
  25694. // 'add' is used for additive cumulative results
  25695. //
  25696. // 'work' is optional and is only present for quaternion types. It is used
  25697. // to store intermediate quaternion multiplication results
  25698. switch (typeName) {
  25699. case 'quaternion':
  25700. mixFunction = this._slerp;
  25701. mixFunctionAdditive = this._slerpAdditive;
  25702. setIdentity = this._setAdditiveIdentityQuaternion;
  25703. this.buffer = new Float64Array(valueSize * 6);
  25704. this._workIndex = 5;
  25705. break;
  25706. case 'string':
  25707. case 'bool':
  25708. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  25709. // additive is not relevant for non-numeric types
  25710. mixFunctionAdditive = this._select;
  25711. setIdentity = this._setAdditiveIdentityOther;
  25712. this.buffer = new Array(valueSize * 5);
  25713. break;
  25714. default:
  25715. mixFunction = this._lerp;
  25716. mixFunctionAdditive = this._lerpAdditive;
  25717. setIdentity = this._setAdditiveIdentityNumeric;
  25718. this.buffer = new Float64Array(valueSize * 5);
  25719. }
  25720. this._mixBufferRegion = mixFunction;
  25721. this._mixBufferRegionAdditive = mixFunctionAdditive;
  25722. this._setIdentity = setIdentity;
  25723. this._origIndex = 3;
  25724. this._addIndex = 4;
  25725. this.cumulativeWeight = 0;
  25726. this.cumulativeWeightAdditive = 0;
  25727. this.useCount = 0;
  25728. this.referenceCount = 0;
  25729. }
  25730. Object.assign(PropertyMixer.prototype, {
  25731. // accumulate data in the 'incoming' region into 'accu<i>'
  25732. accumulate: function accumulate(accuIndex, weight) {
  25733. // note: happily accumulating nothing when weight = 0, the caller knows
  25734. // the weight and shouldn't have made the call in the first place
  25735. var buffer = this.buffer,
  25736. stride = this.valueSize,
  25737. offset = accuIndex * stride + stride;
  25738. var currentWeight = this.cumulativeWeight;
  25739. if (currentWeight === 0) {
  25740. // accuN := incoming * weight
  25741. for (var i = 0; i !== stride; ++i) {
  25742. buffer[offset + i] = buffer[i];
  25743. }
  25744. currentWeight = weight;
  25745. } else {
  25746. // accuN := accuN + incoming * weight
  25747. currentWeight += weight;
  25748. var mix = weight / currentWeight;
  25749. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  25750. }
  25751. this.cumulativeWeight = currentWeight;
  25752. },
  25753. // accumulate data in the 'incoming' region into 'add'
  25754. accumulateAdditive: function accumulateAdditive(weight) {
  25755. var buffer = this.buffer,
  25756. stride = this.valueSize,
  25757. offset = stride * this._addIndex;
  25758. if (this.cumulativeWeightAdditive === 0) {
  25759. // add = identity
  25760. this._setIdentity();
  25761. } // add := add + incoming * weight
  25762. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  25763. this.cumulativeWeightAdditive += weight;
  25764. },
  25765. // apply the state of 'accu<i>' to the binding when accus differ
  25766. apply: function apply(accuIndex) {
  25767. var stride = this.valueSize,
  25768. buffer = this.buffer,
  25769. offset = accuIndex * stride + stride,
  25770. weight = this.cumulativeWeight,
  25771. weightAdditive = this.cumulativeWeightAdditive,
  25772. binding = this.binding;
  25773. this.cumulativeWeight = 0;
  25774. this.cumulativeWeightAdditive = 0;
  25775. if (weight < 1) {
  25776. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25777. var originalValueOffset = stride * this._origIndex;
  25778. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  25779. }
  25780. if (weightAdditive > 0) {
  25781. // accuN := accuN + additive accuN
  25782. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  25783. }
  25784. for (var i = stride, e = stride + stride; i !== e; ++i) {
  25785. if (buffer[i] !== buffer[i + stride]) {
  25786. // value has changed -> update scene graph
  25787. binding.setValue(buffer, offset);
  25788. break;
  25789. }
  25790. }
  25791. },
  25792. // remember the state of the bound property and copy it to both accus
  25793. saveOriginalState: function saveOriginalState() {
  25794. var binding = this.binding;
  25795. var buffer = this.buffer,
  25796. stride = this.valueSize,
  25797. originalValueOffset = stride * this._origIndex;
  25798. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  25799. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  25800. buffer[i] = buffer[originalValueOffset + i % stride];
  25801. } // Add to identity for additive
  25802. this._setIdentity();
  25803. this.cumulativeWeight = 0;
  25804. this.cumulativeWeightAdditive = 0;
  25805. },
  25806. // apply the state previously taken via 'saveOriginalState' to the binding
  25807. restoreOriginalState: function restoreOriginalState() {
  25808. var originalValueOffset = this.valueSize * 3;
  25809. this.binding.setValue(this.buffer, originalValueOffset);
  25810. },
  25811. _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
  25812. var startIndex = this._addIndex * this.valueSize;
  25813. var endIndex = startIndex + this.valueSize;
  25814. for (var i = startIndex; i < endIndex; i++) {
  25815. this.buffer[i] = 0;
  25816. }
  25817. },
  25818. _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
  25819. this._setAdditiveIdentityNumeric();
  25820. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  25821. },
  25822. _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
  25823. var startIndex = this._origIndex * this.valueSize;
  25824. var targetIndex = this._addIndex * this.valueSize;
  25825. for (var i = 0; i < this.valueSize; i++) {
  25826. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  25827. }
  25828. },
  25829. // mix functions
  25830. _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
  25831. if (t >= 0.5) {
  25832. for (var i = 0; i !== stride; ++i) {
  25833. buffer[dstOffset + i] = buffer[srcOffset + i];
  25834. }
  25835. }
  25836. },
  25837. _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
  25838. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  25839. },
  25840. _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25841. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  25842. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  25843. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  25844. },
  25845. _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  25846. var s = 1 - t;
  25847. for (var i = 0; i !== stride; ++i) {
  25848. var j = dstOffset + i;
  25849. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  25850. }
  25851. },
  25852. _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25853. for (var i = 0; i !== stride; ++i) {
  25854. var j = dstOffset + i;
  25855. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  25856. }
  25857. }
  25858. });
  25859. // Characters [].:/ are reserved for track binding syntax.
  25860. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  25861. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  25862. // only latin characters, and the unicode \p{L} is not yet supported. So
  25863. // instead, we exclude reserved characters and match everything else.
  25864. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  25865. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  25866. // be matched to parse the rest of the track name.
  25867. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  25868. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  25869. // characters. Accessor may contain any character except closing bracket.
  25870. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  25871. // contain any non-bracket characters.
  25872. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  25873. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  25874. var _supportedObjectNames = ['material', 'materials', 'bones'];
  25875. function Composite(targetGroup, path, optionalParsedPath) {
  25876. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  25877. this._targetGroup = targetGroup;
  25878. this._bindings = targetGroup.subscribe_(path, parsedPath);
  25879. }
  25880. Object.assign(Composite.prototype, {
  25881. getValue: function getValue(array, offset) {
  25882. this.bind(); // bind all binding
  25883. var firstValidIndex = this._targetGroup.nCachedObjects_,
  25884. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  25885. if (binding !== undefined) binding.getValue(array, offset);
  25886. },
  25887. setValue: function setValue(array, offset) {
  25888. var bindings = this._bindings;
  25889. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25890. bindings[i].setValue(array, offset);
  25891. }
  25892. },
  25893. bind: function bind() {
  25894. var bindings = this._bindings;
  25895. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25896. bindings[i].bind();
  25897. }
  25898. },
  25899. unbind: function unbind() {
  25900. var bindings = this._bindings;
  25901. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25902. bindings[i].unbind();
  25903. }
  25904. }
  25905. });
  25906. function PropertyBinding(rootNode, path, parsedPath) {
  25907. this.path = path;
  25908. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  25909. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  25910. this.rootNode = rootNode;
  25911. }
  25912. Object.assign(PropertyBinding, {
  25913. Composite: Composite,
  25914. create: function create(root, path, parsedPath) {
  25915. if (!(root && root.isAnimationObjectGroup)) {
  25916. return new PropertyBinding(root, path, parsedPath);
  25917. } else {
  25918. return new PropertyBinding.Composite(root, path, parsedPath);
  25919. }
  25920. },
  25921. /**
  25922. * Replaces spaces with underscores and removes unsupported characters from
  25923. * node names, to ensure compatibility with parseTrackName().
  25924. *
  25925. * @param {string} name Node name to be sanitized.
  25926. * @return {string}
  25927. */
  25928. sanitizeNodeName: function sanitizeNodeName(name) {
  25929. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  25930. },
  25931. parseTrackName: function parseTrackName(trackName) {
  25932. var matches = _trackRe.exec(trackName);
  25933. if (!matches) {
  25934. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  25935. }
  25936. var results = {
  25937. // directoryName: matches[ 1 ], // (tschw) currently unused
  25938. nodeName: matches[2],
  25939. objectName: matches[3],
  25940. objectIndex: matches[4],
  25941. propertyName: matches[5],
  25942. // required
  25943. propertyIndex: matches[6]
  25944. };
  25945. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  25946. if (lastDot !== undefined && lastDot !== -1) {
  25947. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  25948. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  25949. // 'bar' could be the objectName, or part of a nodeName (which can
  25950. // include '.' characters).
  25951. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  25952. results.nodeName = results.nodeName.substring(0, lastDot);
  25953. results.objectName = objectName;
  25954. }
  25955. }
  25956. if (results.propertyName === null || results.propertyName.length === 0) {
  25957. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  25958. }
  25959. return results;
  25960. },
  25961. findNode: function findNode(root, nodeName) {
  25962. if (!nodeName || nodeName === '' || nodeName === '.' || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  25963. return root;
  25964. } // search into skeleton bones.
  25965. if (root.skeleton) {
  25966. var bone = root.skeleton.getBoneByName(nodeName);
  25967. if (bone !== undefined) {
  25968. return bone;
  25969. }
  25970. } // search into node subtree.
  25971. if (root.children) {
  25972. var searchNodeSubtree = function searchNodeSubtree(children) {
  25973. for (var i = 0; i < children.length; i++) {
  25974. var childNode = children[i];
  25975. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  25976. return childNode;
  25977. }
  25978. var result = searchNodeSubtree(childNode.children);
  25979. if (result) return result;
  25980. }
  25981. return null;
  25982. };
  25983. var subTreeNode = searchNodeSubtree(root.children);
  25984. if (subTreeNode) {
  25985. return subTreeNode;
  25986. }
  25987. }
  25988. return null;
  25989. }
  25990. });
  25991. Object.assign(PropertyBinding.prototype, {
  25992. // prototype, continued
  25993. // these are used to "bind" a nonexistent property
  25994. _getValue_unavailable: function _getValue_unavailable() {},
  25995. _setValue_unavailable: function _setValue_unavailable() {},
  25996. BindingType: {
  25997. Direct: 0,
  25998. EntireArray: 1,
  25999. ArrayElement: 2,
  26000. HasFromToArray: 3
  26001. },
  26002. Versioning: {
  26003. None: 0,
  26004. NeedsUpdate: 1,
  26005. MatrixWorldNeedsUpdate: 2
  26006. },
  26007. GetterByBindingType: [function getValue_direct(buffer, offset) {
  26008. buffer[offset] = this.node[this.propertyName];
  26009. }, function getValue_array(buffer, offset) {
  26010. var source = this.resolvedProperty;
  26011. for (var i = 0, n = source.length; i !== n; ++i) {
  26012. buffer[offset++] = source[i];
  26013. }
  26014. }, function getValue_arrayElement(buffer, offset) {
  26015. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  26016. }, function getValue_toArray(buffer, offset) {
  26017. this.resolvedProperty.toArray(buffer, offset);
  26018. }],
  26019. SetterByBindingTypeAndVersioning: [[// Direct
  26020. function setValue_direct(buffer, offset) {
  26021. this.targetObject[this.propertyName] = buffer[offset];
  26022. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  26023. this.targetObject[this.propertyName] = buffer[offset];
  26024. this.targetObject.needsUpdate = true;
  26025. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  26026. this.targetObject[this.propertyName] = buffer[offset];
  26027. this.targetObject.matrixWorldNeedsUpdate = true;
  26028. }], [// EntireArray
  26029. function setValue_array(buffer, offset) {
  26030. var dest = this.resolvedProperty;
  26031. for (var i = 0, n = dest.length; i !== n; ++i) {
  26032. dest[i] = buffer[offset++];
  26033. }
  26034. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  26035. var dest = this.resolvedProperty;
  26036. for (var i = 0, n = dest.length; i !== n; ++i) {
  26037. dest[i] = buffer[offset++];
  26038. }
  26039. this.targetObject.needsUpdate = true;
  26040. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  26041. var dest = this.resolvedProperty;
  26042. for (var i = 0, n = dest.length; i !== n; ++i) {
  26043. dest[i] = buffer[offset++];
  26044. }
  26045. this.targetObject.matrixWorldNeedsUpdate = true;
  26046. }], [// ArrayElement
  26047. function setValue_arrayElement(buffer, offset) {
  26048. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26049. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  26050. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26051. this.targetObject.needsUpdate = true;
  26052. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  26053. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26054. this.targetObject.matrixWorldNeedsUpdate = true;
  26055. }], [// HasToFromArray
  26056. function setValue_fromArray(buffer, offset) {
  26057. this.resolvedProperty.fromArray(buffer, offset);
  26058. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  26059. this.resolvedProperty.fromArray(buffer, offset);
  26060. this.targetObject.needsUpdate = true;
  26061. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  26062. this.resolvedProperty.fromArray(buffer, offset);
  26063. this.targetObject.matrixWorldNeedsUpdate = true;
  26064. }]],
  26065. getValue: function getValue_unbound(targetArray, offset) {
  26066. this.bind();
  26067. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  26068. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  26069. // prototype version of these methods with one that represents
  26070. // the bound state. When the property is not found, the methods
  26071. // become no-ops.
  26072. },
  26073. setValue: function getValue_unbound(sourceArray, offset) {
  26074. this.bind();
  26075. this.setValue(sourceArray, offset);
  26076. },
  26077. // create getter / setter pair for a property in the scene graph
  26078. bind: function bind() {
  26079. var targetObject = this.node;
  26080. var parsedPath = this.parsedPath;
  26081. var objectName = parsedPath.objectName;
  26082. var propertyName = parsedPath.propertyName;
  26083. var propertyIndex = parsedPath.propertyIndex;
  26084. if (!targetObject) {
  26085. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  26086. this.node = targetObject;
  26087. } // set fail state so we can just 'return' on error
  26088. this.getValue = this._getValue_unavailable;
  26089. this.setValue = this._setValue_unavailable; // ensure there is a value node
  26090. if (!targetObject) {
  26091. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  26092. return;
  26093. }
  26094. if (objectName) {
  26095. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  26096. switch (objectName) {
  26097. case 'materials':
  26098. if (!targetObject.material) {
  26099. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  26100. return;
  26101. }
  26102. if (!targetObject.material.materials) {
  26103. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  26104. return;
  26105. }
  26106. targetObject = targetObject.material.materials;
  26107. break;
  26108. case 'bones':
  26109. if (!targetObject.skeleton) {
  26110. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  26111. return;
  26112. } // potential future optimization: skip this if propertyIndex is already an integer
  26113. // and convert the integer string to a true integer.
  26114. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  26115. for (var i = 0; i < targetObject.length; i++) {
  26116. if (targetObject[i].name === objectIndex) {
  26117. objectIndex = i;
  26118. break;
  26119. }
  26120. }
  26121. break;
  26122. default:
  26123. if (targetObject[objectName] === undefined) {
  26124. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  26125. return;
  26126. }
  26127. targetObject = targetObject[objectName];
  26128. }
  26129. if (objectIndex !== undefined) {
  26130. if (targetObject[objectIndex] === undefined) {
  26131. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  26132. return;
  26133. }
  26134. targetObject = targetObject[objectIndex];
  26135. }
  26136. } // resolve property
  26137. var nodeProperty = targetObject[propertyName];
  26138. if (nodeProperty === undefined) {
  26139. var nodeName = parsedPath.nodeName;
  26140. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  26141. return;
  26142. } // determine versioning scheme
  26143. var versioning = this.Versioning.None;
  26144. this.targetObject = targetObject;
  26145. if (targetObject.needsUpdate !== undefined) {
  26146. // material
  26147. versioning = this.Versioning.NeedsUpdate;
  26148. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  26149. // node transform
  26150. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26151. } // determine how the property gets bound
  26152. var bindingType = this.BindingType.Direct;
  26153. if (propertyIndex !== undefined) {
  26154. // access a sub element of the property array (only primitives are supported right now)
  26155. if (propertyName === 'morphTargetInfluences') {
  26156. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26157. // support resolving morphTarget names into indices.
  26158. if (!targetObject.geometry) {
  26159. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  26160. return;
  26161. }
  26162. if (targetObject.geometry.isBufferGeometry) {
  26163. if (!targetObject.geometry.morphAttributes) {
  26164. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  26165. return;
  26166. }
  26167. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  26168. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  26169. }
  26170. } else {
  26171. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  26172. return;
  26173. }
  26174. }
  26175. bindingType = this.BindingType.ArrayElement;
  26176. this.resolvedProperty = nodeProperty;
  26177. this.propertyIndex = propertyIndex;
  26178. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  26179. // must use copy for Object3D.Euler/Quaternion
  26180. bindingType = this.BindingType.HasFromToArray;
  26181. this.resolvedProperty = nodeProperty;
  26182. } else if (Array.isArray(nodeProperty)) {
  26183. bindingType = this.BindingType.EntireArray;
  26184. this.resolvedProperty = nodeProperty;
  26185. } else {
  26186. this.propertyName = propertyName;
  26187. } // select getter / setter
  26188. this.getValue = this.GetterByBindingType[bindingType];
  26189. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  26190. },
  26191. unbind: function unbind() {
  26192. this.node = null; // back to the prototype version of getValue / setValue
  26193. // note: avoiding to mutate the shape of 'this' via 'delete'
  26194. this.getValue = this._getValue_unbound;
  26195. this.setValue = this._setValue_unbound;
  26196. }
  26197. }); // DECLARE ALIAS AFTER assign prototype
  26198. Object.assign(PropertyBinding.prototype, {
  26199. // initial state of these methods that calls 'bind'
  26200. _getValue_unbound: PropertyBinding.prototype.getValue,
  26201. _setValue_unbound: PropertyBinding.prototype.setValue
  26202. });
  26203. /**
  26204. *
  26205. * A group of objects that receives a shared animation state.
  26206. *
  26207. * Usage:
  26208. *
  26209. * - Add objects you would otherwise pass as 'root' to the
  26210. * constructor or the .clipAction method of AnimationMixer.
  26211. *
  26212. * - Instead pass this object as 'root'.
  26213. *
  26214. * - You can also add and remove objects later when the mixer
  26215. * is running.
  26216. *
  26217. * Note:
  26218. *
  26219. * Objects of this class appear as one object to the mixer,
  26220. * so cache control of the individual objects must be done
  26221. * on the group.
  26222. *
  26223. * Limitation:
  26224. *
  26225. * - The animated properties must be compatible among the
  26226. * all objects in the group.
  26227. *
  26228. * - A single property can either be controlled through a
  26229. * target group or directly, but not both.
  26230. */
  26231. function AnimationObjectGroup() {
  26232. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  26233. this._objects = Array.prototype.slice.call(arguments);
  26234. this.nCachedObjects_ = 0; // threshold
  26235. // note: read by PropertyBinding.Composite
  26236. var indices = {};
  26237. this._indicesByUUID = indices; // for bookkeeping
  26238. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26239. indices[arguments[i].uuid] = i;
  26240. }
  26241. this._paths = []; // inside: string
  26242. this._parsedPaths = []; // inside: { we don't care, here }
  26243. this._bindings = []; // inside: Array< PropertyBinding >
  26244. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26245. var scope = this;
  26246. this.stats = {
  26247. objects: {
  26248. get total() {
  26249. return scope._objects.length;
  26250. },
  26251. get inUse() {
  26252. return this.total - scope.nCachedObjects_;
  26253. }
  26254. },
  26255. get bindingsPerObject() {
  26256. return scope._bindings.length;
  26257. }
  26258. };
  26259. }
  26260. Object.assign(AnimationObjectGroup.prototype, {
  26261. isAnimationObjectGroup: true,
  26262. add: function add() {
  26263. var objects = this._objects,
  26264. indicesByUUID = this._indicesByUUID,
  26265. paths = this._paths,
  26266. parsedPaths = this._parsedPaths,
  26267. bindings = this._bindings,
  26268. nBindings = bindings.length;
  26269. var knownObject = undefined,
  26270. nObjects = objects.length,
  26271. nCachedObjects = this.nCachedObjects_;
  26272. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26273. var object = arguments[i],
  26274. uuid = object.uuid;
  26275. var index = indicesByUUID[uuid];
  26276. if (index === undefined) {
  26277. // unknown object -> add it to the ACTIVE region
  26278. index = nObjects++;
  26279. indicesByUUID[uuid] = index;
  26280. objects.push(object); // accounting is done, now do the same for all bindings
  26281. for (var j = 0, m = nBindings; j !== m; ++j) {
  26282. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  26283. }
  26284. } else if (index < nCachedObjects) {
  26285. knownObject = objects[index]; // move existing object to the ACTIVE region
  26286. var firstActiveIndex = --nCachedObjects,
  26287. lastCachedObject = objects[firstActiveIndex];
  26288. indicesByUUID[lastCachedObject.uuid] = index;
  26289. objects[index] = lastCachedObject;
  26290. indicesByUUID[uuid] = firstActiveIndex;
  26291. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  26292. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  26293. var bindingsForPath = bindings[_j],
  26294. lastCached = bindingsForPath[firstActiveIndex];
  26295. var binding = bindingsForPath[index];
  26296. bindingsForPath[index] = lastCached;
  26297. if (binding === undefined) {
  26298. // since we do not bother to create new bindings
  26299. // for objects that are cached, the binding may
  26300. // or may not exist
  26301. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  26302. }
  26303. bindingsForPath[firstActiveIndex] = binding;
  26304. }
  26305. } else if (objects[index] !== knownObject) {
  26306. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  26307. } // else the object is already where we want it to be
  26308. } // for arguments
  26309. this.nCachedObjects_ = nCachedObjects;
  26310. },
  26311. remove: function remove() {
  26312. var objects = this._objects,
  26313. indicesByUUID = this._indicesByUUID,
  26314. bindings = this._bindings,
  26315. nBindings = bindings.length;
  26316. var nCachedObjects = this.nCachedObjects_;
  26317. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26318. var object = arguments[i],
  26319. uuid = object.uuid,
  26320. index = indicesByUUID[uuid];
  26321. if (index !== undefined && index >= nCachedObjects) {
  26322. // move existing object into the CACHED region
  26323. var lastCachedIndex = nCachedObjects++,
  26324. firstActiveObject = objects[lastCachedIndex];
  26325. indicesByUUID[firstActiveObject.uuid] = index;
  26326. objects[index] = firstActiveObject;
  26327. indicesByUUID[uuid] = lastCachedIndex;
  26328. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  26329. for (var j = 0, m = nBindings; j !== m; ++j) {
  26330. var bindingsForPath = bindings[j],
  26331. firstActive = bindingsForPath[lastCachedIndex],
  26332. binding = bindingsForPath[index];
  26333. bindingsForPath[index] = firstActive;
  26334. bindingsForPath[lastCachedIndex] = binding;
  26335. }
  26336. }
  26337. } // for arguments
  26338. this.nCachedObjects_ = nCachedObjects;
  26339. },
  26340. // remove & forget
  26341. uncache: function uncache() {
  26342. var objects = this._objects,
  26343. indicesByUUID = this._indicesByUUID,
  26344. bindings = this._bindings,
  26345. nBindings = bindings.length;
  26346. var nCachedObjects = this.nCachedObjects_,
  26347. nObjects = objects.length;
  26348. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26349. var object = arguments[i],
  26350. uuid = object.uuid,
  26351. index = indicesByUUID[uuid];
  26352. if (index !== undefined) {
  26353. delete indicesByUUID[uuid];
  26354. if (index < nCachedObjects) {
  26355. // object is cached, shrink the CACHED region
  26356. var firstActiveIndex = --nCachedObjects,
  26357. lastCachedObject = objects[firstActiveIndex],
  26358. lastIndex = --nObjects,
  26359. lastObject = objects[lastIndex]; // last cached object takes this object's place
  26360. indicesByUUID[lastCachedObject.uuid] = index;
  26361. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  26362. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  26363. objects[firstActiveIndex] = lastObject;
  26364. objects.pop(); // accounting is done, now do the same for all bindings
  26365. for (var j = 0, m = nBindings; j !== m; ++j) {
  26366. var bindingsForPath = bindings[j],
  26367. lastCached = bindingsForPath[firstActiveIndex],
  26368. last = bindingsForPath[lastIndex];
  26369. bindingsForPath[index] = lastCached;
  26370. bindingsForPath[firstActiveIndex] = last;
  26371. bindingsForPath.pop();
  26372. }
  26373. } else {
  26374. // object is active, just swap with the last and pop
  26375. var _lastIndex = --nObjects,
  26376. _lastObject = objects[_lastIndex];
  26377. if (_lastIndex > 0) {
  26378. indicesByUUID[_lastObject.uuid] = index;
  26379. }
  26380. objects[index] = _lastObject;
  26381. objects.pop(); // accounting is done, now do the same for all bindings
  26382. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  26383. var _bindingsForPath = bindings[_j2];
  26384. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  26385. _bindingsForPath.pop();
  26386. }
  26387. } // cached or active
  26388. } // if object is known
  26389. } // for arguments
  26390. this.nCachedObjects_ = nCachedObjects;
  26391. },
  26392. // Internal interface used by befriended PropertyBinding.Composite:
  26393. subscribe_: function subscribe_(path, parsedPath) {
  26394. // returns an array of bindings for the given path that is changed
  26395. // according to the contained objects in the group
  26396. var indicesByPath = this._bindingsIndicesByPath;
  26397. var index = indicesByPath[path];
  26398. var bindings = this._bindings;
  26399. if (index !== undefined) return bindings[index];
  26400. var paths = this._paths,
  26401. parsedPaths = this._parsedPaths,
  26402. objects = this._objects,
  26403. nObjects = objects.length,
  26404. nCachedObjects = this.nCachedObjects_,
  26405. bindingsForPath = new Array(nObjects);
  26406. index = bindings.length;
  26407. indicesByPath[path] = index;
  26408. paths.push(path);
  26409. parsedPaths.push(parsedPath);
  26410. bindings.push(bindingsForPath);
  26411. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  26412. var object = objects[i];
  26413. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  26414. }
  26415. return bindingsForPath;
  26416. },
  26417. unsubscribe_: function unsubscribe_(path) {
  26418. // tells the group to forget about a property path and no longer
  26419. // update the array previously obtained with 'subscribe_'
  26420. var indicesByPath = this._bindingsIndicesByPath,
  26421. index = indicesByPath[path];
  26422. if (index !== undefined) {
  26423. var paths = this._paths,
  26424. parsedPaths = this._parsedPaths,
  26425. bindings = this._bindings,
  26426. lastBindingsIndex = bindings.length - 1,
  26427. lastBindings = bindings[lastBindingsIndex],
  26428. lastBindingsPath = path[lastBindingsIndex];
  26429. indicesByPath[lastBindingsPath] = index;
  26430. bindings[index] = lastBindings;
  26431. bindings.pop();
  26432. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  26433. parsedPaths.pop();
  26434. paths[index] = paths[lastBindingsIndex];
  26435. paths.pop();
  26436. }
  26437. }
  26438. });
  26439. var AnimationAction = /*#__PURE__*/function () {
  26440. function AnimationAction(mixer, clip, localRoot, blendMode) {
  26441. if (localRoot === void 0) {
  26442. localRoot = null;
  26443. }
  26444. if (blendMode === void 0) {
  26445. blendMode = clip.blendMode;
  26446. }
  26447. this._mixer = mixer;
  26448. this._clip = clip;
  26449. this._localRoot = localRoot;
  26450. this.blendMode = blendMode;
  26451. var tracks = clip.tracks,
  26452. nTracks = tracks.length,
  26453. interpolants = new Array(nTracks);
  26454. var interpolantSettings = {
  26455. endingStart: ZeroCurvatureEnding,
  26456. endingEnd: ZeroCurvatureEnding
  26457. };
  26458. for (var i = 0; i !== nTracks; ++i) {
  26459. var interpolant = tracks[i].createInterpolant(null);
  26460. interpolants[i] = interpolant;
  26461. interpolant.settings = interpolantSettings;
  26462. }
  26463. this._interpolantSettings = interpolantSettings;
  26464. this._interpolants = interpolants; // bound by the mixer
  26465. // inside: PropertyMixer (managed by the mixer)
  26466. this._propertyBindings = new Array(nTracks);
  26467. this._cacheIndex = null; // for the memory manager
  26468. this._byClipCacheIndex = null; // for the memory manager
  26469. this._timeScaleInterpolant = null;
  26470. this._weightInterpolant = null;
  26471. this.loop = LoopRepeat;
  26472. this._loopCount = -1; // global mixer time when the action is to be started
  26473. // it's set back to 'null' upon start of the action
  26474. this._startTime = null; // scaled local time of the action
  26475. // gets clamped or wrapped to 0..clip.duration according to loop
  26476. this.time = 0;
  26477. this.timeScale = 1;
  26478. this._effectiveTimeScale = 1;
  26479. this.weight = 1;
  26480. this._effectiveWeight = 1;
  26481. this.repetitions = Infinity; // no. of repetitions when looping
  26482. this.paused = false; // true -> zero effective time scale
  26483. this.enabled = true; // false -> zero effective weight
  26484. this.clampWhenFinished = false; // keep feeding the last frame?
  26485. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  26486. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  26487. } // State & Scheduling
  26488. var _proto = AnimationAction.prototype;
  26489. _proto.play = function play() {
  26490. this._mixer._activateAction(this);
  26491. return this;
  26492. };
  26493. _proto.stop = function stop() {
  26494. this._mixer._deactivateAction(this);
  26495. return this.reset();
  26496. };
  26497. _proto.reset = function reset() {
  26498. this.paused = false;
  26499. this.enabled = true;
  26500. this.time = 0; // restart clip
  26501. this._loopCount = -1; // forget previous loops
  26502. this._startTime = null; // forget scheduling
  26503. return this.stopFading().stopWarping();
  26504. };
  26505. _proto.isRunning = function isRunning() {
  26506. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  26507. } // return true when play has been called
  26508. ;
  26509. _proto.isScheduled = function isScheduled() {
  26510. return this._mixer._isActiveAction(this);
  26511. };
  26512. _proto.startAt = function startAt(time) {
  26513. this._startTime = time;
  26514. return this;
  26515. };
  26516. _proto.setLoop = function setLoop(mode, repetitions) {
  26517. this.loop = mode;
  26518. this.repetitions = repetitions;
  26519. return this;
  26520. } // Weight
  26521. // set the weight stopping any scheduled fading
  26522. // although .enabled = false yields an effective weight of zero, this
  26523. // method does *not* change .enabled, because it would be confusing
  26524. ;
  26525. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  26526. this.weight = weight; // note: same logic as when updated at runtime
  26527. this._effectiveWeight = this.enabled ? weight : 0;
  26528. return this.stopFading();
  26529. } // return the weight considering fading and .enabled
  26530. ;
  26531. _proto.getEffectiveWeight = function getEffectiveWeight() {
  26532. return this._effectiveWeight;
  26533. };
  26534. _proto.fadeIn = function fadeIn(duration) {
  26535. return this._scheduleFading(duration, 0, 1);
  26536. };
  26537. _proto.fadeOut = function fadeOut(duration) {
  26538. return this._scheduleFading(duration, 1, 0);
  26539. };
  26540. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  26541. fadeOutAction.fadeOut(duration);
  26542. this.fadeIn(duration);
  26543. if (warp) {
  26544. var fadeInDuration = this._clip.duration,
  26545. fadeOutDuration = fadeOutAction._clip.duration,
  26546. startEndRatio = fadeOutDuration / fadeInDuration,
  26547. endStartRatio = fadeInDuration / fadeOutDuration;
  26548. fadeOutAction.warp(1.0, startEndRatio, duration);
  26549. this.warp(endStartRatio, 1.0, duration);
  26550. }
  26551. return this;
  26552. };
  26553. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  26554. return fadeInAction.crossFadeFrom(this, duration, warp);
  26555. };
  26556. _proto.stopFading = function stopFading() {
  26557. var weightInterpolant = this._weightInterpolant;
  26558. if (weightInterpolant !== null) {
  26559. this._weightInterpolant = null;
  26560. this._mixer._takeBackControlInterpolant(weightInterpolant);
  26561. }
  26562. return this;
  26563. } // Time Scale Control
  26564. // set the time scale stopping any scheduled warping
  26565. // although .paused = true yields an effective time scale of zero, this
  26566. // method does *not* change .paused, because it would be confusing
  26567. ;
  26568. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  26569. this.timeScale = timeScale;
  26570. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26571. return this.stopWarping();
  26572. } // return the time scale considering warping and .paused
  26573. ;
  26574. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  26575. return this._effectiveTimeScale;
  26576. };
  26577. _proto.setDuration = function setDuration(duration) {
  26578. this.timeScale = this._clip.duration / duration;
  26579. return this.stopWarping();
  26580. };
  26581. _proto.syncWith = function syncWith(action) {
  26582. this.time = action.time;
  26583. this.timeScale = action.timeScale;
  26584. return this.stopWarping();
  26585. };
  26586. _proto.halt = function halt(duration) {
  26587. return this.warp(this._effectiveTimeScale, 0, duration);
  26588. };
  26589. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  26590. var mixer = this._mixer,
  26591. now = mixer.time,
  26592. timeScale = this.timeScale;
  26593. var interpolant = this._timeScaleInterpolant;
  26594. if (interpolant === null) {
  26595. interpolant = mixer._lendControlInterpolant();
  26596. this._timeScaleInterpolant = interpolant;
  26597. }
  26598. var times = interpolant.parameterPositions,
  26599. values = interpolant.sampleValues;
  26600. times[0] = now;
  26601. times[1] = now + duration;
  26602. values[0] = startTimeScale / timeScale;
  26603. values[1] = endTimeScale / timeScale;
  26604. return this;
  26605. };
  26606. _proto.stopWarping = function stopWarping() {
  26607. var timeScaleInterpolant = this._timeScaleInterpolant;
  26608. if (timeScaleInterpolant !== null) {
  26609. this._timeScaleInterpolant = null;
  26610. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  26611. }
  26612. return this;
  26613. } // Object Accessors
  26614. ;
  26615. _proto.getMixer = function getMixer() {
  26616. return this._mixer;
  26617. };
  26618. _proto.getClip = function getClip() {
  26619. return this._clip;
  26620. };
  26621. _proto.getRoot = function getRoot() {
  26622. return this._localRoot || this._mixer._root;
  26623. } // Interna
  26624. ;
  26625. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  26626. // called by the mixer
  26627. if (!this.enabled) {
  26628. // call ._updateWeight() to update ._effectiveWeight
  26629. this._updateWeight(time);
  26630. return;
  26631. }
  26632. var startTime = this._startTime;
  26633. if (startTime !== null) {
  26634. // check for scheduled start of action
  26635. var timeRunning = (time - startTime) * timeDirection;
  26636. if (timeRunning < 0 || timeDirection === 0) {
  26637. return; // yet to come / don't decide when delta = 0
  26638. } // start
  26639. this._startTime = null; // unschedule
  26640. deltaTime = timeDirection * timeRunning;
  26641. } // apply time scale and advance time
  26642. deltaTime *= this._updateTimeScale(time);
  26643. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  26644. // an effective weight of 0
  26645. var weight = this._updateWeight(time);
  26646. if (weight > 0) {
  26647. var _interpolants = this._interpolants;
  26648. var propertyMixers = this._propertyBindings;
  26649. switch (this.blendMode) {
  26650. case AdditiveAnimationBlendMode:
  26651. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  26652. _interpolants[j].evaluate(clipTime);
  26653. propertyMixers[j].accumulateAdditive(weight);
  26654. }
  26655. break;
  26656. case NormalAnimationBlendMode:
  26657. default:
  26658. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  26659. _interpolants[_j].evaluate(clipTime);
  26660. propertyMixers[_j].accumulate(accuIndex, weight);
  26661. }
  26662. }
  26663. }
  26664. };
  26665. _proto._updateWeight = function _updateWeight(time) {
  26666. var weight = 0;
  26667. if (this.enabled) {
  26668. weight = this.weight;
  26669. var interpolant = this._weightInterpolant;
  26670. if (interpolant !== null) {
  26671. var interpolantValue = interpolant.evaluate(time)[0];
  26672. weight *= interpolantValue;
  26673. if (time > interpolant.parameterPositions[1]) {
  26674. this.stopFading();
  26675. if (interpolantValue === 0) {
  26676. // faded out, disable
  26677. this.enabled = false;
  26678. }
  26679. }
  26680. }
  26681. }
  26682. this._effectiveWeight = weight;
  26683. return weight;
  26684. };
  26685. _proto._updateTimeScale = function _updateTimeScale(time) {
  26686. var timeScale = 0;
  26687. if (!this.paused) {
  26688. timeScale = this.timeScale;
  26689. var interpolant = this._timeScaleInterpolant;
  26690. if (interpolant !== null) {
  26691. var interpolantValue = interpolant.evaluate(time)[0];
  26692. timeScale *= interpolantValue;
  26693. if (time > interpolant.parameterPositions[1]) {
  26694. this.stopWarping();
  26695. if (timeScale === 0) {
  26696. // motion has halted, pause
  26697. this.paused = true;
  26698. } else {
  26699. // warp done - apply final time scale
  26700. this.timeScale = timeScale;
  26701. }
  26702. }
  26703. }
  26704. }
  26705. this._effectiveTimeScale = timeScale;
  26706. return timeScale;
  26707. };
  26708. _proto._updateTime = function _updateTime(deltaTime) {
  26709. var duration = this._clip.duration;
  26710. var loop = this.loop;
  26711. var time = this.time + deltaTime;
  26712. var loopCount = this._loopCount;
  26713. var pingPong = loop === LoopPingPong;
  26714. if (deltaTime === 0) {
  26715. if (loopCount === -1) return time;
  26716. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  26717. }
  26718. if (loop === LoopOnce) {
  26719. if (loopCount === -1) {
  26720. // just started
  26721. this._loopCount = 0;
  26722. this._setEndings(true, true, false);
  26723. }
  26724. handle_stop: {
  26725. if (time >= duration) {
  26726. time = duration;
  26727. } else if (time < 0) {
  26728. time = 0;
  26729. } else {
  26730. this.time = time;
  26731. break handle_stop;
  26732. }
  26733. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26734. this.time = time;
  26735. this._mixer.dispatchEvent({
  26736. type: 'finished',
  26737. action: this,
  26738. direction: deltaTime < 0 ? -1 : 1
  26739. });
  26740. }
  26741. } else {
  26742. // repetitive Repeat or PingPong
  26743. if (loopCount === -1) {
  26744. // just started
  26745. if (deltaTime >= 0) {
  26746. loopCount = 0;
  26747. this._setEndings(true, this.repetitions === 0, pingPong);
  26748. } else {
  26749. // when looping in reverse direction, the initial
  26750. // transition through zero counts as a repetition,
  26751. // so leave loopCount at -1
  26752. this._setEndings(this.repetitions === 0, true, pingPong);
  26753. }
  26754. }
  26755. if (time >= duration || time < 0) {
  26756. // wrap around
  26757. var loopDelta = Math.floor(time / duration); // signed
  26758. time -= duration * loopDelta;
  26759. loopCount += Math.abs(loopDelta);
  26760. var pending = this.repetitions - loopCount;
  26761. if (pending <= 0) {
  26762. // have to stop (switch state, clamp time, fire event)
  26763. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26764. time = deltaTime > 0 ? duration : 0;
  26765. this.time = time;
  26766. this._mixer.dispatchEvent({
  26767. type: 'finished',
  26768. action: this,
  26769. direction: deltaTime > 0 ? 1 : -1
  26770. });
  26771. } else {
  26772. // keep running
  26773. if (pending === 1) {
  26774. // entering the last round
  26775. var atStart = deltaTime < 0;
  26776. this._setEndings(atStart, !atStart, pingPong);
  26777. } else {
  26778. this._setEndings(false, false, pingPong);
  26779. }
  26780. this._loopCount = loopCount;
  26781. this.time = time;
  26782. this._mixer.dispatchEvent({
  26783. type: 'loop',
  26784. action: this,
  26785. loopDelta: loopDelta
  26786. });
  26787. }
  26788. } else {
  26789. this.time = time;
  26790. }
  26791. if (pingPong && (loopCount & 1) === 1) {
  26792. // invert time for the "pong round"
  26793. return duration - time;
  26794. }
  26795. }
  26796. return time;
  26797. };
  26798. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  26799. var settings = this._interpolantSettings;
  26800. if (pingPong) {
  26801. settings.endingStart = ZeroSlopeEnding;
  26802. settings.endingEnd = ZeroSlopeEnding;
  26803. } else {
  26804. // assuming for LoopOnce atStart == atEnd == true
  26805. if (atStart) {
  26806. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26807. } else {
  26808. settings.endingStart = WrapAroundEnding;
  26809. }
  26810. if (atEnd) {
  26811. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26812. } else {
  26813. settings.endingEnd = WrapAroundEnding;
  26814. }
  26815. }
  26816. };
  26817. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  26818. var mixer = this._mixer,
  26819. now = mixer.time;
  26820. var interpolant = this._weightInterpolant;
  26821. if (interpolant === null) {
  26822. interpolant = mixer._lendControlInterpolant();
  26823. this._weightInterpolant = interpolant;
  26824. }
  26825. var times = interpolant.parameterPositions,
  26826. values = interpolant.sampleValues;
  26827. times[0] = now;
  26828. values[0] = weightNow;
  26829. times[1] = now + duration;
  26830. values[1] = weightThen;
  26831. return this;
  26832. };
  26833. return AnimationAction;
  26834. }();
  26835. function AnimationMixer(root) {
  26836. this._root = root;
  26837. this._initMemoryManager();
  26838. this._accuIndex = 0;
  26839. this.time = 0;
  26840. this.timeScale = 1.0;
  26841. }
  26842. AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  26843. constructor: AnimationMixer,
  26844. _bindAction: function _bindAction(action, prototypeAction) {
  26845. var root = action._localRoot || this._root,
  26846. tracks = action._clip.tracks,
  26847. nTracks = tracks.length,
  26848. bindings = action._propertyBindings,
  26849. interpolants = action._interpolants,
  26850. rootUuid = root.uuid,
  26851. bindingsByRoot = this._bindingsByRootAndName;
  26852. var bindingsByName = bindingsByRoot[rootUuid];
  26853. if (bindingsByName === undefined) {
  26854. bindingsByName = {};
  26855. bindingsByRoot[rootUuid] = bindingsByName;
  26856. }
  26857. for (var i = 0; i !== nTracks; ++i) {
  26858. var track = tracks[i],
  26859. trackName = track.name;
  26860. var binding = bindingsByName[trackName];
  26861. if (binding !== undefined) {
  26862. bindings[i] = binding;
  26863. } else {
  26864. binding = bindings[i];
  26865. if (binding !== undefined) {
  26866. // existing binding, make sure the cache knows
  26867. if (binding._cacheIndex === null) {
  26868. ++binding.referenceCount;
  26869. this._addInactiveBinding(binding, rootUuid, trackName);
  26870. }
  26871. continue;
  26872. }
  26873. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  26874. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  26875. ++binding.referenceCount;
  26876. this._addInactiveBinding(binding, rootUuid, trackName);
  26877. bindings[i] = binding;
  26878. }
  26879. interpolants[i].resultBuffer = binding.buffer;
  26880. }
  26881. },
  26882. _activateAction: function _activateAction(action) {
  26883. if (!this._isActiveAction(action)) {
  26884. if (action._cacheIndex === null) {
  26885. // this action has been forgotten by the cache, but the user
  26886. // appears to be still using it -> rebind
  26887. var rootUuid = (action._localRoot || this._root).uuid,
  26888. clipUuid = action._clip.uuid,
  26889. actionsForClip = this._actionsByClip[clipUuid];
  26890. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  26891. this._addInactiveAction(action, clipUuid, rootUuid);
  26892. }
  26893. var bindings = action._propertyBindings; // increment reference counts / sort out state
  26894. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26895. var binding = bindings[i];
  26896. if (binding.useCount++ === 0) {
  26897. this._lendBinding(binding);
  26898. binding.saveOriginalState();
  26899. }
  26900. }
  26901. this._lendAction(action);
  26902. }
  26903. },
  26904. _deactivateAction: function _deactivateAction(action) {
  26905. if (this._isActiveAction(action)) {
  26906. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  26907. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26908. var binding = bindings[i];
  26909. if (--binding.useCount === 0) {
  26910. binding.restoreOriginalState();
  26911. this._takeBackBinding(binding);
  26912. }
  26913. }
  26914. this._takeBackAction(action);
  26915. }
  26916. },
  26917. // Memory manager
  26918. _initMemoryManager: function _initMemoryManager() {
  26919. this._actions = []; // 'nActiveActions' followed by inactive ones
  26920. this._nActiveActions = 0;
  26921. this._actionsByClip = {}; // inside:
  26922. // {
  26923. // knownActions: Array< AnimationAction > - used as prototypes
  26924. // actionByRoot: AnimationAction - lookup
  26925. // }
  26926. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  26927. this._nActiveBindings = 0;
  26928. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  26929. this._controlInterpolants = []; // same game as above
  26930. this._nActiveControlInterpolants = 0;
  26931. var scope = this;
  26932. this.stats = {
  26933. actions: {
  26934. get total() {
  26935. return scope._actions.length;
  26936. },
  26937. get inUse() {
  26938. return scope._nActiveActions;
  26939. }
  26940. },
  26941. bindings: {
  26942. get total() {
  26943. return scope._bindings.length;
  26944. },
  26945. get inUse() {
  26946. return scope._nActiveBindings;
  26947. }
  26948. },
  26949. controlInterpolants: {
  26950. get total() {
  26951. return scope._controlInterpolants.length;
  26952. },
  26953. get inUse() {
  26954. return scope._nActiveControlInterpolants;
  26955. }
  26956. }
  26957. };
  26958. },
  26959. // Memory management for AnimationAction objects
  26960. _isActiveAction: function _isActiveAction(action) {
  26961. var index = action._cacheIndex;
  26962. return index !== null && index < this._nActiveActions;
  26963. },
  26964. _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
  26965. var actions = this._actions,
  26966. actionsByClip = this._actionsByClip;
  26967. var actionsForClip = actionsByClip[clipUuid];
  26968. if (actionsForClip === undefined) {
  26969. actionsForClip = {
  26970. knownActions: [action],
  26971. actionByRoot: {}
  26972. };
  26973. action._byClipCacheIndex = 0;
  26974. actionsByClip[clipUuid] = actionsForClip;
  26975. } else {
  26976. var knownActions = actionsForClip.knownActions;
  26977. action._byClipCacheIndex = knownActions.length;
  26978. knownActions.push(action);
  26979. }
  26980. action._cacheIndex = actions.length;
  26981. actions.push(action);
  26982. actionsForClip.actionByRoot[rootUuid] = action;
  26983. },
  26984. _removeInactiveAction: function _removeInactiveAction(action) {
  26985. var actions = this._actions,
  26986. lastInactiveAction = actions[actions.length - 1],
  26987. cacheIndex = action._cacheIndex;
  26988. lastInactiveAction._cacheIndex = cacheIndex;
  26989. actions[cacheIndex] = lastInactiveAction;
  26990. actions.pop();
  26991. action._cacheIndex = null;
  26992. var clipUuid = action._clip.uuid,
  26993. actionsByClip = this._actionsByClip,
  26994. actionsForClip = actionsByClip[clipUuid],
  26995. knownActionsForClip = actionsForClip.knownActions,
  26996. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  26997. byClipCacheIndex = action._byClipCacheIndex;
  26998. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  26999. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  27000. knownActionsForClip.pop();
  27001. action._byClipCacheIndex = null;
  27002. var actionByRoot = actionsForClip.actionByRoot,
  27003. rootUuid = (action._localRoot || this._root).uuid;
  27004. delete actionByRoot[rootUuid];
  27005. if (knownActionsForClip.length === 0) {
  27006. delete actionsByClip[clipUuid];
  27007. }
  27008. this._removeInactiveBindingsForAction(action);
  27009. },
  27010. _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
  27011. var bindings = action._propertyBindings;
  27012. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27013. var binding = bindings[i];
  27014. if (--binding.referenceCount === 0) {
  27015. this._removeInactiveBinding(binding);
  27016. }
  27017. }
  27018. },
  27019. _lendAction: function _lendAction(action) {
  27020. // [ active actions | inactive actions ]
  27021. // [ active actions >| inactive actions ]
  27022. // s a
  27023. // <-swap->
  27024. // a s
  27025. var actions = this._actions,
  27026. prevIndex = action._cacheIndex,
  27027. lastActiveIndex = this._nActiveActions++,
  27028. firstInactiveAction = actions[lastActiveIndex];
  27029. action._cacheIndex = lastActiveIndex;
  27030. actions[lastActiveIndex] = action;
  27031. firstInactiveAction._cacheIndex = prevIndex;
  27032. actions[prevIndex] = firstInactiveAction;
  27033. },
  27034. _takeBackAction: function _takeBackAction(action) {
  27035. // [ active actions | inactive actions ]
  27036. // [ active actions |< inactive actions ]
  27037. // a s
  27038. // <-swap->
  27039. // s a
  27040. var actions = this._actions,
  27041. prevIndex = action._cacheIndex,
  27042. firstInactiveIndex = --this._nActiveActions,
  27043. lastActiveAction = actions[firstInactiveIndex];
  27044. action._cacheIndex = firstInactiveIndex;
  27045. actions[firstInactiveIndex] = action;
  27046. lastActiveAction._cacheIndex = prevIndex;
  27047. actions[prevIndex] = lastActiveAction;
  27048. },
  27049. // Memory management for PropertyMixer objects
  27050. _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
  27051. var bindingsByRoot = this._bindingsByRootAndName,
  27052. bindings = this._bindings;
  27053. var bindingByName = bindingsByRoot[rootUuid];
  27054. if (bindingByName === undefined) {
  27055. bindingByName = {};
  27056. bindingsByRoot[rootUuid] = bindingByName;
  27057. }
  27058. bindingByName[trackName] = binding;
  27059. binding._cacheIndex = bindings.length;
  27060. bindings.push(binding);
  27061. },
  27062. _removeInactiveBinding: function _removeInactiveBinding(binding) {
  27063. var bindings = this._bindings,
  27064. propBinding = binding.binding,
  27065. rootUuid = propBinding.rootNode.uuid,
  27066. trackName = propBinding.path,
  27067. bindingsByRoot = this._bindingsByRootAndName,
  27068. bindingByName = bindingsByRoot[rootUuid],
  27069. lastInactiveBinding = bindings[bindings.length - 1],
  27070. cacheIndex = binding._cacheIndex;
  27071. lastInactiveBinding._cacheIndex = cacheIndex;
  27072. bindings[cacheIndex] = lastInactiveBinding;
  27073. bindings.pop();
  27074. delete bindingByName[trackName];
  27075. if (Object.keys(bindingByName).length === 0) {
  27076. delete bindingsByRoot[rootUuid];
  27077. }
  27078. },
  27079. _lendBinding: function _lendBinding(binding) {
  27080. var bindings = this._bindings,
  27081. prevIndex = binding._cacheIndex,
  27082. lastActiveIndex = this._nActiveBindings++,
  27083. firstInactiveBinding = bindings[lastActiveIndex];
  27084. binding._cacheIndex = lastActiveIndex;
  27085. bindings[lastActiveIndex] = binding;
  27086. firstInactiveBinding._cacheIndex = prevIndex;
  27087. bindings[prevIndex] = firstInactiveBinding;
  27088. },
  27089. _takeBackBinding: function _takeBackBinding(binding) {
  27090. var bindings = this._bindings,
  27091. prevIndex = binding._cacheIndex,
  27092. firstInactiveIndex = --this._nActiveBindings,
  27093. lastActiveBinding = bindings[firstInactiveIndex];
  27094. binding._cacheIndex = firstInactiveIndex;
  27095. bindings[firstInactiveIndex] = binding;
  27096. lastActiveBinding._cacheIndex = prevIndex;
  27097. bindings[prevIndex] = lastActiveBinding;
  27098. },
  27099. // Memory management of Interpolants for weight and time scale
  27100. _lendControlInterpolant: function _lendControlInterpolant() {
  27101. var interpolants = this._controlInterpolants,
  27102. lastActiveIndex = this._nActiveControlInterpolants++;
  27103. var interpolant = interpolants[lastActiveIndex];
  27104. if (interpolant === undefined) {
  27105. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  27106. interpolant.__cacheIndex = lastActiveIndex;
  27107. interpolants[lastActiveIndex] = interpolant;
  27108. }
  27109. return interpolant;
  27110. },
  27111. _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
  27112. var interpolants = this._controlInterpolants,
  27113. prevIndex = interpolant.__cacheIndex,
  27114. firstInactiveIndex = --this._nActiveControlInterpolants,
  27115. lastActiveInterpolant = interpolants[firstInactiveIndex];
  27116. interpolant.__cacheIndex = firstInactiveIndex;
  27117. interpolants[firstInactiveIndex] = interpolant;
  27118. lastActiveInterpolant.__cacheIndex = prevIndex;
  27119. interpolants[prevIndex] = lastActiveInterpolant;
  27120. },
  27121. _controlInterpolantsResultBuffer: new Float32Array(1),
  27122. // return an action for a clip optionally using a custom root target
  27123. // object (this method allocates a lot of dynamic memory in case a
  27124. // previously unknown clip/root combination is specified)
  27125. clipAction: function clipAction(clip, optionalRoot, blendMode) {
  27126. var root = optionalRoot || this._root,
  27127. rootUuid = root.uuid;
  27128. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  27129. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  27130. var actionsForClip = this._actionsByClip[clipUuid];
  27131. var prototypeAction = null;
  27132. if (blendMode === undefined) {
  27133. if (clipObject !== null) {
  27134. blendMode = clipObject.blendMode;
  27135. } else {
  27136. blendMode = NormalAnimationBlendMode;
  27137. }
  27138. }
  27139. if (actionsForClip !== undefined) {
  27140. var existingAction = actionsForClip.actionByRoot[rootUuid];
  27141. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  27142. return existingAction;
  27143. } // we know the clip, so we don't have to parse all
  27144. // the bindings again but can just copy
  27145. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  27146. if (clipObject === null) clipObject = prototypeAction._clip;
  27147. } // clip must be known when specified via string
  27148. if (clipObject === null) return null; // allocate all resources required to run it
  27149. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  27150. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  27151. this._addInactiveAction(newAction, clipUuid, rootUuid);
  27152. return newAction;
  27153. },
  27154. // get an existing action
  27155. existingAction: function existingAction(clip, optionalRoot) {
  27156. var root = optionalRoot || this._root,
  27157. rootUuid = root.uuid,
  27158. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  27159. clipUuid = clipObject ? clipObject.uuid : clip,
  27160. actionsForClip = this._actionsByClip[clipUuid];
  27161. if (actionsForClip !== undefined) {
  27162. return actionsForClip.actionByRoot[rootUuid] || null;
  27163. }
  27164. return null;
  27165. },
  27166. // deactivates all previously scheduled actions
  27167. stopAllAction: function stopAllAction() {
  27168. var actions = this._actions,
  27169. nActions = this._nActiveActions;
  27170. for (var i = nActions - 1; i >= 0; --i) {
  27171. actions[i].stop();
  27172. }
  27173. return this;
  27174. },
  27175. // advance the time and update apply the animation
  27176. update: function update(deltaTime) {
  27177. deltaTime *= this.timeScale;
  27178. var actions = this._actions,
  27179. nActions = this._nActiveActions,
  27180. time = this.time += deltaTime,
  27181. timeDirection = Math.sign(deltaTime),
  27182. accuIndex = this._accuIndex ^= 1; // run active actions
  27183. for (var i = 0; i !== nActions; ++i) {
  27184. var action = actions[i];
  27185. action._update(time, deltaTime, timeDirection, accuIndex);
  27186. } // update scene graph
  27187. var bindings = this._bindings,
  27188. nBindings = this._nActiveBindings;
  27189. for (var _i = 0; _i !== nBindings; ++_i) {
  27190. bindings[_i].apply(accuIndex);
  27191. }
  27192. return this;
  27193. },
  27194. // Allows you to seek to a specific time in an animation.
  27195. setTime: function setTime(timeInSeconds) {
  27196. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27197. for (var i = 0; i < this._actions.length; i++) {
  27198. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27199. }
  27200. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  27201. },
  27202. // return this mixer's root target object
  27203. getRoot: function getRoot() {
  27204. return this._root;
  27205. },
  27206. // free all resources specific to a particular clip
  27207. uncacheClip: function uncacheClip(clip) {
  27208. var actions = this._actions,
  27209. clipUuid = clip.uuid,
  27210. actionsByClip = this._actionsByClip,
  27211. actionsForClip = actionsByClip[clipUuid];
  27212. if (actionsForClip !== undefined) {
  27213. // note: just calling _removeInactiveAction would mess up the
  27214. // iteration state and also require updating the state we can
  27215. // just throw away
  27216. var actionsToRemove = actionsForClip.knownActions;
  27217. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  27218. var action = actionsToRemove[i];
  27219. this._deactivateAction(action);
  27220. var cacheIndex = action._cacheIndex,
  27221. lastInactiveAction = actions[actions.length - 1];
  27222. action._cacheIndex = null;
  27223. action._byClipCacheIndex = null;
  27224. lastInactiveAction._cacheIndex = cacheIndex;
  27225. actions[cacheIndex] = lastInactiveAction;
  27226. actions.pop();
  27227. this._removeInactiveBindingsForAction(action);
  27228. }
  27229. delete actionsByClip[clipUuid];
  27230. }
  27231. },
  27232. // free all resources specific to a particular root target object
  27233. uncacheRoot: function uncacheRoot(root) {
  27234. var rootUuid = root.uuid,
  27235. actionsByClip = this._actionsByClip;
  27236. for (var clipUuid in actionsByClip) {
  27237. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  27238. action = actionByRoot[rootUuid];
  27239. if (action !== undefined) {
  27240. this._deactivateAction(action);
  27241. this._removeInactiveAction(action);
  27242. }
  27243. }
  27244. var bindingsByRoot = this._bindingsByRootAndName,
  27245. bindingByName = bindingsByRoot[rootUuid];
  27246. if (bindingByName !== undefined) {
  27247. for (var trackName in bindingByName) {
  27248. var binding = bindingByName[trackName];
  27249. binding.restoreOriginalState();
  27250. this._removeInactiveBinding(binding);
  27251. }
  27252. }
  27253. },
  27254. // remove a targeted clip from the cache
  27255. uncacheAction: function uncacheAction(clip, optionalRoot) {
  27256. var action = this.existingAction(clip, optionalRoot);
  27257. if (action !== null) {
  27258. this._deactivateAction(action);
  27259. this._removeInactiveAction(action);
  27260. }
  27261. }
  27262. });
  27263. var Uniform = /*#__PURE__*/function () {
  27264. function Uniform(value) {
  27265. if (typeof value === 'string') {
  27266. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  27267. value = arguments[1];
  27268. }
  27269. this.value = value;
  27270. }
  27271. var _proto = Uniform.prototype;
  27272. _proto.clone = function clone() {
  27273. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  27274. };
  27275. return Uniform;
  27276. }();
  27277. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27278. InterleavedBuffer.call(this, array, stride);
  27279. this.meshPerAttribute = meshPerAttribute || 1;
  27280. }
  27281. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27282. constructor: InstancedInterleavedBuffer,
  27283. isInstancedInterleavedBuffer: true,
  27284. copy: function copy(source) {
  27285. InterleavedBuffer.prototype.copy.call(this, source);
  27286. this.meshPerAttribute = source.meshPerAttribute;
  27287. return this;
  27288. },
  27289. clone: function clone(data) {
  27290. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27291. ib.meshPerAttribute = this.meshPerAttribute;
  27292. return ib;
  27293. },
  27294. toJSON: function toJSON(data) {
  27295. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27296. json.isInstancedInterleavedBuffer = true;
  27297. json.meshPerAttribute = this.meshPerAttribute;
  27298. return json;
  27299. }
  27300. });
  27301. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27302. this.buffer = buffer;
  27303. this.type = type;
  27304. this.itemSize = itemSize;
  27305. this.elementSize = elementSize;
  27306. this.count = count;
  27307. this.version = 0;
  27308. }
  27309. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27310. set: function set(value) {
  27311. if (value === true) this.version++;
  27312. }
  27313. });
  27314. Object.assign(GLBufferAttribute.prototype, {
  27315. isGLBufferAttribute: true,
  27316. setBuffer: function setBuffer(buffer) {
  27317. this.buffer = buffer;
  27318. return this;
  27319. },
  27320. setType: function setType(type, elementSize) {
  27321. this.type = type;
  27322. this.elementSize = elementSize;
  27323. return this;
  27324. },
  27325. setItemSize: function setItemSize(itemSize) {
  27326. this.itemSize = itemSize;
  27327. return this;
  27328. },
  27329. setCount: function setCount(count) {
  27330. this.count = count;
  27331. return this;
  27332. }
  27333. });
  27334. function Raycaster(origin, direction, near, far) {
  27335. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27336. this.near = near || 0;
  27337. this.far = far || Infinity;
  27338. this.camera = null;
  27339. this.layers = new Layers();
  27340. this.params = {
  27341. Mesh: {},
  27342. Line: {
  27343. threshold: 1
  27344. },
  27345. LOD: {},
  27346. Points: {
  27347. threshold: 1
  27348. },
  27349. Sprite: {}
  27350. };
  27351. Object.defineProperties(this.params, {
  27352. PointCloud: {
  27353. get: function get() {
  27354. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27355. return this.Points;
  27356. }
  27357. }
  27358. });
  27359. }
  27360. function ascSort(a, b) {
  27361. return a.distance - b.distance;
  27362. }
  27363. function _intersectObject(object, raycaster, intersects, recursive) {
  27364. if (object.layers.test(raycaster.layers)) {
  27365. object.raycast(raycaster, intersects);
  27366. }
  27367. if (recursive === true) {
  27368. var children = object.children;
  27369. for (var i = 0, l = children.length; i < l; i++) {
  27370. _intersectObject(children[i], raycaster, intersects, true);
  27371. }
  27372. }
  27373. }
  27374. Object.assign(Raycaster.prototype, {
  27375. set: function set(origin, direction) {
  27376. // direction is assumed to be normalized (for accurate distance calculations)
  27377. this.ray.set(origin, direction);
  27378. },
  27379. setFromCamera: function setFromCamera(coords, camera) {
  27380. if (camera && camera.isPerspectiveCamera) {
  27381. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27382. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27383. this.camera = camera;
  27384. } else if (camera && camera.isOrthographicCamera) {
  27385. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27386. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27387. this.camera = camera;
  27388. } else {
  27389. console.error('THREE.Raycaster: Unsupported camera type: ' + camera.type);
  27390. }
  27391. },
  27392. intersectObject: function intersectObject(object, recursive, optionalTarget) {
  27393. var intersects = optionalTarget || [];
  27394. _intersectObject(object, this, intersects, recursive);
  27395. intersects.sort(ascSort);
  27396. return intersects;
  27397. },
  27398. intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
  27399. var intersects = optionalTarget || [];
  27400. if (Array.isArray(objects) === false) {
  27401. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  27402. return intersects;
  27403. }
  27404. for (var i = 0, l = objects.length; i < l; i++) {
  27405. _intersectObject(objects[i], this, intersects, recursive);
  27406. }
  27407. intersects.sort(ascSort);
  27408. return intersects;
  27409. }
  27410. });
  27411. /**
  27412. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27413. *
  27414. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27415. * The azimuthal angle (theta) is measured from the positive z-axis.
  27416. */
  27417. var Spherical = /*#__PURE__*/function () {
  27418. function Spherical(radius, phi, theta) {
  27419. if (radius === void 0) {
  27420. radius = 1;
  27421. }
  27422. if (phi === void 0) {
  27423. phi = 0;
  27424. }
  27425. if (theta === void 0) {
  27426. theta = 0;
  27427. }
  27428. this.radius = radius;
  27429. this.phi = phi; // polar angle
  27430. this.theta = theta; // azimuthal angle
  27431. return this;
  27432. }
  27433. var _proto = Spherical.prototype;
  27434. _proto.set = function set(radius, phi, theta) {
  27435. this.radius = radius;
  27436. this.phi = phi;
  27437. this.theta = theta;
  27438. return this;
  27439. };
  27440. _proto.clone = function clone() {
  27441. return new this.constructor().copy(this);
  27442. };
  27443. _proto.copy = function copy(other) {
  27444. this.radius = other.radius;
  27445. this.phi = other.phi;
  27446. this.theta = other.theta;
  27447. return this;
  27448. } // restrict phi to be betwee EPS and PI-EPS
  27449. ;
  27450. _proto.makeSafe = function makeSafe() {
  27451. var EPS = 0.000001;
  27452. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  27453. return this;
  27454. };
  27455. _proto.setFromVector3 = function setFromVector3(v) {
  27456. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27457. };
  27458. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27459. this.radius = Math.sqrt(x * x + y * y + z * z);
  27460. if (this.radius === 0) {
  27461. this.theta = 0;
  27462. this.phi = 0;
  27463. } else {
  27464. this.theta = Math.atan2(x, z);
  27465. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  27466. }
  27467. return this;
  27468. };
  27469. return Spherical;
  27470. }();
  27471. /**
  27472. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27473. */
  27474. var Cylindrical = /*#__PURE__*/function () {
  27475. function Cylindrical(radius, theta, y) {
  27476. this.radius = radius !== undefined ? radius : 1.0; // distance from the origin to a point in the x-z plane
  27477. this.theta = theta !== undefined ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27478. this.y = y !== undefined ? y : 0; // height above the x-z plane
  27479. return this;
  27480. }
  27481. var _proto = Cylindrical.prototype;
  27482. _proto.set = function set(radius, theta, y) {
  27483. this.radius = radius;
  27484. this.theta = theta;
  27485. this.y = y;
  27486. return this;
  27487. };
  27488. _proto.clone = function clone() {
  27489. return new this.constructor().copy(this);
  27490. };
  27491. _proto.copy = function copy(other) {
  27492. this.radius = other.radius;
  27493. this.theta = other.theta;
  27494. this.y = other.y;
  27495. return this;
  27496. };
  27497. _proto.setFromVector3 = function setFromVector3(v) {
  27498. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27499. };
  27500. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27501. this.radius = Math.sqrt(x * x + z * z);
  27502. this.theta = Math.atan2(x, z);
  27503. this.y = y;
  27504. return this;
  27505. };
  27506. return Cylindrical;
  27507. }();
  27508. var _vector$8 = /*@__PURE__*/new Vector2();
  27509. var Box2 = /*#__PURE__*/function () {
  27510. function Box2(min, max) {
  27511. Object.defineProperty(this, 'isBox2', {
  27512. value: true
  27513. });
  27514. this.min = min !== undefined ? min : new Vector2(+Infinity, +Infinity);
  27515. this.max = max !== undefined ? max : new Vector2(-Infinity, -Infinity);
  27516. }
  27517. var _proto = Box2.prototype;
  27518. _proto.set = function set(min, max) {
  27519. this.min.copy(min);
  27520. this.max.copy(max);
  27521. return this;
  27522. };
  27523. _proto.setFromPoints = function setFromPoints(points) {
  27524. this.makeEmpty();
  27525. for (var i = 0, il = points.length; i < il; i++) {
  27526. this.expandByPoint(points[i]);
  27527. }
  27528. return this;
  27529. };
  27530. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  27531. var halfSize = _vector$8.copy(size).multiplyScalar(0.5);
  27532. this.min.copy(center).sub(halfSize);
  27533. this.max.copy(center).add(halfSize);
  27534. return this;
  27535. };
  27536. _proto.clone = function clone() {
  27537. return new this.constructor().copy(this);
  27538. };
  27539. _proto.copy = function copy(box) {
  27540. this.min.copy(box.min);
  27541. this.max.copy(box.max);
  27542. return this;
  27543. };
  27544. _proto.makeEmpty = function makeEmpty() {
  27545. this.min.x = this.min.y = +Infinity;
  27546. this.max.x = this.max.y = -Infinity;
  27547. return this;
  27548. };
  27549. _proto.isEmpty = function isEmpty() {
  27550. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27551. return this.max.x < this.min.x || this.max.y < this.min.y;
  27552. };
  27553. _proto.getCenter = function getCenter(target) {
  27554. if (target === undefined) {
  27555. console.warn('THREE.Box2: .getCenter() target is now required');
  27556. target = new Vector2();
  27557. }
  27558. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  27559. };
  27560. _proto.getSize = function getSize(target) {
  27561. if (target === undefined) {
  27562. console.warn('THREE.Box2: .getSize() target is now required');
  27563. target = new Vector2();
  27564. }
  27565. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  27566. };
  27567. _proto.expandByPoint = function expandByPoint(point) {
  27568. this.min.min(point);
  27569. this.max.max(point);
  27570. return this;
  27571. };
  27572. _proto.expandByVector = function expandByVector(vector) {
  27573. this.min.sub(vector);
  27574. this.max.add(vector);
  27575. return this;
  27576. };
  27577. _proto.expandByScalar = function expandByScalar(scalar) {
  27578. this.min.addScalar(-scalar);
  27579. this.max.addScalar(scalar);
  27580. return this;
  27581. };
  27582. _proto.containsPoint = function containsPoint(point) {
  27583. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  27584. };
  27585. _proto.containsBox = function containsBox(box) {
  27586. 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;
  27587. };
  27588. _proto.getParameter = function getParameter(point, target) {
  27589. // This can potentially have a divide by zero if the box
  27590. // has a size dimension of 0.
  27591. if (target === undefined) {
  27592. console.warn('THREE.Box2: .getParameter() target is now required');
  27593. target = new Vector2();
  27594. }
  27595. 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));
  27596. };
  27597. _proto.intersectsBox = function intersectsBox(box) {
  27598. // using 4 splitting planes to rule out intersections
  27599. 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;
  27600. };
  27601. _proto.clampPoint = function clampPoint(point, target) {
  27602. if (target === undefined) {
  27603. console.warn('THREE.Box2: .clampPoint() target is now required');
  27604. target = new Vector2();
  27605. }
  27606. return target.copy(point).clamp(this.min, this.max);
  27607. };
  27608. _proto.distanceToPoint = function distanceToPoint(point) {
  27609. var clampedPoint = _vector$8.copy(point).clamp(this.min, this.max);
  27610. return clampedPoint.sub(point).length();
  27611. };
  27612. _proto.intersect = function intersect(box) {
  27613. this.min.max(box.min);
  27614. this.max.min(box.max);
  27615. return this;
  27616. };
  27617. _proto.union = function union(box) {
  27618. this.min.min(box.min);
  27619. this.max.max(box.max);
  27620. return this;
  27621. };
  27622. _proto.translate = function translate(offset) {
  27623. this.min.add(offset);
  27624. this.max.add(offset);
  27625. return this;
  27626. };
  27627. _proto.equals = function equals(box) {
  27628. return box.min.equals(this.min) && box.max.equals(this.max);
  27629. };
  27630. return Box2;
  27631. }();
  27632. var _startP = /*@__PURE__*/new Vector3();
  27633. var _startEnd = /*@__PURE__*/new Vector3();
  27634. var Line3 = /*#__PURE__*/function () {
  27635. function Line3(start, end) {
  27636. this.start = start !== undefined ? start : new Vector3();
  27637. this.end = end !== undefined ? end : new Vector3();
  27638. }
  27639. var _proto = Line3.prototype;
  27640. _proto.set = function set(start, end) {
  27641. this.start.copy(start);
  27642. this.end.copy(end);
  27643. return this;
  27644. };
  27645. _proto.clone = function clone() {
  27646. return new this.constructor().copy(this);
  27647. };
  27648. _proto.copy = function copy(line) {
  27649. this.start.copy(line.start);
  27650. this.end.copy(line.end);
  27651. return this;
  27652. };
  27653. _proto.getCenter = function getCenter(target) {
  27654. if (target === undefined) {
  27655. console.warn('THREE.Line3: .getCenter() target is now required');
  27656. target = new Vector3();
  27657. }
  27658. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  27659. };
  27660. _proto.delta = function delta(target) {
  27661. if (target === undefined) {
  27662. console.warn('THREE.Line3: .delta() target is now required');
  27663. target = new Vector3();
  27664. }
  27665. return target.subVectors(this.end, this.start);
  27666. };
  27667. _proto.distanceSq = function distanceSq() {
  27668. return this.start.distanceToSquared(this.end);
  27669. };
  27670. _proto.distance = function distance() {
  27671. return this.start.distanceTo(this.end);
  27672. };
  27673. _proto.at = function at(t, target) {
  27674. if (target === undefined) {
  27675. console.warn('THREE.Line3: .at() target is now required');
  27676. target = new Vector3();
  27677. }
  27678. return this.delta(target).multiplyScalar(t).add(this.start);
  27679. };
  27680. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  27681. _startP.subVectors(point, this.start);
  27682. _startEnd.subVectors(this.end, this.start);
  27683. var startEnd2 = _startEnd.dot(_startEnd);
  27684. var startEnd_startP = _startEnd.dot(_startP);
  27685. var t = startEnd_startP / startEnd2;
  27686. if (clampToLine) {
  27687. t = MathUtils.clamp(t, 0, 1);
  27688. }
  27689. return t;
  27690. };
  27691. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  27692. var t = this.closestPointToPointParameter(point, clampToLine);
  27693. if (target === undefined) {
  27694. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  27695. target = new Vector3();
  27696. }
  27697. return this.delta(target).multiplyScalar(t).add(this.start);
  27698. };
  27699. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  27700. this.start.applyMatrix4(matrix);
  27701. this.end.applyMatrix4(matrix);
  27702. return this;
  27703. };
  27704. _proto.equals = function equals(line) {
  27705. return line.start.equals(this.start) && line.end.equals(this.end);
  27706. };
  27707. return Line3;
  27708. }();
  27709. function ImmediateRenderObject(material) {
  27710. Object3D.call(this);
  27711. this.material = material;
  27712. this.render = function ()
  27713. /* renderCallback */
  27714. {};
  27715. this.hasPositions = false;
  27716. this.hasNormals = false;
  27717. this.hasColors = false;
  27718. this.hasUvs = false;
  27719. this.positionArray = null;
  27720. this.normalArray = null;
  27721. this.colorArray = null;
  27722. this.uvArray = null;
  27723. this.count = 0;
  27724. }
  27725. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  27726. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27727. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27728. var _vector$9 = /*@__PURE__*/new Vector3();
  27729. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  27730. _inheritsLoose(SpotLightHelper, _Object3D);
  27731. function SpotLightHelper(light, color) {
  27732. var _this;
  27733. _this = _Object3D.call(this) || this;
  27734. _this.light = light;
  27735. _this.light.updateMatrixWorld();
  27736. _this.matrix = light.matrixWorld;
  27737. _this.matrixAutoUpdate = false;
  27738. _this.color = color;
  27739. var geometry = new BufferGeometry();
  27740. 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];
  27741. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  27742. var p1 = i / l * Math.PI * 2;
  27743. var p2 = j / l * Math.PI * 2;
  27744. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  27745. }
  27746. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  27747. var material = new LineBasicMaterial({
  27748. fog: false,
  27749. toneMapped: false
  27750. });
  27751. _this.cone = new LineSegments(geometry, material);
  27752. _this.add(_this.cone);
  27753. _this.update();
  27754. return _this;
  27755. }
  27756. var _proto = SpotLightHelper.prototype;
  27757. _proto.dispose = function dispose() {
  27758. this.cone.geometry.dispose();
  27759. this.cone.material.dispose();
  27760. };
  27761. _proto.update = function update() {
  27762. this.light.updateMatrixWorld();
  27763. var coneLength = this.light.distance ? this.light.distance : 1000;
  27764. var coneWidth = coneLength * Math.tan(this.light.angle);
  27765. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  27766. _vector$9.setFromMatrixPosition(this.light.target.matrixWorld);
  27767. this.cone.lookAt(_vector$9);
  27768. if (this.color !== undefined) {
  27769. this.cone.material.color.set(this.color);
  27770. } else {
  27771. this.cone.material.color.copy(this.light.color);
  27772. }
  27773. };
  27774. return SpotLightHelper;
  27775. }(Object3D);
  27776. var _vector$a = /*@__PURE__*/new Vector3();
  27777. var _boneMatrix = /*@__PURE__*/new Matrix4();
  27778. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  27779. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  27780. _inheritsLoose(SkeletonHelper, _LineSegments);
  27781. function SkeletonHelper(object) {
  27782. var _this;
  27783. var bones = getBoneList(object);
  27784. var geometry = new BufferGeometry();
  27785. var vertices = [];
  27786. var colors = [];
  27787. var color1 = new Color(0, 0, 1);
  27788. var color2 = new Color(0, 1, 0);
  27789. for (var i = 0; i < bones.length; i++) {
  27790. var bone = bones[i];
  27791. if (bone.parent && bone.parent.isBone) {
  27792. vertices.push(0, 0, 0);
  27793. vertices.push(0, 0, 0);
  27794. colors.push(color1.r, color1.g, color1.b);
  27795. colors.push(color2.r, color2.g, color2.b);
  27796. }
  27797. }
  27798. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27799. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27800. var material = new LineBasicMaterial({
  27801. vertexColors: true,
  27802. depthTest: false,
  27803. depthWrite: false,
  27804. toneMapped: false,
  27805. transparent: true
  27806. });
  27807. _this = _LineSegments.call(this, geometry, material) || this;
  27808. _this.type = 'SkeletonHelper';
  27809. _this.isSkeletonHelper = true;
  27810. _this.root = object;
  27811. _this.bones = bones;
  27812. _this.matrix = object.matrixWorld;
  27813. _this.matrixAutoUpdate = false;
  27814. return _this;
  27815. }
  27816. var _proto = SkeletonHelper.prototype;
  27817. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  27818. var bones = this.bones;
  27819. var geometry = this.geometry;
  27820. var position = geometry.getAttribute('position');
  27821. _matrixWorldInv.copy(this.root.matrixWorld).invert();
  27822. for (var i = 0, j = 0; i < bones.length; i++) {
  27823. var bone = bones[i];
  27824. if (bone.parent && bone.parent.isBone) {
  27825. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  27826. _vector$a.setFromMatrixPosition(_boneMatrix);
  27827. position.setXYZ(j, _vector$a.x, _vector$a.y, _vector$a.z);
  27828. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  27829. _vector$a.setFromMatrixPosition(_boneMatrix);
  27830. position.setXYZ(j + 1, _vector$a.x, _vector$a.y, _vector$a.z);
  27831. j += 2;
  27832. }
  27833. }
  27834. geometry.getAttribute('position').needsUpdate = true;
  27835. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  27836. };
  27837. return SkeletonHelper;
  27838. }(LineSegments);
  27839. function getBoneList(object) {
  27840. var boneList = [];
  27841. if (object && object.isBone) {
  27842. boneList.push(object);
  27843. }
  27844. for (var i = 0; i < object.children.length; i++) {
  27845. boneList.push.apply(boneList, getBoneList(object.children[i]));
  27846. }
  27847. return boneList;
  27848. }
  27849. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  27850. _inheritsLoose(PointLightHelper, _Mesh);
  27851. function PointLightHelper(light, sphereSize, color) {
  27852. var _this;
  27853. var geometry = new SphereGeometry(sphereSize, 4, 2);
  27854. var material = new MeshBasicMaterial({
  27855. wireframe: true,
  27856. fog: false,
  27857. toneMapped: false
  27858. });
  27859. _this = _Mesh.call(this, geometry, material) || this;
  27860. _this.light = light;
  27861. _this.light.updateMatrixWorld();
  27862. _this.color = color;
  27863. _this.type = 'PointLightHelper';
  27864. _this.matrix = _this.light.matrixWorld;
  27865. _this.matrixAutoUpdate = false;
  27866. _this.update();
  27867. /*
  27868. // TODO: delete this comment?
  27869. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27870. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27871. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27872. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27873. const d = light.distance;
  27874. if ( d === 0.0 ) {
  27875. this.lightDistance.visible = false;
  27876. } else {
  27877. this.lightDistance.scale.set( d, d, d );
  27878. }
  27879. this.add( this.lightDistance );
  27880. */
  27881. return _this;
  27882. }
  27883. var _proto = PointLightHelper.prototype;
  27884. _proto.dispose = function dispose() {
  27885. this.geometry.dispose();
  27886. this.material.dispose();
  27887. };
  27888. _proto.update = function update() {
  27889. if (this.color !== undefined) {
  27890. this.material.color.set(this.color);
  27891. } else {
  27892. this.material.color.copy(this.light.color);
  27893. }
  27894. /*
  27895. const d = this.light.distance;
  27896. if ( d === 0.0 ) {
  27897. this.lightDistance.visible = false;
  27898. } else {
  27899. this.lightDistance.visible = true;
  27900. this.lightDistance.scale.set( d, d, d );
  27901. }
  27902. */
  27903. };
  27904. return PointLightHelper;
  27905. }(Mesh);
  27906. var _vector$b = /*@__PURE__*/new Vector3();
  27907. var _color1 = /*@__PURE__*/new Color();
  27908. var _color2 = /*@__PURE__*/new Color();
  27909. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  27910. _inheritsLoose(HemisphereLightHelper, _Object3D);
  27911. function HemisphereLightHelper(light, size, color) {
  27912. var _this;
  27913. _this = _Object3D.call(this) || this;
  27914. _this.light = light;
  27915. _this.light.updateMatrixWorld();
  27916. _this.matrix = light.matrixWorld;
  27917. _this.matrixAutoUpdate = false;
  27918. _this.color = color;
  27919. var geometry = new OctahedronGeometry(size);
  27920. geometry.rotateY(Math.PI * 0.5);
  27921. _this.material = new MeshBasicMaterial({
  27922. wireframe: true,
  27923. fog: false,
  27924. toneMapped: false
  27925. });
  27926. if (_this.color === undefined) _this.material.vertexColors = true;
  27927. var position = geometry.getAttribute('position');
  27928. var colors = new Float32Array(position.count * 3);
  27929. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  27930. _this.add(new Mesh(geometry, _this.material));
  27931. _this.update();
  27932. return _this;
  27933. }
  27934. var _proto = HemisphereLightHelper.prototype;
  27935. _proto.dispose = function dispose() {
  27936. this.children[0].geometry.dispose();
  27937. this.children[0].material.dispose();
  27938. };
  27939. _proto.update = function update() {
  27940. var mesh = this.children[0];
  27941. if (this.color !== undefined) {
  27942. this.material.color.set(this.color);
  27943. } else {
  27944. var colors = mesh.geometry.getAttribute('color');
  27945. _color1.copy(this.light.color);
  27946. _color2.copy(this.light.groundColor);
  27947. for (var i = 0, l = colors.count; i < l; i++) {
  27948. var color = i < l / 2 ? _color1 : _color2;
  27949. colors.setXYZ(i, color.r, color.g, color.b);
  27950. }
  27951. colors.needsUpdate = true;
  27952. }
  27953. mesh.lookAt(_vector$b.setFromMatrixPosition(this.light.matrixWorld).negate());
  27954. };
  27955. return HemisphereLightHelper;
  27956. }(Object3D);
  27957. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  27958. _inheritsLoose(GridHelper, _LineSegments);
  27959. function GridHelper(size, divisions, color1, color2) {
  27960. var _this;
  27961. if (size === void 0) {
  27962. size = 10;
  27963. }
  27964. if (divisions === void 0) {
  27965. divisions = 10;
  27966. }
  27967. if (color1 === void 0) {
  27968. color1 = 0x444444;
  27969. }
  27970. if (color2 === void 0) {
  27971. color2 = 0x888888;
  27972. }
  27973. color1 = new Color(color1);
  27974. color2 = new Color(color2);
  27975. var center = divisions / 2;
  27976. var step = size / divisions;
  27977. var halfSize = size / 2;
  27978. var vertices = [],
  27979. colors = [];
  27980. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  27981. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  27982. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  27983. var color = i === center ? color1 : color2;
  27984. color.toArray(colors, j);
  27985. j += 3;
  27986. color.toArray(colors, j);
  27987. j += 3;
  27988. color.toArray(colors, j);
  27989. j += 3;
  27990. color.toArray(colors, j);
  27991. j += 3;
  27992. }
  27993. var geometry = new BufferGeometry();
  27994. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27995. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27996. var material = new LineBasicMaterial({
  27997. vertexColors: true,
  27998. toneMapped: false
  27999. });
  28000. _this = _LineSegments.call(this, geometry, material) || this;
  28001. _this.type = 'GridHelper';
  28002. return _this;
  28003. }
  28004. return GridHelper;
  28005. }(LineSegments);
  28006. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  28007. _inheritsLoose(PolarGridHelper, _LineSegments);
  28008. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  28009. var _this;
  28010. if (radius === void 0) {
  28011. radius = 10;
  28012. }
  28013. if (radials === void 0) {
  28014. radials = 16;
  28015. }
  28016. if (circles === void 0) {
  28017. circles = 8;
  28018. }
  28019. if (divisions === void 0) {
  28020. divisions = 64;
  28021. }
  28022. if (color1 === void 0) {
  28023. color1 = 0x444444;
  28024. }
  28025. if (color2 === void 0) {
  28026. color2 = 0x888888;
  28027. }
  28028. color1 = new Color(color1);
  28029. color2 = new Color(color2);
  28030. var vertices = [];
  28031. var colors = []; // create the radials
  28032. for (var i = 0; i <= radials; i++) {
  28033. var v = i / radials * (Math.PI * 2);
  28034. var x = Math.sin(v) * radius;
  28035. var z = Math.cos(v) * radius;
  28036. vertices.push(0, 0, 0);
  28037. vertices.push(x, 0, z);
  28038. var color = i & 1 ? color1 : color2;
  28039. colors.push(color.r, color.g, color.b);
  28040. colors.push(color.r, color.g, color.b);
  28041. } // create the circles
  28042. for (var _i = 0; _i <= circles; _i++) {
  28043. var _color = _i & 1 ? color1 : color2;
  28044. var r = radius - radius / circles * _i;
  28045. for (var j = 0; j < divisions; j++) {
  28046. // first vertex
  28047. var _v = j / divisions * (Math.PI * 2);
  28048. var _x = Math.sin(_v) * r;
  28049. var _z = Math.cos(_v) * r;
  28050. vertices.push(_x, 0, _z);
  28051. colors.push(_color.r, _color.g, _color.b); // second vertex
  28052. _v = (j + 1) / divisions * (Math.PI * 2);
  28053. _x = Math.sin(_v) * r;
  28054. _z = Math.cos(_v) * r;
  28055. vertices.push(_x, 0, _z);
  28056. colors.push(_color.r, _color.g, _color.b);
  28057. }
  28058. }
  28059. var geometry = new BufferGeometry();
  28060. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28061. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28062. var material = new LineBasicMaterial({
  28063. vertexColors: true,
  28064. toneMapped: false
  28065. });
  28066. _this = _LineSegments.call(this, geometry, material) || this;
  28067. _this.type = 'PolarGridHelper';
  28068. return _this;
  28069. }
  28070. return PolarGridHelper;
  28071. }(LineSegments);
  28072. var _v1$6 = /*@__PURE__*/new Vector3();
  28073. var _v2$3 = /*@__PURE__*/new Vector3();
  28074. var _v3$1 = /*@__PURE__*/new Vector3();
  28075. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  28076. _inheritsLoose(DirectionalLightHelper, _Object3D);
  28077. function DirectionalLightHelper(light, size, color) {
  28078. var _this;
  28079. _this = _Object3D.call(this) || this;
  28080. _this.light = light;
  28081. _this.light.updateMatrixWorld();
  28082. _this.matrix = light.matrixWorld;
  28083. _this.matrixAutoUpdate = false;
  28084. _this.color = color;
  28085. if (size === undefined) size = 1;
  28086. var geometry = new BufferGeometry();
  28087. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  28088. var material = new LineBasicMaterial({
  28089. fog: false,
  28090. toneMapped: false
  28091. });
  28092. _this.lightPlane = new Line(geometry, material);
  28093. _this.add(_this.lightPlane);
  28094. geometry = new BufferGeometry();
  28095. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  28096. _this.targetLine = new Line(geometry, material);
  28097. _this.add(_this.targetLine);
  28098. _this.update();
  28099. return _this;
  28100. }
  28101. var _proto = DirectionalLightHelper.prototype;
  28102. _proto.dispose = function dispose() {
  28103. this.lightPlane.geometry.dispose();
  28104. this.lightPlane.material.dispose();
  28105. this.targetLine.geometry.dispose();
  28106. this.targetLine.material.dispose();
  28107. };
  28108. _proto.update = function update() {
  28109. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  28110. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  28111. _v3$1.subVectors(_v2$3, _v1$6);
  28112. this.lightPlane.lookAt(_v2$3);
  28113. if (this.color !== undefined) {
  28114. this.lightPlane.material.color.set(this.color);
  28115. this.targetLine.material.color.set(this.color);
  28116. } else {
  28117. this.lightPlane.material.color.copy(this.light.color);
  28118. this.targetLine.material.color.copy(this.light.color);
  28119. }
  28120. this.targetLine.lookAt(_v2$3);
  28121. this.targetLine.scale.z = _v3$1.length();
  28122. };
  28123. return DirectionalLightHelper;
  28124. }(Object3D);
  28125. var _vector$c = /*@__PURE__*/new Vector3();
  28126. var _camera = /*@__PURE__*/new Camera();
  28127. /**
  28128. * - shows frustum, line of sight and up of the camera
  28129. * - suitable for fast updates
  28130. * - based on frustum visualization in lightgl.js shadowmap example
  28131. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28132. */
  28133. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  28134. _inheritsLoose(CameraHelper, _LineSegments);
  28135. function CameraHelper(camera) {
  28136. var _this;
  28137. var geometry = new BufferGeometry();
  28138. var material = new LineBasicMaterial({
  28139. color: 0xffffff,
  28140. vertexColors: true,
  28141. toneMapped: false
  28142. });
  28143. var vertices = [];
  28144. var colors = [];
  28145. var pointMap = {}; // colors
  28146. var colorFrustum = new Color(0xffaa00);
  28147. var colorCone = new Color(0xff0000);
  28148. var colorUp = new Color(0x00aaff);
  28149. var colorTarget = new Color(0xffffff);
  28150. var colorCross = new Color(0x333333); // near
  28151. addLine('n1', 'n2', colorFrustum);
  28152. addLine('n2', 'n4', colorFrustum);
  28153. addLine('n4', 'n3', colorFrustum);
  28154. addLine('n3', 'n1', colorFrustum); // far
  28155. addLine('f1', 'f2', colorFrustum);
  28156. addLine('f2', 'f4', colorFrustum);
  28157. addLine('f4', 'f3', colorFrustum);
  28158. addLine('f3', 'f1', colorFrustum); // sides
  28159. addLine('n1', 'f1', colorFrustum);
  28160. addLine('n2', 'f2', colorFrustum);
  28161. addLine('n3', 'f3', colorFrustum);
  28162. addLine('n4', 'f4', colorFrustum); // cone
  28163. addLine('p', 'n1', colorCone);
  28164. addLine('p', 'n2', colorCone);
  28165. addLine('p', 'n3', colorCone);
  28166. addLine('p', 'n4', colorCone); // up
  28167. addLine('u1', 'u2', colorUp);
  28168. addLine('u2', 'u3', colorUp);
  28169. addLine('u3', 'u1', colorUp); // target
  28170. addLine('c', 't', colorTarget);
  28171. addLine('p', 'c', colorCross); // cross
  28172. addLine('cn1', 'cn2', colorCross);
  28173. addLine('cn3', 'cn4', colorCross);
  28174. addLine('cf1', 'cf2', colorCross);
  28175. addLine('cf3', 'cf4', colorCross);
  28176. function addLine(a, b, color) {
  28177. addPoint(a, color);
  28178. addPoint(b, color);
  28179. }
  28180. function addPoint(id, color) {
  28181. vertices.push(0, 0, 0);
  28182. colors.push(color.r, color.g, color.b);
  28183. if (pointMap[id] === undefined) {
  28184. pointMap[id] = [];
  28185. }
  28186. pointMap[id].push(vertices.length / 3 - 1);
  28187. }
  28188. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28189. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28190. _this = _LineSegments.call(this, geometry, material) || this;
  28191. _this.type = 'CameraHelper';
  28192. _this.camera = camera;
  28193. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  28194. _this.matrix = camera.matrixWorld;
  28195. _this.matrixAutoUpdate = false;
  28196. _this.pointMap = pointMap;
  28197. _this.update();
  28198. return _this;
  28199. }
  28200. var _proto = CameraHelper.prototype;
  28201. _proto.update = function update() {
  28202. var geometry = this.geometry;
  28203. var pointMap = this.pointMap;
  28204. var w = 1,
  28205. h = 1; // we need just camera projection matrix inverse
  28206. // world matrix must be identity
  28207. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  28208. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  28209. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  28210. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  28211. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  28212. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  28213. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  28214. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  28215. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  28216. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  28217. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  28218. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  28219. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  28220. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  28221. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  28222. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  28223. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  28224. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  28225. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  28226. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  28227. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  28228. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  28229. geometry.getAttribute('position').needsUpdate = true;
  28230. };
  28231. return CameraHelper;
  28232. }(LineSegments);
  28233. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  28234. _vector$c.set(x, y, z).unproject(camera);
  28235. var points = pointMap[point];
  28236. if (points !== undefined) {
  28237. var position = geometry.getAttribute('position');
  28238. for (var i = 0, l = points.length; i < l; i++) {
  28239. position.setXYZ(points[i], _vector$c.x, _vector$c.y, _vector$c.z);
  28240. }
  28241. }
  28242. }
  28243. var _box$3 = /*@__PURE__*/new Box3();
  28244. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  28245. _inheritsLoose(BoxHelper, _LineSegments);
  28246. function BoxHelper(object, color) {
  28247. var _this;
  28248. if (color === void 0) {
  28249. color = 0xffff00;
  28250. }
  28251. 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]);
  28252. var positions = new Float32Array(8 * 3);
  28253. var geometry = new BufferGeometry();
  28254. geometry.setIndex(new BufferAttribute(indices, 1));
  28255. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28256. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28257. color: color,
  28258. toneMapped: false
  28259. })) || this;
  28260. _this.object = object;
  28261. _this.type = 'BoxHelper';
  28262. _this.matrixAutoUpdate = false;
  28263. _this.update();
  28264. return _this;
  28265. }
  28266. var _proto = BoxHelper.prototype;
  28267. _proto.update = function update(object) {
  28268. if (object !== undefined) {
  28269. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28270. }
  28271. if (this.object !== undefined) {
  28272. _box$3.setFromObject(this.object);
  28273. }
  28274. if (_box$3.isEmpty()) return;
  28275. var min = _box$3.min;
  28276. var max = _box$3.max;
  28277. /*
  28278. 5____4
  28279. 1/___0/|
  28280. | 6__|_7
  28281. 2/___3/
  28282. 0: max.x, max.y, max.z
  28283. 1: min.x, max.y, max.z
  28284. 2: min.x, min.y, max.z
  28285. 3: max.x, min.y, max.z
  28286. 4: max.x, max.y, min.z
  28287. 5: min.x, max.y, min.z
  28288. 6: min.x, min.y, min.z
  28289. 7: max.x, min.y, min.z
  28290. */
  28291. var position = this.geometry.attributes.position;
  28292. var array = position.array;
  28293. array[0] = max.x;
  28294. array[1] = max.y;
  28295. array[2] = max.z;
  28296. array[3] = min.x;
  28297. array[4] = max.y;
  28298. array[5] = max.z;
  28299. array[6] = min.x;
  28300. array[7] = min.y;
  28301. array[8] = max.z;
  28302. array[9] = max.x;
  28303. array[10] = min.y;
  28304. array[11] = max.z;
  28305. array[12] = max.x;
  28306. array[13] = max.y;
  28307. array[14] = min.z;
  28308. array[15] = min.x;
  28309. array[16] = max.y;
  28310. array[17] = min.z;
  28311. array[18] = min.x;
  28312. array[19] = min.y;
  28313. array[20] = min.z;
  28314. array[21] = max.x;
  28315. array[22] = min.y;
  28316. array[23] = min.z;
  28317. position.needsUpdate = true;
  28318. this.geometry.computeBoundingSphere();
  28319. };
  28320. _proto.setFromObject = function setFromObject(object) {
  28321. this.object = object;
  28322. this.update();
  28323. return this;
  28324. };
  28325. _proto.copy = function copy(source) {
  28326. LineSegments.prototype.copy.call(this, source);
  28327. this.object = source.object;
  28328. return this;
  28329. };
  28330. return BoxHelper;
  28331. }(LineSegments);
  28332. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28333. _inheritsLoose(Box3Helper, _LineSegments);
  28334. function Box3Helper(box, color) {
  28335. var _this;
  28336. if (color === void 0) {
  28337. color = 0xffff00;
  28338. }
  28339. 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]);
  28340. 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];
  28341. var geometry = new BufferGeometry();
  28342. geometry.setIndex(new BufferAttribute(indices, 1));
  28343. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28344. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28345. color: color,
  28346. toneMapped: false
  28347. })) || this;
  28348. _this.box = box;
  28349. _this.type = 'Box3Helper';
  28350. _this.geometry.computeBoundingSphere();
  28351. return _this;
  28352. }
  28353. var _proto = Box3Helper.prototype;
  28354. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28355. var box = this.box;
  28356. if (box.isEmpty()) return;
  28357. box.getCenter(this.position);
  28358. box.getSize(this.scale);
  28359. this.scale.multiplyScalar(0.5);
  28360. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28361. };
  28362. return Box3Helper;
  28363. }(LineSegments);
  28364. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28365. _inheritsLoose(PlaneHelper, _Line);
  28366. function PlaneHelper(plane, size, hex) {
  28367. var _this;
  28368. if (size === void 0) {
  28369. size = 1;
  28370. }
  28371. if (hex === void 0) {
  28372. hex = 0xffff00;
  28373. }
  28374. var color = hex;
  28375. 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];
  28376. var geometry = new BufferGeometry();
  28377. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28378. geometry.computeBoundingSphere();
  28379. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28380. color: color,
  28381. toneMapped: false
  28382. })) || this;
  28383. _this.type = 'PlaneHelper';
  28384. _this.plane = plane;
  28385. _this.size = size;
  28386. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28387. var geometry2 = new BufferGeometry();
  28388. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28389. geometry2.computeBoundingSphere();
  28390. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28391. color: color,
  28392. opacity: 0.2,
  28393. transparent: true,
  28394. depthWrite: false,
  28395. toneMapped: false
  28396. })));
  28397. return _this;
  28398. }
  28399. var _proto = PlaneHelper.prototype;
  28400. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28401. var scale = -this.plane.constant;
  28402. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28403. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28404. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28405. this.lookAt(this.plane.normal);
  28406. _Line.prototype.updateMatrixWorld.call(this, force);
  28407. };
  28408. return PlaneHelper;
  28409. }(Line);
  28410. var _axis = /*@__PURE__*/new Vector3();
  28411. var _lineGeometry, _coneGeometry;
  28412. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28413. _inheritsLoose(ArrowHelper, _Object3D);
  28414. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28415. var _this;
  28416. _this = _Object3D.call(this) || this; // dir is assumed to be normalized
  28417. _this.type = 'ArrowHelper';
  28418. if (dir === undefined) dir = new Vector3(0, 0, 1);
  28419. if (origin === undefined) origin = new Vector3(0, 0, 0);
  28420. if (length === undefined) length = 1;
  28421. if (color === undefined) color = 0xffff00;
  28422. if (headLength === undefined) headLength = 0.2 * length;
  28423. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28424. if (_lineGeometry === undefined) {
  28425. _lineGeometry = new BufferGeometry();
  28426. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28427. _coneGeometry = new CylinderGeometry(0, 0.5, 1, 5, 1);
  28428. _coneGeometry.translate(0, -0.5, 0);
  28429. }
  28430. _this.position.copy(origin);
  28431. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28432. color: color,
  28433. toneMapped: false
  28434. }));
  28435. _this.line.matrixAutoUpdate = false;
  28436. _this.add(_this.line);
  28437. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  28438. color: color,
  28439. toneMapped: false
  28440. }));
  28441. _this.cone.matrixAutoUpdate = false;
  28442. _this.add(_this.cone);
  28443. _this.setDirection(dir);
  28444. _this.setLength(length, headLength, headWidth);
  28445. return _this;
  28446. }
  28447. var _proto = ArrowHelper.prototype;
  28448. _proto.setDirection = function setDirection(dir) {
  28449. // dir is assumed to be normalized
  28450. if (dir.y > 0.99999) {
  28451. this.quaternion.set(0, 0, 0, 1);
  28452. } else if (dir.y < -0.99999) {
  28453. this.quaternion.set(1, 0, 0, 0);
  28454. } else {
  28455. _axis.set(dir.z, 0, -dir.x).normalize();
  28456. var radians = Math.acos(dir.y);
  28457. this.quaternion.setFromAxisAngle(_axis, radians);
  28458. }
  28459. };
  28460. _proto.setLength = function setLength(length, headLength, headWidth) {
  28461. if (headLength === undefined) headLength = 0.2 * length;
  28462. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28463. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  28464. this.line.updateMatrix();
  28465. this.cone.scale.set(headWidth, headLength, headWidth);
  28466. this.cone.position.y = length;
  28467. this.cone.updateMatrix();
  28468. };
  28469. _proto.setColor = function setColor(color) {
  28470. this.line.material.color.set(color);
  28471. this.cone.material.color.set(color);
  28472. };
  28473. _proto.copy = function copy(source) {
  28474. _Object3D.prototype.copy.call(this, source, false);
  28475. this.line.copy(source.line);
  28476. this.cone.copy(source.cone);
  28477. return this;
  28478. };
  28479. return ArrowHelper;
  28480. }(Object3D);
  28481. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  28482. _inheritsLoose(AxesHelper, _LineSegments);
  28483. function AxesHelper(size) {
  28484. var _this;
  28485. if (size === void 0) {
  28486. size = 1;
  28487. }
  28488. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  28489. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  28490. var geometry = new BufferGeometry();
  28491. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28492. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28493. var material = new LineBasicMaterial({
  28494. vertexColors: true,
  28495. toneMapped: false
  28496. });
  28497. _this = _LineSegments.call(this, geometry, material) || this;
  28498. _this.type = 'AxesHelper';
  28499. return _this;
  28500. }
  28501. return AxesHelper;
  28502. }(LineSegments);
  28503. var _floatView = new Float32Array(1);
  28504. var _int32View = new Int32Array(_floatView.buffer);
  28505. var DataUtils = {
  28506. // Converts float32 to float16 (stored as uint16 value).
  28507. toHalfFloat: function toHalfFloat(val) {
  28508. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  28509. /* This method is faster than the OpenEXR implementation (very often
  28510. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  28511. * by James Tursa?s half-precision code. */
  28512. _floatView[0] = val;
  28513. var x = _int32View[0];
  28514. var bits = x >> 16 & 0x8000;
  28515. /* Get the sign */
  28516. var m = x >> 12 & 0x07ff;
  28517. /* Keep one extra bit for rounding */
  28518. var e = x >> 23 & 0xff;
  28519. /* Using int is faster here */
  28520. /* If zero, or denormal, or exponent underflows too much for a denormal
  28521. * half, return signed zero. */
  28522. if (e < 103) return bits;
  28523. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  28524. if (e > 142) {
  28525. bits |= 0x7c00;
  28526. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  28527. * not Inf, so make sure we set one mantissa bit too. */
  28528. bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;
  28529. return bits;
  28530. }
  28531. /* If exponent underflows but not too much, return a denormal */
  28532. if (e < 113) {
  28533. m |= 0x0800;
  28534. /* Extra rounding may overflow and set mantissa to 0 and exponent
  28535. * to 1, which is OK. */
  28536. bits |= (m >> 114 - e) + (m >> 113 - e & 1);
  28537. return bits;
  28538. }
  28539. bits |= e - 112 << 10 | m >> 1;
  28540. /* Extra rounding. An overflow will set mantissa to 0 and increment
  28541. * the exponent, which is OK. */
  28542. bits += m & 1;
  28543. return bits;
  28544. }
  28545. };
  28546. var _ENCODINGS;
  28547. var LOD_MIN = 4;
  28548. var LOD_MAX = 8;
  28549. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  28550. // chosen to approximate a Trowbridge-Reitz distribution function times the
  28551. // geometric shadowing function. These sigma values squared must match the
  28552. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  28553. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  28554. 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
  28555. // samples and exit early, but not recompile the shader.
  28556. var MAX_SAMPLES = 20;
  28557. 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);
  28558. var backgroundMaterial = new MeshBasicMaterial({
  28559. side: BackSide,
  28560. depthWrite: false,
  28561. depthTest: false
  28562. });
  28563. var backgroundBox = new Mesh(new BoxGeometry(), backgroundMaterial);
  28564. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  28565. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  28566. _lodPlanes = _createPlanes2._lodPlanes,
  28567. _sizeLods = _createPlanes2._sizeLods,
  28568. _sigmas = _createPlanes2._sigmas;
  28569. var _clearColor = /*@__PURE__*/new Color();
  28570. var _oldTarget = null; // Golden Ratio
  28571. var PHI = (1 + Math.sqrt(5)) / 2;
  28572. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  28573. // same axis), used as axis directions evenly spread on a sphere.
  28574. 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)];
  28575. /**
  28576. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28577. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28578. * blur to be quickly accessed based on material roughness. It is packed into a
  28579. * special CubeUV format that allows us to perform custom interpolation so that
  28580. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  28581. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  28582. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  28583. * higher roughness levels. In this way we maintain resolution to smoothly
  28584. * interpolate diffuse lighting while limiting sampling computation.
  28585. */
  28586. function convertLinearToRGBE(color) {
  28587. var maxComponent = Math.max(color.r, color.g, color.b);
  28588. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  28589. color.multiplyScalar(Math.pow(2.0, -fExp));
  28590. var alpha = (fExp + 128.0) / 255.0;
  28591. return alpha;
  28592. }
  28593. var PMREMGenerator = /*#__PURE__*/function () {
  28594. function PMREMGenerator(renderer) {
  28595. this._renderer = renderer;
  28596. this._pingPongRenderTarget = null;
  28597. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  28598. this._equirectShader = null;
  28599. this._cubemapShader = null;
  28600. this._compileMaterial(this._blurMaterial);
  28601. }
  28602. /**
  28603. * Generates a PMREM from a supplied Scene, which can be faster than using an
  28604. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  28605. * in radians to be applied to the scene before PMREM generation. Optional near
  28606. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  28607. * is placed at the origin).
  28608. */
  28609. var _proto = PMREMGenerator.prototype;
  28610. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  28611. if (sigma === void 0) {
  28612. sigma = 0;
  28613. }
  28614. if (near === void 0) {
  28615. near = 0.1;
  28616. }
  28617. if (far === void 0) {
  28618. far = 100;
  28619. }
  28620. _oldTarget = this._renderer.getRenderTarget();
  28621. var cubeUVRenderTarget = this._allocateTargets();
  28622. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  28623. if (sigma > 0) {
  28624. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  28625. }
  28626. this._applyPMREM(cubeUVRenderTarget);
  28627. this._cleanup(cubeUVRenderTarget);
  28628. return cubeUVRenderTarget;
  28629. }
  28630. /**
  28631. * Generates a PMREM from an equirectangular texture, which can be either LDR
  28632. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  28633. * as this matches best with the 256 x 256 cubemap output.
  28634. */
  28635. ;
  28636. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  28637. return this._fromTexture(equirectangular);
  28638. }
  28639. /**
  28640. * Generates a PMREM from an cubemap texture, which can be either LDR
  28641. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  28642. * as this matches best with the 256 x 256 cubemap output.
  28643. */
  28644. ;
  28645. _proto.fromCubemap = function fromCubemap(cubemap) {
  28646. return this._fromTexture(cubemap);
  28647. }
  28648. /**
  28649. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  28650. * your texture's network fetch for increased concurrency.
  28651. */
  28652. ;
  28653. _proto.compileCubemapShader = function compileCubemapShader() {
  28654. if (this._cubemapShader === null) {
  28655. this._cubemapShader = _getCubemapShader();
  28656. this._compileMaterial(this._cubemapShader);
  28657. }
  28658. }
  28659. /**
  28660. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  28661. * your texture's network fetch for increased concurrency.
  28662. */
  28663. ;
  28664. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  28665. if (this._equirectShader === null) {
  28666. this._equirectShader = _getEquirectShader();
  28667. this._compileMaterial(this._equirectShader);
  28668. }
  28669. }
  28670. /**
  28671. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  28672. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  28673. * one of them will cause any others to also become unusable.
  28674. */
  28675. ;
  28676. _proto.dispose = function dispose() {
  28677. this._blurMaterial.dispose();
  28678. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  28679. if (this._equirectShader !== null) this._equirectShader.dispose();
  28680. for (var i = 0; i < _lodPlanes.length; i++) {
  28681. _lodPlanes[i].dispose();
  28682. }
  28683. } // private interface
  28684. ;
  28685. _proto._cleanup = function _cleanup(outputTarget) {
  28686. this._pingPongRenderTarget.dispose();
  28687. this._renderer.setRenderTarget(_oldTarget);
  28688. outputTarget.scissorTest = false;
  28689. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  28690. };
  28691. _proto._fromTexture = function _fromTexture(texture) {
  28692. _oldTarget = this._renderer.getRenderTarget();
  28693. var cubeUVRenderTarget = this._allocateTargets(texture);
  28694. this._textureToCubeUV(texture, cubeUVRenderTarget);
  28695. this._applyPMREM(cubeUVRenderTarget);
  28696. this._cleanup(cubeUVRenderTarget);
  28697. return cubeUVRenderTarget;
  28698. };
  28699. _proto._allocateTargets = function _allocateTargets(texture) {
  28700. // warning: null texture is valid
  28701. var params = {
  28702. magFilter: NearestFilter,
  28703. minFilter: NearestFilter,
  28704. generateMipmaps: false,
  28705. type: UnsignedByteType,
  28706. format: RGBEFormat,
  28707. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  28708. depthBuffer: false
  28709. };
  28710. var cubeUVRenderTarget = _createRenderTarget(params);
  28711. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  28712. this._pingPongRenderTarget = _createRenderTarget(params);
  28713. return cubeUVRenderTarget;
  28714. };
  28715. _proto._compileMaterial = function _compileMaterial(material) {
  28716. var tmpMesh = new Mesh(_lodPlanes[0], material);
  28717. this._renderer.compile(tmpMesh, _flatCamera);
  28718. };
  28719. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  28720. var fov = 90;
  28721. var aspect = 1;
  28722. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  28723. var upSign = [1, -1, 1, 1, 1, 1];
  28724. var forwardSign = [1, 1, 1, -1, -1, -1];
  28725. var renderer = this._renderer;
  28726. var originalAutoClear = renderer.autoClear;
  28727. var outputEncoding = renderer.outputEncoding;
  28728. var toneMapping = renderer.toneMapping;
  28729. renderer.getClearColor(_clearColor);
  28730. renderer.toneMapping = NoToneMapping;
  28731. renderer.outputEncoding = LinearEncoding;
  28732. renderer.autoClear = false;
  28733. var useSolidColor = false;
  28734. var background = scene.background;
  28735. if (background) {
  28736. if (background.isColor) {
  28737. backgroundMaterial.color.copy(background).convertSRGBToLinear();
  28738. scene.background = null;
  28739. var alpha = convertLinearToRGBE(backgroundMaterial.color);
  28740. backgroundMaterial.opacity = alpha;
  28741. useSolidColor = true;
  28742. }
  28743. } else {
  28744. backgroundMaterial.color.copy(_clearColor).convertSRGBToLinear();
  28745. var _alpha = convertLinearToRGBE(backgroundMaterial.color);
  28746. backgroundMaterial.opacity = _alpha;
  28747. useSolidColor = true;
  28748. }
  28749. for (var i = 0; i < 6; i++) {
  28750. var col = i % 3;
  28751. if (col == 0) {
  28752. cubeCamera.up.set(0, upSign[i], 0);
  28753. cubeCamera.lookAt(forwardSign[i], 0, 0);
  28754. } else if (col == 1) {
  28755. cubeCamera.up.set(0, 0, upSign[i]);
  28756. cubeCamera.lookAt(0, forwardSign[i], 0);
  28757. } else {
  28758. cubeCamera.up.set(0, upSign[i], 0);
  28759. cubeCamera.lookAt(0, 0, forwardSign[i]);
  28760. }
  28761. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  28762. renderer.setRenderTarget(cubeUVRenderTarget);
  28763. if (useSolidColor) {
  28764. renderer.render(backgroundBox, cubeCamera);
  28765. }
  28766. renderer.render(scene, cubeCamera);
  28767. }
  28768. renderer.toneMapping = toneMapping;
  28769. renderer.outputEncoding = outputEncoding;
  28770. renderer.autoClear = originalAutoClear;
  28771. };
  28772. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  28773. var renderer = this._renderer;
  28774. if (texture.isCubeTexture) {
  28775. if (this._cubemapShader == null) {
  28776. this._cubemapShader = _getCubemapShader();
  28777. }
  28778. } else {
  28779. if (this._equirectShader == null) {
  28780. this._equirectShader = _getEquirectShader();
  28781. }
  28782. }
  28783. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  28784. var mesh = new Mesh(_lodPlanes[0], material);
  28785. var uniforms = material.uniforms;
  28786. uniforms['envMap'].value = texture;
  28787. if (!texture.isCubeTexture) {
  28788. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  28789. }
  28790. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  28791. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  28792. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  28793. renderer.setRenderTarget(cubeUVRenderTarget);
  28794. renderer.render(mesh, _flatCamera);
  28795. };
  28796. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  28797. var renderer = this._renderer;
  28798. var autoClear = renderer.autoClear;
  28799. renderer.autoClear = false;
  28800. for (var i = 1; i < TOTAL_LODS; i++) {
  28801. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  28802. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  28803. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  28804. }
  28805. renderer.autoClear = autoClear;
  28806. }
  28807. /**
  28808. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  28809. * vertically and horizontally, but this breaks down on a cube. Here we apply
  28810. * the blur latitudinally (around the poles), and then longitudinally (towards
  28811. * the poles) to approximate the orthogonally-separable blur. It is least
  28812. * accurate at the poles, but still does a decent job.
  28813. */
  28814. ;
  28815. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  28816. var pingPongRenderTarget = this._pingPongRenderTarget;
  28817. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  28818. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  28819. };
  28820. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  28821. var renderer = this._renderer;
  28822. var blurMaterial = this._blurMaterial;
  28823. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  28824. console.error('blur direction must be either latitudinal or longitudinal!');
  28825. } // Number of standard deviations at which to cut off the discrete approximation.
  28826. var STANDARD_DEVIATIONS = 3;
  28827. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  28828. var blurUniforms = blurMaterial.uniforms;
  28829. var pixels = _sizeLods[lodIn] - 1;
  28830. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  28831. var sigmaPixels = sigmaRadians / radiansPerPixel;
  28832. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  28833. if (samples > MAX_SAMPLES) {
  28834. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  28835. }
  28836. var weights = [];
  28837. var sum = 0;
  28838. for (var i = 0; i < MAX_SAMPLES; ++i) {
  28839. var _x = i / sigmaPixels;
  28840. var weight = Math.exp(-_x * _x / 2);
  28841. weights.push(weight);
  28842. if (i == 0) {
  28843. sum += weight;
  28844. } else if (i < samples) {
  28845. sum += 2 * weight;
  28846. }
  28847. }
  28848. for (var _i = 0; _i < weights.length; _i++) {
  28849. weights[_i] = weights[_i] / sum;
  28850. }
  28851. blurUniforms['envMap'].value = targetIn.texture;
  28852. blurUniforms['samples'].value = samples;
  28853. blurUniforms['weights'].value = weights;
  28854. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  28855. if (poleAxis) {
  28856. blurUniforms['poleAxis'].value = poleAxis;
  28857. }
  28858. blurUniforms['dTheta'].value = radiansPerPixel;
  28859. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  28860. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28861. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28862. var outputSize = _sizeLods[lodOut];
  28863. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  28864. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  28865. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  28866. renderer.setRenderTarget(targetOut);
  28867. renderer.render(blurMesh, _flatCamera);
  28868. };
  28869. return PMREMGenerator;
  28870. }();
  28871. function _isLDR(texture) {
  28872. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  28873. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  28874. }
  28875. function _createPlanes() {
  28876. var _lodPlanes = [];
  28877. var _sizeLods = [];
  28878. var _sigmas = [];
  28879. var lod = LOD_MAX;
  28880. for (var i = 0; i < TOTAL_LODS; i++) {
  28881. var sizeLod = Math.pow(2, lod);
  28882. _sizeLods.push(sizeLod);
  28883. var sigma = 1.0 / sizeLod;
  28884. if (i > LOD_MAX - LOD_MIN) {
  28885. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  28886. } else if (i == 0) {
  28887. sigma = 0;
  28888. }
  28889. _sigmas.push(sigma);
  28890. var texelSize = 1.0 / (sizeLod - 1);
  28891. var min = -texelSize / 2;
  28892. var max = 1 + texelSize / 2;
  28893. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  28894. var cubeFaces = 6;
  28895. var vertices = 6;
  28896. var positionSize = 3;
  28897. var uvSize = 2;
  28898. var faceIndexSize = 1;
  28899. var position = new Float32Array(positionSize * vertices * cubeFaces);
  28900. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  28901. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  28902. for (var face = 0; face < cubeFaces; face++) {
  28903. var x = face % 3 * 2 / 3 - 1;
  28904. var y = face > 2 ? 0 : -1;
  28905. 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];
  28906. position.set(coordinates, positionSize * vertices * face);
  28907. uv.set(uv1, uvSize * vertices * face);
  28908. var fill = [face, face, face, face, face, face];
  28909. faceIndex.set(fill, faceIndexSize * vertices * face);
  28910. }
  28911. var planes = new BufferGeometry();
  28912. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  28913. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  28914. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  28915. _lodPlanes.push(planes);
  28916. if (lod > LOD_MIN) {
  28917. lod--;
  28918. }
  28919. }
  28920. return {
  28921. _lodPlanes: _lodPlanes,
  28922. _sizeLods: _sizeLods,
  28923. _sigmas: _sigmas
  28924. };
  28925. }
  28926. function _createRenderTarget(params) {
  28927. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  28928. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  28929. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  28930. cubeUVRenderTarget.scissorTest = true;
  28931. return cubeUVRenderTarget;
  28932. }
  28933. function _setViewport(target, x, y, width, height) {
  28934. target.viewport.set(x, y, width, height);
  28935. target.scissor.set(x, y, width, height);
  28936. }
  28937. function _getBlurShader(maxSamples) {
  28938. var weights = new Float32Array(maxSamples);
  28939. var poleAxis = new Vector3(0, 1, 0);
  28940. var shaderMaterial = new RawShaderMaterial({
  28941. name: 'SphericalGaussianBlur',
  28942. defines: {
  28943. 'n': maxSamples
  28944. },
  28945. uniforms: {
  28946. 'envMap': {
  28947. value: null
  28948. },
  28949. 'samples': {
  28950. value: 1
  28951. },
  28952. 'weights': {
  28953. value: weights
  28954. },
  28955. 'latitudinal': {
  28956. value: false
  28957. },
  28958. 'dTheta': {
  28959. value: 0
  28960. },
  28961. 'mipInt': {
  28962. value: 0
  28963. },
  28964. 'poleAxis': {
  28965. value: poleAxis
  28966. },
  28967. 'inputEncoding': {
  28968. value: ENCODINGS[LinearEncoding]
  28969. },
  28970. 'outputEncoding': {
  28971. value: ENCODINGS[LinearEncoding]
  28972. }
  28973. },
  28974. vertexShader: _getCommonVertexShader(),
  28975. fragmentShader:
  28976. /* glsl */
  28977. "\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",
  28978. blending: NoBlending,
  28979. depthTest: false,
  28980. depthWrite: false
  28981. });
  28982. return shaderMaterial;
  28983. }
  28984. function _getEquirectShader() {
  28985. var texelSize = new Vector2(1, 1);
  28986. var shaderMaterial = new RawShaderMaterial({
  28987. name: 'EquirectangularToCubeUV',
  28988. uniforms: {
  28989. 'envMap': {
  28990. value: null
  28991. },
  28992. 'texelSize': {
  28993. value: texelSize
  28994. },
  28995. 'inputEncoding': {
  28996. value: ENCODINGS[LinearEncoding]
  28997. },
  28998. 'outputEncoding': {
  28999. value: ENCODINGS[LinearEncoding]
  29000. }
  29001. },
  29002. vertexShader: _getCommonVertexShader(),
  29003. fragmentShader:
  29004. /* glsl */
  29005. "\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",
  29006. blending: NoBlending,
  29007. depthTest: false,
  29008. depthWrite: false
  29009. });
  29010. return shaderMaterial;
  29011. }
  29012. function _getCubemapShader() {
  29013. var shaderMaterial = new RawShaderMaterial({
  29014. name: 'CubemapToCubeUV',
  29015. uniforms: {
  29016. 'envMap': {
  29017. value: null
  29018. },
  29019. 'inputEncoding': {
  29020. value: ENCODINGS[LinearEncoding]
  29021. },
  29022. 'outputEncoding': {
  29023. value: ENCODINGS[LinearEncoding]
  29024. }
  29025. },
  29026. vertexShader: _getCommonVertexShader(),
  29027. fragmentShader:
  29028. /* glsl */
  29029. "\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",
  29030. blending: NoBlending,
  29031. depthTest: false,
  29032. depthWrite: false
  29033. });
  29034. return shaderMaterial;
  29035. }
  29036. function _getCommonVertexShader() {
  29037. return (
  29038. /* glsl */
  29039. "\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"
  29040. );
  29041. }
  29042. function _getEncodings() {
  29043. return (
  29044. /* glsl */
  29045. "\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"
  29046. );
  29047. }
  29048. var LineStrip = 0;
  29049. var LinePieces = 1;
  29050. var NoColors = 0;
  29051. var FaceColors = 1;
  29052. var VertexColors = 2;
  29053. function MeshFaceMaterial(materials) {
  29054. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  29055. return materials;
  29056. }
  29057. function MultiMaterial(materials) {
  29058. if (materials === void 0) {
  29059. materials = [];
  29060. }
  29061. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  29062. materials.isMultiMaterial = true;
  29063. materials.materials = materials;
  29064. materials.clone = function () {
  29065. return materials.slice();
  29066. };
  29067. return materials;
  29068. }
  29069. function PointCloud(geometry, material) {
  29070. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  29071. return new Points(geometry, material);
  29072. }
  29073. function Particle(material) {
  29074. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  29075. return new Sprite(material);
  29076. }
  29077. function ParticleSystem(geometry, material) {
  29078. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  29079. return new Points(geometry, material);
  29080. }
  29081. function PointCloudMaterial(parameters) {
  29082. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  29083. return new PointsMaterial(parameters);
  29084. }
  29085. function ParticleBasicMaterial(parameters) {
  29086. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  29087. return new PointsMaterial(parameters);
  29088. }
  29089. function ParticleSystemMaterial(parameters) {
  29090. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  29091. return new PointsMaterial(parameters);
  29092. }
  29093. function Vertex(x, y, z) {
  29094. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  29095. return new Vector3(x, y, z);
  29096. } //
  29097. function DynamicBufferAttribute(array, itemSize) {
  29098. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  29099. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  29100. }
  29101. function Int8Attribute(array, itemSize) {
  29102. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  29103. return new Int8BufferAttribute(array, itemSize);
  29104. }
  29105. function Uint8Attribute(array, itemSize) {
  29106. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  29107. return new Uint8BufferAttribute(array, itemSize);
  29108. }
  29109. function Uint8ClampedAttribute(array, itemSize) {
  29110. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  29111. return new Uint8ClampedBufferAttribute(array, itemSize);
  29112. }
  29113. function Int16Attribute(array, itemSize) {
  29114. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  29115. return new Int16BufferAttribute(array, itemSize);
  29116. }
  29117. function Uint16Attribute(array, itemSize) {
  29118. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  29119. return new Uint16BufferAttribute(array, itemSize);
  29120. }
  29121. function Int32Attribute(array, itemSize) {
  29122. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  29123. return new Int32BufferAttribute(array, itemSize);
  29124. }
  29125. function Uint32Attribute(array, itemSize) {
  29126. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  29127. return new Uint32BufferAttribute(array, itemSize);
  29128. }
  29129. function Float32Attribute(array, itemSize) {
  29130. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  29131. return new Float32BufferAttribute(array, itemSize);
  29132. }
  29133. function Float64Attribute(array, itemSize) {
  29134. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  29135. return new Float64BufferAttribute(array, itemSize);
  29136. } //
  29137. Curve.create = function (construct, getPoint) {
  29138. console.log('THREE.Curve.create() has been deprecated');
  29139. construct.prototype = Object.create(Curve.prototype);
  29140. construct.prototype.constructor = construct;
  29141. construct.prototype.getPoint = getPoint;
  29142. return construct;
  29143. }; //
  29144. Object.assign(Path.prototype, {
  29145. fromPoints: function fromPoints(points) {
  29146. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  29147. return this.setFromPoints(points);
  29148. }
  29149. }); //
  29150. function ClosedSplineCurve3(points) {
  29151. console.warn('THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29152. CatmullRomCurve3.call(this, points);
  29153. this.type = 'catmullrom';
  29154. this.closed = true;
  29155. }
  29156. ClosedSplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29157. function SplineCurve3(points) {
  29158. console.warn('THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29159. CatmullRomCurve3.call(this, points);
  29160. this.type = 'catmullrom';
  29161. }
  29162. SplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29163. function Spline(points) {
  29164. console.warn('THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.');
  29165. CatmullRomCurve3.call(this, points);
  29166. this.type = 'catmullrom';
  29167. }
  29168. Spline.prototype = Object.create(CatmullRomCurve3.prototype);
  29169. Object.assign(Spline.prototype, {
  29170. initFromArray: function initFromArray()
  29171. /* a */
  29172. {
  29173. console.error('THREE.Spline: .initFromArray() has been removed.');
  29174. },
  29175. getControlPointsArray: function getControlPointsArray()
  29176. /* optionalTarget */
  29177. {
  29178. console.error('THREE.Spline: .getControlPointsArray() has been removed.');
  29179. },
  29180. reparametrizeByArcLength: function reparametrizeByArcLength()
  29181. /* samplingCoef */
  29182. {
  29183. console.error('THREE.Spline: .reparametrizeByArcLength() has been removed.');
  29184. }
  29185. }); //
  29186. function AxisHelper(size) {
  29187. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  29188. return new AxesHelper(size);
  29189. }
  29190. function BoundingBoxHelper(object, color) {
  29191. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  29192. return new BoxHelper(object, color);
  29193. }
  29194. function EdgesHelper(object, hex) {
  29195. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  29196. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  29197. color: hex !== undefined ? hex : 0xffffff
  29198. }));
  29199. }
  29200. GridHelper.prototype.setColors = function () {
  29201. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  29202. };
  29203. SkeletonHelper.prototype.update = function () {
  29204. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  29205. };
  29206. function WireframeHelper(object, hex) {
  29207. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  29208. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  29209. color: hex !== undefined ? hex : 0xffffff
  29210. }));
  29211. } //
  29212. Object.assign(Loader.prototype, {
  29213. extractUrlBase: function extractUrlBase(url) {
  29214. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  29215. return LoaderUtils.extractUrlBase(url);
  29216. }
  29217. });
  29218. Loader.Handlers = {
  29219. add: function add()
  29220. /* regex, loader */
  29221. {
  29222. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  29223. },
  29224. get: function get()
  29225. /* file */
  29226. {
  29227. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  29228. }
  29229. };
  29230. function XHRLoader(manager) {
  29231. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  29232. return new FileLoader(manager);
  29233. }
  29234. function BinaryTextureLoader(manager) {
  29235. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  29236. return new DataTextureLoader(manager);
  29237. } //
  29238. Object.assign(Box2.prototype, {
  29239. center: function center(optionalTarget) {
  29240. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  29241. return this.getCenter(optionalTarget);
  29242. },
  29243. empty: function empty() {
  29244. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  29245. return this.isEmpty();
  29246. },
  29247. isIntersectionBox: function isIntersectionBox(box) {
  29248. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  29249. return this.intersectsBox(box);
  29250. },
  29251. size: function size(optionalTarget) {
  29252. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  29253. return this.getSize(optionalTarget);
  29254. }
  29255. });
  29256. Object.assign(Box3.prototype, {
  29257. center: function center(optionalTarget) {
  29258. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  29259. return this.getCenter(optionalTarget);
  29260. },
  29261. empty: function empty() {
  29262. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  29263. return this.isEmpty();
  29264. },
  29265. isIntersectionBox: function isIntersectionBox(box) {
  29266. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  29267. return this.intersectsBox(box);
  29268. },
  29269. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29270. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29271. return this.intersectsSphere(sphere);
  29272. },
  29273. size: function size(optionalTarget) {
  29274. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  29275. return this.getSize(optionalTarget);
  29276. }
  29277. });
  29278. Object.assign(Sphere.prototype, {
  29279. empty: function empty() {
  29280. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  29281. return this.isEmpty();
  29282. }
  29283. });
  29284. Frustum.prototype.setFromMatrix = function (m) {
  29285. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  29286. return this.setFromProjectionMatrix(m);
  29287. };
  29288. Line3.prototype.center = function (optionalTarget) {
  29289. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  29290. return this.getCenter(optionalTarget);
  29291. };
  29292. Object.assign(MathUtils, {
  29293. random16: function random16() {
  29294. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  29295. return Math.random();
  29296. },
  29297. nearestPowerOfTwo: function nearestPowerOfTwo(value) {
  29298. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  29299. return MathUtils.floorPowerOfTwo(value);
  29300. },
  29301. nextPowerOfTwo: function nextPowerOfTwo(value) {
  29302. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29303. return MathUtils.ceilPowerOfTwo(value);
  29304. }
  29305. });
  29306. Object.assign(Matrix3.prototype, {
  29307. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29308. console.warn('THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29309. return this.toArray(array, offset);
  29310. },
  29311. multiplyVector3: function multiplyVector3(vector) {
  29312. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29313. return vector.applyMatrix3(this);
  29314. },
  29315. multiplyVector3Array: function multiplyVector3Array()
  29316. /* a */
  29317. {
  29318. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29319. },
  29320. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29321. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29322. return attribute.applyMatrix3(this);
  29323. },
  29324. applyToVector3Array: function applyToVector3Array()
  29325. /* array, offset, length */
  29326. {
  29327. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29328. },
  29329. getInverse: function getInverse(matrix) {
  29330. console.warn('THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29331. return this.copy(matrix).invert();
  29332. }
  29333. });
  29334. Object.assign(Matrix4.prototype, {
  29335. extractPosition: function extractPosition(m) {
  29336. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29337. return this.copyPosition(m);
  29338. },
  29339. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29340. console.warn('THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29341. return this.toArray(array, offset);
  29342. },
  29343. getPosition: function getPosition() {
  29344. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29345. return new Vector3().setFromMatrixColumn(this, 3);
  29346. },
  29347. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  29348. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29349. return this.makeRotationFromQuaternion(q);
  29350. },
  29351. multiplyToArray: function multiplyToArray() {
  29352. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29353. },
  29354. multiplyVector3: function multiplyVector3(vector) {
  29355. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29356. return vector.applyMatrix4(this);
  29357. },
  29358. multiplyVector4: function multiplyVector4(vector) {
  29359. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29360. return vector.applyMatrix4(this);
  29361. },
  29362. multiplyVector3Array: function multiplyVector3Array()
  29363. /* a */
  29364. {
  29365. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29366. },
  29367. rotateAxis: function rotateAxis(v) {
  29368. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29369. v.transformDirection(this);
  29370. },
  29371. crossVector: function crossVector(vector) {
  29372. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29373. return vector.applyMatrix4(this);
  29374. },
  29375. translate: function translate() {
  29376. console.error('THREE.Matrix4: .translate() has been removed.');
  29377. },
  29378. rotateX: function rotateX() {
  29379. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29380. },
  29381. rotateY: function rotateY() {
  29382. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29383. },
  29384. rotateZ: function rotateZ() {
  29385. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29386. },
  29387. rotateByAxis: function rotateByAxis() {
  29388. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29389. },
  29390. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29391. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29392. return attribute.applyMatrix4(this);
  29393. },
  29394. applyToVector3Array: function applyToVector3Array()
  29395. /* array, offset, length */
  29396. {
  29397. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29398. },
  29399. makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
  29400. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29401. return this.makePerspective(left, right, top, bottom, near, far);
  29402. },
  29403. getInverse: function getInverse(matrix) {
  29404. console.warn('THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29405. return this.copy(matrix).invert();
  29406. }
  29407. });
  29408. Plane.prototype.isIntersectionLine = function (line) {
  29409. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29410. return this.intersectsLine(line);
  29411. };
  29412. Object.assign(Quaternion.prototype, {
  29413. multiplyVector3: function multiplyVector3(vector) {
  29414. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29415. return vector.applyQuaternion(this);
  29416. },
  29417. inverse: function inverse() {
  29418. console.warn('THREE.Quaternion: .inverse() has been renamed to invert().');
  29419. return this.invert();
  29420. }
  29421. });
  29422. Object.assign(Ray.prototype, {
  29423. isIntersectionBox: function isIntersectionBox(box) {
  29424. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29425. return this.intersectsBox(box);
  29426. },
  29427. isIntersectionPlane: function isIntersectionPlane(plane) {
  29428. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29429. return this.intersectsPlane(plane);
  29430. },
  29431. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29432. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29433. return this.intersectsSphere(sphere);
  29434. }
  29435. });
  29436. Object.assign(Triangle.prototype, {
  29437. area: function area() {
  29438. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  29439. return this.getArea();
  29440. },
  29441. barycoordFromPoint: function barycoordFromPoint(point, target) {
  29442. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29443. return this.getBarycoord(point, target);
  29444. },
  29445. midpoint: function midpoint(target) {
  29446. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  29447. return this.getMidpoint(target);
  29448. },
  29449. normal: function normal(target) {
  29450. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29451. return this.getNormal(target);
  29452. },
  29453. plane: function plane(target) {
  29454. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  29455. return this.getPlane(target);
  29456. }
  29457. });
  29458. Object.assign(Triangle, {
  29459. barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
  29460. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29461. return Triangle.getBarycoord(point, a, b, c, target);
  29462. },
  29463. normal: function normal(a, b, c, target) {
  29464. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29465. return Triangle.getNormal(a, b, c, target);
  29466. }
  29467. });
  29468. Object.assign(Shape.prototype, {
  29469. extractAllPoints: function extractAllPoints(divisions) {
  29470. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  29471. return this.extractPoints(divisions);
  29472. },
  29473. extrude: function extrude(options) {
  29474. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  29475. return new ExtrudeGeometry(this, options);
  29476. },
  29477. makeGeometry: function makeGeometry(options) {
  29478. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  29479. return new ShapeGeometry(this, options);
  29480. }
  29481. });
  29482. Object.assign(Vector2.prototype, {
  29483. fromAttribute: function fromAttribute(attribute, index, offset) {
  29484. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29485. return this.fromBufferAttribute(attribute, index, offset);
  29486. },
  29487. distanceToManhattan: function distanceToManhattan(v) {
  29488. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29489. return this.manhattanDistanceTo(v);
  29490. },
  29491. lengthManhattan: function lengthManhattan() {
  29492. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  29493. return this.manhattanLength();
  29494. }
  29495. });
  29496. Object.assign(Vector3.prototype, {
  29497. setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
  29498. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  29499. },
  29500. setEulerFromQuaternion: function setEulerFromQuaternion() {
  29501. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  29502. },
  29503. getPositionFromMatrix: function getPositionFromMatrix(m) {
  29504. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  29505. return this.setFromMatrixPosition(m);
  29506. },
  29507. getScaleFromMatrix: function getScaleFromMatrix(m) {
  29508. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  29509. return this.setFromMatrixScale(m);
  29510. },
  29511. getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
  29512. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  29513. return this.setFromMatrixColumn(matrix, index);
  29514. },
  29515. applyProjection: function applyProjection(m) {
  29516. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  29517. return this.applyMatrix4(m);
  29518. },
  29519. fromAttribute: function fromAttribute(attribute, index, offset) {
  29520. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29521. return this.fromBufferAttribute(attribute, index, offset);
  29522. },
  29523. distanceToManhattan: function distanceToManhattan(v) {
  29524. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29525. return this.manhattanDistanceTo(v);
  29526. },
  29527. lengthManhattan: function lengthManhattan() {
  29528. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  29529. return this.manhattanLength();
  29530. }
  29531. });
  29532. Object.assign(Vector4.prototype, {
  29533. fromAttribute: function fromAttribute(attribute, index, offset) {
  29534. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29535. return this.fromBufferAttribute(attribute, index, offset);
  29536. },
  29537. lengthManhattan: function lengthManhattan() {
  29538. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  29539. return this.manhattanLength();
  29540. }
  29541. }); //
  29542. Object.assign(Object3D.prototype, {
  29543. getChildByName: function getChildByName(name) {
  29544. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  29545. return this.getObjectByName(name);
  29546. },
  29547. renderDepth: function renderDepth() {
  29548. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  29549. },
  29550. translate: function translate(distance, axis) {
  29551. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  29552. return this.translateOnAxis(axis, distance);
  29553. },
  29554. getWorldRotation: function getWorldRotation() {
  29555. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  29556. },
  29557. applyMatrix: function applyMatrix(matrix) {
  29558. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  29559. return this.applyMatrix4(matrix);
  29560. }
  29561. });
  29562. Object.defineProperties(Object3D.prototype, {
  29563. eulerOrder: {
  29564. get: function get() {
  29565. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29566. return this.rotation.order;
  29567. },
  29568. set: function set(value) {
  29569. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29570. this.rotation.order = value;
  29571. }
  29572. },
  29573. useQuaternion: {
  29574. get: function get() {
  29575. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29576. },
  29577. set: function set() {
  29578. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29579. }
  29580. }
  29581. });
  29582. Object.assign(Mesh.prototype, {
  29583. setDrawMode: function setDrawMode() {
  29584. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29585. }
  29586. });
  29587. Object.defineProperties(Mesh.prototype, {
  29588. drawMode: {
  29589. get: function get() {
  29590. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  29591. return TrianglesDrawMode;
  29592. },
  29593. set: function set() {
  29594. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29595. }
  29596. }
  29597. });
  29598. Object.defineProperties(LOD.prototype, {
  29599. objects: {
  29600. get: function get() {
  29601. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  29602. return this.levels;
  29603. }
  29604. }
  29605. });
  29606. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  29607. get: function get() {
  29608. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29609. },
  29610. set: function set() {
  29611. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29612. }
  29613. });
  29614. SkinnedMesh.prototype.initBones = function () {
  29615. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  29616. };
  29617. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  29618. get: function get() {
  29619. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29620. return this.arcLengthDivisions;
  29621. },
  29622. set: function set(value) {
  29623. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29624. this.arcLengthDivisions = value;
  29625. }
  29626. }); //
  29627. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  29628. console.warn('THREE.PerspectiveCamera.setLens is deprecated. ' + 'Use .setFocalLength and .filmGauge for a photographic setup.');
  29629. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  29630. this.setFocalLength(focalLength);
  29631. }; //
  29632. Object.defineProperties(Light.prototype, {
  29633. onlyShadow: {
  29634. set: function set() {
  29635. console.warn('THREE.Light: .onlyShadow has been removed.');
  29636. }
  29637. },
  29638. shadowCameraFov: {
  29639. set: function set(value) {
  29640. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  29641. this.shadow.camera.fov = value;
  29642. }
  29643. },
  29644. shadowCameraLeft: {
  29645. set: function set(value) {
  29646. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  29647. this.shadow.camera.left = value;
  29648. }
  29649. },
  29650. shadowCameraRight: {
  29651. set: function set(value) {
  29652. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  29653. this.shadow.camera.right = value;
  29654. }
  29655. },
  29656. shadowCameraTop: {
  29657. set: function set(value) {
  29658. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  29659. this.shadow.camera.top = value;
  29660. }
  29661. },
  29662. shadowCameraBottom: {
  29663. set: function set(value) {
  29664. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  29665. this.shadow.camera.bottom = value;
  29666. }
  29667. },
  29668. shadowCameraNear: {
  29669. set: function set(value) {
  29670. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  29671. this.shadow.camera.near = value;
  29672. }
  29673. },
  29674. shadowCameraFar: {
  29675. set: function set(value) {
  29676. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  29677. this.shadow.camera.far = value;
  29678. }
  29679. },
  29680. shadowCameraVisible: {
  29681. set: function set() {
  29682. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  29683. }
  29684. },
  29685. shadowBias: {
  29686. set: function set(value) {
  29687. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  29688. this.shadow.bias = value;
  29689. }
  29690. },
  29691. shadowDarkness: {
  29692. set: function set() {
  29693. console.warn('THREE.Light: .shadowDarkness has been removed.');
  29694. }
  29695. },
  29696. shadowMapWidth: {
  29697. set: function set(value) {
  29698. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  29699. this.shadow.mapSize.width = value;
  29700. }
  29701. },
  29702. shadowMapHeight: {
  29703. set: function set(value) {
  29704. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  29705. this.shadow.mapSize.height = value;
  29706. }
  29707. }
  29708. }); //
  29709. Object.defineProperties(BufferAttribute.prototype, {
  29710. length: {
  29711. get: function get() {
  29712. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  29713. return this.array.length;
  29714. }
  29715. },
  29716. dynamic: {
  29717. get: function get() {
  29718. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29719. return this.usage === DynamicDrawUsage;
  29720. },
  29721. set: function set()
  29722. /* value */
  29723. {
  29724. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29725. this.setUsage(DynamicDrawUsage);
  29726. }
  29727. }
  29728. });
  29729. Object.assign(BufferAttribute.prototype, {
  29730. setDynamic: function setDynamic(value) {
  29731. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29732. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29733. return this;
  29734. },
  29735. copyIndicesArray: function copyIndicesArray()
  29736. /* indices */
  29737. {
  29738. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  29739. },
  29740. setArray: function setArray()
  29741. /* array */
  29742. {
  29743. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29744. }
  29745. });
  29746. Object.assign(BufferGeometry.prototype, {
  29747. addIndex: function addIndex(index) {
  29748. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  29749. this.setIndex(index);
  29750. },
  29751. addAttribute: function addAttribute(name, attribute) {
  29752. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  29753. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  29754. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  29755. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  29756. }
  29757. if (name === 'index') {
  29758. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  29759. this.setIndex(attribute);
  29760. return this;
  29761. }
  29762. return this.setAttribute(name, attribute);
  29763. },
  29764. addDrawCall: function addDrawCall(start, count, indexOffset) {
  29765. if (indexOffset !== undefined) {
  29766. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  29767. }
  29768. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  29769. this.addGroup(start, count);
  29770. },
  29771. clearDrawCalls: function clearDrawCalls() {
  29772. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  29773. this.clearGroups();
  29774. },
  29775. computeOffsets: function computeOffsets() {
  29776. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  29777. },
  29778. removeAttribute: function removeAttribute(name) {
  29779. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  29780. return this.deleteAttribute(name);
  29781. },
  29782. applyMatrix: function applyMatrix(matrix) {
  29783. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29784. return this.applyMatrix4(matrix);
  29785. }
  29786. });
  29787. Object.defineProperties(BufferGeometry.prototype, {
  29788. drawcalls: {
  29789. get: function get() {
  29790. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  29791. return this.groups;
  29792. }
  29793. },
  29794. offsets: {
  29795. get: function get() {
  29796. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  29797. return this.groups;
  29798. }
  29799. }
  29800. });
  29801. Object.defineProperties(InstancedBufferGeometry.prototype, {
  29802. maxInstancedCount: {
  29803. get: function get() {
  29804. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29805. return this.instanceCount;
  29806. },
  29807. set: function set(value) {
  29808. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29809. this.instanceCount = value;
  29810. }
  29811. }
  29812. });
  29813. Object.defineProperties(Raycaster.prototype, {
  29814. linePrecision: {
  29815. get: function get() {
  29816. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29817. return this.params.Line.threshold;
  29818. },
  29819. set: function set(value) {
  29820. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29821. this.params.Line.threshold = value;
  29822. }
  29823. }
  29824. });
  29825. Object.defineProperties(InterleavedBuffer.prototype, {
  29826. dynamic: {
  29827. get: function get() {
  29828. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29829. return this.usage === DynamicDrawUsage;
  29830. },
  29831. set: function set(value) {
  29832. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29833. this.setUsage(value);
  29834. }
  29835. }
  29836. });
  29837. Object.assign(InterleavedBuffer.prototype, {
  29838. setDynamic: function setDynamic(value) {
  29839. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29840. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29841. return this;
  29842. },
  29843. setArray: function setArray()
  29844. /* array */
  29845. {
  29846. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29847. }
  29848. }); //
  29849. Object.assign(ExtrudeGeometry.prototype, {
  29850. getArrays: function getArrays() {
  29851. console.error('THREE.ExtrudeGeometry: .getArrays() has been removed.');
  29852. },
  29853. addShapeList: function addShapeList() {
  29854. console.error('THREE.ExtrudeGeometry: .addShapeList() has been removed.');
  29855. },
  29856. addShape: function addShape() {
  29857. console.error('THREE.ExtrudeGeometry: .addShape() has been removed.');
  29858. }
  29859. }); //
  29860. Object.assign(Scene.prototype, {
  29861. dispose: function dispose() {
  29862. console.error('THREE.Scene: .dispose() has been removed.');
  29863. }
  29864. }); //
  29865. Object.defineProperties(Uniform.prototype, {
  29866. dynamic: {
  29867. set: function set() {
  29868. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  29869. }
  29870. },
  29871. onUpdate: {
  29872. value: function value() {
  29873. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  29874. return this;
  29875. }
  29876. }
  29877. }); //
  29878. Object.defineProperties(Material.prototype, {
  29879. wrapAround: {
  29880. get: function get() {
  29881. console.warn('THREE.Material: .wrapAround has been removed.');
  29882. },
  29883. set: function set() {
  29884. console.warn('THREE.Material: .wrapAround has been removed.');
  29885. }
  29886. },
  29887. overdraw: {
  29888. get: function get() {
  29889. console.warn('THREE.Material: .overdraw has been removed.');
  29890. },
  29891. set: function set() {
  29892. console.warn('THREE.Material: .overdraw has been removed.');
  29893. }
  29894. },
  29895. wrapRGB: {
  29896. get: function get() {
  29897. console.warn('THREE.Material: .wrapRGB has been removed.');
  29898. return new Color();
  29899. }
  29900. },
  29901. shading: {
  29902. get: function get() {
  29903. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29904. },
  29905. set: function set(value) {
  29906. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29907. this.flatShading = value === FlatShading;
  29908. }
  29909. },
  29910. stencilMask: {
  29911. get: function get() {
  29912. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29913. return this.stencilFuncMask;
  29914. },
  29915. set: function set(value) {
  29916. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29917. this.stencilFuncMask = value;
  29918. }
  29919. }
  29920. });
  29921. Object.defineProperties(MeshPhongMaterial.prototype, {
  29922. metal: {
  29923. get: function get() {
  29924. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  29925. return false;
  29926. },
  29927. set: function set() {
  29928. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  29929. }
  29930. }
  29931. });
  29932. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  29933. transparency: {
  29934. get: function get() {
  29935. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29936. return this.transmission;
  29937. },
  29938. set: function set(value) {
  29939. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29940. this.transmission = value;
  29941. }
  29942. }
  29943. });
  29944. Object.defineProperties(ShaderMaterial.prototype, {
  29945. derivatives: {
  29946. get: function get() {
  29947. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29948. return this.extensions.derivatives;
  29949. },
  29950. set: function set(value) {
  29951. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29952. this.extensions.derivatives = value;
  29953. }
  29954. }
  29955. }); //
  29956. Object.assign(WebGLRenderer.prototype, {
  29957. clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
  29958. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  29959. this.setRenderTarget(renderTarget);
  29960. this.clear(color, depth, stencil);
  29961. },
  29962. animate: function animate(callback) {
  29963. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  29964. this.setAnimationLoop(callback);
  29965. },
  29966. getCurrentRenderTarget: function getCurrentRenderTarget() {
  29967. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  29968. return this.getRenderTarget();
  29969. },
  29970. getMaxAnisotropy: function getMaxAnisotropy() {
  29971. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  29972. return this.capabilities.getMaxAnisotropy();
  29973. },
  29974. getPrecision: function getPrecision() {
  29975. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  29976. return this.capabilities.precision;
  29977. },
  29978. resetGLState: function resetGLState() {
  29979. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  29980. return this.state.reset();
  29981. },
  29982. supportsFloatTextures: function supportsFloatTextures() {
  29983. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  29984. return this.extensions.get('OES_texture_float');
  29985. },
  29986. supportsHalfFloatTextures: function supportsHalfFloatTextures() {
  29987. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  29988. return this.extensions.get('OES_texture_half_float');
  29989. },
  29990. supportsStandardDerivatives: function supportsStandardDerivatives() {
  29991. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  29992. return this.extensions.get('OES_standard_derivatives');
  29993. },
  29994. supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
  29995. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  29996. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  29997. },
  29998. supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
  29999. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  30000. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  30001. },
  30002. supportsBlendMinMax: function supportsBlendMinMax() {
  30003. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  30004. return this.extensions.get('EXT_blend_minmax');
  30005. },
  30006. supportsVertexTextures: function supportsVertexTextures() {
  30007. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  30008. return this.capabilities.vertexTextures;
  30009. },
  30010. supportsInstancedArrays: function supportsInstancedArrays() {
  30011. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  30012. return this.extensions.get('ANGLE_instanced_arrays');
  30013. },
  30014. enableScissorTest: function enableScissorTest(boolean) {
  30015. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  30016. this.setScissorTest(boolean);
  30017. },
  30018. initMaterial: function initMaterial() {
  30019. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  30020. },
  30021. addPrePlugin: function addPrePlugin() {
  30022. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  30023. },
  30024. addPostPlugin: function addPostPlugin() {
  30025. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  30026. },
  30027. updateShadowMap: function updateShadowMap() {
  30028. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  30029. },
  30030. setFaceCulling: function setFaceCulling() {
  30031. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  30032. },
  30033. allocTextureUnit: function allocTextureUnit() {
  30034. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  30035. },
  30036. setTexture: function setTexture() {
  30037. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  30038. },
  30039. setTexture2D: function setTexture2D() {
  30040. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  30041. },
  30042. setTextureCube: function setTextureCube() {
  30043. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  30044. },
  30045. getActiveMipMapLevel: function getActiveMipMapLevel() {
  30046. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  30047. return this.getActiveMipmapLevel();
  30048. }
  30049. });
  30050. Object.defineProperties(WebGLRenderer.prototype, {
  30051. shadowMapEnabled: {
  30052. get: function get() {
  30053. return this.shadowMap.enabled;
  30054. },
  30055. set: function set(value) {
  30056. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  30057. this.shadowMap.enabled = value;
  30058. }
  30059. },
  30060. shadowMapType: {
  30061. get: function get() {
  30062. return this.shadowMap.type;
  30063. },
  30064. set: function set(value) {
  30065. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  30066. this.shadowMap.type = value;
  30067. }
  30068. },
  30069. shadowMapCullFace: {
  30070. get: function get() {
  30071. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30072. return undefined;
  30073. },
  30074. set: function set()
  30075. /* value */
  30076. {
  30077. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30078. }
  30079. },
  30080. context: {
  30081. get: function get() {
  30082. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  30083. return this.getContext();
  30084. }
  30085. },
  30086. vr: {
  30087. get: function get() {
  30088. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  30089. return this.xr;
  30090. }
  30091. },
  30092. gammaInput: {
  30093. get: function get() {
  30094. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30095. return false;
  30096. },
  30097. set: function set() {
  30098. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30099. }
  30100. },
  30101. gammaOutput: {
  30102. get: function get() {
  30103. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30104. return false;
  30105. },
  30106. set: function set(value) {
  30107. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30108. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  30109. }
  30110. },
  30111. toneMappingWhitePoint: {
  30112. get: function get() {
  30113. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30114. return 1.0;
  30115. },
  30116. set: function set() {
  30117. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30118. }
  30119. }
  30120. });
  30121. Object.defineProperties(WebGLShadowMap.prototype, {
  30122. cullFace: {
  30123. get: function get() {
  30124. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30125. return undefined;
  30126. },
  30127. set: function set()
  30128. /* cullFace */
  30129. {
  30130. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30131. }
  30132. },
  30133. renderReverseSided: {
  30134. get: function get() {
  30135. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30136. return undefined;
  30137. },
  30138. set: function set() {
  30139. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30140. }
  30141. },
  30142. renderSingleSided: {
  30143. get: function get() {
  30144. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30145. return undefined;
  30146. },
  30147. set: function set() {
  30148. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30149. }
  30150. }
  30151. });
  30152. function WebGLRenderTargetCube(width, height, options) {
  30153. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  30154. return new WebGLCubeRenderTarget(width, options);
  30155. } //
  30156. Object.defineProperties(WebGLRenderTarget.prototype, {
  30157. wrapS: {
  30158. get: function get() {
  30159. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30160. return this.texture.wrapS;
  30161. },
  30162. set: function set(value) {
  30163. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30164. this.texture.wrapS = value;
  30165. }
  30166. },
  30167. wrapT: {
  30168. get: function get() {
  30169. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30170. return this.texture.wrapT;
  30171. },
  30172. set: function set(value) {
  30173. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30174. this.texture.wrapT = value;
  30175. }
  30176. },
  30177. magFilter: {
  30178. get: function get() {
  30179. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30180. return this.texture.magFilter;
  30181. },
  30182. set: function set(value) {
  30183. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30184. this.texture.magFilter = value;
  30185. }
  30186. },
  30187. minFilter: {
  30188. get: function get() {
  30189. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30190. return this.texture.minFilter;
  30191. },
  30192. set: function set(value) {
  30193. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30194. this.texture.minFilter = value;
  30195. }
  30196. },
  30197. anisotropy: {
  30198. get: function get() {
  30199. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30200. return this.texture.anisotropy;
  30201. },
  30202. set: function set(value) {
  30203. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30204. this.texture.anisotropy = value;
  30205. }
  30206. },
  30207. offset: {
  30208. get: function get() {
  30209. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30210. return this.texture.offset;
  30211. },
  30212. set: function set(value) {
  30213. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30214. this.texture.offset = value;
  30215. }
  30216. },
  30217. repeat: {
  30218. get: function get() {
  30219. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30220. return this.texture.repeat;
  30221. },
  30222. set: function set(value) {
  30223. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30224. this.texture.repeat = value;
  30225. }
  30226. },
  30227. format: {
  30228. get: function get() {
  30229. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30230. return this.texture.format;
  30231. },
  30232. set: function set(value) {
  30233. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30234. this.texture.format = value;
  30235. }
  30236. },
  30237. type: {
  30238. get: function get() {
  30239. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30240. return this.texture.type;
  30241. },
  30242. set: function set(value) {
  30243. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30244. this.texture.type = value;
  30245. }
  30246. },
  30247. generateMipmaps: {
  30248. get: function get() {
  30249. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30250. return this.texture.generateMipmaps;
  30251. },
  30252. set: function set(value) {
  30253. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30254. this.texture.generateMipmaps = value;
  30255. }
  30256. }
  30257. }); //
  30258. Object.defineProperties(Audio.prototype, {
  30259. load: {
  30260. value: function value(file) {
  30261. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  30262. var scope = this;
  30263. var audioLoader = new AudioLoader();
  30264. audioLoader.load(file, function (buffer) {
  30265. scope.setBuffer(buffer);
  30266. });
  30267. return this;
  30268. }
  30269. },
  30270. startTime: {
  30271. set: function set() {
  30272. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  30273. }
  30274. }
  30275. });
  30276. AudioAnalyser.prototype.getData = function () {
  30277. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  30278. return this.getFrequencyData();
  30279. }; //
  30280. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  30281. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  30282. return this.update(renderer, scene);
  30283. };
  30284. CubeCamera.prototype.clear = function (renderer, color, depth, stencil) {
  30285. console.warn('THREE.CubeCamera: .clear() is now .renderTarget.clear().');
  30286. return this.renderTarget.clear(renderer, color, depth, stencil);
  30287. };
  30288. ImageUtils.crossOrigin = undefined;
  30289. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30290. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30291. var loader = new TextureLoader();
  30292. loader.setCrossOrigin(this.crossOrigin);
  30293. var texture = loader.load(url, onLoad, undefined, onError);
  30294. if (mapping) texture.mapping = mapping;
  30295. return texture;
  30296. };
  30297. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30298. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30299. var loader = new CubeTextureLoader();
  30300. loader.setCrossOrigin(this.crossOrigin);
  30301. var texture = loader.load(urls, onLoad, undefined, onError);
  30302. if (mapping) texture.mapping = mapping;
  30303. return texture;
  30304. };
  30305. ImageUtils.loadCompressedTexture = function () {
  30306. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30307. };
  30308. ImageUtils.loadCompressedTextureCube = function () {
  30309. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30310. }; //
  30311. function CanvasRenderer() {
  30312. console.error('THREE.CanvasRenderer has been removed');
  30313. } //
  30314. function JSONLoader() {
  30315. console.error('THREE.JSONLoader has been removed.');
  30316. } //
  30317. var SceneUtils = {
  30318. createMultiMaterialObject: function createMultiMaterialObject()
  30319. /* geometry, materials */
  30320. {
  30321. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30322. },
  30323. detach: function detach()
  30324. /* child, parent, scene */
  30325. {
  30326. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30327. },
  30328. attach: function attach()
  30329. /* child, scene, parent */
  30330. {
  30331. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30332. }
  30333. }; //
  30334. function LensFlare() {
  30335. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30336. }
  30337. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30338. /* eslint-disable no-undef */
  30339. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30340. detail: {
  30341. revision: REVISION
  30342. }
  30343. }));
  30344. /* eslint-enable no-undef */
  30345. }
  30346. if (typeof window !== 'undefined') {
  30347. if (window.__THREE__) {
  30348. console.warn('WARNING: Multiple instances of Three.js being imported.');
  30349. } else {
  30350. window.__THREE__ = REVISION;
  30351. }
  30352. }
  30353. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30354. exports.AddEquation = AddEquation;
  30355. exports.AddOperation = AddOperation;
  30356. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30357. exports.AdditiveBlending = AdditiveBlending;
  30358. exports.AlphaFormat = AlphaFormat;
  30359. exports.AlwaysDepth = AlwaysDepth;
  30360. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30361. exports.AmbientLight = AmbientLight;
  30362. exports.AmbientLightProbe = AmbientLightProbe;
  30363. exports.AnimationClip = AnimationClip;
  30364. exports.AnimationLoader = AnimationLoader;
  30365. exports.AnimationMixer = AnimationMixer;
  30366. exports.AnimationObjectGroup = AnimationObjectGroup;
  30367. exports.AnimationUtils = AnimationUtils;
  30368. exports.ArcCurve = ArcCurve;
  30369. exports.ArrayCamera = ArrayCamera;
  30370. exports.ArrowHelper = ArrowHelper;
  30371. exports.Audio = Audio;
  30372. exports.AudioAnalyser = AudioAnalyser;
  30373. exports.AudioContext = AudioContext;
  30374. exports.AudioListener = AudioListener;
  30375. exports.AudioLoader = AudioLoader;
  30376. exports.AxesHelper = AxesHelper;
  30377. exports.AxisHelper = AxisHelper;
  30378. exports.BackSide = BackSide;
  30379. exports.BasicDepthPacking = BasicDepthPacking;
  30380. exports.BasicShadowMap = BasicShadowMap;
  30381. exports.BinaryTextureLoader = BinaryTextureLoader;
  30382. exports.Bone = Bone;
  30383. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30384. exports.BoundingBoxHelper = BoundingBoxHelper;
  30385. exports.Box2 = Box2;
  30386. exports.Box3 = Box3;
  30387. exports.Box3Helper = Box3Helper;
  30388. exports.BoxBufferGeometry = BoxGeometry;
  30389. exports.BoxGeometry = BoxGeometry;
  30390. exports.BoxHelper = BoxHelper;
  30391. exports.BufferAttribute = BufferAttribute;
  30392. exports.BufferGeometry = BufferGeometry;
  30393. exports.BufferGeometryLoader = BufferGeometryLoader;
  30394. exports.ByteType = ByteType;
  30395. exports.Cache = Cache;
  30396. exports.Camera = Camera;
  30397. exports.CameraHelper = CameraHelper;
  30398. exports.CanvasRenderer = CanvasRenderer;
  30399. exports.CanvasTexture = CanvasTexture;
  30400. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30401. exports.CineonToneMapping = CineonToneMapping;
  30402. exports.CircleBufferGeometry = CircleGeometry;
  30403. exports.CircleGeometry = CircleGeometry;
  30404. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30405. exports.Clock = Clock;
  30406. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  30407. exports.Color = Color;
  30408. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30409. exports.CompressedTexture = CompressedTexture;
  30410. exports.CompressedTextureLoader = CompressedTextureLoader;
  30411. exports.ConeBufferGeometry = ConeGeometry;
  30412. exports.ConeGeometry = ConeGeometry;
  30413. exports.CubeCamera = CubeCamera;
  30414. exports.CubeReflectionMapping = CubeReflectionMapping;
  30415. exports.CubeRefractionMapping = CubeRefractionMapping;
  30416. exports.CubeTexture = CubeTexture;
  30417. exports.CubeTextureLoader = CubeTextureLoader;
  30418. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  30419. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  30420. exports.CubicBezierCurve = CubicBezierCurve;
  30421. exports.CubicBezierCurve3 = CubicBezierCurve3;
  30422. exports.CubicInterpolant = CubicInterpolant;
  30423. exports.CullFaceBack = CullFaceBack;
  30424. exports.CullFaceFront = CullFaceFront;
  30425. exports.CullFaceFrontBack = CullFaceFrontBack;
  30426. exports.CullFaceNone = CullFaceNone;
  30427. exports.Curve = Curve;
  30428. exports.CurvePath = CurvePath;
  30429. exports.CustomBlending = CustomBlending;
  30430. exports.CustomToneMapping = CustomToneMapping;
  30431. exports.CylinderBufferGeometry = CylinderGeometry;
  30432. exports.CylinderGeometry = CylinderGeometry;
  30433. exports.Cylindrical = Cylindrical;
  30434. exports.DataTexture = DataTexture;
  30435. exports.DataTexture2DArray = DataTexture2DArray;
  30436. exports.DataTexture3D = DataTexture3D;
  30437. exports.DataTextureLoader = DataTextureLoader;
  30438. exports.DataUtils = DataUtils;
  30439. exports.DecrementStencilOp = DecrementStencilOp;
  30440. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  30441. exports.DefaultLoadingManager = DefaultLoadingManager;
  30442. exports.DepthFormat = DepthFormat;
  30443. exports.DepthStencilFormat = DepthStencilFormat;
  30444. exports.DepthTexture = DepthTexture;
  30445. exports.DirectionalLight = DirectionalLight;
  30446. exports.DirectionalLightHelper = DirectionalLightHelper;
  30447. exports.DiscreteInterpolant = DiscreteInterpolant;
  30448. exports.DodecahedronBufferGeometry = DodecahedronGeometry;
  30449. exports.DodecahedronGeometry = DodecahedronGeometry;
  30450. exports.DoubleSide = DoubleSide;
  30451. exports.DstAlphaFactor = DstAlphaFactor;
  30452. exports.DstColorFactor = DstColorFactor;
  30453. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  30454. exports.DynamicCopyUsage = DynamicCopyUsage;
  30455. exports.DynamicDrawUsage = DynamicDrawUsage;
  30456. exports.DynamicReadUsage = DynamicReadUsage;
  30457. exports.EdgesGeometry = EdgesGeometry;
  30458. exports.EdgesHelper = EdgesHelper;
  30459. exports.EllipseCurve = EllipseCurve;
  30460. exports.EqualDepth = EqualDepth;
  30461. exports.EqualStencilFunc = EqualStencilFunc;
  30462. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  30463. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  30464. exports.Euler = Euler;
  30465. exports.EventDispatcher = EventDispatcher;
  30466. exports.ExtrudeBufferGeometry = ExtrudeGeometry;
  30467. exports.ExtrudeGeometry = ExtrudeGeometry;
  30468. exports.FaceColors = FaceColors;
  30469. exports.FileLoader = FileLoader;
  30470. exports.FlatShading = FlatShading;
  30471. exports.Float16BufferAttribute = Float16BufferAttribute;
  30472. exports.Float32Attribute = Float32Attribute;
  30473. exports.Float32BufferAttribute = Float32BufferAttribute;
  30474. exports.Float64Attribute = Float64Attribute;
  30475. exports.Float64BufferAttribute = Float64BufferAttribute;
  30476. exports.FloatType = FloatType;
  30477. exports.Fog = Fog;
  30478. exports.FogExp2 = FogExp2;
  30479. exports.Font = Font;
  30480. exports.FontLoader = FontLoader;
  30481. exports.FrontSide = FrontSide;
  30482. exports.Frustum = Frustum;
  30483. exports.GLBufferAttribute = GLBufferAttribute;
  30484. exports.GLSL1 = GLSL1;
  30485. exports.GLSL3 = GLSL3;
  30486. exports.GammaEncoding = GammaEncoding;
  30487. exports.GreaterDepth = GreaterDepth;
  30488. exports.GreaterEqualDepth = GreaterEqualDepth;
  30489. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  30490. exports.GreaterStencilFunc = GreaterStencilFunc;
  30491. exports.GridHelper = GridHelper;
  30492. exports.Group = Group;
  30493. exports.HalfFloatType = HalfFloatType;
  30494. exports.HemisphereLight = HemisphereLight;
  30495. exports.HemisphereLightHelper = HemisphereLightHelper;
  30496. exports.HemisphereLightProbe = HemisphereLightProbe;
  30497. exports.IcosahedronBufferGeometry = IcosahedronGeometry;
  30498. exports.IcosahedronGeometry = IcosahedronGeometry;
  30499. exports.ImageBitmapLoader = ImageBitmapLoader;
  30500. exports.ImageLoader = ImageLoader;
  30501. exports.ImageUtils = ImageUtils;
  30502. exports.ImmediateRenderObject = ImmediateRenderObject;
  30503. exports.IncrementStencilOp = IncrementStencilOp;
  30504. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  30505. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  30506. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  30507. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  30508. exports.InstancedMesh = InstancedMesh;
  30509. exports.Int16Attribute = Int16Attribute;
  30510. exports.Int16BufferAttribute = Int16BufferAttribute;
  30511. exports.Int32Attribute = Int32Attribute;
  30512. exports.Int32BufferAttribute = Int32BufferAttribute;
  30513. exports.Int8Attribute = Int8Attribute;
  30514. exports.Int8BufferAttribute = Int8BufferAttribute;
  30515. exports.IntType = IntType;
  30516. exports.InterleavedBuffer = InterleavedBuffer;
  30517. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  30518. exports.Interpolant = Interpolant;
  30519. exports.InterpolateDiscrete = InterpolateDiscrete;
  30520. exports.InterpolateLinear = InterpolateLinear;
  30521. exports.InterpolateSmooth = InterpolateSmooth;
  30522. exports.InvertStencilOp = InvertStencilOp;
  30523. exports.JSONLoader = JSONLoader;
  30524. exports.KeepStencilOp = KeepStencilOp;
  30525. exports.KeyframeTrack = KeyframeTrack;
  30526. exports.LOD = LOD;
  30527. exports.LatheBufferGeometry = LatheGeometry;
  30528. exports.LatheGeometry = LatheGeometry;
  30529. exports.Layers = Layers;
  30530. exports.LensFlare = LensFlare;
  30531. exports.LessDepth = LessDepth;
  30532. exports.LessEqualDepth = LessEqualDepth;
  30533. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  30534. exports.LessStencilFunc = LessStencilFunc;
  30535. exports.Light = Light;
  30536. exports.LightProbe = LightProbe;
  30537. exports.Line = Line;
  30538. exports.Line3 = Line3;
  30539. exports.LineBasicMaterial = LineBasicMaterial;
  30540. exports.LineCurve = LineCurve;
  30541. exports.LineCurve3 = LineCurve3;
  30542. exports.LineDashedMaterial = LineDashedMaterial;
  30543. exports.LineLoop = LineLoop;
  30544. exports.LinePieces = LinePieces;
  30545. exports.LineSegments = LineSegments;
  30546. exports.LineStrip = LineStrip;
  30547. exports.LinearEncoding = LinearEncoding;
  30548. exports.LinearFilter = LinearFilter;
  30549. exports.LinearInterpolant = LinearInterpolant;
  30550. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  30551. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  30552. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  30553. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  30554. exports.LinearToneMapping = LinearToneMapping;
  30555. exports.Loader = Loader;
  30556. exports.LoaderUtils = LoaderUtils;
  30557. exports.LoadingManager = LoadingManager;
  30558. exports.LogLuvEncoding = LogLuvEncoding;
  30559. exports.LoopOnce = LoopOnce;
  30560. exports.LoopPingPong = LoopPingPong;
  30561. exports.LoopRepeat = LoopRepeat;
  30562. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  30563. exports.LuminanceFormat = LuminanceFormat;
  30564. exports.MOUSE = MOUSE;
  30565. exports.Material = Material;
  30566. exports.MaterialLoader = MaterialLoader;
  30567. exports.Math = MathUtils;
  30568. exports.MathUtils = MathUtils;
  30569. exports.Matrix3 = Matrix3;
  30570. exports.Matrix4 = Matrix4;
  30571. exports.MaxEquation = MaxEquation;
  30572. exports.Mesh = Mesh;
  30573. exports.MeshBasicMaterial = MeshBasicMaterial;
  30574. exports.MeshDepthMaterial = MeshDepthMaterial;
  30575. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  30576. exports.MeshFaceMaterial = MeshFaceMaterial;
  30577. exports.MeshLambertMaterial = MeshLambertMaterial;
  30578. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  30579. exports.MeshNormalMaterial = MeshNormalMaterial;
  30580. exports.MeshPhongMaterial = MeshPhongMaterial;
  30581. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  30582. exports.MeshStandardMaterial = MeshStandardMaterial;
  30583. exports.MeshToonMaterial = MeshToonMaterial;
  30584. exports.MinEquation = MinEquation;
  30585. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  30586. exports.MixOperation = MixOperation;
  30587. exports.MultiMaterial = MultiMaterial;
  30588. exports.MultiplyBlending = MultiplyBlending;
  30589. exports.MultiplyOperation = MultiplyOperation;
  30590. exports.NearestFilter = NearestFilter;
  30591. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  30592. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  30593. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  30594. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  30595. exports.NeverDepth = NeverDepth;
  30596. exports.NeverStencilFunc = NeverStencilFunc;
  30597. exports.NoBlending = NoBlending;
  30598. exports.NoColors = NoColors;
  30599. exports.NoToneMapping = NoToneMapping;
  30600. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  30601. exports.NormalBlending = NormalBlending;
  30602. exports.NotEqualDepth = NotEqualDepth;
  30603. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  30604. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  30605. exports.Object3D = Object3D;
  30606. exports.ObjectLoader = ObjectLoader;
  30607. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  30608. exports.OctahedronBufferGeometry = OctahedronGeometry;
  30609. exports.OctahedronGeometry = OctahedronGeometry;
  30610. exports.OneFactor = OneFactor;
  30611. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  30612. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  30613. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  30614. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  30615. exports.OrthographicCamera = OrthographicCamera;
  30616. exports.PCFShadowMap = PCFShadowMap;
  30617. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  30618. exports.PMREMGenerator = PMREMGenerator;
  30619. exports.ParametricBufferGeometry = ParametricGeometry;
  30620. exports.ParametricGeometry = ParametricGeometry;
  30621. exports.Particle = Particle;
  30622. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  30623. exports.ParticleSystem = ParticleSystem;
  30624. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  30625. exports.Path = Path;
  30626. exports.PerspectiveCamera = PerspectiveCamera;
  30627. exports.Plane = Plane;
  30628. exports.PlaneBufferGeometry = PlaneGeometry;
  30629. exports.PlaneGeometry = PlaneGeometry;
  30630. exports.PlaneHelper = PlaneHelper;
  30631. exports.PointCloud = PointCloud;
  30632. exports.PointCloudMaterial = PointCloudMaterial;
  30633. exports.PointLight = PointLight;
  30634. exports.PointLightHelper = PointLightHelper;
  30635. exports.Points = Points;
  30636. exports.PointsMaterial = PointsMaterial;
  30637. exports.PolarGridHelper = PolarGridHelper;
  30638. exports.PolyhedronBufferGeometry = PolyhedronGeometry;
  30639. exports.PolyhedronGeometry = PolyhedronGeometry;
  30640. exports.PositionalAudio = PositionalAudio;
  30641. exports.PropertyBinding = PropertyBinding;
  30642. exports.PropertyMixer = PropertyMixer;
  30643. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  30644. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  30645. exports.Quaternion = Quaternion;
  30646. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  30647. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  30648. exports.REVISION = REVISION;
  30649. exports.RGBADepthPacking = RGBADepthPacking;
  30650. exports.RGBAFormat = RGBAFormat;
  30651. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  30652. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  30653. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  30654. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  30655. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  30656. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  30657. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  30658. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  30659. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  30660. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  30661. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  30662. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  30663. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  30664. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  30665. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  30666. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  30667. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  30668. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  30669. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  30670. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  30671. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  30672. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  30673. exports.RGBDEncoding = RGBDEncoding;
  30674. exports.RGBEEncoding = RGBEEncoding;
  30675. exports.RGBEFormat = RGBEFormat;
  30676. exports.RGBFormat = RGBFormat;
  30677. exports.RGBIntegerFormat = RGBIntegerFormat;
  30678. exports.RGBM16Encoding = RGBM16Encoding;
  30679. exports.RGBM7Encoding = RGBM7Encoding;
  30680. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  30681. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  30682. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  30683. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  30684. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  30685. exports.RGFormat = RGFormat;
  30686. exports.RGIntegerFormat = RGIntegerFormat;
  30687. exports.RawShaderMaterial = RawShaderMaterial;
  30688. exports.Ray = Ray;
  30689. exports.Raycaster = Raycaster;
  30690. exports.RectAreaLight = RectAreaLight;
  30691. exports.RedFormat = RedFormat;
  30692. exports.RedIntegerFormat = RedIntegerFormat;
  30693. exports.ReinhardToneMapping = ReinhardToneMapping;
  30694. exports.RepeatWrapping = RepeatWrapping;
  30695. exports.ReplaceStencilOp = ReplaceStencilOp;
  30696. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  30697. exports.RingBufferGeometry = RingGeometry;
  30698. exports.RingGeometry = RingGeometry;
  30699. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  30700. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  30701. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  30702. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  30703. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  30704. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  30705. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  30706. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  30707. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  30708. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  30709. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  30710. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  30711. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  30712. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  30713. exports.Scene = Scene;
  30714. exports.SceneUtils = SceneUtils;
  30715. exports.ShaderChunk = ShaderChunk;
  30716. exports.ShaderLib = ShaderLib;
  30717. exports.ShaderMaterial = ShaderMaterial;
  30718. exports.ShadowMaterial = ShadowMaterial;
  30719. exports.Shape = Shape;
  30720. exports.ShapeBufferGeometry = ShapeGeometry;
  30721. exports.ShapeGeometry = ShapeGeometry;
  30722. exports.ShapePath = ShapePath;
  30723. exports.ShapeUtils = ShapeUtils;
  30724. exports.ShortType = ShortType;
  30725. exports.Skeleton = Skeleton;
  30726. exports.SkeletonHelper = SkeletonHelper;
  30727. exports.SkinnedMesh = SkinnedMesh;
  30728. exports.SmoothShading = SmoothShading;
  30729. exports.Sphere = Sphere;
  30730. exports.SphereBufferGeometry = SphereGeometry;
  30731. exports.SphereGeometry = SphereGeometry;
  30732. exports.Spherical = Spherical;
  30733. exports.SphericalHarmonics3 = SphericalHarmonics3;
  30734. exports.Spline = Spline;
  30735. exports.SplineCurve = SplineCurve;
  30736. exports.SplineCurve3 = SplineCurve3;
  30737. exports.SpotLight = SpotLight;
  30738. exports.SpotLightHelper = SpotLightHelper;
  30739. exports.Sprite = Sprite;
  30740. exports.SpriteMaterial = SpriteMaterial;
  30741. exports.SrcAlphaFactor = SrcAlphaFactor;
  30742. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  30743. exports.SrcColorFactor = SrcColorFactor;
  30744. exports.StaticCopyUsage = StaticCopyUsage;
  30745. exports.StaticDrawUsage = StaticDrawUsage;
  30746. exports.StaticReadUsage = StaticReadUsage;
  30747. exports.StereoCamera = StereoCamera;
  30748. exports.StreamCopyUsage = StreamCopyUsage;
  30749. exports.StreamDrawUsage = StreamDrawUsage;
  30750. exports.StreamReadUsage = StreamReadUsage;
  30751. exports.StringKeyframeTrack = StringKeyframeTrack;
  30752. exports.SubtractEquation = SubtractEquation;
  30753. exports.SubtractiveBlending = SubtractiveBlending;
  30754. exports.TOUCH = TOUCH;
  30755. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  30756. exports.TetrahedronBufferGeometry = TetrahedronGeometry;
  30757. exports.TetrahedronGeometry = TetrahedronGeometry;
  30758. exports.TextBufferGeometry = TextGeometry;
  30759. exports.TextGeometry = TextGeometry;
  30760. exports.Texture = Texture;
  30761. exports.TextureLoader = TextureLoader;
  30762. exports.TorusBufferGeometry = TorusGeometry;
  30763. exports.TorusGeometry = TorusGeometry;
  30764. exports.TorusKnotBufferGeometry = TorusKnotGeometry;
  30765. exports.TorusKnotGeometry = TorusKnotGeometry;
  30766. exports.Triangle = Triangle;
  30767. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  30768. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  30769. exports.TrianglesDrawMode = TrianglesDrawMode;
  30770. exports.TubeBufferGeometry = TubeGeometry;
  30771. exports.TubeGeometry = TubeGeometry;
  30772. exports.UVMapping = UVMapping;
  30773. exports.Uint16Attribute = Uint16Attribute;
  30774. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  30775. exports.Uint32Attribute = Uint32Attribute;
  30776. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  30777. exports.Uint8Attribute = Uint8Attribute;
  30778. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  30779. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  30780. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  30781. exports.Uniform = Uniform;
  30782. exports.UniformsLib = UniformsLib;
  30783. exports.UniformsUtils = UniformsUtils;
  30784. exports.UnsignedByteType = UnsignedByteType;
  30785. exports.UnsignedInt248Type = UnsignedInt248Type;
  30786. exports.UnsignedIntType = UnsignedIntType;
  30787. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  30788. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  30789. exports.UnsignedShort565Type = UnsignedShort565Type;
  30790. exports.UnsignedShortType = UnsignedShortType;
  30791. exports.VSMShadowMap = VSMShadowMap;
  30792. exports.Vector2 = Vector2;
  30793. exports.Vector3 = Vector3;
  30794. exports.Vector4 = Vector4;
  30795. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  30796. exports.Vertex = Vertex;
  30797. exports.VertexColors = VertexColors;
  30798. exports.VideoTexture = VideoTexture;
  30799. exports.WebGL1Renderer = WebGL1Renderer;
  30800. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  30801. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  30802. exports.WebGLRenderTarget = WebGLRenderTarget;
  30803. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  30804. exports.WebGLRenderer = WebGLRenderer;
  30805. exports.WebGLUtils = WebGLUtils;
  30806. exports.WireframeGeometry = WireframeGeometry;
  30807. exports.WireframeHelper = WireframeHelper;
  30808. exports.WrapAroundEnding = WrapAroundEnding;
  30809. exports.XHRLoader = XHRLoader;
  30810. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  30811. exports.ZeroFactor = ZeroFactor;
  30812. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  30813. exports.ZeroStencilOp = ZeroStencilOp;
  30814. exports.sRGBEncoding = sRGBEncoding;
  30815. Object.defineProperty(exports, '__esModule', { value: true });
  30816. })));