three.js 1.2 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279
  1. // threejs.org/license
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.THREE = {}));
  6. }(this, (function (exports) { 'use strict';
  7. // Polyfills
  8. if (Number.EPSILON === undefined) {
  9. Number.EPSILON = Math.pow(2, -52);
  10. }
  11. if (Number.isInteger === undefined) {
  12. // Missing in IE
  13. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  14. Number.isInteger = function (value) {
  15. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  16. };
  17. } //
  18. if (Math.sign === undefined) {
  19. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  20. Math.sign = function (x) {
  21. return x < 0 ? -1 : x > 0 ? 1 : +x;
  22. };
  23. }
  24. if ('name' in Function.prototype === false) {
  25. // Missing in IE
  26. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  27. Object.defineProperty(Function.prototype, 'name', {
  28. get: function get() {
  29. return this.toString().match(/^\s*function\s*([^\(\s]*)/)[1];
  30. }
  31. });
  32. }
  33. if (Object.assign === undefined) {
  34. // Missing in IE
  35. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  36. Object.assign = function (target) {
  37. if (target === undefined || target === null) {
  38. throw new TypeError('Cannot convert undefined or null to object');
  39. }
  40. var output = Object(target);
  41. for (var index = 1; index < arguments.length; index++) {
  42. var source = arguments[index];
  43. if (source !== undefined && source !== null) {
  44. for (var nextKey in source) {
  45. if (Object.prototype.hasOwnProperty.call(source, nextKey)) {
  46. output[nextKey] = source[nextKey];
  47. }
  48. }
  49. }
  50. }
  51. return output;
  52. };
  53. }
  54. /**
  55. * Copyright (c) 2014-present, Facebook, Inc.
  56. *
  57. * This source code is licensed under the MIT license found in the
  58. * LICENSE file in the root directory of this source tree.
  59. */
  60. var runtime = function (exports) {
  61. var Op = Object.prototype;
  62. var hasOwn = Op.hasOwnProperty;
  63. var undefined$1; // More compressible than void 0.
  64. var $Symbol = typeof Symbol === "function" ? Symbol : {};
  65. var iteratorSymbol = $Symbol.iterator || "@@iterator";
  66. var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
  67. var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  68. function define(obj, key, value) {
  69. Object.defineProperty(obj, key, {
  70. value: value,
  71. enumerable: true,
  72. configurable: true,
  73. writable: true
  74. });
  75. return obj[key];
  76. }
  77. try {
  78. // IE 8 has a broken Object.defineProperty that only works on DOM objects.
  79. define({}, "");
  80. } catch (err) {
  81. define = function define(obj, key, value) {
  82. return obj[key] = value;
  83. };
  84. }
  85. function wrap(innerFn, outerFn, self, tryLocsList) {
  86. // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
  87. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
  88. var generator = Object.create(protoGenerator.prototype);
  89. var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
  90. // .throw, and .return methods.
  91. generator._invoke = makeInvokeMethod(innerFn, self, context);
  92. return generator;
  93. }
  94. exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
  95. // record like context.tryEntries[i].completion. This interface could
  96. // have been (and was previously) designed to take a closure to be
  97. // invoked without arguments, but in all the cases we care about we
  98. // already have an existing method we want to call, so there's no need
  99. // to create a new function object. We can even get away with assuming
  100. // the method takes exactly one argument, since that happens to be true
  101. // in every case, so we don't have to touch the arguments object. The
  102. // only additional allocation required is the completion record, which
  103. // has a stable shape and so hopefully should be cheap to allocate.
  104. function tryCatch(fn, obj, arg) {
  105. try {
  106. return {
  107. type: "normal",
  108. arg: fn.call(obj, arg)
  109. };
  110. } catch (err) {
  111. return {
  112. type: "throw",
  113. arg: err
  114. };
  115. }
  116. }
  117. var GenStateSuspendedStart = "suspendedStart";
  118. var GenStateSuspendedYield = "suspendedYield";
  119. var GenStateExecuting = "executing";
  120. var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
  121. // breaking out of the dispatch switch statement.
  122. var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
  123. // .constructor.prototype properties for functions that return Generator
  124. // objects. For full spec compliance, you may wish to configure your
  125. // minifier not to mangle the names of these two functions.
  126. function Generator() {}
  127. function GeneratorFunction() {}
  128. function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
  129. // don't natively support it.
  130. var IteratorPrototype = {};
  131. IteratorPrototype[iteratorSymbol] = function () {
  132. return this;
  133. };
  134. var getProto = Object.getPrototypeOf;
  135. var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  136. if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
  137. // This environment has a native %IteratorPrototype%; use it instead
  138. // of the polyfill.
  139. IteratorPrototype = NativeIteratorPrototype;
  140. }
  141. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  142. GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
  143. GeneratorFunctionPrototype.constructor = GeneratorFunction;
  144. GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
  145. // Iterator interface in terms of a single ._invoke method.
  146. function defineIteratorMethods(prototype) {
  147. ["next", "throw", "return"].forEach(function (method) {
  148. define(prototype, method, function (arg) {
  149. return this._invoke(method, arg);
  150. });
  151. });
  152. }
  153. exports.isGeneratorFunction = function (genFun) {
  154. var ctor = typeof genFun === "function" && genFun.constructor;
  155. return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
  156. // do is to check its .name property.
  157. (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
  158. };
  159. exports.mark = function (genFun) {
  160. if (Object.setPrototypeOf) {
  161. Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
  162. } else {
  163. genFun.__proto__ = GeneratorFunctionPrototype;
  164. define(genFun, toStringTagSymbol, "GeneratorFunction");
  165. }
  166. genFun.prototype = Object.create(Gp);
  167. return genFun;
  168. }; // Within the body of any async function, `await x` is transformed to
  169. // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
  170. // `hasOwn.call(value, "__await")` to determine if the yielded value is
  171. // meant to be awaited.
  172. exports.awrap = function (arg) {
  173. return {
  174. __await: arg
  175. };
  176. };
  177. function AsyncIterator(generator, PromiseImpl) {
  178. function invoke(method, arg, resolve, reject) {
  179. var record = tryCatch(generator[method], generator, arg);
  180. if (record.type === "throw") {
  181. reject(record.arg);
  182. } else {
  183. var result = record.arg;
  184. var value = result.value;
  185. if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
  186. return PromiseImpl.resolve(value.__await).then(function (value) {
  187. invoke("next", value, resolve, reject);
  188. }, function (err) {
  189. invoke("throw", err, resolve, reject);
  190. });
  191. }
  192. return PromiseImpl.resolve(value).then(function (unwrapped) {
  193. // When a yielded Promise is resolved, its final value becomes
  194. // the .value of the Promise<{value,done}> result for the
  195. // current iteration.
  196. result.value = unwrapped;
  197. resolve(result);
  198. }, function (error) {
  199. // If a rejected Promise was yielded, throw the rejection back
  200. // into the async generator function so it can be handled there.
  201. return invoke("throw", error, resolve, reject);
  202. });
  203. }
  204. }
  205. var previousPromise;
  206. function enqueue(method, arg) {
  207. function callInvokeWithMethodAndArg() {
  208. return new PromiseImpl(function (resolve, reject) {
  209. invoke(method, arg, resolve, reject);
  210. });
  211. }
  212. return previousPromise = // If enqueue has been called before, then we want to wait until
  213. // all previous Promises have been resolved before calling invoke,
  214. // so that results are always delivered in the correct order. If
  215. // enqueue has not been called before, then it is important to
  216. // call invoke immediately, without waiting on a callback to fire,
  217. // so that the async generator function has the opportunity to do
  218. // any necessary setup in a predictable way. This predictability
  219. // is why the Promise constructor synchronously invokes its
  220. // executor callback, and why async functions synchronously
  221. // execute code before the first await. Since we implement simple
  222. // async functions in terms of async generators, it is especially
  223. // important to get this right, even though it requires care.
  224. previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
  225. // invocations of the iterator.
  226. callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  227. } // Define the unified helper method that is used to implement .next,
  228. // .throw, and .return (see defineIteratorMethods).
  229. this._invoke = enqueue;
  230. }
  231. defineIteratorMethods(AsyncIterator.prototype);
  232. AsyncIterator.prototype[asyncIteratorSymbol] = function () {
  233. return this;
  234. };
  235. exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
  236. // AsyncIterator objects; they just return a Promise for the value of
  237. // the final result produced by the iterator.
  238. exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  239. if (PromiseImpl === void 0) PromiseImpl = Promise;
  240. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  241. return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
  242. : iter.next().then(function (result) {
  243. return result.done ? result.value : iter.next();
  244. });
  245. };
  246. function makeInvokeMethod(innerFn, self, context) {
  247. var state = GenStateSuspendedStart;
  248. return function invoke(method, arg) {
  249. if (state === GenStateExecuting) {
  250. throw new Error("Generator is already running");
  251. }
  252. if (state === GenStateCompleted) {
  253. if (method === "throw") {
  254. throw arg;
  255. } // Be forgiving, per 25.3.3.3.3 of the spec:
  256. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
  257. return doneResult();
  258. }
  259. context.method = method;
  260. context.arg = arg;
  261. while (true) {
  262. var delegate = context.delegate;
  263. if (delegate) {
  264. var delegateResult = maybeInvokeDelegate(delegate, context);
  265. if (delegateResult) {
  266. if (delegateResult === ContinueSentinel) continue;
  267. return delegateResult;
  268. }
  269. }
  270. if (context.method === "next") {
  271. // Setting context._sent for legacy support of Babel's
  272. // function.sent implementation.
  273. context.sent = context._sent = context.arg;
  274. } else if (context.method === "throw") {
  275. if (state === GenStateSuspendedStart) {
  276. state = GenStateCompleted;
  277. throw context.arg;
  278. }
  279. context.dispatchException(context.arg);
  280. } else if (context.method === "return") {
  281. context.abrupt("return", context.arg);
  282. }
  283. state = GenStateExecuting;
  284. var record = tryCatch(innerFn, self, context);
  285. if (record.type === "normal") {
  286. // If an exception is thrown from innerFn, we leave state ===
  287. // GenStateExecuting and loop back for another invocation.
  288. state = context.done ? GenStateCompleted : GenStateSuspendedYield;
  289. if (record.arg === ContinueSentinel) {
  290. continue;
  291. }
  292. return {
  293. value: record.arg,
  294. done: context.done
  295. };
  296. } else if (record.type === "throw") {
  297. state = GenStateCompleted; // Dispatch the exception by looping back around to the
  298. // context.dispatchException(context.arg) call above.
  299. context.method = "throw";
  300. context.arg = record.arg;
  301. }
  302. }
  303. };
  304. } // Call delegate.iterator[context.method](context.arg) and handle the
  305. // result, either by returning a { value, done } result from the
  306. // delegate iterator, or by modifying context.method and context.arg,
  307. // setting context.delegate to null, and returning the ContinueSentinel.
  308. function maybeInvokeDelegate(delegate, context) {
  309. var method = delegate.iterator[context.method];
  310. if (method === undefined$1) {
  311. // A .throw or .return when the delegate iterator has no .throw
  312. // method always terminates the yield* loop.
  313. context.delegate = null;
  314. if (context.method === "throw") {
  315. // Note: ["return"] must be used for ES3 parsing compatibility.
  316. if (delegate.iterator["return"]) {
  317. // If the delegate iterator has a return method, give it a
  318. // chance to clean up.
  319. context.method = "return";
  320. context.arg = undefined$1;
  321. maybeInvokeDelegate(delegate, context);
  322. if (context.method === "throw") {
  323. // If maybeInvokeDelegate(context) changed context.method from
  324. // "return" to "throw", let that override the TypeError below.
  325. return ContinueSentinel;
  326. }
  327. }
  328. context.method = "throw";
  329. context.arg = new TypeError("The iterator does not provide a 'throw' method");
  330. }
  331. return ContinueSentinel;
  332. }
  333. var record = tryCatch(method, delegate.iterator, context.arg);
  334. if (record.type === "throw") {
  335. context.method = "throw";
  336. context.arg = record.arg;
  337. context.delegate = null;
  338. return ContinueSentinel;
  339. }
  340. var info = record.arg;
  341. if (!info) {
  342. context.method = "throw";
  343. context.arg = new TypeError("iterator result is not an object");
  344. context.delegate = null;
  345. return ContinueSentinel;
  346. }
  347. if (info.done) {
  348. // Assign the result of the finished delegate to the temporary
  349. // variable specified by delegate.resultName (see delegateYield).
  350. context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
  351. context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
  352. // exception, let the outer generator proceed normally. If
  353. // context.method was "next", forget context.arg since it has been
  354. // "consumed" by the delegate iterator. If context.method was
  355. // "return", allow the original .return call to continue in the
  356. // outer generator.
  357. if (context.method !== "return") {
  358. context.method = "next";
  359. context.arg = undefined$1;
  360. }
  361. } else {
  362. // Re-yield the result returned by the delegate method.
  363. return info;
  364. } // The delegate iterator is finished, so forget it and continue with
  365. // the outer generator.
  366. context.delegate = null;
  367. return ContinueSentinel;
  368. } // Define Generator.prototype.{next,throw,return} in terms of the
  369. // unified ._invoke helper method.
  370. defineIteratorMethods(Gp);
  371. define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
  372. // @@iterator function is called on it. Some browsers' implementations of the
  373. // iterator prototype chain incorrectly implement this, causing the Generator
  374. // object to not be returned from this call. This ensures that doesn't happen.
  375. // See https://github.com/facebook/regenerator/issues/274 for more details.
  376. Gp[iteratorSymbol] = function () {
  377. return this;
  378. };
  379. Gp.toString = function () {
  380. return "[object Generator]";
  381. };
  382. function pushTryEntry(locs) {
  383. var entry = {
  384. tryLoc: locs[0]
  385. };
  386. if (1 in locs) {
  387. entry.catchLoc = locs[1];
  388. }
  389. if (2 in locs) {
  390. entry.finallyLoc = locs[2];
  391. entry.afterLoc = locs[3];
  392. }
  393. this.tryEntries.push(entry);
  394. }
  395. function resetTryEntry(entry) {
  396. var record = entry.completion || {};
  397. record.type = "normal";
  398. delete record.arg;
  399. entry.completion = record;
  400. }
  401. function Context(tryLocsList) {
  402. // The root entry object (effectively a try statement without a catch
  403. // or a finally block) gives us a place to store values thrown from
  404. // locations where there is no enclosing try statement.
  405. this.tryEntries = [{
  406. tryLoc: "root"
  407. }];
  408. tryLocsList.forEach(pushTryEntry, this);
  409. this.reset(true);
  410. }
  411. exports.keys = function (object) {
  412. var keys = [];
  413. for (var key in object) {
  414. keys.push(key);
  415. }
  416. keys.reverse(); // Rather than returning an object with a next method, we keep
  417. // things simple and return the next function itself.
  418. return function next() {
  419. while (keys.length) {
  420. var key = keys.pop();
  421. if (key in object) {
  422. next.value = key;
  423. next.done = false;
  424. return next;
  425. }
  426. } // To avoid creating an additional object, we just hang the .value
  427. // and .done properties off the next function object itself. This
  428. // also ensures that the minifier will not anonymize the function.
  429. next.done = true;
  430. return next;
  431. };
  432. };
  433. function values(iterable) {
  434. if (iterable) {
  435. var iteratorMethod = iterable[iteratorSymbol];
  436. if (iteratorMethod) {
  437. return iteratorMethod.call(iterable);
  438. }
  439. if (typeof iterable.next === "function") {
  440. return iterable;
  441. }
  442. if (!isNaN(iterable.length)) {
  443. var i = -1,
  444. next = function next() {
  445. while (++i < iterable.length) {
  446. if (hasOwn.call(iterable, i)) {
  447. next.value = iterable[i];
  448. next.done = false;
  449. return next;
  450. }
  451. }
  452. next.value = undefined$1;
  453. next.done = true;
  454. return next;
  455. };
  456. return next.next = next;
  457. }
  458. } // Return an iterator with no values.
  459. return {
  460. next: doneResult
  461. };
  462. }
  463. exports.values = values;
  464. function doneResult() {
  465. return {
  466. value: undefined$1,
  467. done: true
  468. };
  469. }
  470. Context.prototype = {
  471. constructor: Context,
  472. reset: function reset(skipTempReset) {
  473. this.prev = 0;
  474. this.next = 0; // Resetting context._sent for legacy support of Babel's
  475. // function.sent implementation.
  476. this.sent = this._sent = undefined$1;
  477. this.done = false;
  478. this.delegate = null;
  479. this.method = "next";
  480. this.arg = undefined$1;
  481. this.tryEntries.forEach(resetTryEntry);
  482. if (!skipTempReset) {
  483. for (var name in this) {
  484. // Not sure about the optimal order of these conditions:
  485. if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
  486. this[name] = undefined$1;
  487. }
  488. }
  489. }
  490. },
  491. stop: function stop() {
  492. this.done = true;
  493. var rootEntry = this.tryEntries[0];
  494. var rootRecord = rootEntry.completion;
  495. if (rootRecord.type === "throw") {
  496. throw rootRecord.arg;
  497. }
  498. return this.rval;
  499. },
  500. dispatchException: function dispatchException(exception) {
  501. if (this.done) {
  502. throw exception;
  503. }
  504. var context = this;
  505. function handle(loc, caught) {
  506. record.type = "throw";
  507. record.arg = exception;
  508. context.next = loc;
  509. if (caught) {
  510. // If the dispatched exception was caught by a catch block,
  511. // then let that catch block handle the exception normally.
  512. context.method = "next";
  513. context.arg = undefined$1;
  514. }
  515. return !!caught;
  516. }
  517. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  518. var entry = this.tryEntries[i];
  519. var record = entry.completion;
  520. if (entry.tryLoc === "root") {
  521. // Exception thrown outside of any try block that could handle
  522. // it, so set the completion value of the entire function to
  523. // throw the exception.
  524. return handle("end");
  525. }
  526. if (entry.tryLoc <= this.prev) {
  527. var hasCatch = hasOwn.call(entry, "catchLoc");
  528. var hasFinally = hasOwn.call(entry, "finallyLoc");
  529. if (hasCatch && hasFinally) {
  530. if (this.prev < entry.catchLoc) {
  531. return handle(entry.catchLoc, true);
  532. } else if (this.prev < entry.finallyLoc) {
  533. return handle(entry.finallyLoc);
  534. }
  535. } else if (hasCatch) {
  536. if (this.prev < entry.catchLoc) {
  537. return handle(entry.catchLoc, true);
  538. }
  539. } else if (hasFinally) {
  540. if (this.prev < entry.finallyLoc) {
  541. return handle(entry.finallyLoc);
  542. }
  543. } else {
  544. throw new Error("try statement without catch or finally");
  545. }
  546. }
  547. }
  548. },
  549. abrupt: function abrupt(type, arg) {
  550. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  551. var entry = this.tryEntries[i];
  552. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  553. var finallyEntry = entry;
  554. break;
  555. }
  556. }
  557. if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
  558. // Ignore the finally entry if control is not jumping to a
  559. // location outside the try/catch block.
  560. finallyEntry = null;
  561. }
  562. var record = finallyEntry ? finallyEntry.completion : {};
  563. record.type = type;
  564. record.arg = arg;
  565. if (finallyEntry) {
  566. this.method = "next";
  567. this.next = finallyEntry.finallyLoc;
  568. return ContinueSentinel;
  569. }
  570. return this.complete(record);
  571. },
  572. complete: function complete(record, afterLoc) {
  573. if (record.type === "throw") {
  574. throw record.arg;
  575. }
  576. if (record.type === "break" || record.type === "continue") {
  577. this.next = record.arg;
  578. } else if (record.type === "return") {
  579. this.rval = this.arg = record.arg;
  580. this.method = "return";
  581. this.next = "end";
  582. } else if (record.type === "normal" && afterLoc) {
  583. this.next = afterLoc;
  584. }
  585. return ContinueSentinel;
  586. },
  587. finish: function finish(finallyLoc) {
  588. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  589. var entry = this.tryEntries[i];
  590. if (entry.finallyLoc === finallyLoc) {
  591. this.complete(entry.completion, entry.afterLoc);
  592. resetTryEntry(entry);
  593. return ContinueSentinel;
  594. }
  595. }
  596. },
  597. "catch": function _catch(tryLoc) {
  598. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  599. var entry = this.tryEntries[i];
  600. if (entry.tryLoc === tryLoc) {
  601. var record = entry.completion;
  602. if (record.type === "throw") {
  603. var thrown = record.arg;
  604. resetTryEntry(entry);
  605. }
  606. return thrown;
  607. }
  608. } // The context.catch method must only be called with a location
  609. // argument that corresponds to a known catch block.
  610. throw new Error("illegal catch attempt");
  611. },
  612. delegateYield: function delegateYield(iterable, resultName, nextLoc) {
  613. this.delegate = {
  614. iterator: values(iterable),
  615. resultName: resultName,
  616. nextLoc: nextLoc
  617. };
  618. if (this.method === "next") {
  619. // Deliberately forget the last sent value so that we don't
  620. // accidentally pass it on to the delegate.
  621. this.arg = undefined$1;
  622. }
  623. return ContinueSentinel;
  624. }
  625. }; // Regardless of whether this script is executing as a CommonJS module
  626. // or not, return the runtime object so that we can declare the variable
  627. // regeneratorRuntime in the outer scope, which allows this module to be
  628. // injected easily by `bin/regenerator --include-runtime script.js`.
  629. return exports;
  630. }( // If this script is executing as a CommonJS module, use module.exports
  631. // as the regeneratorRuntime namespace. Otherwise create a new empty
  632. // object. Either way, the resulting object will be used to initialize
  633. // the regeneratorRuntime variable at the top of this file.
  634. typeof module === "object" ? module.exports : {});
  635. try {
  636. regeneratorRuntime = runtime;
  637. } catch (accidentalStrictMode) {
  638. // This module should not be running in strict mode, so the above
  639. // assignment should always work unless something is misconfigured. Just
  640. // in case runtime.js accidentally runs in strict mode, we can escape
  641. // strict mode using a global Function call. This could conceivably fail
  642. // if a Content Security Policy forbids using Function, but in that case
  643. // the proper solution is to fix the accidental strict mode problem. If
  644. // you've misconfigured your bundler to force strict mode and applied a
  645. // CSP to forbid Function, and you're not willing to fix either of those
  646. // problems, please detail your unique predicament in a GitHub issue.
  647. Function("r", "regeneratorRuntime = r")(runtime);
  648. }
  649. var REVISION = '125dev';
  650. var MOUSE = {
  651. LEFT: 0,
  652. MIDDLE: 1,
  653. RIGHT: 2,
  654. ROTATE: 0,
  655. DOLLY: 1,
  656. PAN: 2
  657. };
  658. var TOUCH = {
  659. ROTATE: 0,
  660. PAN: 1,
  661. DOLLY_PAN: 2,
  662. DOLLY_ROTATE: 3
  663. };
  664. var CullFaceNone = 0;
  665. var CullFaceBack = 1;
  666. var CullFaceFront = 2;
  667. var CullFaceFrontBack = 3;
  668. var BasicShadowMap = 0;
  669. var PCFShadowMap = 1;
  670. var PCFSoftShadowMap = 2;
  671. var VSMShadowMap = 3;
  672. var FrontSide = 0;
  673. var BackSide = 1;
  674. var DoubleSide = 2;
  675. var FlatShading = 1;
  676. var SmoothShading = 2;
  677. var NoBlending = 0;
  678. var NormalBlending = 1;
  679. var AdditiveBlending = 2;
  680. var SubtractiveBlending = 3;
  681. var MultiplyBlending = 4;
  682. var CustomBlending = 5;
  683. var AddEquation = 100;
  684. var SubtractEquation = 101;
  685. var ReverseSubtractEquation = 102;
  686. var MinEquation = 103;
  687. var MaxEquation = 104;
  688. var ZeroFactor = 200;
  689. var OneFactor = 201;
  690. var SrcColorFactor = 202;
  691. var OneMinusSrcColorFactor = 203;
  692. var SrcAlphaFactor = 204;
  693. var OneMinusSrcAlphaFactor = 205;
  694. var DstAlphaFactor = 206;
  695. var OneMinusDstAlphaFactor = 207;
  696. var DstColorFactor = 208;
  697. var OneMinusDstColorFactor = 209;
  698. var SrcAlphaSaturateFactor = 210;
  699. var NeverDepth = 0;
  700. var AlwaysDepth = 1;
  701. var LessDepth = 2;
  702. var LessEqualDepth = 3;
  703. var EqualDepth = 4;
  704. var GreaterEqualDepth = 5;
  705. var GreaterDepth = 6;
  706. var NotEqualDepth = 7;
  707. var MultiplyOperation = 0;
  708. var MixOperation = 1;
  709. var AddOperation = 2;
  710. var NoToneMapping = 0;
  711. var LinearToneMapping = 1;
  712. var ReinhardToneMapping = 2;
  713. var CineonToneMapping = 3;
  714. var ACESFilmicToneMapping = 4;
  715. var CustomToneMapping = 5;
  716. var UVMapping = 300;
  717. var CubeReflectionMapping = 301;
  718. var CubeRefractionMapping = 302;
  719. var EquirectangularReflectionMapping = 303;
  720. var EquirectangularRefractionMapping = 304;
  721. var CubeUVReflectionMapping = 306;
  722. var CubeUVRefractionMapping = 307;
  723. var RepeatWrapping = 1000;
  724. var ClampToEdgeWrapping = 1001;
  725. var MirroredRepeatWrapping = 1002;
  726. var NearestFilter = 1003;
  727. var NearestMipmapNearestFilter = 1004;
  728. var NearestMipMapNearestFilter = 1004;
  729. var NearestMipmapLinearFilter = 1005;
  730. var NearestMipMapLinearFilter = 1005;
  731. var LinearFilter = 1006;
  732. var LinearMipmapNearestFilter = 1007;
  733. var LinearMipMapNearestFilter = 1007;
  734. var LinearMipmapLinearFilter = 1008;
  735. var LinearMipMapLinearFilter = 1008;
  736. var UnsignedByteType = 1009;
  737. var ByteType = 1010;
  738. var ShortType = 1011;
  739. var UnsignedShortType = 1012;
  740. var IntType = 1013;
  741. var UnsignedIntType = 1014;
  742. var FloatType = 1015;
  743. var HalfFloatType = 1016;
  744. var UnsignedShort4444Type = 1017;
  745. var UnsignedShort5551Type = 1018;
  746. var UnsignedShort565Type = 1019;
  747. var UnsignedInt248Type = 1020;
  748. var AlphaFormat = 1021;
  749. var RGBFormat = 1022;
  750. var RGBAFormat = 1023;
  751. var LuminanceFormat = 1024;
  752. var LuminanceAlphaFormat = 1025;
  753. var RGBEFormat = RGBAFormat;
  754. var DepthFormat = 1026;
  755. var DepthStencilFormat = 1027;
  756. var RedFormat = 1028;
  757. var RedIntegerFormat = 1029;
  758. var RGFormat = 1030;
  759. var RGIntegerFormat = 1031;
  760. var RGBIntegerFormat = 1032;
  761. var RGBAIntegerFormat = 1033;
  762. var RGB_S3TC_DXT1_Format = 33776;
  763. var RGBA_S3TC_DXT1_Format = 33777;
  764. var RGBA_S3TC_DXT3_Format = 33778;
  765. var RGBA_S3TC_DXT5_Format = 33779;
  766. var RGB_PVRTC_4BPPV1_Format = 35840;
  767. var RGB_PVRTC_2BPPV1_Format = 35841;
  768. var RGBA_PVRTC_4BPPV1_Format = 35842;
  769. var RGBA_PVRTC_2BPPV1_Format = 35843;
  770. var RGB_ETC1_Format = 36196;
  771. var RGB_ETC2_Format = 37492;
  772. var RGBA_ETC2_EAC_Format = 37496;
  773. var RGBA_ASTC_4x4_Format = 37808;
  774. var RGBA_ASTC_5x4_Format = 37809;
  775. var RGBA_ASTC_5x5_Format = 37810;
  776. var RGBA_ASTC_6x5_Format = 37811;
  777. var RGBA_ASTC_6x6_Format = 37812;
  778. var RGBA_ASTC_8x5_Format = 37813;
  779. var RGBA_ASTC_8x6_Format = 37814;
  780. var RGBA_ASTC_8x8_Format = 37815;
  781. var RGBA_ASTC_10x5_Format = 37816;
  782. var RGBA_ASTC_10x6_Format = 37817;
  783. var RGBA_ASTC_10x8_Format = 37818;
  784. var RGBA_ASTC_10x10_Format = 37819;
  785. var RGBA_ASTC_12x10_Format = 37820;
  786. var RGBA_ASTC_12x12_Format = 37821;
  787. var RGBA_BPTC_Format = 36492;
  788. var SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  789. var SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  790. var SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  791. var SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  792. var SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  793. var SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  794. var SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  795. var SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  796. var SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  797. var SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  798. var SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  799. var SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  800. var SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  801. var SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  802. var LoopOnce = 2200;
  803. var LoopRepeat = 2201;
  804. var LoopPingPong = 2202;
  805. var InterpolateDiscrete = 2300;
  806. var InterpolateLinear = 2301;
  807. var InterpolateSmooth = 2302;
  808. var ZeroCurvatureEnding = 2400;
  809. var ZeroSlopeEnding = 2401;
  810. var WrapAroundEnding = 2402;
  811. var NormalAnimationBlendMode = 2500;
  812. var AdditiveAnimationBlendMode = 2501;
  813. var TrianglesDrawMode = 0;
  814. var TriangleStripDrawMode = 1;
  815. var TriangleFanDrawMode = 2;
  816. var LinearEncoding = 3000;
  817. var sRGBEncoding = 3001;
  818. var GammaEncoding = 3007;
  819. var RGBEEncoding = 3002;
  820. var LogLuvEncoding = 3003;
  821. var RGBM7Encoding = 3004;
  822. var RGBM16Encoding = 3005;
  823. var RGBDEncoding = 3006;
  824. var BasicDepthPacking = 3200;
  825. var RGBADepthPacking = 3201;
  826. var TangentSpaceNormalMap = 0;
  827. var ObjectSpaceNormalMap = 1;
  828. var ZeroStencilOp = 0;
  829. var KeepStencilOp = 7680;
  830. var ReplaceStencilOp = 7681;
  831. var IncrementStencilOp = 7682;
  832. var DecrementStencilOp = 7683;
  833. var IncrementWrapStencilOp = 34055;
  834. var DecrementWrapStencilOp = 34056;
  835. var InvertStencilOp = 5386;
  836. var NeverStencilFunc = 512;
  837. var LessStencilFunc = 513;
  838. var EqualStencilFunc = 514;
  839. var LessEqualStencilFunc = 515;
  840. var GreaterStencilFunc = 516;
  841. var NotEqualStencilFunc = 517;
  842. var GreaterEqualStencilFunc = 518;
  843. var AlwaysStencilFunc = 519;
  844. var StaticDrawUsage = 35044;
  845. var DynamicDrawUsage = 35048;
  846. var StreamDrawUsage = 35040;
  847. var StaticReadUsage = 35045;
  848. var DynamicReadUsage = 35049;
  849. var StreamReadUsage = 35041;
  850. var StaticCopyUsage = 35046;
  851. var DynamicCopyUsage = 35050;
  852. var StreamCopyUsage = 35042;
  853. var GLSL1 = '100';
  854. var GLSL3 = '300 es';
  855. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  856. try {
  857. var info = gen[key](arg);
  858. var value = info.value;
  859. } catch (error) {
  860. reject(error);
  861. return;
  862. }
  863. if (info.done) {
  864. resolve(value);
  865. } else {
  866. Promise.resolve(value).then(_next, _throw);
  867. }
  868. }
  869. function _asyncToGenerator(fn) {
  870. return function () {
  871. var self = this,
  872. args = arguments;
  873. return new Promise(function (resolve, reject) {
  874. var gen = fn.apply(self, args);
  875. function _next(value) {
  876. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
  877. }
  878. function _throw(err) {
  879. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
  880. }
  881. _next(undefined);
  882. });
  883. };
  884. }
  885. function _defineProperties(target, props) {
  886. for (var i = 0; i < props.length; i++) {
  887. var descriptor = props[i];
  888. descriptor.enumerable = descriptor.enumerable || false;
  889. descriptor.configurable = true;
  890. if ("value" in descriptor) descriptor.writable = true;
  891. Object.defineProperty(target, descriptor.key, descriptor);
  892. }
  893. }
  894. function _createClass(Constructor, protoProps, staticProps) {
  895. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  896. if (staticProps) _defineProperties(Constructor, staticProps);
  897. return Constructor;
  898. }
  899. function _inheritsLoose(subClass, superClass) {
  900. subClass.prototype = Object.create(superClass.prototype);
  901. subClass.prototype.constructor = subClass;
  902. subClass.__proto__ = superClass;
  903. }
  904. function _assertThisInitialized(self) {
  905. if (self === void 0) {
  906. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  907. }
  908. return self;
  909. }
  910. /**
  911. * https://github.com/mrdoob/eventdispatcher.js/
  912. */
  913. function EventDispatcher() {}
  914. Object.assign(EventDispatcher.prototype, {
  915. addEventListener: function addEventListener(type, listener) {
  916. if (this._listeners === undefined) this._listeners = {};
  917. var listeners = this._listeners;
  918. if (listeners[type] === undefined) {
  919. listeners[type] = [];
  920. }
  921. if (listeners[type].indexOf(listener) === -1) {
  922. listeners[type].push(listener);
  923. }
  924. },
  925. hasEventListener: function hasEventListener(type, listener) {
  926. if (this._listeners === undefined) return false;
  927. var listeners = this._listeners;
  928. return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
  929. },
  930. removeEventListener: function removeEventListener(type, listener) {
  931. if (this._listeners === undefined) return;
  932. var listeners = this._listeners;
  933. var listenerArray = listeners[type];
  934. if (listenerArray !== undefined) {
  935. var index = listenerArray.indexOf(listener);
  936. if (index !== -1) {
  937. listenerArray.splice(index, 1);
  938. }
  939. }
  940. },
  941. dispatchEvent: function dispatchEvent(event) {
  942. if (this._listeners === undefined) return;
  943. var listeners = this._listeners;
  944. var listenerArray = listeners[event.type];
  945. if (listenerArray !== undefined) {
  946. event.target = this; // Make a copy, in case listeners are removed while iterating.
  947. var array = listenerArray.slice(0);
  948. for (var i = 0, l = array.length; i < l; i++) {
  949. array[i].call(this, event);
  950. }
  951. }
  952. }
  953. });
  954. var _lut = [];
  955. for (var i = 0; i < 256; i++) {
  956. _lut[i] = (i < 16 ? '0' : '') + i.toString(16);
  957. }
  958. var _seed = 1234567;
  959. var MathUtils = {
  960. DEG2RAD: Math.PI / 180,
  961. RAD2DEG: 180 / Math.PI,
  962. generateUUID: function generateUUID() {
  963. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  964. var d0 = Math.random() * 0xffffffff | 0;
  965. var d1 = Math.random() * 0xffffffff | 0;
  966. var d2 = Math.random() * 0xffffffff | 0;
  967. var d3 = Math.random() * 0xffffffff | 0;
  968. 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.
  969. return uuid.toUpperCase();
  970. },
  971. clamp: function clamp(value, min, max) {
  972. return Math.max(min, Math.min(max, value));
  973. },
  974. // compute euclidian modulo of m % n
  975. // https://en.wikipedia.org/wiki/Modulo_operation
  976. euclideanModulo: function euclideanModulo(n, m) {
  977. return (n % m + m) % m;
  978. },
  979. // Linear mapping from range <a1, a2> to range <b1, b2>
  980. mapLinear: function mapLinear(x, a1, a2, b1, b2) {
  981. return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
  982. },
  983. // https://en.wikipedia.org/wiki/Linear_interpolation
  984. lerp: function lerp(x, y, t) {
  985. return (1 - t) * x + t * y;
  986. },
  987. // http://en.wikipedia.org/wiki/Smoothstep
  988. smoothstep: function smoothstep(x, min, max) {
  989. if (x <= min) return 0;
  990. if (x >= max) return 1;
  991. x = (x - min) / (max - min);
  992. return x * x * (3 - 2 * x);
  993. },
  994. smootherstep: function smootherstep(x, min, max) {
  995. if (x <= min) return 0;
  996. if (x >= max) return 1;
  997. x = (x - min) / (max - min);
  998. return x * x * x * (x * (x * 6 - 15) + 10);
  999. },
  1000. // Random integer from <low, high> interval
  1001. randInt: function randInt(low, high) {
  1002. return low + Math.floor(Math.random() * (high - low + 1));
  1003. },
  1004. // Random float from <low, high> interval
  1005. randFloat: function randFloat(low, high) {
  1006. return low + Math.random() * (high - low);
  1007. },
  1008. // Random float from <-range/2, range/2> interval
  1009. randFloatSpread: function randFloatSpread(range) {
  1010. return range * (0.5 - Math.random());
  1011. },
  1012. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  1013. seededRandom: function seededRandom(s) {
  1014. if (s !== undefined) _seed = s % 2147483647; // Park-Miller algorithm
  1015. _seed = _seed * 16807 % 2147483647;
  1016. return (_seed - 1) / 2147483646;
  1017. },
  1018. degToRad: function degToRad(degrees) {
  1019. return degrees * MathUtils.DEG2RAD;
  1020. },
  1021. radToDeg: function radToDeg(radians) {
  1022. return radians * MathUtils.RAD2DEG;
  1023. },
  1024. isPowerOfTwo: function isPowerOfTwo(value) {
  1025. return (value & value - 1) === 0 && value !== 0;
  1026. },
  1027. ceilPowerOfTwo: function ceilPowerOfTwo(value) {
  1028. return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
  1029. },
  1030. floorPowerOfTwo: function floorPowerOfTwo(value) {
  1031. return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
  1032. },
  1033. setQuaternionFromProperEuler: function setQuaternionFromProperEuler(q, a, b, c, order) {
  1034. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  1035. // rotations are applied to the axes in the order specified by 'order'
  1036. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  1037. // angles are in radians
  1038. var cos = Math.cos;
  1039. var sin = Math.sin;
  1040. var c2 = cos(b / 2);
  1041. var s2 = sin(b / 2);
  1042. var c13 = cos((a + c) / 2);
  1043. var s13 = sin((a + c) / 2);
  1044. var c1_3 = cos((a - c) / 2);
  1045. var s1_3 = sin((a - c) / 2);
  1046. var c3_1 = cos((c - a) / 2);
  1047. var s3_1 = sin((c - a) / 2);
  1048. switch (order) {
  1049. case 'XYX':
  1050. q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
  1051. break;
  1052. case 'YZY':
  1053. q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
  1054. break;
  1055. case 'ZXZ':
  1056. q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
  1057. break;
  1058. case 'XZX':
  1059. q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
  1060. break;
  1061. case 'YXY':
  1062. q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
  1063. break;
  1064. case 'ZYZ':
  1065. q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
  1066. break;
  1067. default:
  1068. console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order);
  1069. }
  1070. }
  1071. };
  1072. var Vector2 = /*#__PURE__*/function () {
  1073. function Vector2(x, y) {
  1074. if (x === void 0) {
  1075. x = 0;
  1076. }
  1077. if (y === void 0) {
  1078. y = 0;
  1079. }
  1080. Object.defineProperty(this, 'isVector2', {
  1081. value: true
  1082. });
  1083. this.x = x;
  1084. this.y = y;
  1085. }
  1086. var _proto = Vector2.prototype;
  1087. _proto.set = function set(x, y) {
  1088. this.x = x;
  1089. this.y = y;
  1090. return this;
  1091. };
  1092. _proto.setScalar = function setScalar(scalar) {
  1093. this.x = scalar;
  1094. this.y = scalar;
  1095. return this;
  1096. };
  1097. _proto.setX = function setX(x) {
  1098. this.x = x;
  1099. return this;
  1100. };
  1101. _proto.setY = function setY(y) {
  1102. this.y = y;
  1103. return this;
  1104. };
  1105. _proto.setComponent = function setComponent(index, value) {
  1106. switch (index) {
  1107. case 0:
  1108. this.x = value;
  1109. break;
  1110. case 1:
  1111. this.y = value;
  1112. break;
  1113. default:
  1114. throw new Error('index is out of range: ' + index);
  1115. }
  1116. return this;
  1117. };
  1118. _proto.getComponent = function getComponent(index) {
  1119. switch (index) {
  1120. case 0:
  1121. return this.x;
  1122. case 1:
  1123. return this.y;
  1124. default:
  1125. throw new Error('index is out of range: ' + index);
  1126. }
  1127. };
  1128. _proto.clone = function clone() {
  1129. return new this.constructor(this.x, this.y);
  1130. };
  1131. _proto.copy = function copy(v) {
  1132. this.x = v.x;
  1133. this.y = v.y;
  1134. return this;
  1135. };
  1136. _proto.add = function add(v, w) {
  1137. if (w !== undefined) {
  1138. console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1139. return this.addVectors(v, w);
  1140. }
  1141. this.x += v.x;
  1142. this.y += v.y;
  1143. return this;
  1144. };
  1145. _proto.addScalar = function addScalar(s) {
  1146. this.x += s;
  1147. this.y += s;
  1148. return this;
  1149. };
  1150. _proto.addVectors = function addVectors(a, b) {
  1151. this.x = a.x + b.x;
  1152. this.y = a.y + b.y;
  1153. return this;
  1154. };
  1155. _proto.addScaledVector = function addScaledVector(v, s) {
  1156. this.x += v.x * s;
  1157. this.y += v.y * s;
  1158. return this;
  1159. };
  1160. _proto.sub = function sub(v, w) {
  1161. if (w !== undefined) {
  1162. console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  1163. return this.subVectors(v, w);
  1164. }
  1165. this.x -= v.x;
  1166. this.y -= v.y;
  1167. return this;
  1168. };
  1169. _proto.subScalar = function subScalar(s) {
  1170. this.x -= s;
  1171. this.y -= s;
  1172. return this;
  1173. };
  1174. _proto.subVectors = function subVectors(a, b) {
  1175. this.x = a.x - b.x;
  1176. this.y = a.y - b.y;
  1177. return this;
  1178. };
  1179. _proto.multiply = function multiply(v) {
  1180. this.x *= v.x;
  1181. this.y *= v.y;
  1182. return this;
  1183. };
  1184. _proto.multiplyScalar = function multiplyScalar(scalar) {
  1185. this.x *= scalar;
  1186. this.y *= scalar;
  1187. return this;
  1188. };
  1189. _proto.divide = function divide(v) {
  1190. this.x /= v.x;
  1191. this.y /= v.y;
  1192. return this;
  1193. };
  1194. _proto.divideScalar = function divideScalar(scalar) {
  1195. return this.multiplyScalar(1 / scalar);
  1196. };
  1197. _proto.applyMatrix3 = function applyMatrix3(m) {
  1198. var x = this.x,
  1199. y = this.y;
  1200. var e = m.elements;
  1201. this.x = e[0] * x + e[3] * y + e[6];
  1202. this.y = e[1] * x + e[4] * y + e[7];
  1203. return this;
  1204. };
  1205. _proto.min = function min(v) {
  1206. this.x = Math.min(this.x, v.x);
  1207. this.y = Math.min(this.y, v.y);
  1208. return this;
  1209. };
  1210. _proto.max = function max(v) {
  1211. this.x = Math.max(this.x, v.x);
  1212. this.y = Math.max(this.y, v.y);
  1213. return this;
  1214. };
  1215. _proto.clamp = function clamp(min, max) {
  1216. // assumes min < max, componentwise
  1217. this.x = Math.max(min.x, Math.min(max.x, this.x));
  1218. this.y = Math.max(min.y, Math.min(max.y, this.y));
  1219. return this;
  1220. };
  1221. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  1222. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  1223. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  1224. return this;
  1225. };
  1226. _proto.clampLength = function clampLength(min, max) {
  1227. var length = this.length();
  1228. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  1229. };
  1230. _proto.floor = function floor() {
  1231. this.x = Math.floor(this.x);
  1232. this.y = Math.floor(this.y);
  1233. return this;
  1234. };
  1235. _proto.ceil = function ceil() {
  1236. this.x = Math.ceil(this.x);
  1237. this.y = Math.ceil(this.y);
  1238. return this;
  1239. };
  1240. _proto.round = function round() {
  1241. this.x = Math.round(this.x);
  1242. this.y = Math.round(this.y);
  1243. return this;
  1244. };
  1245. _proto.roundToZero = function roundToZero() {
  1246. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  1247. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  1248. return this;
  1249. };
  1250. _proto.negate = function negate() {
  1251. this.x = -this.x;
  1252. this.y = -this.y;
  1253. return this;
  1254. };
  1255. _proto.dot = function dot(v) {
  1256. return this.x * v.x + this.y * v.y;
  1257. };
  1258. _proto.cross = function cross(v) {
  1259. return this.x * v.y - this.y * v.x;
  1260. };
  1261. _proto.lengthSq = function lengthSq() {
  1262. return this.x * this.x + this.y * this.y;
  1263. };
  1264. _proto.length = function length() {
  1265. return Math.sqrt(this.x * this.x + this.y * this.y);
  1266. };
  1267. _proto.manhattanLength = function manhattanLength() {
  1268. return Math.abs(this.x) + Math.abs(this.y);
  1269. };
  1270. _proto.normalize = function normalize() {
  1271. return this.divideScalar(this.length() || 1);
  1272. };
  1273. _proto.angle = function angle() {
  1274. // computes the angle in radians with respect to the positive x-axis
  1275. var angle = Math.atan2(-this.y, -this.x) + Math.PI;
  1276. return angle;
  1277. };
  1278. _proto.distanceTo = function distanceTo(v) {
  1279. return Math.sqrt(this.distanceToSquared(v));
  1280. };
  1281. _proto.distanceToSquared = function distanceToSquared(v) {
  1282. var dx = this.x - v.x,
  1283. dy = this.y - v.y;
  1284. return dx * dx + dy * dy;
  1285. };
  1286. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  1287. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
  1288. };
  1289. _proto.setLength = function setLength(length) {
  1290. return this.normalize().multiplyScalar(length);
  1291. };
  1292. _proto.lerp = function lerp(v, alpha) {
  1293. this.x += (v.x - this.x) * alpha;
  1294. this.y += (v.y - this.y) * alpha;
  1295. return this;
  1296. };
  1297. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  1298. this.x = v1.x + (v2.x - v1.x) * alpha;
  1299. this.y = v1.y + (v2.y - v1.y) * alpha;
  1300. return this;
  1301. };
  1302. _proto.equals = function equals(v) {
  1303. return v.x === this.x && v.y === this.y;
  1304. };
  1305. _proto.fromArray = function fromArray(array, offset) {
  1306. if (offset === void 0) {
  1307. offset = 0;
  1308. }
  1309. this.x = array[offset];
  1310. this.y = array[offset + 1];
  1311. return this;
  1312. };
  1313. _proto.toArray = function toArray(array, offset) {
  1314. if (array === void 0) {
  1315. array = [];
  1316. }
  1317. if (offset === void 0) {
  1318. offset = 0;
  1319. }
  1320. array[offset] = this.x;
  1321. array[offset + 1] = this.y;
  1322. return array;
  1323. };
  1324. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  1325. if (offset !== undefined) {
  1326. console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
  1327. }
  1328. this.x = attribute.getX(index);
  1329. this.y = attribute.getY(index);
  1330. return this;
  1331. };
  1332. _proto.rotateAround = function rotateAround(center, angle) {
  1333. var c = Math.cos(angle),
  1334. s = Math.sin(angle);
  1335. var x = this.x - center.x;
  1336. var y = this.y - center.y;
  1337. this.x = x * c - y * s + center.x;
  1338. this.y = x * s + y * c + center.y;
  1339. return this;
  1340. };
  1341. _proto.random = function random() {
  1342. this.x = Math.random();
  1343. this.y = Math.random();
  1344. return this;
  1345. };
  1346. _createClass(Vector2, [{
  1347. key: "width",
  1348. get: function get() {
  1349. return this.x;
  1350. },
  1351. set: function set(value) {
  1352. this.x = value;
  1353. }
  1354. }, {
  1355. key: "height",
  1356. get: function get() {
  1357. return this.y;
  1358. },
  1359. set: function set(value) {
  1360. this.y = value;
  1361. }
  1362. }]);
  1363. return Vector2;
  1364. }();
  1365. var Matrix3 = /*#__PURE__*/function () {
  1366. function Matrix3() {
  1367. Object.defineProperty(this, 'isMatrix3', {
  1368. value: true
  1369. });
  1370. this.elements = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  1371. if (arguments.length > 0) {
  1372. console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');
  1373. }
  1374. }
  1375. var _proto = Matrix3.prototype;
  1376. _proto.set = function set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
  1377. var te = this.elements;
  1378. te[0] = n11;
  1379. te[1] = n21;
  1380. te[2] = n31;
  1381. te[3] = n12;
  1382. te[4] = n22;
  1383. te[5] = n32;
  1384. te[6] = n13;
  1385. te[7] = n23;
  1386. te[8] = n33;
  1387. return this;
  1388. };
  1389. _proto.identity = function identity() {
  1390. this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
  1391. return this;
  1392. };
  1393. _proto.clone = function clone() {
  1394. return new this.constructor().fromArray(this.elements);
  1395. };
  1396. _proto.copy = function copy(m) {
  1397. var te = this.elements;
  1398. var me = m.elements;
  1399. te[0] = me[0];
  1400. te[1] = me[1];
  1401. te[2] = me[2];
  1402. te[3] = me[3];
  1403. te[4] = me[4];
  1404. te[5] = me[5];
  1405. te[6] = me[6];
  1406. te[7] = me[7];
  1407. te[8] = me[8];
  1408. return this;
  1409. };
  1410. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  1411. xAxis.setFromMatrix3Column(this, 0);
  1412. yAxis.setFromMatrix3Column(this, 1);
  1413. zAxis.setFromMatrix3Column(this, 2);
  1414. return this;
  1415. };
  1416. _proto.setFromMatrix4 = function setFromMatrix4(m) {
  1417. var me = m.elements;
  1418. this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
  1419. return this;
  1420. };
  1421. _proto.multiply = function multiply(m) {
  1422. return this.multiplyMatrices(this, m);
  1423. };
  1424. _proto.premultiply = function premultiply(m) {
  1425. return this.multiplyMatrices(m, this);
  1426. };
  1427. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  1428. var ae = a.elements;
  1429. var be = b.elements;
  1430. var te = this.elements;
  1431. var a11 = ae[0],
  1432. a12 = ae[3],
  1433. a13 = ae[6];
  1434. var a21 = ae[1],
  1435. a22 = ae[4],
  1436. a23 = ae[7];
  1437. var a31 = ae[2],
  1438. a32 = ae[5],
  1439. a33 = ae[8];
  1440. var b11 = be[0],
  1441. b12 = be[3],
  1442. b13 = be[6];
  1443. var b21 = be[1],
  1444. b22 = be[4],
  1445. b23 = be[7];
  1446. var b31 = be[2],
  1447. b32 = be[5],
  1448. b33 = be[8];
  1449. te[0] = a11 * b11 + a12 * b21 + a13 * b31;
  1450. te[3] = a11 * b12 + a12 * b22 + a13 * b32;
  1451. te[6] = a11 * b13 + a12 * b23 + a13 * b33;
  1452. te[1] = a21 * b11 + a22 * b21 + a23 * b31;
  1453. te[4] = a21 * b12 + a22 * b22 + a23 * b32;
  1454. te[7] = a21 * b13 + a22 * b23 + a23 * b33;
  1455. te[2] = a31 * b11 + a32 * b21 + a33 * b31;
  1456. te[5] = a31 * b12 + a32 * b22 + a33 * b32;
  1457. te[8] = a31 * b13 + a32 * b23 + a33 * b33;
  1458. return this;
  1459. };
  1460. _proto.multiplyScalar = function multiplyScalar(s) {
  1461. var te = this.elements;
  1462. te[0] *= s;
  1463. te[3] *= s;
  1464. te[6] *= s;
  1465. te[1] *= s;
  1466. te[4] *= s;
  1467. te[7] *= s;
  1468. te[2] *= s;
  1469. te[5] *= s;
  1470. te[8] *= s;
  1471. return this;
  1472. };
  1473. _proto.determinant = function determinant() {
  1474. var te = this.elements;
  1475. var a = te[0],
  1476. b = te[1],
  1477. c = te[2],
  1478. d = te[3],
  1479. e = te[4],
  1480. f = te[5],
  1481. g = te[6],
  1482. h = te[7],
  1483. i = te[8];
  1484. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  1485. };
  1486. _proto.invert = function invert() {
  1487. var te = this.elements,
  1488. n11 = te[0],
  1489. n21 = te[1],
  1490. n31 = te[2],
  1491. n12 = te[3],
  1492. n22 = te[4],
  1493. n32 = te[5],
  1494. n13 = te[6],
  1495. n23 = te[7],
  1496. n33 = te[8],
  1497. t11 = n33 * n22 - n32 * n23,
  1498. t12 = n32 * n13 - n33 * n12,
  1499. t13 = n23 * n12 - n22 * n13,
  1500. det = n11 * t11 + n21 * t12 + n31 * t13;
  1501. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
  1502. var detInv = 1 / det;
  1503. te[0] = t11 * detInv;
  1504. te[1] = (n31 * n23 - n33 * n21) * detInv;
  1505. te[2] = (n32 * n21 - n31 * n22) * detInv;
  1506. te[3] = t12 * detInv;
  1507. te[4] = (n33 * n11 - n31 * n13) * detInv;
  1508. te[5] = (n31 * n12 - n32 * n11) * detInv;
  1509. te[6] = t13 * detInv;
  1510. te[7] = (n21 * n13 - n23 * n11) * detInv;
  1511. te[8] = (n22 * n11 - n21 * n12) * detInv;
  1512. return this;
  1513. };
  1514. _proto.transpose = function transpose() {
  1515. var tmp;
  1516. var m = this.elements;
  1517. tmp = m[1];
  1518. m[1] = m[3];
  1519. m[3] = tmp;
  1520. tmp = m[2];
  1521. m[2] = m[6];
  1522. m[6] = tmp;
  1523. tmp = m[5];
  1524. m[5] = m[7];
  1525. m[7] = tmp;
  1526. return this;
  1527. };
  1528. _proto.getNormalMatrix = function getNormalMatrix(matrix4) {
  1529. return this.setFromMatrix4(matrix4).copy(this).invert().transpose();
  1530. };
  1531. _proto.transposeIntoArray = function transposeIntoArray(r) {
  1532. var m = this.elements;
  1533. r[0] = m[0];
  1534. r[1] = m[3];
  1535. r[2] = m[6];
  1536. r[3] = m[1];
  1537. r[4] = m[4];
  1538. r[5] = m[7];
  1539. r[6] = m[2];
  1540. r[7] = m[5];
  1541. r[8] = m[8];
  1542. return this;
  1543. };
  1544. _proto.setUvTransform = function setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
  1545. var c = Math.cos(rotation);
  1546. var s = Math.sin(rotation);
  1547. 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);
  1548. return this;
  1549. };
  1550. _proto.scale = function scale(sx, sy) {
  1551. var te = this.elements;
  1552. te[0] *= sx;
  1553. te[3] *= sx;
  1554. te[6] *= sx;
  1555. te[1] *= sy;
  1556. te[4] *= sy;
  1557. te[7] *= sy;
  1558. return this;
  1559. };
  1560. _proto.rotate = function rotate(theta) {
  1561. var c = Math.cos(theta);
  1562. var s = Math.sin(theta);
  1563. var te = this.elements;
  1564. var a11 = te[0],
  1565. a12 = te[3],
  1566. a13 = te[6];
  1567. var a21 = te[1],
  1568. a22 = te[4],
  1569. a23 = te[7];
  1570. te[0] = c * a11 + s * a21;
  1571. te[3] = c * a12 + s * a22;
  1572. te[6] = c * a13 + s * a23;
  1573. te[1] = -s * a11 + c * a21;
  1574. te[4] = -s * a12 + c * a22;
  1575. te[7] = -s * a13 + c * a23;
  1576. return this;
  1577. };
  1578. _proto.translate = function translate(tx, ty) {
  1579. var te = this.elements;
  1580. te[0] += tx * te[2];
  1581. te[3] += tx * te[5];
  1582. te[6] += tx * te[8];
  1583. te[1] += ty * te[2];
  1584. te[4] += ty * te[5];
  1585. te[7] += ty * te[8];
  1586. return this;
  1587. };
  1588. _proto.equals = function equals(matrix) {
  1589. var te = this.elements;
  1590. var me = matrix.elements;
  1591. for (var i = 0; i < 9; i++) {
  1592. if (te[i] !== me[i]) return false;
  1593. }
  1594. return true;
  1595. };
  1596. _proto.fromArray = function fromArray(array, offset) {
  1597. if (offset === void 0) {
  1598. offset = 0;
  1599. }
  1600. for (var i = 0; i < 9; i++) {
  1601. this.elements[i] = array[i + offset];
  1602. }
  1603. return this;
  1604. };
  1605. _proto.toArray = function toArray(array, offset) {
  1606. if (array === void 0) {
  1607. array = [];
  1608. }
  1609. if (offset === void 0) {
  1610. offset = 0;
  1611. }
  1612. var te = this.elements;
  1613. array[offset] = te[0];
  1614. array[offset + 1] = te[1];
  1615. array[offset + 2] = te[2];
  1616. array[offset + 3] = te[3];
  1617. array[offset + 4] = te[4];
  1618. array[offset + 5] = te[5];
  1619. array[offset + 6] = te[6];
  1620. array[offset + 7] = te[7];
  1621. array[offset + 8] = te[8];
  1622. return array;
  1623. };
  1624. return Matrix3;
  1625. }();
  1626. var _canvas;
  1627. var ImageUtils = {
  1628. getDataURL: function getDataURL(image) {
  1629. if (/^data:/i.test(image.src)) {
  1630. return image.src;
  1631. }
  1632. if (typeof HTMLCanvasElement == 'undefined') {
  1633. return image.src;
  1634. }
  1635. var canvas;
  1636. if (image instanceof HTMLCanvasElement) {
  1637. canvas = image;
  1638. } else {
  1639. if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  1640. _canvas.width = image.width;
  1641. _canvas.height = image.height;
  1642. var context = _canvas.getContext('2d');
  1643. if (image instanceof ImageData) {
  1644. context.putImageData(image, 0, 0);
  1645. } else {
  1646. context.drawImage(image, 0, 0, image.width, image.height);
  1647. }
  1648. canvas = _canvas;
  1649. }
  1650. if (canvas.width > 2048 || canvas.height > 2048) {
  1651. return canvas.toDataURL('image/jpeg', 0.6);
  1652. } else {
  1653. return canvas.toDataURL('image/png');
  1654. }
  1655. }
  1656. };
  1657. var textureId = 0;
  1658. function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  1659. if (image === void 0) {
  1660. image = Texture.DEFAULT_IMAGE;
  1661. }
  1662. if (mapping === void 0) {
  1663. mapping = Texture.DEFAULT_MAPPING;
  1664. }
  1665. if (wrapS === void 0) {
  1666. wrapS = ClampToEdgeWrapping;
  1667. }
  1668. if (wrapT === void 0) {
  1669. wrapT = ClampToEdgeWrapping;
  1670. }
  1671. if (magFilter === void 0) {
  1672. magFilter = LinearFilter;
  1673. }
  1674. if (minFilter === void 0) {
  1675. minFilter = LinearMipmapLinearFilter;
  1676. }
  1677. if (format === void 0) {
  1678. format = RGBAFormat;
  1679. }
  1680. if (type === void 0) {
  1681. type = UnsignedByteType;
  1682. }
  1683. if (anisotropy === void 0) {
  1684. anisotropy = 1;
  1685. }
  1686. if (encoding === void 0) {
  1687. encoding = LinearEncoding;
  1688. }
  1689. Object.defineProperty(this, 'id', {
  1690. value: textureId++
  1691. });
  1692. this.uuid = MathUtils.generateUUID();
  1693. this.name = '';
  1694. this.image = image;
  1695. this.mipmaps = [];
  1696. this.mapping = mapping;
  1697. this.wrapS = wrapS;
  1698. this.wrapT = wrapT;
  1699. this.magFilter = magFilter;
  1700. this.minFilter = minFilter;
  1701. this.anisotropy = anisotropy;
  1702. this.format = format;
  1703. this.internalFormat = null;
  1704. this.type = type;
  1705. this.offset = new Vector2(0, 0);
  1706. this.repeat = new Vector2(1, 1);
  1707. this.center = new Vector2(0, 0);
  1708. this.rotation = 0;
  1709. this.matrixAutoUpdate = true;
  1710. this.matrix = new Matrix3();
  1711. this.generateMipmaps = true;
  1712. this.premultiplyAlpha = false;
  1713. this.flipY = true;
  1714. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1715. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1716. //
  1717. // Also changing the encoding after already used by a Material will not automatically make the Material
  1718. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1719. this.encoding = encoding;
  1720. this.version = 0;
  1721. this.onUpdate = null;
  1722. }
  1723. Texture.DEFAULT_IMAGE = undefined;
  1724. Texture.DEFAULT_MAPPING = UVMapping;
  1725. Texture.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1726. constructor: Texture,
  1727. isTexture: true,
  1728. updateMatrix: function updateMatrix() {
  1729. this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  1730. },
  1731. clone: function clone() {
  1732. return new this.constructor().copy(this);
  1733. },
  1734. copy: function copy(source) {
  1735. this.name = source.name;
  1736. this.image = source.image;
  1737. this.mipmaps = source.mipmaps.slice(0);
  1738. this.mapping = source.mapping;
  1739. this.wrapS = source.wrapS;
  1740. this.wrapT = source.wrapT;
  1741. this.magFilter = source.magFilter;
  1742. this.minFilter = source.minFilter;
  1743. this.anisotropy = source.anisotropy;
  1744. this.format = source.format;
  1745. this.internalFormat = source.internalFormat;
  1746. this.type = source.type;
  1747. this.offset.copy(source.offset);
  1748. this.repeat.copy(source.repeat);
  1749. this.center.copy(source.center);
  1750. this.rotation = source.rotation;
  1751. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1752. this.matrix.copy(source.matrix);
  1753. this.generateMipmaps = source.generateMipmaps;
  1754. this.premultiplyAlpha = source.premultiplyAlpha;
  1755. this.flipY = source.flipY;
  1756. this.unpackAlignment = source.unpackAlignment;
  1757. this.encoding = source.encoding;
  1758. return this;
  1759. },
  1760. toJSON: function toJSON(meta) {
  1761. var isRootObject = meta === undefined || typeof meta === 'string';
  1762. if (!isRootObject && meta.textures[this.uuid] !== undefined) {
  1763. return meta.textures[this.uuid];
  1764. }
  1765. var output = {
  1766. metadata: {
  1767. version: 4.5,
  1768. type: 'Texture',
  1769. generator: 'Texture.toJSON'
  1770. },
  1771. uuid: this.uuid,
  1772. name: this.name,
  1773. mapping: this.mapping,
  1774. repeat: [this.repeat.x, this.repeat.y],
  1775. offset: [this.offset.x, this.offset.y],
  1776. center: [this.center.x, this.center.y],
  1777. rotation: this.rotation,
  1778. wrap: [this.wrapS, this.wrapT],
  1779. format: this.format,
  1780. type: this.type,
  1781. encoding: this.encoding,
  1782. minFilter: this.minFilter,
  1783. magFilter: this.magFilter,
  1784. anisotropy: this.anisotropy,
  1785. flipY: this.flipY,
  1786. premultiplyAlpha: this.premultiplyAlpha,
  1787. unpackAlignment: this.unpackAlignment
  1788. };
  1789. if (this.image !== undefined) {
  1790. // TODO: Move to THREE.Image
  1791. var image = this.image;
  1792. if (image.uuid === undefined) {
  1793. image.uuid = MathUtils.generateUUID(); // UGH
  1794. }
  1795. if (!isRootObject && meta.images[image.uuid] === undefined) {
  1796. var url;
  1797. if (Array.isArray(image)) {
  1798. // process array of images e.g. CubeTexture
  1799. url = [];
  1800. for (var i = 0, l = image.length; i < l; i++) {
  1801. // check cube texture with data textures
  1802. if (image[i].isDataTexture) {
  1803. url.push(serializeImage(image[i].image));
  1804. } else {
  1805. url.push(serializeImage(image[i]));
  1806. }
  1807. }
  1808. } else {
  1809. // process single image
  1810. url = serializeImage(image);
  1811. }
  1812. meta.images[image.uuid] = {
  1813. uuid: image.uuid,
  1814. url: url
  1815. };
  1816. }
  1817. output.image = image.uuid;
  1818. }
  1819. if (!isRootObject) {
  1820. meta.textures[this.uuid] = output;
  1821. }
  1822. return output;
  1823. },
  1824. dispose: function dispose() {
  1825. this.dispatchEvent({
  1826. type: 'dispose'
  1827. });
  1828. },
  1829. transformUv: function transformUv(uv) {
  1830. if (this.mapping !== UVMapping) return uv;
  1831. uv.applyMatrix3(this.matrix);
  1832. if (uv.x < 0 || uv.x > 1) {
  1833. switch (this.wrapS) {
  1834. case RepeatWrapping:
  1835. uv.x = uv.x - Math.floor(uv.x);
  1836. break;
  1837. case ClampToEdgeWrapping:
  1838. uv.x = uv.x < 0 ? 0 : 1;
  1839. break;
  1840. case MirroredRepeatWrapping:
  1841. if (Math.abs(Math.floor(uv.x) % 2) === 1) {
  1842. uv.x = Math.ceil(uv.x) - uv.x;
  1843. } else {
  1844. uv.x = uv.x - Math.floor(uv.x);
  1845. }
  1846. break;
  1847. }
  1848. }
  1849. if (uv.y < 0 || uv.y > 1) {
  1850. switch (this.wrapT) {
  1851. case RepeatWrapping:
  1852. uv.y = uv.y - Math.floor(uv.y);
  1853. break;
  1854. case ClampToEdgeWrapping:
  1855. uv.y = uv.y < 0 ? 0 : 1;
  1856. break;
  1857. case MirroredRepeatWrapping:
  1858. if (Math.abs(Math.floor(uv.y) % 2) === 1) {
  1859. uv.y = Math.ceil(uv.y) - uv.y;
  1860. } else {
  1861. uv.y = uv.y - Math.floor(uv.y);
  1862. }
  1863. break;
  1864. }
  1865. }
  1866. if (this.flipY) {
  1867. uv.y = 1 - uv.y;
  1868. }
  1869. return uv;
  1870. }
  1871. });
  1872. Object.defineProperty(Texture.prototype, 'needsUpdate', {
  1873. set: function set(value) {
  1874. if (value === true) this.version++;
  1875. }
  1876. });
  1877. function serializeImage(image) {
  1878. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  1879. // default images
  1880. return ImageUtils.getDataURL(image);
  1881. } else {
  1882. if (image.data) {
  1883. // images of DataTexture
  1884. return {
  1885. data: Array.prototype.slice.call(image.data),
  1886. width: image.width,
  1887. height: image.height,
  1888. type: image.data.constructor.name
  1889. };
  1890. } else {
  1891. console.warn('THREE.Texture: Unable to serialize Texture.');
  1892. return {};
  1893. }
  1894. }
  1895. }
  1896. var Vector4 = /*#__PURE__*/function () {
  1897. function Vector4(x, y, z, w) {
  1898. if (x === void 0) {
  1899. x = 0;
  1900. }
  1901. if (y === void 0) {
  1902. y = 0;
  1903. }
  1904. if (z === void 0) {
  1905. z = 0;
  1906. }
  1907. if (w === void 0) {
  1908. w = 1;
  1909. }
  1910. Object.defineProperty(this, 'isVector4', {
  1911. value: true
  1912. });
  1913. this.x = x;
  1914. this.y = y;
  1915. this.z = z;
  1916. this.w = w;
  1917. }
  1918. var _proto = Vector4.prototype;
  1919. _proto.set = function set(x, y, z, w) {
  1920. this.x = x;
  1921. this.y = y;
  1922. this.z = z;
  1923. this.w = w;
  1924. return this;
  1925. };
  1926. _proto.setScalar = function setScalar(scalar) {
  1927. this.x = scalar;
  1928. this.y = scalar;
  1929. this.z = scalar;
  1930. this.w = scalar;
  1931. return this;
  1932. };
  1933. _proto.setX = function setX(x) {
  1934. this.x = x;
  1935. return this;
  1936. };
  1937. _proto.setY = function setY(y) {
  1938. this.y = y;
  1939. return this;
  1940. };
  1941. _proto.setZ = function setZ(z) {
  1942. this.z = z;
  1943. return this;
  1944. };
  1945. _proto.setW = function setW(w) {
  1946. this.w = w;
  1947. return this;
  1948. };
  1949. _proto.setComponent = function setComponent(index, value) {
  1950. switch (index) {
  1951. case 0:
  1952. this.x = value;
  1953. break;
  1954. case 1:
  1955. this.y = value;
  1956. break;
  1957. case 2:
  1958. this.z = value;
  1959. break;
  1960. case 3:
  1961. this.w = value;
  1962. break;
  1963. default:
  1964. throw new Error('index is out of range: ' + index);
  1965. }
  1966. return this;
  1967. };
  1968. _proto.getComponent = function getComponent(index) {
  1969. switch (index) {
  1970. case 0:
  1971. return this.x;
  1972. case 1:
  1973. return this.y;
  1974. case 2:
  1975. return this.z;
  1976. case 3:
  1977. return this.w;
  1978. default:
  1979. throw new Error('index is out of range: ' + index);
  1980. }
  1981. };
  1982. _proto.clone = function clone() {
  1983. return new this.constructor(this.x, this.y, this.z, this.w);
  1984. };
  1985. _proto.copy = function copy(v) {
  1986. this.x = v.x;
  1987. this.y = v.y;
  1988. this.z = v.z;
  1989. this.w = v.w !== undefined ? v.w : 1;
  1990. return this;
  1991. };
  1992. _proto.add = function add(v, w) {
  1993. if (w !== undefined) {
  1994. console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1995. return this.addVectors(v, w);
  1996. }
  1997. this.x += v.x;
  1998. this.y += v.y;
  1999. this.z += v.z;
  2000. this.w += v.w;
  2001. return this;
  2002. };
  2003. _proto.addScalar = function addScalar(s) {
  2004. this.x += s;
  2005. this.y += s;
  2006. this.z += s;
  2007. this.w += s;
  2008. return this;
  2009. };
  2010. _proto.addVectors = function addVectors(a, b) {
  2011. this.x = a.x + b.x;
  2012. this.y = a.y + b.y;
  2013. this.z = a.z + b.z;
  2014. this.w = a.w + b.w;
  2015. return this;
  2016. };
  2017. _proto.addScaledVector = function addScaledVector(v, s) {
  2018. this.x += v.x * s;
  2019. this.y += v.y * s;
  2020. this.z += v.z * s;
  2021. this.w += v.w * s;
  2022. return this;
  2023. };
  2024. _proto.sub = function sub(v, w) {
  2025. if (w !== undefined) {
  2026. console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2027. return this.subVectors(v, w);
  2028. }
  2029. this.x -= v.x;
  2030. this.y -= v.y;
  2031. this.z -= v.z;
  2032. this.w -= v.w;
  2033. return this;
  2034. };
  2035. _proto.subScalar = function subScalar(s) {
  2036. this.x -= s;
  2037. this.y -= s;
  2038. this.z -= s;
  2039. this.w -= s;
  2040. return this;
  2041. };
  2042. _proto.subVectors = function subVectors(a, b) {
  2043. this.x = a.x - b.x;
  2044. this.y = a.y - b.y;
  2045. this.z = a.z - b.z;
  2046. this.w = a.w - b.w;
  2047. return this;
  2048. };
  2049. _proto.multiply = function multiply(v) {
  2050. this.x *= v.x;
  2051. this.y *= v.y;
  2052. this.z *= v.z;
  2053. this.w *= v.w;
  2054. return this;
  2055. };
  2056. _proto.multiplyScalar = function multiplyScalar(scalar) {
  2057. this.x *= scalar;
  2058. this.y *= scalar;
  2059. this.z *= scalar;
  2060. this.w *= scalar;
  2061. return this;
  2062. };
  2063. _proto.applyMatrix4 = function applyMatrix4(m) {
  2064. var x = this.x,
  2065. y = this.y,
  2066. z = this.z,
  2067. w = this.w;
  2068. var e = m.elements;
  2069. this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
  2070. this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
  2071. this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
  2072. this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
  2073. return this;
  2074. };
  2075. _proto.divideScalar = function divideScalar(scalar) {
  2076. return this.multiplyScalar(1 / scalar);
  2077. };
  2078. _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
  2079. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2080. // q is assumed to be normalized
  2081. this.w = 2 * Math.acos(q.w);
  2082. var s = Math.sqrt(1 - q.w * q.w);
  2083. if (s < 0.0001) {
  2084. this.x = 1;
  2085. this.y = 0;
  2086. this.z = 0;
  2087. } else {
  2088. this.x = q.x / s;
  2089. this.y = q.y / s;
  2090. this.z = q.z / s;
  2091. }
  2092. return this;
  2093. };
  2094. _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
  2095. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2096. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2097. var angle, x, y, z; // variables for result
  2098. var epsilon = 0.01,
  2099. // margin to allow for rounding errors
  2100. epsilon2 = 0.1,
  2101. // margin to distinguish between 0 and 180 degrees
  2102. te = m.elements,
  2103. m11 = te[0],
  2104. m12 = te[4],
  2105. m13 = te[8],
  2106. m21 = te[1],
  2107. m22 = te[5],
  2108. m23 = te[9],
  2109. m31 = te[2],
  2110. m32 = te[6],
  2111. m33 = te[10];
  2112. if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
  2113. // singularity found
  2114. // first check for identity matrix which must have +1 for all terms
  2115. // in leading diagonal and zero in other terms
  2116. if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
  2117. // this singularity is identity matrix so angle = 0
  2118. this.set(1, 0, 0, 0);
  2119. return this; // zero angle, arbitrary axis
  2120. } // otherwise this singularity is angle = 180
  2121. angle = Math.PI;
  2122. var xx = (m11 + 1) / 2;
  2123. var yy = (m22 + 1) / 2;
  2124. var zz = (m33 + 1) / 2;
  2125. var xy = (m12 + m21) / 4;
  2126. var xz = (m13 + m31) / 4;
  2127. var yz = (m23 + m32) / 4;
  2128. if (xx > yy && xx > zz) {
  2129. // m11 is the largest diagonal term
  2130. if (xx < epsilon) {
  2131. x = 0;
  2132. y = 0.707106781;
  2133. z = 0.707106781;
  2134. } else {
  2135. x = Math.sqrt(xx);
  2136. y = xy / x;
  2137. z = xz / x;
  2138. }
  2139. } else if (yy > zz) {
  2140. // m22 is the largest diagonal term
  2141. if (yy < epsilon) {
  2142. x = 0.707106781;
  2143. y = 0;
  2144. z = 0.707106781;
  2145. } else {
  2146. y = Math.sqrt(yy);
  2147. x = xy / y;
  2148. z = yz / y;
  2149. }
  2150. } else {
  2151. // m33 is the largest diagonal term so base result on this
  2152. if (zz < epsilon) {
  2153. x = 0.707106781;
  2154. y = 0.707106781;
  2155. z = 0;
  2156. } else {
  2157. z = Math.sqrt(zz);
  2158. x = xz / z;
  2159. y = yz / z;
  2160. }
  2161. }
  2162. this.set(x, y, z, angle);
  2163. return this; // return 180 deg rotation
  2164. } // as we have reached here there are no singularities so we can handle normally
  2165. var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
  2166. if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2167. // caught by singularity test above, but I've left it in just in case
  2168. this.x = (m32 - m23) / s;
  2169. this.y = (m13 - m31) / s;
  2170. this.z = (m21 - m12) / s;
  2171. this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
  2172. return this;
  2173. };
  2174. _proto.min = function min(v) {
  2175. this.x = Math.min(this.x, v.x);
  2176. this.y = Math.min(this.y, v.y);
  2177. this.z = Math.min(this.z, v.z);
  2178. this.w = Math.min(this.w, v.w);
  2179. return this;
  2180. };
  2181. _proto.max = function max(v) {
  2182. this.x = Math.max(this.x, v.x);
  2183. this.y = Math.max(this.y, v.y);
  2184. this.z = Math.max(this.z, v.z);
  2185. this.w = Math.max(this.w, v.w);
  2186. return this;
  2187. };
  2188. _proto.clamp = function clamp(min, max) {
  2189. // assumes min < max, componentwise
  2190. this.x = Math.max(min.x, Math.min(max.x, this.x));
  2191. this.y = Math.max(min.y, Math.min(max.y, this.y));
  2192. this.z = Math.max(min.z, Math.min(max.z, this.z));
  2193. this.w = Math.max(min.w, Math.min(max.w, this.w));
  2194. return this;
  2195. };
  2196. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  2197. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  2198. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  2199. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  2200. this.w = Math.max(minVal, Math.min(maxVal, this.w));
  2201. return this;
  2202. };
  2203. _proto.clampLength = function clampLength(min, max) {
  2204. var length = this.length();
  2205. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  2206. };
  2207. _proto.floor = function floor() {
  2208. this.x = Math.floor(this.x);
  2209. this.y = Math.floor(this.y);
  2210. this.z = Math.floor(this.z);
  2211. this.w = Math.floor(this.w);
  2212. return this;
  2213. };
  2214. _proto.ceil = function ceil() {
  2215. this.x = Math.ceil(this.x);
  2216. this.y = Math.ceil(this.y);
  2217. this.z = Math.ceil(this.z);
  2218. this.w = Math.ceil(this.w);
  2219. return this;
  2220. };
  2221. _proto.round = function round() {
  2222. this.x = Math.round(this.x);
  2223. this.y = Math.round(this.y);
  2224. this.z = Math.round(this.z);
  2225. this.w = Math.round(this.w);
  2226. return this;
  2227. };
  2228. _proto.roundToZero = function roundToZero() {
  2229. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  2230. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  2231. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  2232. this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
  2233. return this;
  2234. };
  2235. _proto.negate = function negate() {
  2236. this.x = -this.x;
  2237. this.y = -this.y;
  2238. this.z = -this.z;
  2239. this.w = -this.w;
  2240. return this;
  2241. };
  2242. _proto.dot = function dot(v) {
  2243. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2244. };
  2245. _proto.lengthSq = function lengthSq() {
  2246. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2247. };
  2248. _proto.length = function length() {
  2249. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  2250. };
  2251. _proto.manhattanLength = function manhattanLength() {
  2252. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  2253. };
  2254. _proto.normalize = function normalize() {
  2255. return this.divideScalar(this.length() || 1);
  2256. };
  2257. _proto.setLength = function setLength(length) {
  2258. return this.normalize().multiplyScalar(length);
  2259. };
  2260. _proto.lerp = function lerp(v, alpha) {
  2261. this.x += (v.x - this.x) * alpha;
  2262. this.y += (v.y - this.y) * alpha;
  2263. this.z += (v.z - this.z) * alpha;
  2264. this.w += (v.w - this.w) * alpha;
  2265. return this;
  2266. };
  2267. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  2268. this.x = v1.x + (v2.x - v1.x) * alpha;
  2269. this.y = v1.y + (v2.y - v1.y) * alpha;
  2270. this.z = v1.z + (v2.z - v1.z) * alpha;
  2271. this.w = v1.w + (v2.w - v1.w) * alpha;
  2272. return this;
  2273. };
  2274. _proto.equals = function equals(v) {
  2275. return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
  2276. };
  2277. _proto.fromArray = function fromArray(array, offset) {
  2278. if (offset === void 0) {
  2279. offset = 0;
  2280. }
  2281. this.x = array[offset];
  2282. this.y = array[offset + 1];
  2283. this.z = array[offset + 2];
  2284. this.w = array[offset + 3];
  2285. return this;
  2286. };
  2287. _proto.toArray = function toArray(array, offset) {
  2288. if (array === void 0) {
  2289. array = [];
  2290. }
  2291. if (offset === void 0) {
  2292. offset = 0;
  2293. }
  2294. array[offset] = this.x;
  2295. array[offset + 1] = this.y;
  2296. array[offset + 2] = this.z;
  2297. array[offset + 3] = this.w;
  2298. return array;
  2299. };
  2300. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  2301. if (offset !== undefined) {
  2302. console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
  2303. }
  2304. this.x = attribute.getX(index);
  2305. this.y = attribute.getY(index);
  2306. this.z = attribute.getZ(index);
  2307. this.w = attribute.getW(index);
  2308. return this;
  2309. };
  2310. _proto.random = function random() {
  2311. this.x = Math.random();
  2312. this.y = Math.random();
  2313. this.z = Math.random();
  2314. this.w = Math.random();
  2315. return this;
  2316. };
  2317. _createClass(Vector4, [{
  2318. key: "width",
  2319. get: function get() {
  2320. return this.z;
  2321. },
  2322. set: function set(value) {
  2323. this.z = value;
  2324. }
  2325. }, {
  2326. key: "height",
  2327. get: function get() {
  2328. return this.w;
  2329. },
  2330. set: function set(value) {
  2331. this.w = value;
  2332. }
  2333. }]);
  2334. return Vector4;
  2335. }();
  2336. /*
  2337. In options, we can specify:
  2338. * Texture parameters for an auto-generated target texture
  2339. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2340. */
  2341. var WebGLRenderTarget = /*#__PURE__*/function (_EventDispatcher) {
  2342. _inheritsLoose(WebGLRenderTarget, _EventDispatcher);
  2343. function WebGLRenderTarget(width, height, options) {
  2344. var _this;
  2345. _this = _EventDispatcher.call(this) || this;
  2346. Object.defineProperty(_assertThisInitialized(_this), 'isWebGLRenderTarget', {
  2347. value: true
  2348. });
  2349. _this.width = width;
  2350. _this.height = height;
  2351. _this.scissor = new Vector4(0, 0, width, height);
  2352. _this.scissorTest = false;
  2353. _this.viewport = new Vector4(0, 0, width, height);
  2354. options = options || {};
  2355. _this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  2356. _this.texture.image = {};
  2357. _this.texture.image.width = width;
  2358. _this.texture.image.height = height;
  2359. _this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2360. _this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2361. _this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2362. _this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  2363. _this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2364. return _this;
  2365. }
  2366. var _proto = WebGLRenderTarget.prototype;
  2367. _proto.setSize = function setSize(width, height) {
  2368. if (this.width !== width || this.height !== height) {
  2369. this.width = width;
  2370. this.height = height;
  2371. this.texture.image.width = width;
  2372. this.texture.image.height = height;
  2373. this.dispose();
  2374. }
  2375. this.viewport.set(0, 0, width, height);
  2376. this.scissor.set(0, 0, width, height);
  2377. };
  2378. _proto.clone = function clone() {
  2379. return new this.constructor().copy(this);
  2380. };
  2381. _proto.copy = function copy(source) {
  2382. this.width = source.width;
  2383. this.height = source.height;
  2384. this.viewport.copy(source.viewport);
  2385. this.texture = source.texture.clone();
  2386. this.depthBuffer = source.depthBuffer;
  2387. this.stencilBuffer = source.stencilBuffer;
  2388. this.depthTexture = source.depthTexture;
  2389. return this;
  2390. };
  2391. _proto.dispose = function dispose() {
  2392. this.dispatchEvent({
  2393. type: 'dispose'
  2394. });
  2395. };
  2396. return WebGLRenderTarget;
  2397. }(EventDispatcher);
  2398. var WebGLMultisampleRenderTarget = /*#__PURE__*/function (_WebGLRenderTarget) {
  2399. _inheritsLoose(WebGLMultisampleRenderTarget, _WebGLRenderTarget);
  2400. function WebGLMultisampleRenderTarget(width, height, options) {
  2401. var _this;
  2402. _this = _WebGLRenderTarget.call(this, width, height, options) || this;
  2403. Object.defineProperty(_assertThisInitialized(_this), 'isWebGLMultisampleRenderTarget', {
  2404. value: true
  2405. });
  2406. _this.samples = 4;
  2407. return _this;
  2408. }
  2409. var _proto = WebGLMultisampleRenderTarget.prototype;
  2410. _proto.copy = function copy(source) {
  2411. _WebGLRenderTarget.prototype.copy.call(this, source);
  2412. this.samples = source.samples;
  2413. return this;
  2414. };
  2415. return WebGLMultisampleRenderTarget;
  2416. }(WebGLRenderTarget);
  2417. var Quaternion = /*#__PURE__*/function () {
  2418. function Quaternion(x, y, z, w) {
  2419. if (x === void 0) {
  2420. x = 0;
  2421. }
  2422. if (y === void 0) {
  2423. y = 0;
  2424. }
  2425. if (z === void 0) {
  2426. z = 0;
  2427. }
  2428. if (w === void 0) {
  2429. w = 1;
  2430. }
  2431. Object.defineProperty(this, 'isQuaternion', {
  2432. value: true
  2433. });
  2434. this._x = x;
  2435. this._y = y;
  2436. this._z = z;
  2437. this._w = w;
  2438. }
  2439. Quaternion.slerp = function slerp(qa, qb, qm, t) {
  2440. return qm.copy(qa).slerp(qb, t);
  2441. };
  2442. Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
  2443. // fuzz-free, array-based Quaternion SLERP operation
  2444. var x0 = src0[srcOffset0 + 0],
  2445. y0 = src0[srcOffset0 + 1],
  2446. z0 = src0[srcOffset0 + 2],
  2447. w0 = src0[srcOffset0 + 3];
  2448. var x1 = src1[srcOffset1 + 0],
  2449. y1 = src1[srcOffset1 + 1],
  2450. z1 = src1[srcOffset1 + 2],
  2451. w1 = src1[srcOffset1 + 3];
  2452. if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
  2453. var s = 1 - t;
  2454. var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  2455. dir = cos >= 0 ? 1 : -1,
  2456. sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
  2457. if (sqrSin > Number.EPSILON) {
  2458. var sin = Math.sqrt(sqrSin),
  2459. len = Math.atan2(sin, cos * dir);
  2460. s = Math.sin(s * len) / sin;
  2461. t = Math.sin(t * len) / sin;
  2462. }
  2463. var tDir = t * dir;
  2464. x0 = x0 * s + x1 * tDir;
  2465. y0 = y0 * s + y1 * tDir;
  2466. z0 = z0 * s + z1 * tDir;
  2467. w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
  2468. if (s === 1 - t) {
  2469. var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
  2470. x0 *= f;
  2471. y0 *= f;
  2472. z0 *= f;
  2473. w0 *= f;
  2474. }
  2475. }
  2476. dst[dstOffset] = x0;
  2477. dst[dstOffset + 1] = y0;
  2478. dst[dstOffset + 2] = z0;
  2479. dst[dstOffset + 3] = w0;
  2480. };
  2481. Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
  2482. var x0 = src0[srcOffset0];
  2483. var y0 = src0[srcOffset0 + 1];
  2484. var z0 = src0[srcOffset0 + 2];
  2485. var w0 = src0[srcOffset0 + 3];
  2486. var x1 = src1[srcOffset1];
  2487. var y1 = src1[srcOffset1 + 1];
  2488. var z1 = src1[srcOffset1 + 2];
  2489. var w1 = src1[srcOffset1 + 3];
  2490. dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  2491. dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  2492. dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  2493. dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  2494. return dst;
  2495. };
  2496. var _proto = Quaternion.prototype;
  2497. _proto.set = function set(x, y, z, w) {
  2498. this._x = x;
  2499. this._y = y;
  2500. this._z = z;
  2501. this._w = w;
  2502. this._onChangeCallback();
  2503. return this;
  2504. };
  2505. _proto.clone = function clone() {
  2506. return new this.constructor(this._x, this._y, this._z, this._w);
  2507. };
  2508. _proto.copy = function copy(quaternion) {
  2509. this._x = quaternion.x;
  2510. this._y = quaternion.y;
  2511. this._z = quaternion.z;
  2512. this._w = quaternion.w;
  2513. this._onChangeCallback();
  2514. return this;
  2515. };
  2516. _proto.setFromEuler = function setFromEuler(euler, update) {
  2517. if (!(euler && euler.isEuler)) {
  2518. throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
  2519. }
  2520. var x = euler._x,
  2521. y = euler._y,
  2522. z = euler._z,
  2523. order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
  2524. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  2525. // content/SpinCalc.m
  2526. var cos = Math.cos;
  2527. var sin = Math.sin;
  2528. var c1 = cos(x / 2);
  2529. var c2 = cos(y / 2);
  2530. var c3 = cos(z / 2);
  2531. var s1 = sin(x / 2);
  2532. var s2 = sin(y / 2);
  2533. var s3 = sin(z / 2);
  2534. switch (order) {
  2535. case 'XYZ':
  2536. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2537. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2538. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2539. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2540. break;
  2541. case 'YXZ':
  2542. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2543. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2544. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2545. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2546. break;
  2547. case 'ZXY':
  2548. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2549. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2550. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2551. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2552. break;
  2553. case 'ZYX':
  2554. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2555. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2556. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2557. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2558. break;
  2559. case 'YZX':
  2560. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2561. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2562. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2563. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2564. break;
  2565. case 'XZY':
  2566. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2567. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2568. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2569. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2570. break;
  2571. default:
  2572. console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
  2573. }
  2574. if (update !== false) this._onChangeCallback();
  2575. return this;
  2576. };
  2577. _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
  2578. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  2579. // assumes axis is normalized
  2580. var halfAngle = angle / 2,
  2581. s = Math.sin(halfAngle);
  2582. this._x = axis.x * s;
  2583. this._y = axis.y * s;
  2584. this._z = axis.z * s;
  2585. this._w = Math.cos(halfAngle);
  2586. this._onChangeCallback();
  2587. return this;
  2588. };
  2589. _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
  2590. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  2591. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2592. var te = m.elements,
  2593. m11 = te[0],
  2594. m12 = te[4],
  2595. m13 = te[8],
  2596. m21 = te[1],
  2597. m22 = te[5],
  2598. m23 = te[9],
  2599. m31 = te[2],
  2600. m32 = te[6],
  2601. m33 = te[10],
  2602. trace = m11 + m22 + m33;
  2603. if (trace > 0) {
  2604. var s = 0.5 / Math.sqrt(trace + 1.0);
  2605. this._w = 0.25 / s;
  2606. this._x = (m32 - m23) * s;
  2607. this._y = (m13 - m31) * s;
  2608. this._z = (m21 - m12) * s;
  2609. } else if (m11 > m22 && m11 > m33) {
  2610. var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  2611. this._w = (m32 - m23) / _s;
  2612. this._x = 0.25 * _s;
  2613. this._y = (m12 + m21) / _s;
  2614. this._z = (m13 + m31) / _s;
  2615. } else if (m22 > m33) {
  2616. var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  2617. this._w = (m13 - m31) / _s2;
  2618. this._x = (m12 + m21) / _s2;
  2619. this._y = 0.25 * _s2;
  2620. this._z = (m23 + m32) / _s2;
  2621. } else {
  2622. var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  2623. this._w = (m21 - m12) / _s3;
  2624. this._x = (m13 + m31) / _s3;
  2625. this._y = (m23 + m32) / _s3;
  2626. this._z = 0.25 * _s3;
  2627. }
  2628. this._onChangeCallback();
  2629. return this;
  2630. };
  2631. _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
  2632. // assumes direction vectors vFrom and vTo are normalized
  2633. var EPS = 0.000001;
  2634. var r = vFrom.dot(vTo) + 1;
  2635. if (r < EPS) {
  2636. r = 0;
  2637. if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
  2638. this._x = -vFrom.y;
  2639. this._y = vFrom.x;
  2640. this._z = 0;
  2641. this._w = r;
  2642. } else {
  2643. this._x = 0;
  2644. this._y = -vFrom.z;
  2645. this._z = vFrom.y;
  2646. this._w = r;
  2647. }
  2648. } else {
  2649. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  2650. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  2651. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  2652. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  2653. this._w = r;
  2654. }
  2655. return this.normalize();
  2656. };
  2657. _proto.angleTo = function angleTo(q) {
  2658. return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
  2659. };
  2660. _proto.rotateTowards = function rotateTowards(q, step) {
  2661. var angle = this.angleTo(q);
  2662. if (angle === 0) return this;
  2663. var t = Math.min(1, step / angle);
  2664. this.slerp(q, t);
  2665. return this;
  2666. };
  2667. _proto.identity = function identity() {
  2668. return this.set(0, 0, 0, 1);
  2669. };
  2670. _proto.invert = function invert() {
  2671. // quaternion is assumed to have unit length
  2672. return this.conjugate();
  2673. };
  2674. _proto.conjugate = function conjugate() {
  2675. this._x *= -1;
  2676. this._y *= -1;
  2677. this._z *= -1;
  2678. this._onChangeCallback();
  2679. return this;
  2680. };
  2681. _proto.dot = function dot(v) {
  2682. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  2683. };
  2684. _proto.lengthSq = function lengthSq() {
  2685. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  2686. };
  2687. _proto.length = function length() {
  2688. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  2689. };
  2690. _proto.normalize = function normalize() {
  2691. var l = this.length();
  2692. if (l === 0) {
  2693. this._x = 0;
  2694. this._y = 0;
  2695. this._z = 0;
  2696. this._w = 1;
  2697. } else {
  2698. l = 1 / l;
  2699. this._x = this._x * l;
  2700. this._y = this._y * l;
  2701. this._z = this._z * l;
  2702. this._w = this._w * l;
  2703. }
  2704. this._onChangeCallback();
  2705. return this;
  2706. };
  2707. _proto.multiply = function multiply(q, p) {
  2708. if (p !== undefined) {
  2709. console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
  2710. return this.multiplyQuaternions(q, p);
  2711. }
  2712. return this.multiplyQuaternions(this, q);
  2713. };
  2714. _proto.premultiply = function premultiply(q) {
  2715. return this.multiplyQuaternions(q, this);
  2716. };
  2717. _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
  2718. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2719. var qax = a._x,
  2720. qay = a._y,
  2721. qaz = a._z,
  2722. qaw = a._w;
  2723. var qbx = b._x,
  2724. qby = b._y,
  2725. qbz = b._z,
  2726. qbw = b._w;
  2727. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2728. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2729. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2730. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2731. this._onChangeCallback();
  2732. return this;
  2733. };
  2734. _proto.slerp = function slerp(qb, t) {
  2735. if (t === 0) return this;
  2736. if (t === 1) return this.copy(qb);
  2737. var x = this._x,
  2738. y = this._y,
  2739. z = this._z,
  2740. w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2741. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2742. if (cosHalfTheta < 0) {
  2743. this._w = -qb._w;
  2744. this._x = -qb._x;
  2745. this._y = -qb._y;
  2746. this._z = -qb._z;
  2747. cosHalfTheta = -cosHalfTheta;
  2748. } else {
  2749. this.copy(qb);
  2750. }
  2751. if (cosHalfTheta >= 1.0) {
  2752. this._w = w;
  2753. this._x = x;
  2754. this._y = y;
  2755. this._z = z;
  2756. return this;
  2757. }
  2758. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2759. if (sqrSinHalfTheta <= Number.EPSILON) {
  2760. var s = 1 - t;
  2761. this._w = s * w + t * this._w;
  2762. this._x = s * x + t * this._x;
  2763. this._y = s * y + t * this._y;
  2764. this._z = s * z + t * this._z;
  2765. this.normalize();
  2766. this._onChangeCallback();
  2767. return this;
  2768. }
  2769. var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
  2770. var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
  2771. var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
  2772. ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
  2773. this._w = w * ratioA + this._w * ratioB;
  2774. this._x = x * ratioA + this._x * ratioB;
  2775. this._y = y * ratioA + this._y * ratioB;
  2776. this._z = z * ratioA + this._z * ratioB;
  2777. this._onChangeCallback();
  2778. return this;
  2779. };
  2780. _proto.equals = function equals(quaternion) {
  2781. return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
  2782. };
  2783. _proto.fromArray = function fromArray(array, offset) {
  2784. if (offset === void 0) {
  2785. offset = 0;
  2786. }
  2787. this._x = array[offset];
  2788. this._y = array[offset + 1];
  2789. this._z = array[offset + 2];
  2790. this._w = array[offset + 3];
  2791. this._onChangeCallback();
  2792. return this;
  2793. };
  2794. _proto.toArray = function toArray(array, offset) {
  2795. if (array === void 0) {
  2796. array = [];
  2797. }
  2798. if (offset === void 0) {
  2799. offset = 0;
  2800. }
  2801. array[offset] = this._x;
  2802. array[offset + 1] = this._y;
  2803. array[offset + 2] = this._z;
  2804. array[offset + 3] = this._w;
  2805. return array;
  2806. };
  2807. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  2808. this._x = attribute.getX(index);
  2809. this._y = attribute.getY(index);
  2810. this._z = attribute.getZ(index);
  2811. this._w = attribute.getW(index);
  2812. return this;
  2813. };
  2814. _proto._onChange = function _onChange(callback) {
  2815. this._onChangeCallback = callback;
  2816. return this;
  2817. };
  2818. _proto._onChangeCallback = function _onChangeCallback() {};
  2819. _createClass(Quaternion, [{
  2820. key: "x",
  2821. get: function get() {
  2822. return this._x;
  2823. },
  2824. set: function set(value) {
  2825. this._x = value;
  2826. this._onChangeCallback();
  2827. }
  2828. }, {
  2829. key: "y",
  2830. get: function get() {
  2831. return this._y;
  2832. },
  2833. set: function set(value) {
  2834. this._y = value;
  2835. this._onChangeCallback();
  2836. }
  2837. }, {
  2838. key: "z",
  2839. get: function get() {
  2840. return this._z;
  2841. },
  2842. set: function set(value) {
  2843. this._z = value;
  2844. this._onChangeCallback();
  2845. }
  2846. }, {
  2847. key: "w",
  2848. get: function get() {
  2849. return this._w;
  2850. },
  2851. set: function set(value) {
  2852. this._w = value;
  2853. this._onChangeCallback();
  2854. }
  2855. }]);
  2856. return Quaternion;
  2857. }();
  2858. var Vector3 = /*#__PURE__*/function () {
  2859. function Vector3(x, y, z) {
  2860. if (x === void 0) {
  2861. x = 0;
  2862. }
  2863. if (y === void 0) {
  2864. y = 0;
  2865. }
  2866. if (z === void 0) {
  2867. z = 0;
  2868. }
  2869. Object.defineProperty(this, 'isVector3', {
  2870. value: true
  2871. });
  2872. this.x = x;
  2873. this.y = y;
  2874. this.z = z;
  2875. }
  2876. var _proto = Vector3.prototype;
  2877. _proto.set = function set(x, y, z) {
  2878. if (z === undefined) z = this.z; // sprite.scale.set(x,y)
  2879. this.x = x;
  2880. this.y = y;
  2881. this.z = z;
  2882. return this;
  2883. };
  2884. _proto.setScalar = function setScalar(scalar) {
  2885. this.x = scalar;
  2886. this.y = scalar;
  2887. this.z = scalar;
  2888. return this;
  2889. };
  2890. _proto.setX = function setX(x) {
  2891. this.x = x;
  2892. return this;
  2893. };
  2894. _proto.setY = function setY(y) {
  2895. this.y = y;
  2896. return this;
  2897. };
  2898. _proto.setZ = function setZ(z) {
  2899. this.z = z;
  2900. return this;
  2901. };
  2902. _proto.setComponent = function setComponent(index, value) {
  2903. switch (index) {
  2904. case 0:
  2905. this.x = value;
  2906. break;
  2907. case 1:
  2908. this.y = value;
  2909. break;
  2910. case 2:
  2911. this.z = value;
  2912. break;
  2913. default:
  2914. throw new Error('index is out of range: ' + index);
  2915. }
  2916. return this;
  2917. };
  2918. _proto.getComponent = function getComponent(index) {
  2919. switch (index) {
  2920. case 0:
  2921. return this.x;
  2922. case 1:
  2923. return this.y;
  2924. case 2:
  2925. return this.z;
  2926. default:
  2927. throw new Error('index is out of range: ' + index);
  2928. }
  2929. };
  2930. _proto.clone = function clone() {
  2931. return new this.constructor(this.x, this.y, this.z);
  2932. };
  2933. _proto.copy = function copy(v) {
  2934. this.x = v.x;
  2935. this.y = v.y;
  2936. this.z = v.z;
  2937. return this;
  2938. };
  2939. _proto.add = function add(v, w) {
  2940. if (w !== undefined) {
  2941. console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2942. return this.addVectors(v, w);
  2943. }
  2944. this.x += v.x;
  2945. this.y += v.y;
  2946. this.z += v.z;
  2947. return this;
  2948. };
  2949. _proto.addScalar = function addScalar(s) {
  2950. this.x += s;
  2951. this.y += s;
  2952. this.z += s;
  2953. return this;
  2954. };
  2955. _proto.addVectors = function addVectors(a, b) {
  2956. this.x = a.x + b.x;
  2957. this.y = a.y + b.y;
  2958. this.z = a.z + b.z;
  2959. return this;
  2960. };
  2961. _proto.addScaledVector = function addScaledVector(v, s) {
  2962. this.x += v.x * s;
  2963. this.y += v.y * s;
  2964. this.z += v.z * s;
  2965. return this;
  2966. };
  2967. _proto.sub = function sub(v, w) {
  2968. if (w !== undefined) {
  2969. console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2970. return this.subVectors(v, w);
  2971. }
  2972. this.x -= v.x;
  2973. this.y -= v.y;
  2974. this.z -= v.z;
  2975. return this;
  2976. };
  2977. _proto.subScalar = function subScalar(s) {
  2978. this.x -= s;
  2979. this.y -= s;
  2980. this.z -= s;
  2981. return this;
  2982. };
  2983. _proto.subVectors = function subVectors(a, b) {
  2984. this.x = a.x - b.x;
  2985. this.y = a.y - b.y;
  2986. this.z = a.z - b.z;
  2987. return this;
  2988. };
  2989. _proto.multiply = function multiply(v, w) {
  2990. if (w !== undefined) {
  2991. console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
  2992. return this.multiplyVectors(v, w);
  2993. }
  2994. this.x *= v.x;
  2995. this.y *= v.y;
  2996. this.z *= v.z;
  2997. return this;
  2998. };
  2999. _proto.multiplyScalar = function multiplyScalar(scalar) {
  3000. this.x *= scalar;
  3001. this.y *= scalar;
  3002. this.z *= scalar;
  3003. return this;
  3004. };
  3005. _proto.multiplyVectors = function multiplyVectors(a, b) {
  3006. this.x = a.x * b.x;
  3007. this.y = a.y * b.y;
  3008. this.z = a.z * b.z;
  3009. return this;
  3010. };
  3011. _proto.applyEuler = function applyEuler(euler) {
  3012. if (!(euler && euler.isEuler)) {
  3013. console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
  3014. }
  3015. return this.applyQuaternion(_quaternion.setFromEuler(euler));
  3016. };
  3017. _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
  3018. return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
  3019. };
  3020. _proto.applyMatrix3 = function applyMatrix3(m) {
  3021. var x = this.x,
  3022. y = this.y,
  3023. z = this.z;
  3024. var e = m.elements;
  3025. this.x = e[0] * x + e[3] * y + e[6] * z;
  3026. this.y = e[1] * x + e[4] * y + e[7] * z;
  3027. this.z = e[2] * x + e[5] * y + e[8] * z;
  3028. return this;
  3029. };
  3030. _proto.applyNormalMatrix = function applyNormalMatrix(m) {
  3031. return this.applyMatrix3(m).normalize();
  3032. };
  3033. _proto.applyMatrix4 = function applyMatrix4(m) {
  3034. var x = this.x,
  3035. y = this.y,
  3036. z = this.z;
  3037. var e = m.elements;
  3038. var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
  3039. this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
  3040. this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
  3041. this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
  3042. return this;
  3043. };
  3044. _proto.applyQuaternion = function applyQuaternion(q) {
  3045. var x = this.x,
  3046. y = this.y,
  3047. z = this.z;
  3048. var qx = q.x,
  3049. qy = q.y,
  3050. qz = q.z,
  3051. qw = q.w; // calculate quat * vector
  3052. var ix = qw * x + qy * z - qz * y;
  3053. var iy = qw * y + qz * x - qx * z;
  3054. var iz = qw * z + qx * y - qy * x;
  3055. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  3056. this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  3057. this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  3058. this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  3059. return this;
  3060. };
  3061. _proto.project = function project(camera) {
  3062. return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
  3063. };
  3064. _proto.unproject = function unproject(camera) {
  3065. return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
  3066. };
  3067. _proto.transformDirection = function transformDirection(m) {
  3068. // input: THREE.Matrix4 affine matrix
  3069. // vector interpreted as a direction
  3070. var x = this.x,
  3071. y = this.y,
  3072. z = this.z;
  3073. var e = m.elements;
  3074. this.x = e[0] * x + e[4] * y + e[8] * z;
  3075. this.y = e[1] * x + e[5] * y + e[9] * z;
  3076. this.z = e[2] * x + e[6] * y + e[10] * z;
  3077. return this.normalize();
  3078. };
  3079. _proto.divide = function divide(v) {
  3080. this.x /= v.x;
  3081. this.y /= v.y;
  3082. this.z /= v.z;
  3083. return this;
  3084. };
  3085. _proto.divideScalar = function divideScalar(scalar) {
  3086. return this.multiplyScalar(1 / scalar);
  3087. };
  3088. _proto.min = function min(v) {
  3089. this.x = Math.min(this.x, v.x);
  3090. this.y = Math.min(this.y, v.y);
  3091. this.z = Math.min(this.z, v.z);
  3092. return this;
  3093. };
  3094. _proto.max = function max(v) {
  3095. this.x = Math.max(this.x, v.x);
  3096. this.y = Math.max(this.y, v.y);
  3097. this.z = Math.max(this.z, v.z);
  3098. return this;
  3099. };
  3100. _proto.clamp = function clamp(min, max) {
  3101. // assumes min < max, componentwise
  3102. this.x = Math.max(min.x, Math.min(max.x, this.x));
  3103. this.y = Math.max(min.y, Math.min(max.y, this.y));
  3104. this.z = Math.max(min.z, Math.min(max.z, this.z));
  3105. return this;
  3106. };
  3107. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  3108. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  3109. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  3110. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  3111. return this;
  3112. };
  3113. _proto.clampLength = function clampLength(min, max) {
  3114. var length = this.length();
  3115. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  3116. };
  3117. _proto.floor = function floor() {
  3118. this.x = Math.floor(this.x);
  3119. this.y = Math.floor(this.y);
  3120. this.z = Math.floor(this.z);
  3121. return this;
  3122. };
  3123. _proto.ceil = function ceil() {
  3124. this.x = Math.ceil(this.x);
  3125. this.y = Math.ceil(this.y);
  3126. this.z = Math.ceil(this.z);
  3127. return this;
  3128. };
  3129. _proto.round = function round() {
  3130. this.x = Math.round(this.x);
  3131. this.y = Math.round(this.y);
  3132. this.z = Math.round(this.z);
  3133. return this;
  3134. };
  3135. _proto.roundToZero = function roundToZero() {
  3136. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  3137. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  3138. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  3139. return this;
  3140. };
  3141. _proto.negate = function negate() {
  3142. this.x = -this.x;
  3143. this.y = -this.y;
  3144. this.z = -this.z;
  3145. return this;
  3146. };
  3147. _proto.dot = function dot(v) {
  3148. return this.x * v.x + this.y * v.y + this.z * v.z;
  3149. } // TODO lengthSquared?
  3150. ;
  3151. _proto.lengthSq = function lengthSq() {
  3152. return this.x * this.x + this.y * this.y + this.z * this.z;
  3153. };
  3154. _proto.length = function length() {
  3155. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  3156. };
  3157. _proto.manhattanLength = function manhattanLength() {
  3158. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  3159. };
  3160. _proto.normalize = function normalize() {
  3161. return this.divideScalar(this.length() || 1);
  3162. };
  3163. _proto.setLength = function setLength(length) {
  3164. return this.normalize().multiplyScalar(length);
  3165. };
  3166. _proto.lerp = function lerp(v, alpha) {
  3167. this.x += (v.x - this.x) * alpha;
  3168. this.y += (v.y - this.y) * alpha;
  3169. this.z += (v.z - this.z) * alpha;
  3170. return this;
  3171. };
  3172. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  3173. this.x = v1.x + (v2.x - v1.x) * alpha;
  3174. this.y = v1.y + (v2.y - v1.y) * alpha;
  3175. this.z = v1.z + (v2.z - v1.z) * alpha;
  3176. return this;
  3177. };
  3178. _proto.cross = function cross(v, w) {
  3179. if (w !== undefined) {
  3180. console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
  3181. return this.crossVectors(v, w);
  3182. }
  3183. return this.crossVectors(this, v);
  3184. };
  3185. _proto.crossVectors = function crossVectors(a, b) {
  3186. var ax = a.x,
  3187. ay = a.y,
  3188. az = a.z;
  3189. var bx = b.x,
  3190. by = b.y,
  3191. bz = b.z;
  3192. this.x = ay * bz - az * by;
  3193. this.y = az * bx - ax * bz;
  3194. this.z = ax * by - ay * bx;
  3195. return this;
  3196. };
  3197. _proto.projectOnVector = function projectOnVector(v) {
  3198. var denominator = v.lengthSq();
  3199. if (denominator === 0) return this.set(0, 0, 0);
  3200. var scalar = v.dot(this) / denominator;
  3201. return this.copy(v).multiplyScalar(scalar);
  3202. };
  3203. _proto.projectOnPlane = function projectOnPlane(planeNormal) {
  3204. _vector.copy(this).projectOnVector(planeNormal);
  3205. return this.sub(_vector);
  3206. };
  3207. _proto.reflect = function reflect(normal) {
  3208. // reflect incident vector off plane orthogonal to normal
  3209. // normal is assumed to have unit length
  3210. return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
  3211. };
  3212. _proto.angleTo = function angleTo(v) {
  3213. var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
  3214. if (denominator === 0) return Math.PI / 2;
  3215. var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
  3216. return Math.acos(MathUtils.clamp(theta, -1, 1));
  3217. };
  3218. _proto.distanceTo = function distanceTo(v) {
  3219. return Math.sqrt(this.distanceToSquared(v));
  3220. };
  3221. _proto.distanceToSquared = function distanceToSquared(v) {
  3222. var dx = this.x - v.x,
  3223. dy = this.y - v.y,
  3224. dz = this.z - v.z;
  3225. return dx * dx + dy * dy + dz * dz;
  3226. };
  3227. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  3228. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
  3229. };
  3230. _proto.setFromSpherical = function setFromSpherical(s) {
  3231. return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
  3232. };
  3233. _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
  3234. var sinPhiRadius = Math.sin(phi) * radius;
  3235. this.x = sinPhiRadius * Math.sin(theta);
  3236. this.y = Math.cos(phi) * radius;
  3237. this.z = sinPhiRadius * Math.cos(theta);
  3238. return this;
  3239. };
  3240. _proto.setFromCylindrical = function setFromCylindrical(c) {
  3241. return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
  3242. };
  3243. _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
  3244. this.x = radius * Math.sin(theta);
  3245. this.y = y;
  3246. this.z = radius * Math.cos(theta);
  3247. return this;
  3248. };
  3249. _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
  3250. var e = m.elements;
  3251. this.x = e[12];
  3252. this.y = e[13];
  3253. this.z = e[14];
  3254. return this;
  3255. };
  3256. _proto.setFromMatrixScale = function setFromMatrixScale(m) {
  3257. var sx = this.setFromMatrixColumn(m, 0).length();
  3258. var sy = this.setFromMatrixColumn(m, 1).length();
  3259. var sz = this.setFromMatrixColumn(m, 2).length();
  3260. this.x = sx;
  3261. this.y = sy;
  3262. this.z = sz;
  3263. return this;
  3264. };
  3265. _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
  3266. return this.fromArray(m.elements, index * 4);
  3267. };
  3268. _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
  3269. return this.fromArray(m.elements, index * 3);
  3270. };
  3271. _proto.equals = function equals(v) {
  3272. return v.x === this.x && v.y === this.y && v.z === this.z;
  3273. };
  3274. _proto.fromArray = function fromArray(array, offset) {
  3275. if (offset === void 0) {
  3276. offset = 0;
  3277. }
  3278. this.x = array[offset];
  3279. this.y = array[offset + 1];
  3280. this.z = array[offset + 2];
  3281. return this;
  3282. };
  3283. _proto.toArray = function toArray(array, offset) {
  3284. if (array === void 0) {
  3285. array = [];
  3286. }
  3287. if (offset === void 0) {
  3288. offset = 0;
  3289. }
  3290. array[offset] = this.x;
  3291. array[offset + 1] = this.y;
  3292. array[offset + 2] = this.z;
  3293. return array;
  3294. };
  3295. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  3296. if (offset !== undefined) {
  3297. console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
  3298. }
  3299. this.x = attribute.getX(index);
  3300. this.y = attribute.getY(index);
  3301. this.z = attribute.getZ(index);
  3302. return this;
  3303. };
  3304. _proto.random = function random() {
  3305. this.x = Math.random();
  3306. this.y = Math.random();
  3307. this.z = Math.random();
  3308. return this;
  3309. };
  3310. return Vector3;
  3311. }();
  3312. var _vector = /*@__PURE__*/new Vector3();
  3313. var _quaternion = /*@__PURE__*/new Quaternion();
  3314. var Box3 = /*#__PURE__*/function () {
  3315. function Box3(min, max) {
  3316. Object.defineProperty(this, 'isBox3', {
  3317. value: true
  3318. });
  3319. this.min = min !== undefined ? min : new Vector3(+Infinity, +Infinity, +Infinity);
  3320. this.max = max !== undefined ? max : new Vector3(-Infinity, -Infinity, -Infinity);
  3321. }
  3322. var _proto = Box3.prototype;
  3323. _proto.set = function set(min, max) {
  3324. this.min.copy(min);
  3325. this.max.copy(max);
  3326. return this;
  3327. };
  3328. _proto.setFromArray = function setFromArray(array) {
  3329. var minX = +Infinity;
  3330. var minY = +Infinity;
  3331. var minZ = +Infinity;
  3332. var maxX = -Infinity;
  3333. var maxY = -Infinity;
  3334. var maxZ = -Infinity;
  3335. for (var i = 0, l = array.length; i < l; i += 3) {
  3336. var x = array[i];
  3337. var y = array[i + 1];
  3338. var z = array[i + 2];
  3339. if (x < minX) minX = x;
  3340. if (y < minY) minY = y;
  3341. if (z < minZ) minZ = z;
  3342. if (x > maxX) maxX = x;
  3343. if (y > maxY) maxY = y;
  3344. if (z > maxZ) maxZ = z;
  3345. }
  3346. this.min.set(minX, minY, minZ);
  3347. this.max.set(maxX, maxY, maxZ);
  3348. return this;
  3349. };
  3350. _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
  3351. var minX = +Infinity;
  3352. var minY = +Infinity;
  3353. var minZ = +Infinity;
  3354. var maxX = -Infinity;
  3355. var maxY = -Infinity;
  3356. var maxZ = -Infinity;
  3357. for (var i = 0, l = attribute.count; i < l; i++) {
  3358. var x = attribute.getX(i);
  3359. var y = attribute.getY(i);
  3360. var z = attribute.getZ(i);
  3361. if (x < minX) minX = x;
  3362. if (y < minY) minY = y;
  3363. if (z < minZ) minZ = z;
  3364. if (x > maxX) maxX = x;
  3365. if (y > maxY) maxY = y;
  3366. if (z > maxZ) maxZ = z;
  3367. }
  3368. this.min.set(minX, minY, minZ);
  3369. this.max.set(maxX, maxY, maxZ);
  3370. return this;
  3371. };
  3372. _proto.setFromPoints = function setFromPoints(points) {
  3373. this.makeEmpty();
  3374. for (var i = 0, il = points.length; i < il; i++) {
  3375. this.expandByPoint(points[i]);
  3376. }
  3377. return this;
  3378. };
  3379. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  3380. var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
  3381. this.min.copy(center).sub(halfSize);
  3382. this.max.copy(center).add(halfSize);
  3383. return this;
  3384. };
  3385. _proto.setFromObject = function setFromObject(object) {
  3386. this.makeEmpty();
  3387. return this.expandByObject(object);
  3388. };
  3389. _proto.clone = function clone() {
  3390. return new this.constructor().copy(this);
  3391. };
  3392. _proto.copy = function copy(box) {
  3393. this.min.copy(box.min);
  3394. this.max.copy(box.max);
  3395. return this;
  3396. };
  3397. _proto.makeEmpty = function makeEmpty() {
  3398. this.min.x = this.min.y = this.min.z = +Infinity;
  3399. this.max.x = this.max.y = this.max.z = -Infinity;
  3400. return this;
  3401. };
  3402. _proto.isEmpty = function isEmpty() {
  3403. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3404. return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  3405. };
  3406. _proto.getCenter = function getCenter(target) {
  3407. if (target === undefined) {
  3408. console.warn('THREE.Box3: .getCenter() target is now required');
  3409. target = new Vector3();
  3410. }
  3411. return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  3412. };
  3413. _proto.getSize = function getSize(target) {
  3414. if (target === undefined) {
  3415. console.warn('THREE.Box3: .getSize() target is now required');
  3416. target = new Vector3();
  3417. }
  3418. return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
  3419. };
  3420. _proto.expandByPoint = function expandByPoint(point) {
  3421. this.min.min(point);
  3422. this.max.max(point);
  3423. return this;
  3424. };
  3425. _proto.expandByVector = function expandByVector(vector) {
  3426. this.min.sub(vector);
  3427. this.max.add(vector);
  3428. return this;
  3429. };
  3430. _proto.expandByScalar = function expandByScalar(scalar) {
  3431. this.min.addScalar(-scalar);
  3432. this.max.addScalar(scalar);
  3433. return this;
  3434. };
  3435. _proto.expandByObject = function expandByObject(object) {
  3436. // Computes the world-axis-aligned bounding box of an object (including its children),
  3437. // accounting for both the object's, and children's, world transforms
  3438. object.updateWorldMatrix(false, false);
  3439. var geometry = object.geometry;
  3440. if (geometry !== undefined) {
  3441. if (geometry.boundingBox === null) {
  3442. geometry.computeBoundingBox();
  3443. }
  3444. _box.copy(geometry.boundingBox);
  3445. _box.applyMatrix4(object.matrixWorld);
  3446. this.union(_box);
  3447. }
  3448. var children = object.children;
  3449. for (var i = 0, l = children.length; i < l; i++) {
  3450. this.expandByObject(children[i]);
  3451. }
  3452. return this;
  3453. };
  3454. _proto.containsPoint = function containsPoint(point) {
  3455. 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;
  3456. };
  3457. _proto.containsBox = function containsBox(box) {
  3458. 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;
  3459. };
  3460. _proto.getParameter = function getParameter(point, target) {
  3461. // This can potentially have a divide by zero if the box
  3462. // has a size dimension of 0.
  3463. if (target === undefined) {
  3464. console.warn('THREE.Box3: .getParameter() target is now required');
  3465. target = new Vector3();
  3466. }
  3467. 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));
  3468. };
  3469. _proto.intersectsBox = function intersectsBox(box) {
  3470. // using 6 splitting planes to rule out intersections.
  3471. 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;
  3472. };
  3473. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3474. // Find the point on the AABB closest to the sphere center.
  3475. this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
  3476. return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
  3477. };
  3478. _proto.intersectsPlane = function intersectsPlane(plane) {
  3479. // We compute the minimum and maximum dot product values. If those values
  3480. // are on the same side (back or front) of the plane, then there is no intersection.
  3481. var min, max;
  3482. if (plane.normal.x > 0) {
  3483. min = plane.normal.x * this.min.x;
  3484. max = plane.normal.x * this.max.x;
  3485. } else {
  3486. min = plane.normal.x * this.max.x;
  3487. max = plane.normal.x * this.min.x;
  3488. }
  3489. if (plane.normal.y > 0) {
  3490. min += plane.normal.y * this.min.y;
  3491. max += plane.normal.y * this.max.y;
  3492. } else {
  3493. min += plane.normal.y * this.max.y;
  3494. max += plane.normal.y * this.min.y;
  3495. }
  3496. if (plane.normal.z > 0) {
  3497. min += plane.normal.z * this.min.z;
  3498. max += plane.normal.z * this.max.z;
  3499. } else {
  3500. min += plane.normal.z * this.max.z;
  3501. max += plane.normal.z * this.min.z;
  3502. }
  3503. return min <= -plane.constant && max >= -plane.constant;
  3504. };
  3505. _proto.intersectsTriangle = function intersectsTriangle(triangle) {
  3506. if (this.isEmpty()) {
  3507. return false;
  3508. } // compute box center and extents
  3509. this.getCenter(_center);
  3510. _extents.subVectors(this.max, _center); // translate triangle to aabb origin
  3511. _v0.subVectors(triangle.a, _center);
  3512. _v1.subVectors(triangle.b, _center);
  3513. _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
  3514. _f0.subVectors(_v1, _v0);
  3515. _f1.subVectors(_v2, _v1);
  3516. _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
  3517. // 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
  3518. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3519. 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];
  3520. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  3521. return false;
  3522. } // test 3 face normals from the aabb
  3523. axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  3524. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  3525. return false;
  3526. } // finally testing the face normal of the triangle
  3527. // use already existing triangle edge vectors here
  3528. _triangleNormal.crossVectors(_f0, _f1);
  3529. axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
  3530. return satForAxes(axes, _v0, _v1, _v2, _extents);
  3531. };
  3532. _proto.clampPoint = function clampPoint(point, target) {
  3533. if (target === undefined) {
  3534. console.warn('THREE.Box3: .clampPoint() target is now required');
  3535. target = new Vector3();
  3536. }
  3537. return target.copy(point).clamp(this.min, this.max);
  3538. };
  3539. _proto.distanceToPoint = function distanceToPoint(point) {
  3540. var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
  3541. return clampedPoint.sub(point).length();
  3542. };
  3543. _proto.getBoundingSphere = function getBoundingSphere(target) {
  3544. if (target === undefined) {
  3545. console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
  3546. }
  3547. this.getCenter(target.center);
  3548. target.radius = this.getSize(_vector$1).length() * 0.5;
  3549. return target;
  3550. };
  3551. _proto.intersect = function intersect(box) {
  3552. this.min.max(box.min);
  3553. 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.
  3554. if (this.isEmpty()) this.makeEmpty();
  3555. return this;
  3556. };
  3557. _proto.union = function union(box) {
  3558. this.min.min(box.min);
  3559. this.max.max(box.max);
  3560. return this;
  3561. };
  3562. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3563. // transform of empty box is an empty box.
  3564. if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  3565. _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
  3566. _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
  3567. _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
  3568. _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
  3569. _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
  3570. _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
  3571. _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
  3572. _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
  3573. this.setFromPoints(_points);
  3574. return this;
  3575. };
  3576. _proto.translate = function translate(offset) {
  3577. this.min.add(offset);
  3578. this.max.add(offset);
  3579. return this;
  3580. };
  3581. _proto.equals = function equals(box) {
  3582. return box.min.equals(this.min) && box.max.equals(this.max);
  3583. };
  3584. return Box3;
  3585. }();
  3586. function satForAxes(axes, v0, v1, v2, extents) {
  3587. for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
  3588. _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
  3589. 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
  3590. var p0 = v0.dot(_testAxis);
  3591. var p1 = v1.dot(_testAxis);
  3592. var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
  3593. if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
  3594. // points of the projected triangle are outside the projected half-length of the aabb
  3595. // the axis is seperating and we can exit
  3596. return false;
  3597. }
  3598. }
  3599. return true;
  3600. }
  3601. 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()];
  3602. var _vector$1 = /*@__PURE__*/new Vector3();
  3603. var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
  3604. var _v0 = /*@__PURE__*/new Vector3();
  3605. var _v1 = /*@__PURE__*/new Vector3();
  3606. var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
  3607. var _f0 = /*@__PURE__*/new Vector3();
  3608. var _f1 = /*@__PURE__*/new Vector3();
  3609. var _f2 = /*@__PURE__*/new Vector3();
  3610. var _center = /*@__PURE__*/new Vector3();
  3611. var _extents = /*@__PURE__*/new Vector3();
  3612. var _triangleNormal = /*@__PURE__*/new Vector3();
  3613. var _testAxis = /*@__PURE__*/new Vector3();
  3614. var _box$1 = /*@__PURE__*/new Box3();
  3615. var Sphere = /*#__PURE__*/function () {
  3616. function Sphere(center, radius) {
  3617. this.center = center !== undefined ? center : new Vector3();
  3618. this.radius = radius !== undefined ? radius : -1;
  3619. }
  3620. var _proto = Sphere.prototype;
  3621. _proto.set = function set(center, radius) {
  3622. this.center.copy(center);
  3623. this.radius = radius;
  3624. return this;
  3625. };
  3626. _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
  3627. var center = this.center;
  3628. if (optionalCenter !== undefined) {
  3629. center.copy(optionalCenter);
  3630. } else {
  3631. _box$1.setFromPoints(points).getCenter(center);
  3632. }
  3633. var maxRadiusSq = 0;
  3634. for (var i = 0, il = points.length; i < il; i++) {
  3635. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
  3636. }
  3637. this.radius = Math.sqrt(maxRadiusSq);
  3638. return this;
  3639. };
  3640. _proto.clone = function clone() {
  3641. return new this.constructor().copy(this);
  3642. };
  3643. _proto.copy = function copy(sphere) {
  3644. this.center.copy(sphere.center);
  3645. this.radius = sphere.radius;
  3646. return this;
  3647. };
  3648. _proto.isEmpty = function isEmpty() {
  3649. return this.radius < 0;
  3650. };
  3651. _proto.makeEmpty = function makeEmpty() {
  3652. this.center.set(0, 0, 0);
  3653. this.radius = -1;
  3654. return this;
  3655. };
  3656. _proto.containsPoint = function containsPoint(point) {
  3657. return point.distanceToSquared(this.center) <= this.radius * this.radius;
  3658. };
  3659. _proto.distanceToPoint = function distanceToPoint(point) {
  3660. return point.distanceTo(this.center) - this.radius;
  3661. };
  3662. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3663. var radiusSum = this.radius + sphere.radius;
  3664. return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
  3665. };
  3666. _proto.intersectsBox = function intersectsBox(box) {
  3667. return box.intersectsSphere(this);
  3668. };
  3669. _proto.intersectsPlane = function intersectsPlane(plane) {
  3670. return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
  3671. };
  3672. _proto.clampPoint = function clampPoint(point, target) {
  3673. var deltaLengthSq = this.center.distanceToSquared(point);
  3674. if (target === undefined) {
  3675. console.warn('THREE.Sphere: .clampPoint() target is now required');
  3676. target = new Vector3();
  3677. }
  3678. target.copy(point);
  3679. if (deltaLengthSq > this.radius * this.radius) {
  3680. target.sub(this.center).normalize();
  3681. target.multiplyScalar(this.radius).add(this.center);
  3682. }
  3683. return target;
  3684. };
  3685. _proto.getBoundingBox = function getBoundingBox(target) {
  3686. if (target === undefined) {
  3687. console.warn('THREE.Sphere: .getBoundingBox() target is now required');
  3688. target = new Box3();
  3689. }
  3690. if (this.isEmpty()) {
  3691. // Empty sphere produces empty bounding box
  3692. target.makeEmpty();
  3693. return target;
  3694. }
  3695. target.set(this.center, this.center);
  3696. target.expandByScalar(this.radius);
  3697. return target;
  3698. };
  3699. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3700. this.center.applyMatrix4(matrix);
  3701. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3702. return this;
  3703. };
  3704. _proto.translate = function translate(offset) {
  3705. this.center.add(offset);
  3706. return this;
  3707. };
  3708. _proto.equals = function equals(sphere) {
  3709. return sphere.center.equals(this.center) && sphere.radius === this.radius;
  3710. };
  3711. return Sphere;
  3712. }();
  3713. var _vector$2 = /*@__PURE__*/new Vector3();
  3714. var _segCenter = /*@__PURE__*/new Vector3();
  3715. var _segDir = /*@__PURE__*/new Vector3();
  3716. var _diff = /*@__PURE__*/new Vector3();
  3717. var _edge1 = /*@__PURE__*/new Vector3();
  3718. var _edge2 = /*@__PURE__*/new Vector3();
  3719. var _normal = /*@__PURE__*/new Vector3();
  3720. var Ray = /*#__PURE__*/function () {
  3721. function Ray(origin, direction) {
  3722. this.origin = origin !== undefined ? origin : new Vector3();
  3723. this.direction = direction !== undefined ? direction : new Vector3(0, 0, -1);
  3724. }
  3725. var _proto = Ray.prototype;
  3726. _proto.set = function set(origin, direction) {
  3727. this.origin.copy(origin);
  3728. this.direction.copy(direction);
  3729. return this;
  3730. };
  3731. _proto.clone = function clone() {
  3732. return new this.constructor().copy(this);
  3733. };
  3734. _proto.copy = function copy(ray) {
  3735. this.origin.copy(ray.origin);
  3736. this.direction.copy(ray.direction);
  3737. return this;
  3738. };
  3739. _proto.at = function at(t, target) {
  3740. if (target === undefined) {
  3741. console.warn('THREE.Ray: .at() target is now required');
  3742. target = new Vector3();
  3743. }
  3744. return target.copy(this.direction).multiplyScalar(t).add(this.origin);
  3745. };
  3746. _proto.lookAt = function lookAt(v) {
  3747. this.direction.copy(v).sub(this.origin).normalize();
  3748. return this;
  3749. };
  3750. _proto.recast = function recast(t) {
  3751. this.origin.copy(this.at(t, _vector$2));
  3752. return this;
  3753. };
  3754. _proto.closestPointToPoint = function closestPointToPoint(point, target) {
  3755. if (target === undefined) {
  3756. console.warn('THREE.Ray: .closestPointToPoint() target is now required');
  3757. target = new Vector3();
  3758. }
  3759. target.subVectors(point, this.origin);
  3760. var directionDistance = target.dot(this.direction);
  3761. if (directionDistance < 0) {
  3762. return target.copy(this.origin);
  3763. }
  3764. return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3765. };
  3766. _proto.distanceToPoint = function distanceToPoint(point) {
  3767. return Math.sqrt(this.distanceSqToPoint(point));
  3768. };
  3769. _proto.distanceSqToPoint = function distanceSqToPoint(point) {
  3770. var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
  3771. if (directionDistance < 0) {
  3772. return this.origin.distanceToSquared(point);
  3773. }
  3774. _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3775. return _vector$2.distanceToSquared(point);
  3776. };
  3777. _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
  3778. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3779. // It returns the min distance between the ray and the segment
  3780. // defined by v0 and v1
  3781. // It can also set two optional targets :
  3782. // - The closest point on the ray
  3783. // - The closest point on the segment
  3784. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
  3785. _segDir.copy(v1).sub(v0).normalize();
  3786. _diff.copy(this.origin).sub(_segCenter);
  3787. var segExtent = v0.distanceTo(v1) * 0.5;
  3788. var a01 = -this.direction.dot(_segDir);
  3789. var b0 = _diff.dot(this.direction);
  3790. var b1 = -_diff.dot(_segDir);
  3791. var c = _diff.lengthSq();
  3792. var det = Math.abs(1 - a01 * a01);
  3793. var s0, s1, sqrDist, extDet;
  3794. if (det > 0) {
  3795. // The ray and segment are not parallel.
  3796. s0 = a01 * b1 - b0;
  3797. s1 = a01 * b0 - b1;
  3798. extDet = segExtent * det;
  3799. if (s0 >= 0) {
  3800. if (s1 >= -extDet) {
  3801. if (s1 <= extDet) {
  3802. // region 0
  3803. // Minimum at interior points of ray and segment.
  3804. var invDet = 1 / det;
  3805. s0 *= invDet;
  3806. s1 *= invDet;
  3807. sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
  3808. } else {
  3809. // region 1
  3810. s1 = segExtent;
  3811. s0 = Math.max(0, -(a01 * s1 + b0));
  3812. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3813. }
  3814. } else {
  3815. // region 5
  3816. s1 = -segExtent;
  3817. s0 = Math.max(0, -(a01 * s1 + b0));
  3818. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3819. }
  3820. } else {
  3821. if (s1 <= -extDet) {
  3822. // region 4
  3823. s0 = Math.max(0, -(-a01 * segExtent + b0));
  3824. s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3825. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3826. } else if (s1 <= extDet) {
  3827. // region 3
  3828. s0 = 0;
  3829. s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
  3830. sqrDist = s1 * (s1 + 2 * b1) + c;
  3831. } else {
  3832. // region 2
  3833. s0 = Math.max(0, -(a01 * segExtent + b0));
  3834. s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3835. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3836. }
  3837. }
  3838. } else {
  3839. // Ray and segment are parallel.
  3840. s1 = a01 > 0 ? -segExtent : segExtent;
  3841. s0 = Math.max(0, -(a01 * s1 + b0));
  3842. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3843. }
  3844. if (optionalPointOnRay) {
  3845. optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
  3846. }
  3847. if (optionalPointOnSegment) {
  3848. optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
  3849. }
  3850. return sqrDist;
  3851. };
  3852. _proto.intersectSphere = function intersectSphere(sphere, target) {
  3853. _vector$2.subVectors(sphere.center, this.origin);
  3854. var tca = _vector$2.dot(this.direction);
  3855. var d2 = _vector$2.dot(_vector$2) - tca * tca;
  3856. var radius2 = sphere.radius * sphere.radius;
  3857. if (d2 > radius2) return null;
  3858. var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
  3859. var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
  3860. var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
  3861. if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
  3862. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3863. // in order to always return an intersect point that is in front of the ray.
  3864. 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
  3865. return this.at(t0, target);
  3866. };
  3867. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3868. return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
  3869. };
  3870. _proto.distanceToPlane = function distanceToPlane(plane) {
  3871. var denominator = plane.normal.dot(this.direction);
  3872. if (denominator === 0) {
  3873. // line is coplanar, return origin
  3874. if (plane.distanceToPoint(this.origin) === 0) {
  3875. return 0;
  3876. } // Null is preferable to undefined since undefined means.... it is undefined
  3877. return null;
  3878. }
  3879. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
  3880. return t >= 0 ? t : null;
  3881. };
  3882. _proto.intersectPlane = function intersectPlane(plane, target) {
  3883. var t = this.distanceToPlane(plane);
  3884. if (t === null) {
  3885. return null;
  3886. }
  3887. return this.at(t, target);
  3888. };
  3889. _proto.intersectsPlane = function intersectsPlane(plane) {
  3890. // check if the ray lies on the plane first
  3891. var distToPoint = plane.distanceToPoint(this.origin);
  3892. if (distToPoint === 0) {
  3893. return true;
  3894. }
  3895. var denominator = plane.normal.dot(this.direction);
  3896. if (denominator * distToPoint < 0) {
  3897. return true;
  3898. } // ray origin is behind the plane (and is pointing behind it)
  3899. return false;
  3900. };
  3901. _proto.intersectBox = function intersectBox(box, target) {
  3902. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3903. var invdirx = 1 / this.direction.x,
  3904. invdiry = 1 / this.direction.y,
  3905. invdirz = 1 / this.direction.z;
  3906. var origin = this.origin;
  3907. if (invdirx >= 0) {
  3908. tmin = (box.min.x - origin.x) * invdirx;
  3909. tmax = (box.max.x - origin.x) * invdirx;
  3910. } else {
  3911. tmin = (box.max.x - origin.x) * invdirx;
  3912. tmax = (box.min.x - origin.x) * invdirx;
  3913. }
  3914. if (invdiry >= 0) {
  3915. tymin = (box.min.y - origin.y) * invdiry;
  3916. tymax = (box.max.y - origin.y) * invdiry;
  3917. } else {
  3918. tymin = (box.max.y - origin.y) * invdiry;
  3919. tymax = (box.min.y - origin.y) * invdiry;
  3920. }
  3921. if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
  3922. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3923. if (tymin > tmin || tmin !== tmin) tmin = tymin;
  3924. if (tymax < tmax || tmax !== tmax) tmax = tymax;
  3925. if (invdirz >= 0) {
  3926. tzmin = (box.min.z - origin.z) * invdirz;
  3927. tzmax = (box.max.z - origin.z) * invdirz;
  3928. } else {
  3929. tzmin = (box.max.z - origin.z) * invdirz;
  3930. tzmax = (box.min.z - origin.z) * invdirz;
  3931. }
  3932. if (tmin > tzmax || tzmin > tmax) return null;
  3933. if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
  3934. if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
  3935. if (tmax < 0) return null;
  3936. return this.at(tmin >= 0 ? tmin : tmax, target);
  3937. };
  3938. _proto.intersectsBox = function intersectsBox(box) {
  3939. return this.intersectBox(box, _vector$2) !== null;
  3940. };
  3941. _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
  3942. // Compute the offset origin, edges, and normal.
  3943. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3944. _edge1.subVectors(b, a);
  3945. _edge2.subVectors(c, a);
  3946. _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3947. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3948. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3949. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3950. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3951. var DdN = this.direction.dot(_normal);
  3952. var sign;
  3953. if (DdN > 0) {
  3954. if (backfaceCulling) return null;
  3955. sign = 1;
  3956. } else if (DdN < 0) {
  3957. sign = -1;
  3958. DdN = -DdN;
  3959. } else {
  3960. return null;
  3961. }
  3962. _diff.subVectors(this.origin, a);
  3963. var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
  3964. if (DdQxE2 < 0) {
  3965. return null;
  3966. }
  3967. var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
  3968. if (DdE1xQ < 0) {
  3969. return null;
  3970. } // b1+b2 > 1, no intersection
  3971. if (DdQxE2 + DdE1xQ > DdN) {
  3972. return null;
  3973. } // Line intersects triangle, check if ray does.
  3974. var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
  3975. if (QdN < 0) {
  3976. return null;
  3977. } // Ray intersects triangle.
  3978. return this.at(QdN / DdN, target);
  3979. };
  3980. _proto.applyMatrix4 = function applyMatrix4(matrix4) {
  3981. this.origin.applyMatrix4(matrix4);
  3982. this.direction.transformDirection(matrix4);
  3983. return this;
  3984. };
  3985. _proto.equals = function equals(ray) {
  3986. return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
  3987. };
  3988. return Ray;
  3989. }();
  3990. var Matrix4 = /*#__PURE__*/function () {
  3991. function Matrix4() {
  3992. Object.defineProperty(this, 'isMatrix4', {
  3993. value: true
  3994. });
  3995. this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  3996. if (arguments.length > 0) {
  3997. console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
  3998. }
  3999. }
  4000. var _proto = Matrix4.prototype;
  4001. _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
  4002. var te = this.elements;
  4003. te[0] = n11;
  4004. te[4] = n12;
  4005. te[8] = n13;
  4006. te[12] = n14;
  4007. te[1] = n21;
  4008. te[5] = n22;
  4009. te[9] = n23;
  4010. te[13] = n24;
  4011. te[2] = n31;
  4012. te[6] = n32;
  4013. te[10] = n33;
  4014. te[14] = n34;
  4015. te[3] = n41;
  4016. te[7] = n42;
  4017. te[11] = n43;
  4018. te[15] = n44;
  4019. return this;
  4020. };
  4021. _proto.identity = function identity() {
  4022. this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4023. return this;
  4024. };
  4025. _proto.clone = function clone() {
  4026. return new Matrix4().fromArray(this.elements);
  4027. };
  4028. _proto.copy = function copy(m) {
  4029. var te = this.elements;
  4030. var me = m.elements;
  4031. te[0] = me[0];
  4032. te[1] = me[1];
  4033. te[2] = me[2];
  4034. te[3] = me[3];
  4035. te[4] = me[4];
  4036. te[5] = me[5];
  4037. te[6] = me[6];
  4038. te[7] = me[7];
  4039. te[8] = me[8];
  4040. te[9] = me[9];
  4041. te[10] = me[10];
  4042. te[11] = me[11];
  4043. te[12] = me[12];
  4044. te[13] = me[13];
  4045. te[14] = me[14];
  4046. te[15] = me[15];
  4047. return this;
  4048. };
  4049. _proto.copyPosition = function copyPosition(m) {
  4050. var te = this.elements,
  4051. me = m.elements;
  4052. te[12] = me[12];
  4053. te[13] = me[13];
  4054. te[14] = me[14];
  4055. return this;
  4056. };
  4057. _proto.setFromMatrix3 = function setFromMatrix3(m) {
  4058. var me = m.elements;
  4059. 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);
  4060. return this;
  4061. };
  4062. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  4063. xAxis.setFromMatrixColumn(this, 0);
  4064. yAxis.setFromMatrixColumn(this, 1);
  4065. zAxis.setFromMatrixColumn(this, 2);
  4066. return this;
  4067. };
  4068. _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
  4069. 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);
  4070. return this;
  4071. };
  4072. _proto.extractRotation = function extractRotation(m) {
  4073. // this method does not support reflection matrices
  4074. var te = this.elements;
  4075. var me = m.elements;
  4076. var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
  4077. var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
  4078. var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
  4079. te[0] = me[0] * scaleX;
  4080. te[1] = me[1] * scaleX;
  4081. te[2] = me[2] * scaleX;
  4082. te[3] = 0;
  4083. te[4] = me[4] * scaleY;
  4084. te[5] = me[5] * scaleY;
  4085. te[6] = me[6] * scaleY;
  4086. te[7] = 0;
  4087. te[8] = me[8] * scaleZ;
  4088. te[9] = me[9] * scaleZ;
  4089. te[10] = me[10] * scaleZ;
  4090. te[11] = 0;
  4091. te[12] = 0;
  4092. te[13] = 0;
  4093. te[14] = 0;
  4094. te[15] = 1;
  4095. return this;
  4096. };
  4097. _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
  4098. if (!(euler && euler.isEuler)) {
  4099. console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
  4100. }
  4101. var te = this.elements;
  4102. var x = euler.x,
  4103. y = euler.y,
  4104. z = euler.z;
  4105. var a = Math.cos(x),
  4106. b = Math.sin(x);
  4107. var c = Math.cos(y),
  4108. d = Math.sin(y);
  4109. var e = Math.cos(z),
  4110. f = Math.sin(z);
  4111. if (euler.order === 'XYZ') {
  4112. var ae = a * e,
  4113. af = a * f,
  4114. be = b * e,
  4115. bf = b * f;
  4116. te[0] = c * e;
  4117. te[4] = -c * f;
  4118. te[8] = d;
  4119. te[1] = af + be * d;
  4120. te[5] = ae - bf * d;
  4121. te[9] = -b * c;
  4122. te[2] = bf - ae * d;
  4123. te[6] = be + af * d;
  4124. te[10] = a * c;
  4125. } else if (euler.order === 'YXZ') {
  4126. var ce = c * e,
  4127. cf = c * f,
  4128. de = d * e,
  4129. df = d * f;
  4130. te[0] = ce + df * b;
  4131. te[4] = de * b - cf;
  4132. te[8] = a * d;
  4133. te[1] = a * f;
  4134. te[5] = a * e;
  4135. te[9] = -b;
  4136. te[2] = cf * b - de;
  4137. te[6] = df + ce * b;
  4138. te[10] = a * c;
  4139. } else if (euler.order === 'ZXY') {
  4140. var _ce = c * e,
  4141. _cf = c * f,
  4142. _de = d * e,
  4143. _df = d * f;
  4144. te[0] = _ce - _df * b;
  4145. te[4] = -a * f;
  4146. te[8] = _de + _cf * b;
  4147. te[1] = _cf + _de * b;
  4148. te[5] = a * e;
  4149. te[9] = _df - _ce * b;
  4150. te[2] = -a * d;
  4151. te[6] = b;
  4152. te[10] = a * c;
  4153. } else if (euler.order === 'ZYX') {
  4154. var _ae = a * e,
  4155. _af = a * f,
  4156. _be = b * e,
  4157. _bf = b * f;
  4158. te[0] = c * e;
  4159. te[4] = _be * d - _af;
  4160. te[8] = _ae * d + _bf;
  4161. te[1] = c * f;
  4162. te[5] = _bf * d + _ae;
  4163. te[9] = _af * d - _be;
  4164. te[2] = -d;
  4165. te[6] = b * c;
  4166. te[10] = a * c;
  4167. } else if (euler.order === 'YZX') {
  4168. var ac = a * c,
  4169. ad = a * d,
  4170. bc = b * c,
  4171. bd = b * d;
  4172. te[0] = c * e;
  4173. te[4] = bd - ac * f;
  4174. te[8] = bc * f + ad;
  4175. te[1] = f;
  4176. te[5] = a * e;
  4177. te[9] = -b * e;
  4178. te[2] = -d * e;
  4179. te[6] = ad * f + bc;
  4180. te[10] = ac - bd * f;
  4181. } else if (euler.order === 'XZY') {
  4182. var _ac = a * c,
  4183. _ad = a * d,
  4184. _bc = b * c,
  4185. _bd = b * d;
  4186. te[0] = c * e;
  4187. te[4] = -f;
  4188. te[8] = d * e;
  4189. te[1] = _ac * f + _bd;
  4190. te[5] = a * e;
  4191. te[9] = _ad * f - _bc;
  4192. te[2] = _bc * f - _ad;
  4193. te[6] = b * e;
  4194. te[10] = _bd * f + _ac;
  4195. } // bottom row
  4196. te[3] = 0;
  4197. te[7] = 0;
  4198. te[11] = 0; // last column
  4199. te[12] = 0;
  4200. te[13] = 0;
  4201. te[14] = 0;
  4202. te[15] = 1;
  4203. return this;
  4204. };
  4205. _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
  4206. return this.compose(_zero, q, _one);
  4207. };
  4208. _proto.lookAt = function lookAt(eye, target, up) {
  4209. var te = this.elements;
  4210. _z.subVectors(eye, target);
  4211. if (_z.lengthSq() === 0) {
  4212. // eye and target are in the same position
  4213. _z.z = 1;
  4214. }
  4215. _z.normalize();
  4216. _x.crossVectors(up, _z);
  4217. if (_x.lengthSq() === 0) {
  4218. // up and z are parallel
  4219. if (Math.abs(up.z) === 1) {
  4220. _z.x += 0.0001;
  4221. } else {
  4222. _z.z += 0.0001;
  4223. }
  4224. _z.normalize();
  4225. _x.crossVectors(up, _z);
  4226. }
  4227. _x.normalize();
  4228. _y.crossVectors(_z, _x);
  4229. te[0] = _x.x;
  4230. te[4] = _y.x;
  4231. te[8] = _z.x;
  4232. te[1] = _x.y;
  4233. te[5] = _y.y;
  4234. te[9] = _z.y;
  4235. te[2] = _x.z;
  4236. te[6] = _y.z;
  4237. te[10] = _z.z;
  4238. return this;
  4239. };
  4240. _proto.multiply = function multiply(m, n) {
  4241. if (n !== undefined) {
  4242. console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
  4243. return this.multiplyMatrices(m, n);
  4244. }
  4245. return this.multiplyMatrices(this, m);
  4246. };
  4247. _proto.premultiply = function premultiply(m) {
  4248. return this.multiplyMatrices(m, this);
  4249. };
  4250. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  4251. var ae = a.elements;
  4252. var be = b.elements;
  4253. var te = this.elements;
  4254. var a11 = ae[0],
  4255. a12 = ae[4],
  4256. a13 = ae[8],
  4257. a14 = ae[12];
  4258. var a21 = ae[1],
  4259. a22 = ae[5],
  4260. a23 = ae[9],
  4261. a24 = ae[13];
  4262. var a31 = ae[2],
  4263. a32 = ae[6],
  4264. a33 = ae[10],
  4265. a34 = ae[14];
  4266. var a41 = ae[3],
  4267. a42 = ae[7],
  4268. a43 = ae[11],
  4269. a44 = ae[15];
  4270. var b11 = be[0],
  4271. b12 = be[4],
  4272. b13 = be[8],
  4273. b14 = be[12];
  4274. var b21 = be[1],
  4275. b22 = be[5],
  4276. b23 = be[9],
  4277. b24 = be[13];
  4278. var b31 = be[2],
  4279. b32 = be[6],
  4280. b33 = be[10],
  4281. b34 = be[14];
  4282. var b41 = be[3],
  4283. b42 = be[7],
  4284. b43 = be[11],
  4285. b44 = be[15];
  4286. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  4287. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  4288. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  4289. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  4290. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  4291. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  4292. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  4293. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  4294. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  4295. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  4296. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  4297. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  4298. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  4299. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  4300. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  4301. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  4302. return this;
  4303. };
  4304. _proto.multiplyScalar = function multiplyScalar(s) {
  4305. var te = this.elements;
  4306. te[0] *= s;
  4307. te[4] *= s;
  4308. te[8] *= s;
  4309. te[12] *= s;
  4310. te[1] *= s;
  4311. te[5] *= s;
  4312. te[9] *= s;
  4313. te[13] *= s;
  4314. te[2] *= s;
  4315. te[6] *= s;
  4316. te[10] *= s;
  4317. te[14] *= s;
  4318. te[3] *= s;
  4319. te[7] *= s;
  4320. te[11] *= s;
  4321. te[15] *= s;
  4322. return this;
  4323. };
  4324. _proto.determinant = function determinant() {
  4325. var te = this.elements;
  4326. var n11 = te[0],
  4327. n12 = te[4],
  4328. n13 = te[8],
  4329. n14 = te[12];
  4330. var n21 = te[1],
  4331. n22 = te[5],
  4332. n23 = te[9],
  4333. n24 = te[13];
  4334. var n31 = te[2],
  4335. n32 = te[6],
  4336. n33 = te[10],
  4337. n34 = te[14];
  4338. var n41 = te[3],
  4339. n42 = te[7],
  4340. n43 = te[11],
  4341. n44 = te[15]; //TODO: make this more efficient
  4342. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  4343. 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);
  4344. };
  4345. _proto.transpose = function transpose() {
  4346. var te = this.elements;
  4347. var tmp;
  4348. tmp = te[1];
  4349. te[1] = te[4];
  4350. te[4] = tmp;
  4351. tmp = te[2];
  4352. te[2] = te[8];
  4353. te[8] = tmp;
  4354. tmp = te[6];
  4355. te[6] = te[9];
  4356. te[9] = tmp;
  4357. tmp = te[3];
  4358. te[3] = te[12];
  4359. te[12] = tmp;
  4360. tmp = te[7];
  4361. te[7] = te[13];
  4362. te[13] = tmp;
  4363. tmp = te[11];
  4364. te[11] = te[14];
  4365. te[14] = tmp;
  4366. return this;
  4367. };
  4368. _proto.setPosition = function setPosition(x, y, z) {
  4369. var te = this.elements;
  4370. if (x.isVector3) {
  4371. te[12] = x.x;
  4372. te[13] = x.y;
  4373. te[14] = x.z;
  4374. } else {
  4375. te[12] = x;
  4376. te[13] = y;
  4377. te[14] = z;
  4378. }
  4379. return this;
  4380. };
  4381. _proto.invert = function invert() {
  4382. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  4383. var te = this.elements,
  4384. n11 = te[0],
  4385. n21 = te[1],
  4386. n31 = te[2],
  4387. n41 = te[3],
  4388. n12 = te[4],
  4389. n22 = te[5],
  4390. n32 = te[6],
  4391. n42 = te[7],
  4392. n13 = te[8],
  4393. n23 = te[9],
  4394. n33 = te[10],
  4395. n43 = te[11],
  4396. n14 = te[12],
  4397. n24 = te[13],
  4398. n34 = te[14],
  4399. n44 = te[15],
  4400. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  4401. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  4402. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  4403. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  4404. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  4405. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  4406. var detInv = 1 / det;
  4407. te[0] = t11 * detInv;
  4408. te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
  4409. te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
  4410. te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
  4411. te[4] = t12 * detInv;
  4412. te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
  4413. te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
  4414. te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
  4415. te[8] = t13 * detInv;
  4416. te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
  4417. te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
  4418. te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
  4419. te[12] = t14 * detInv;
  4420. te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
  4421. te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
  4422. te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
  4423. return this;
  4424. };
  4425. _proto.scale = function scale(v) {
  4426. var te = this.elements;
  4427. var x = v.x,
  4428. y = v.y,
  4429. z = v.z;
  4430. te[0] *= x;
  4431. te[4] *= y;
  4432. te[8] *= z;
  4433. te[1] *= x;
  4434. te[5] *= y;
  4435. te[9] *= z;
  4436. te[2] *= x;
  4437. te[6] *= y;
  4438. te[10] *= z;
  4439. te[3] *= x;
  4440. te[7] *= y;
  4441. te[11] *= z;
  4442. return this;
  4443. };
  4444. _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
  4445. var te = this.elements;
  4446. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  4447. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  4448. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  4449. return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
  4450. };
  4451. _proto.makeTranslation = function makeTranslation(x, y, z) {
  4452. this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
  4453. return this;
  4454. };
  4455. _proto.makeRotationX = function makeRotationX(theta) {
  4456. var c = Math.cos(theta),
  4457. s = Math.sin(theta);
  4458. this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
  4459. return this;
  4460. };
  4461. _proto.makeRotationY = function makeRotationY(theta) {
  4462. var c = Math.cos(theta),
  4463. s = Math.sin(theta);
  4464. this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
  4465. return this;
  4466. };
  4467. _proto.makeRotationZ = function makeRotationZ(theta) {
  4468. var c = Math.cos(theta),
  4469. s = Math.sin(theta);
  4470. this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4471. return this;
  4472. };
  4473. _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
  4474. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  4475. var c = Math.cos(angle);
  4476. var s = Math.sin(angle);
  4477. var t = 1 - c;
  4478. var x = axis.x,
  4479. y = axis.y,
  4480. z = axis.z;
  4481. var tx = t * x,
  4482. ty = t * y;
  4483. 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);
  4484. return this;
  4485. };
  4486. _proto.makeScale = function makeScale(x, y, z) {
  4487. this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
  4488. return this;
  4489. };
  4490. _proto.makeShear = function makeShear(x, y, z) {
  4491. this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
  4492. return this;
  4493. };
  4494. _proto.compose = function compose(position, quaternion, scale) {
  4495. var te = this.elements;
  4496. var x = quaternion._x,
  4497. y = quaternion._y,
  4498. z = quaternion._z,
  4499. w = quaternion._w;
  4500. var x2 = x + x,
  4501. y2 = y + y,
  4502. z2 = z + z;
  4503. var xx = x * x2,
  4504. xy = x * y2,
  4505. xz = x * z2;
  4506. var yy = y * y2,
  4507. yz = y * z2,
  4508. zz = z * z2;
  4509. var wx = w * x2,
  4510. wy = w * y2,
  4511. wz = w * z2;
  4512. var sx = scale.x,
  4513. sy = scale.y,
  4514. sz = scale.z;
  4515. te[0] = (1 - (yy + zz)) * sx;
  4516. te[1] = (xy + wz) * sx;
  4517. te[2] = (xz - wy) * sx;
  4518. te[3] = 0;
  4519. te[4] = (xy - wz) * sy;
  4520. te[5] = (1 - (xx + zz)) * sy;
  4521. te[6] = (yz + wx) * sy;
  4522. te[7] = 0;
  4523. te[8] = (xz + wy) * sz;
  4524. te[9] = (yz - wx) * sz;
  4525. te[10] = (1 - (xx + yy)) * sz;
  4526. te[11] = 0;
  4527. te[12] = position.x;
  4528. te[13] = position.y;
  4529. te[14] = position.z;
  4530. te[15] = 1;
  4531. return this;
  4532. };
  4533. _proto.decompose = function decompose(position, quaternion, scale) {
  4534. var te = this.elements;
  4535. var sx = _v1$1.set(te[0], te[1], te[2]).length();
  4536. var sy = _v1$1.set(te[4], te[5], te[6]).length();
  4537. var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
  4538. var det = this.determinant();
  4539. if (det < 0) sx = -sx;
  4540. position.x = te[12];
  4541. position.y = te[13];
  4542. position.z = te[14]; // scale the rotation part
  4543. _m1.copy(this);
  4544. var invSX = 1 / sx;
  4545. var invSY = 1 / sy;
  4546. var invSZ = 1 / sz;
  4547. _m1.elements[0] *= invSX;
  4548. _m1.elements[1] *= invSX;
  4549. _m1.elements[2] *= invSX;
  4550. _m1.elements[4] *= invSY;
  4551. _m1.elements[5] *= invSY;
  4552. _m1.elements[6] *= invSY;
  4553. _m1.elements[8] *= invSZ;
  4554. _m1.elements[9] *= invSZ;
  4555. _m1.elements[10] *= invSZ;
  4556. quaternion.setFromRotationMatrix(_m1);
  4557. scale.x = sx;
  4558. scale.y = sy;
  4559. scale.z = sz;
  4560. return this;
  4561. };
  4562. _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
  4563. if (far === undefined) {
  4564. console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
  4565. }
  4566. var te = this.elements;
  4567. var x = 2 * near / (right - left);
  4568. var y = 2 * near / (top - bottom);
  4569. var a = (right + left) / (right - left);
  4570. var b = (top + bottom) / (top - bottom);
  4571. var c = -(far + near) / (far - near);
  4572. var d = -2 * far * near / (far - near);
  4573. te[0] = x;
  4574. te[4] = 0;
  4575. te[8] = a;
  4576. te[12] = 0;
  4577. te[1] = 0;
  4578. te[5] = y;
  4579. te[9] = b;
  4580. te[13] = 0;
  4581. te[2] = 0;
  4582. te[6] = 0;
  4583. te[10] = c;
  4584. te[14] = d;
  4585. te[3] = 0;
  4586. te[7] = 0;
  4587. te[11] = -1;
  4588. te[15] = 0;
  4589. return this;
  4590. };
  4591. _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
  4592. var te = this.elements;
  4593. var w = 1.0 / (right - left);
  4594. var h = 1.0 / (top - bottom);
  4595. var p = 1.0 / (far - near);
  4596. var x = (right + left) * w;
  4597. var y = (top + bottom) * h;
  4598. var z = (far + near) * p;
  4599. te[0] = 2 * w;
  4600. te[4] = 0;
  4601. te[8] = 0;
  4602. te[12] = -x;
  4603. te[1] = 0;
  4604. te[5] = 2 * h;
  4605. te[9] = 0;
  4606. te[13] = -y;
  4607. te[2] = 0;
  4608. te[6] = 0;
  4609. te[10] = -2 * p;
  4610. te[14] = -z;
  4611. te[3] = 0;
  4612. te[7] = 0;
  4613. te[11] = 0;
  4614. te[15] = 1;
  4615. return this;
  4616. };
  4617. _proto.equals = function equals(matrix) {
  4618. var te = this.elements;
  4619. var me = matrix.elements;
  4620. for (var i = 0; i < 16; i++) {
  4621. if (te[i] !== me[i]) return false;
  4622. }
  4623. return true;
  4624. };
  4625. _proto.fromArray = function fromArray(array, offset) {
  4626. if (offset === void 0) {
  4627. offset = 0;
  4628. }
  4629. for (var i = 0; i < 16; i++) {
  4630. this.elements[i] = array[i + offset];
  4631. }
  4632. return this;
  4633. };
  4634. _proto.toArray = function toArray(array, offset) {
  4635. if (array === void 0) {
  4636. array = [];
  4637. }
  4638. if (offset === void 0) {
  4639. offset = 0;
  4640. }
  4641. var te = this.elements;
  4642. array[offset] = te[0];
  4643. array[offset + 1] = te[1];
  4644. array[offset + 2] = te[2];
  4645. array[offset + 3] = te[3];
  4646. array[offset + 4] = te[4];
  4647. array[offset + 5] = te[5];
  4648. array[offset + 6] = te[6];
  4649. array[offset + 7] = te[7];
  4650. array[offset + 8] = te[8];
  4651. array[offset + 9] = te[9];
  4652. array[offset + 10] = te[10];
  4653. array[offset + 11] = te[11];
  4654. array[offset + 12] = te[12];
  4655. array[offset + 13] = te[13];
  4656. array[offset + 14] = te[14];
  4657. array[offset + 15] = te[15];
  4658. return array;
  4659. };
  4660. return Matrix4;
  4661. }();
  4662. var _v1$1 = /*@__PURE__*/new Vector3();
  4663. var _m1 = /*@__PURE__*/new Matrix4();
  4664. var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
  4665. var _one = /*@__PURE__*/new Vector3(1, 1, 1);
  4666. var _x = /*@__PURE__*/new Vector3();
  4667. var _y = /*@__PURE__*/new Vector3();
  4668. var _z = /*@__PURE__*/new Vector3();
  4669. var Euler = /*#__PURE__*/function () {
  4670. function Euler(x, y, z, order) {
  4671. if (x === void 0) {
  4672. x = 0;
  4673. }
  4674. if (y === void 0) {
  4675. y = 0;
  4676. }
  4677. if (z === void 0) {
  4678. z = 0;
  4679. }
  4680. if (order === void 0) {
  4681. order = Euler.DefaultOrder;
  4682. }
  4683. Object.defineProperty(this, 'isEuler', {
  4684. value: true
  4685. });
  4686. this._x = x;
  4687. this._y = y;
  4688. this._z = z;
  4689. this._order = order;
  4690. }
  4691. var _proto = Euler.prototype;
  4692. _proto.set = function set(x, y, z, order) {
  4693. this._x = x;
  4694. this._y = y;
  4695. this._z = z;
  4696. this._order = order || this._order;
  4697. this._onChangeCallback();
  4698. return this;
  4699. };
  4700. _proto.clone = function clone() {
  4701. return new this.constructor(this._x, this._y, this._z, this._order);
  4702. };
  4703. _proto.copy = function copy(euler) {
  4704. this._x = euler._x;
  4705. this._y = euler._y;
  4706. this._z = euler._z;
  4707. this._order = euler._order;
  4708. this._onChangeCallback();
  4709. return this;
  4710. };
  4711. _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
  4712. var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4713. var te = m.elements;
  4714. var m11 = te[0],
  4715. m12 = te[4],
  4716. m13 = te[8];
  4717. var m21 = te[1],
  4718. m22 = te[5],
  4719. m23 = te[9];
  4720. var m31 = te[2],
  4721. m32 = te[6],
  4722. m33 = te[10];
  4723. order = order || this._order;
  4724. switch (order) {
  4725. case 'XYZ':
  4726. this._y = Math.asin(clamp(m13, -1, 1));
  4727. if (Math.abs(m13) < 0.9999999) {
  4728. this._x = Math.atan2(-m23, m33);
  4729. this._z = Math.atan2(-m12, m11);
  4730. } else {
  4731. this._x = Math.atan2(m32, m22);
  4732. this._z = 0;
  4733. }
  4734. break;
  4735. case 'YXZ':
  4736. this._x = Math.asin(-clamp(m23, -1, 1));
  4737. if (Math.abs(m23) < 0.9999999) {
  4738. this._y = Math.atan2(m13, m33);
  4739. this._z = Math.atan2(m21, m22);
  4740. } else {
  4741. this._y = Math.atan2(-m31, m11);
  4742. this._z = 0;
  4743. }
  4744. break;
  4745. case 'ZXY':
  4746. this._x = Math.asin(clamp(m32, -1, 1));
  4747. if (Math.abs(m32) < 0.9999999) {
  4748. this._y = Math.atan2(-m31, m33);
  4749. this._z = Math.atan2(-m12, m22);
  4750. } else {
  4751. this._y = 0;
  4752. this._z = Math.atan2(m21, m11);
  4753. }
  4754. break;
  4755. case 'ZYX':
  4756. this._y = Math.asin(-clamp(m31, -1, 1));
  4757. if (Math.abs(m31) < 0.9999999) {
  4758. this._x = Math.atan2(m32, m33);
  4759. this._z = Math.atan2(m21, m11);
  4760. } else {
  4761. this._x = 0;
  4762. this._z = Math.atan2(-m12, m22);
  4763. }
  4764. break;
  4765. case 'YZX':
  4766. this._z = Math.asin(clamp(m21, -1, 1));
  4767. if (Math.abs(m21) < 0.9999999) {
  4768. this._x = Math.atan2(-m23, m22);
  4769. this._y = Math.atan2(-m31, m11);
  4770. } else {
  4771. this._x = 0;
  4772. this._y = Math.atan2(m13, m33);
  4773. }
  4774. break;
  4775. case 'XZY':
  4776. this._z = Math.asin(-clamp(m12, -1, 1));
  4777. if (Math.abs(m12) < 0.9999999) {
  4778. this._x = Math.atan2(m32, m22);
  4779. this._y = Math.atan2(m13, m11);
  4780. } else {
  4781. this._x = Math.atan2(-m23, m33);
  4782. this._y = 0;
  4783. }
  4784. break;
  4785. default:
  4786. console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
  4787. }
  4788. this._order = order;
  4789. if (update !== false) this._onChangeCallback();
  4790. return this;
  4791. };
  4792. _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
  4793. _matrix.makeRotationFromQuaternion(q);
  4794. return this.setFromRotationMatrix(_matrix, order, update);
  4795. };
  4796. _proto.setFromVector3 = function setFromVector3(v, order) {
  4797. return this.set(v.x, v.y, v.z, order || this._order);
  4798. };
  4799. _proto.reorder = function reorder(newOrder) {
  4800. // WARNING: this discards revolution information -bhouston
  4801. _quaternion$1.setFromEuler(this);
  4802. return this.setFromQuaternion(_quaternion$1, newOrder);
  4803. };
  4804. _proto.equals = function equals(euler) {
  4805. return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
  4806. };
  4807. _proto.fromArray = function fromArray(array) {
  4808. this._x = array[0];
  4809. this._y = array[1];
  4810. this._z = array[2];
  4811. if (array[3] !== undefined) this._order = array[3];
  4812. this._onChangeCallback();
  4813. return this;
  4814. };
  4815. _proto.toArray = function toArray(array, offset) {
  4816. if (array === void 0) {
  4817. array = [];
  4818. }
  4819. if (offset === void 0) {
  4820. offset = 0;
  4821. }
  4822. array[offset] = this._x;
  4823. array[offset + 1] = this._y;
  4824. array[offset + 2] = this._z;
  4825. array[offset + 3] = this._order;
  4826. return array;
  4827. };
  4828. _proto.toVector3 = function toVector3(optionalResult) {
  4829. if (optionalResult) {
  4830. return optionalResult.set(this._x, this._y, this._z);
  4831. } else {
  4832. return new Vector3(this._x, this._y, this._z);
  4833. }
  4834. };
  4835. _proto._onChange = function _onChange(callback) {
  4836. this._onChangeCallback = callback;
  4837. return this;
  4838. };
  4839. _proto._onChangeCallback = function _onChangeCallback() {};
  4840. _createClass(Euler, [{
  4841. key: "x",
  4842. get: function get() {
  4843. return this._x;
  4844. },
  4845. set: function set(value) {
  4846. this._x = value;
  4847. this._onChangeCallback();
  4848. }
  4849. }, {
  4850. key: "y",
  4851. get: function get() {
  4852. return this._y;
  4853. },
  4854. set: function set(value) {
  4855. this._y = value;
  4856. this._onChangeCallback();
  4857. }
  4858. }, {
  4859. key: "z",
  4860. get: function get() {
  4861. return this._z;
  4862. },
  4863. set: function set(value) {
  4864. this._z = value;
  4865. this._onChangeCallback();
  4866. }
  4867. }, {
  4868. key: "order",
  4869. get: function get() {
  4870. return this._order;
  4871. },
  4872. set: function set(value) {
  4873. this._order = value;
  4874. this._onChangeCallback();
  4875. }
  4876. }]);
  4877. return Euler;
  4878. }();
  4879. Euler.DefaultOrder = 'XYZ';
  4880. Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
  4881. var _matrix = /*@__PURE__*/new Matrix4();
  4882. var _quaternion$1 = /*@__PURE__*/new Quaternion();
  4883. var Layers = /*#__PURE__*/function () {
  4884. function Layers() {
  4885. this.mask = 1 | 0;
  4886. }
  4887. var _proto = Layers.prototype;
  4888. _proto.set = function set(channel) {
  4889. this.mask = 1 << channel | 0;
  4890. };
  4891. _proto.enable = function enable(channel) {
  4892. this.mask |= 1 << channel | 0;
  4893. };
  4894. _proto.enableAll = function enableAll() {
  4895. this.mask = 0xffffffff | 0;
  4896. };
  4897. _proto.toggle = function toggle(channel) {
  4898. this.mask ^= 1 << channel | 0;
  4899. };
  4900. _proto.disable = function disable(channel) {
  4901. this.mask &= ~(1 << channel | 0);
  4902. };
  4903. _proto.disableAll = function disableAll() {
  4904. this.mask = 0;
  4905. };
  4906. _proto.test = function test(layers) {
  4907. return (this.mask & layers.mask) !== 0;
  4908. };
  4909. return Layers;
  4910. }();
  4911. var _object3DId = 0;
  4912. var _v1$2 = new Vector3();
  4913. var _q1 = new Quaternion();
  4914. var _m1$1 = new Matrix4();
  4915. var _target = new Vector3();
  4916. var _position = new Vector3();
  4917. var _scale = new Vector3();
  4918. var _quaternion$2 = new Quaternion();
  4919. var _xAxis = new Vector3(1, 0, 0);
  4920. var _yAxis = new Vector3(0, 1, 0);
  4921. var _zAxis = new Vector3(0, 0, 1);
  4922. var _addedEvent = {
  4923. type: 'added'
  4924. };
  4925. var _removedEvent = {
  4926. type: 'removed'
  4927. };
  4928. function Object3D() {
  4929. Object.defineProperty(this, 'id', {
  4930. value: _object3DId++
  4931. });
  4932. this.uuid = MathUtils.generateUUID();
  4933. this.name = '';
  4934. this.type = 'Object3D';
  4935. this.parent = null;
  4936. this.children = [];
  4937. this.up = Object3D.DefaultUp.clone();
  4938. var position = new Vector3();
  4939. var rotation = new Euler();
  4940. var quaternion = new Quaternion();
  4941. var scale = new Vector3(1, 1, 1);
  4942. function onRotationChange() {
  4943. quaternion.setFromEuler(rotation, false);
  4944. }
  4945. function onQuaternionChange() {
  4946. rotation.setFromQuaternion(quaternion, undefined, false);
  4947. }
  4948. rotation._onChange(onRotationChange);
  4949. quaternion._onChange(onQuaternionChange);
  4950. Object.defineProperties(this, {
  4951. position: {
  4952. configurable: true,
  4953. enumerable: true,
  4954. value: position
  4955. },
  4956. rotation: {
  4957. configurable: true,
  4958. enumerable: true,
  4959. value: rotation
  4960. },
  4961. quaternion: {
  4962. configurable: true,
  4963. enumerable: true,
  4964. value: quaternion
  4965. },
  4966. scale: {
  4967. configurable: true,
  4968. enumerable: true,
  4969. value: scale
  4970. },
  4971. modelViewMatrix: {
  4972. value: new Matrix4()
  4973. },
  4974. normalMatrix: {
  4975. value: new Matrix3()
  4976. }
  4977. });
  4978. this.matrix = new Matrix4();
  4979. this.matrixWorld = new Matrix4();
  4980. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  4981. this.matrixWorldNeedsUpdate = false;
  4982. this.layers = new Layers();
  4983. this.visible = true;
  4984. this.castShadow = false;
  4985. this.receiveShadow = false;
  4986. this.frustumCulled = true;
  4987. this.renderOrder = 0;
  4988. this.animations = [];
  4989. this.userData = {};
  4990. }
  4991. Object3D.DefaultUp = new Vector3(0, 1, 0);
  4992. Object3D.DefaultMatrixAutoUpdate = true;
  4993. Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  4994. constructor: Object3D,
  4995. isObject3D: true,
  4996. onBeforeRender: function onBeforeRender() {},
  4997. onAfterRender: function onAfterRender() {},
  4998. applyMatrix4: function applyMatrix4(matrix) {
  4999. if (this.matrixAutoUpdate) this.updateMatrix();
  5000. this.matrix.premultiply(matrix);
  5001. this.matrix.decompose(this.position, this.quaternion, this.scale);
  5002. },
  5003. applyQuaternion: function applyQuaternion(q) {
  5004. this.quaternion.premultiply(q);
  5005. return this;
  5006. },
  5007. setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
  5008. // assumes axis is normalized
  5009. this.quaternion.setFromAxisAngle(axis, angle);
  5010. },
  5011. setRotationFromEuler: function setRotationFromEuler(euler) {
  5012. this.quaternion.setFromEuler(euler, true);
  5013. },
  5014. setRotationFromMatrix: function setRotationFromMatrix(m) {
  5015. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5016. this.quaternion.setFromRotationMatrix(m);
  5017. },
  5018. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  5019. // assumes q is normalized
  5020. this.quaternion.copy(q);
  5021. },
  5022. rotateOnAxis: function rotateOnAxis(axis, angle) {
  5023. // rotate object on axis in object space
  5024. // axis is assumed to be normalized
  5025. _q1.setFromAxisAngle(axis, angle);
  5026. this.quaternion.multiply(_q1);
  5027. return this;
  5028. },
  5029. rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
  5030. // rotate object on axis in world space
  5031. // axis is assumed to be normalized
  5032. // method assumes no rotated parent
  5033. _q1.setFromAxisAngle(axis, angle);
  5034. this.quaternion.premultiply(_q1);
  5035. return this;
  5036. },
  5037. rotateX: function rotateX(angle) {
  5038. return this.rotateOnAxis(_xAxis, angle);
  5039. },
  5040. rotateY: function rotateY(angle) {
  5041. return this.rotateOnAxis(_yAxis, angle);
  5042. },
  5043. rotateZ: function rotateZ(angle) {
  5044. return this.rotateOnAxis(_zAxis, angle);
  5045. },
  5046. translateOnAxis: function translateOnAxis(axis, distance) {
  5047. // translate object by distance along axis in object space
  5048. // axis is assumed to be normalized
  5049. _v1$2.copy(axis).applyQuaternion(this.quaternion);
  5050. this.position.add(_v1$2.multiplyScalar(distance));
  5051. return this;
  5052. },
  5053. translateX: function translateX(distance) {
  5054. return this.translateOnAxis(_xAxis, distance);
  5055. },
  5056. translateY: function translateY(distance) {
  5057. return this.translateOnAxis(_yAxis, distance);
  5058. },
  5059. translateZ: function translateZ(distance) {
  5060. return this.translateOnAxis(_zAxis, distance);
  5061. },
  5062. localToWorld: function localToWorld(vector) {
  5063. return vector.applyMatrix4(this.matrixWorld);
  5064. },
  5065. worldToLocal: function worldToLocal(vector) {
  5066. return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert());
  5067. },
  5068. lookAt: function lookAt(x, y, z) {
  5069. // This method does not support objects having non-uniformly-scaled parent(s)
  5070. if (x.isVector3) {
  5071. _target.copy(x);
  5072. } else {
  5073. _target.set(x, y, z);
  5074. }
  5075. var parent = this.parent;
  5076. this.updateWorldMatrix(true, false);
  5077. _position.setFromMatrixPosition(this.matrixWorld);
  5078. if (this.isCamera || this.isLight) {
  5079. _m1$1.lookAt(_position, _target, this.up);
  5080. } else {
  5081. _m1$1.lookAt(_target, _position, this.up);
  5082. }
  5083. this.quaternion.setFromRotationMatrix(_m1$1);
  5084. if (parent) {
  5085. _m1$1.extractRotation(parent.matrixWorld);
  5086. _q1.setFromRotationMatrix(_m1$1);
  5087. this.quaternion.premultiply(_q1.invert());
  5088. }
  5089. },
  5090. add: function add(object) {
  5091. if (arguments.length > 1) {
  5092. for (var i = 0; i < arguments.length; i++) {
  5093. this.add(arguments[i]);
  5094. }
  5095. return this;
  5096. }
  5097. if (object === this) {
  5098. console.error('THREE.Object3D.add: object can\'t be added as a child of itself.', object);
  5099. return this;
  5100. }
  5101. if (object && object.isObject3D) {
  5102. if (object.parent !== null) {
  5103. object.parent.remove(object);
  5104. }
  5105. object.parent = this;
  5106. this.children.push(object);
  5107. object.dispatchEvent(_addedEvent);
  5108. } else {
  5109. console.error('THREE.Object3D.add: object not an instance of THREE.Object3D.', object);
  5110. }
  5111. return this;
  5112. },
  5113. remove: function remove(object) {
  5114. if (arguments.length > 1) {
  5115. for (var i = 0; i < arguments.length; i++) {
  5116. this.remove(arguments[i]);
  5117. }
  5118. return this;
  5119. }
  5120. var index = this.children.indexOf(object);
  5121. if (index !== -1) {
  5122. object.parent = null;
  5123. this.children.splice(index, 1);
  5124. object.dispatchEvent(_removedEvent);
  5125. }
  5126. return this;
  5127. },
  5128. clear: function clear() {
  5129. for (var i = 0; i < this.children.length; i++) {
  5130. var object = this.children[i];
  5131. object.parent = null;
  5132. object.dispatchEvent(_removedEvent);
  5133. }
  5134. this.children.length = 0;
  5135. return this;
  5136. },
  5137. attach: function attach(object) {
  5138. // adds object as a child of this, while maintaining the object's world transform
  5139. this.updateWorldMatrix(true, false);
  5140. _m1$1.copy(this.matrixWorld).invert();
  5141. if (object.parent !== null) {
  5142. object.parent.updateWorldMatrix(true, false);
  5143. _m1$1.multiply(object.parent.matrixWorld);
  5144. }
  5145. object.applyMatrix4(_m1$1);
  5146. object.updateWorldMatrix(false, false);
  5147. this.add(object);
  5148. return this;
  5149. },
  5150. getObjectById: function getObjectById(id) {
  5151. return this.getObjectByProperty('id', id);
  5152. },
  5153. getObjectByName: function getObjectByName(name) {
  5154. return this.getObjectByProperty('name', name);
  5155. },
  5156. getObjectByProperty: function getObjectByProperty(name, value) {
  5157. if (this[name] === value) return this;
  5158. for (var i = 0, l = this.children.length; i < l; i++) {
  5159. var child = this.children[i];
  5160. var object = child.getObjectByProperty(name, value);
  5161. if (object !== undefined) {
  5162. return object;
  5163. }
  5164. }
  5165. return undefined;
  5166. },
  5167. getWorldPosition: function getWorldPosition(target) {
  5168. if (target === undefined) {
  5169. console.warn('THREE.Object3D: .getWorldPosition() target is now required');
  5170. target = new Vector3();
  5171. }
  5172. this.updateWorldMatrix(true, false);
  5173. return target.setFromMatrixPosition(this.matrixWorld);
  5174. },
  5175. getWorldQuaternion: function getWorldQuaternion(target) {
  5176. if (target === undefined) {
  5177. console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
  5178. target = new Quaternion();
  5179. }
  5180. this.updateWorldMatrix(true, false);
  5181. this.matrixWorld.decompose(_position, target, _scale);
  5182. return target;
  5183. },
  5184. getWorldScale: function getWorldScale(target) {
  5185. if (target === undefined) {
  5186. console.warn('THREE.Object3D: .getWorldScale() target is now required');
  5187. target = new Vector3();
  5188. }
  5189. this.updateWorldMatrix(true, false);
  5190. this.matrixWorld.decompose(_position, _quaternion$2, target);
  5191. return target;
  5192. },
  5193. getWorldDirection: function getWorldDirection(target) {
  5194. if (target === undefined) {
  5195. console.warn('THREE.Object3D: .getWorldDirection() target is now required');
  5196. target = new Vector3();
  5197. }
  5198. this.updateWorldMatrix(true, false);
  5199. var e = this.matrixWorld.elements;
  5200. return target.set(e[8], e[9], e[10]).normalize();
  5201. },
  5202. raycast: function raycast() {},
  5203. traverse: function traverse(callback) {
  5204. callback(this);
  5205. var children = this.children;
  5206. for (var i = 0, l = children.length; i < l; i++) {
  5207. children[i].traverse(callback);
  5208. }
  5209. },
  5210. traverseVisible: function traverseVisible(callback) {
  5211. if (this.visible === false) return;
  5212. callback(this);
  5213. var children = this.children;
  5214. for (var i = 0, l = children.length; i < l; i++) {
  5215. children[i].traverseVisible(callback);
  5216. }
  5217. },
  5218. traverseAncestors: function traverseAncestors(callback) {
  5219. var parent = this.parent;
  5220. if (parent !== null) {
  5221. callback(parent);
  5222. parent.traverseAncestors(callback);
  5223. }
  5224. },
  5225. updateMatrix: function updateMatrix() {
  5226. this.matrix.compose(this.position, this.quaternion, this.scale);
  5227. this.matrixWorldNeedsUpdate = true;
  5228. },
  5229. updateMatrixWorld: function updateMatrixWorld(force) {
  5230. if (this.matrixAutoUpdate) this.updateMatrix();
  5231. if (this.matrixWorldNeedsUpdate || force) {
  5232. if (this.parent === null) {
  5233. this.matrixWorld.copy(this.matrix);
  5234. } else {
  5235. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  5236. }
  5237. this.matrixWorldNeedsUpdate = false;
  5238. force = true;
  5239. } // update children
  5240. var children = this.children;
  5241. for (var i = 0, l = children.length; i < l; i++) {
  5242. children[i].updateMatrixWorld(force);
  5243. }
  5244. },
  5245. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  5246. var parent = this.parent;
  5247. if (updateParents === true && parent !== null) {
  5248. parent.updateWorldMatrix(true, false);
  5249. }
  5250. if (this.matrixAutoUpdate) this.updateMatrix();
  5251. if (this.parent === null) {
  5252. this.matrixWorld.copy(this.matrix);
  5253. } else {
  5254. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  5255. } // update children
  5256. if (updateChildren === true) {
  5257. var children = this.children;
  5258. for (var i = 0, l = children.length; i < l; i++) {
  5259. children[i].updateWorldMatrix(false, true);
  5260. }
  5261. }
  5262. },
  5263. toJSON: function toJSON(meta) {
  5264. // meta is a string when called from JSON.stringify
  5265. var isRootObject = meta === undefined || typeof meta === 'string';
  5266. var output = {}; // meta is a hash used to collect geometries, materials.
  5267. // not providing it implies that this is the root object
  5268. // being serialized.
  5269. if (isRootObject) {
  5270. // initialize meta obj
  5271. meta = {
  5272. geometries: {},
  5273. materials: {},
  5274. textures: {},
  5275. images: {},
  5276. shapes: {},
  5277. skeletons: {},
  5278. animations: {}
  5279. };
  5280. output.metadata = {
  5281. version: 4.5,
  5282. type: 'Object',
  5283. generator: 'Object3D.toJSON'
  5284. };
  5285. } // standard Object3D serialization
  5286. var object = {};
  5287. object.uuid = this.uuid;
  5288. object.type = this.type;
  5289. if (this.name !== '') object.name = this.name;
  5290. if (this.castShadow === true) object.castShadow = true;
  5291. if (this.receiveShadow === true) object.receiveShadow = true;
  5292. if (this.visible === false) object.visible = false;
  5293. if (this.frustumCulled === false) object.frustumCulled = false;
  5294. if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
  5295. if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
  5296. object.layers = this.layers.mask;
  5297. object.matrix = this.matrix.toArray();
  5298. if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
  5299. if (this.isInstancedMesh) {
  5300. object.type = 'InstancedMesh';
  5301. object.count = this.count;
  5302. object.instanceMatrix = this.instanceMatrix.toJSON();
  5303. } //
  5304. function serialize(library, element) {
  5305. if (library[element.uuid] === undefined) {
  5306. library[element.uuid] = element.toJSON(meta);
  5307. }
  5308. return element.uuid;
  5309. }
  5310. if (this.isMesh || this.isLine || this.isPoints) {
  5311. object.geometry = serialize(meta.geometries, this.geometry);
  5312. var parameters = this.geometry.parameters;
  5313. if (parameters !== undefined && parameters.shapes !== undefined) {
  5314. var shapes = parameters.shapes;
  5315. if (Array.isArray(shapes)) {
  5316. for (var i = 0, l = shapes.length; i < l; i++) {
  5317. var shape = shapes[i];
  5318. serialize(meta.shapes, shape);
  5319. }
  5320. } else {
  5321. serialize(meta.shapes, shapes);
  5322. }
  5323. }
  5324. }
  5325. if (this.isSkinnedMesh) {
  5326. object.bindMode = this.bindMode;
  5327. object.bindMatrix = this.bindMatrix.toArray();
  5328. if (this.skeleton !== undefined) {
  5329. serialize(meta.skeletons, this.skeleton);
  5330. object.skeleton = this.skeleton.uuid;
  5331. }
  5332. }
  5333. if (this.material !== undefined) {
  5334. if (Array.isArray(this.material)) {
  5335. var uuids = [];
  5336. for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
  5337. uuids.push(serialize(meta.materials, this.material[_i]));
  5338. }
  5339. object.material = uuids;
  5340. } else {
  5341. object.material = serialize(meta.materials, this.material);
  5342. }
  5343. } //
  5344. if (this.children.length > 0) {
  5345. object.children = [];
  5346. for (var _i2 = 0; _i2 < this.children.length; _i2++) {
  5347. object.children.push(this.children[_i2].toJSON(meta).object);
  5348. }
  5349. } //
  5350. if (this.animations.length > 0) {
  5351. object.animations = [];
  5352. for (var _i3 = 0; _i3 < this.animations.length; _i3++) {
  5353. var animation = this.animations[_i3];
  5354. object.animations.push(serialize(meta.animations, animation));
  5355. }
  5356. }
  5357. if (isRootObject) {
  5358. var geometries = extractFromCache(meta.geometries);
  5359. var materials = extractFromCache(meta.materials);
  5360. var textures = extractFromCache(meta.textures);
  5361. var images = extractFromCache(meta.images);
  5362. var _shapes = extractFromCache(meta.shapes);
  5363. var skeletons = extractFromCache(meta.skeletons);
  5364. var animations = extractFromCache(meta.animations);
  5365. if (geometries.length > 0) output.geometries = geometries;
  5366. if (materials.length > 0) output.materials = materials;
  5367. if (textures.length > 0) output.textures = textures;
  5368. if (images.length > 0) output.images = images;
  5369. if (_shapes.length > 0) output.shapes = _shapes;
  5370. if (skeletons.length > 0) output.skeletons = skeletons;
  5371. if (animations.length > 0) output.animations = animations;
  5372. }
  5373. output.object = object;
  5374. return output; // extract data from the cache hash
  5375. // remove metadata on each item
  5376. // and return as array
  5377. function extractFromCache(cache) {
  5378. var values = [];
  5379. for (var key in cache) {
  5380. var data = cache[key];
  5381. delete data.metadata;
  5382. values.push(data);
  5383. }
  5384. return values;
  5385. }
  5386. },
  5387. clone: function clone(recursive) {
  5388. return new this.constructor().copy(this, recursive);
  5389. },
  5390. copy: function copy(source, recursive) {
  5391. if (recursive === void 0) {
  5392. recursive = true;
  5393. }
  5394. this.name = source.name;
  5395. this.up.copy(source.up);
  5396. this.position.copy(source.position);
  5397. this.rotation.order = source.rotation.order;
  5398. this.quaternion.copy(source.quaternion);
  5399. this.scale.copy(source.scale);
  5400. this.matrix.copy(source.matrix);
  5401. this.matrixWorld.copy(source.matrixWorld);
  5402. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5403. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5404. this.layers.mask = source.layers.mask;
  5405. this.visible = source.visible;
  5406. this.castShadow = source.castShadow;
  5407. this.receiveShadow = source.receiveShadow;
  5408. this.frustumCulled = source.frustumCulled;
  5409. this.renderOrder = source.renderOrder;
  5410. this.userData = JSON.parse(JSON.stringify(source.userData));
  5411. if (recursive === true) {
  5412. for (var i = 0; i < source.children.length; i++) {
  5413. var child = source.children[i];
  5414. this.add(child.clone());
  5415. }
  5416. }
  5417. return this;
  5418. }
  5419. });
  5420. var _vector1 = /*@__PURE__*/new Vector3();
  5421. var _vector2 = /*@__PURE__*/new Vector3();
  5422. var _normalMatrix = /*@__PURE__*/new Matrix3();
  5423. var Plane = /*#__PURE__*/function () {
  5424. function Plane(normal, constant) {
  5425. Object.defineProperty(this, 'isPlane', {
  5426. value: true
  5427. }); // normal is assumed to be normalized
  5428. this.normal = normal !== undefined ? normal : new Vector3(1, 0, 0);
  5429. this.constant = constant !== undefined ? constant : 0;
  5430. }
  5431. var _proto = Plane.prototype;
  5432. _proto.set = function set(normal, constant) {
  5433. this.normal.copy(normal);
  5434. this.constant = constant;
  5435. return this;
  5436. };
  5437. _proto.setComponents = function setComponents(x, y, z, w) {
  5438. this.normal.set(x, y, z);
  5439. this.constant = w;
  5440. return this;
  5441. };
  5442. _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
  5443. this.normal.copy(normal);
  5444. this.constant = -point.dot(this.normal);
  5445. return this;
  5446. };
  5447. _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
  5448. 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)?
  5449. this.setFromNormalAndCoplanarPoint(normal, a);
  5450. return this;
  5451. };
  5452. _proto.clone = function clone() {
  5453. return new this.constructor().copy(this);
  5454. };
  5455. _proto.copy = function copy(plane) {
  5456. this.normal.copy(plane.normal);
  5457. this.constant = plane.constant;
  5458. return this;
  5459. };
  5460. _proto.normalize = function normalize() {
  5461. // Note: will lead to a divide by zero if the plane is invalid.
  5462. var inverseNormalLength = 1.0 / this.normal.length();
  5463. this.normal.multiplyScalar(inverseNormalLength);
  5464. this.constant *= inverseNormalLength;
  5465. return this;
  5466. };
  5467. _proto.negate = function negate() {
  5468. this.constant *= -1;
  5469. this.normal.negate();
  5470. return this;
  5471. };
  5472. _proto.distanceToPoint = function distanceToPoint(point) {
  5473. return this.normal.dot(point) + this.constant;
  5474. };
  5475. _proto.distanceToSphere = function distanceToSphere(sphere) {
  5476. return this.distanceToPoint(sphere.center) - sphere.radius;
  5477. };
  5478. _proto.projectPoint = function projectPoint(point, target) {
  5479. if (target === undefined) {
  5480. console.warn('THREE.Plane: .projectPoint() target is now required');
  5481. target = new Vector3();
  5482. }
  5483. return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
  5484. };
  5485. _proto.intersectLine = function intersectLine(line, target) {
  5486. if (target === undefined) {
  5487. console.warn('THREE.Plane: .intersectLine() target is now required');
  5488. target = new Vector3();
  5489. }
  5490. var direction = line.delta(_vector1);
  5491. var denominator = this.normal.dot(direction);
  5492. if (denominator === 0) {
  5493. // line is coplanar, return origin
  5494. if (this.distanceToPoint(line.start) === 0) {
  5495. return target.copy(line.start);
  5496. } // Unsure if this is the correct method to handle this case.
  5497. return undefined;
  5498. }
  5499. var t = -(line.start.dot(this.normal) + this.constant) / denominator;
  5500. if (t < 0 || t > 1) {
  5501. return undefined;
  5502. }
  5503. return target.copy(direction).multiplyScalar(t).add(line.start);
  5504. };
  5505. _proto.intersectsLine = function intersectsLine(line) {
  5506. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  5507. var startSign = this.distanceToPoint(line.start);
  5508. var endSign = this.distanceToPoint(line.end);
  5509. return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
  5510. };
  5511. _proto.intersectsBox = function intersectsBox(box) {
  5512. return box.intersectsPlane(this);
  5513. };
  5514. _proto.intersectsSphere = function intersectsSphere(sphere) {
  5515. return sphere.intersectsPlane(this);
  5516. };
  5517. _proto.coplanarPoint = function coplanarPoint(target) {
  5518. if (target === undefined) {
  5519. console.warn('THREE.Plane: .coplanarPoint() target is now required');
  5520. target = new Vector3();
  5521. }
  5522. return target.copy(this.normal).multiplyScalar(-this.constant);
  5523. };
  5524. _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
  5525. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
  5526. var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
  5527. var normal = this.normal.applyMatrix3(normalMatrix).normalize();
  5528. this.constant = -referencePoint.dot(normal);
  5529. return this;
  5530. };
  5531. _proto.translate = function translate(offset) {
  5532. this.constant -= offset.dot(this.normal);
  5533. return this;
  5534. };
  5535. _proto.equals = function equals(plane) {
  5536. return plane.normal.equals(this.normal) && plane.constant === this.constant;
  5537. };
  5538. return Plane;
  5539. }();
  5540. var _v0$1 = /*@__PURE__*/new Vector3();
  5541. var _v1$3 = /*@__PURE__*/new Vector3();
  5542. var _v2$1 = /*@__PURE__*/new Vector3();
  5543. var _v3 = /*@__PURE__*/new Vector3();
  5544. var _vab = /*@__PURE__*/new Vector3();
  5545. var _vac = /*@__PURE__*/new Vector3();
  5546. var _vbc = /*@__PURE__*/new Vector3();
  5547. var _vap = /*@__PURE__*/new Vector3();
  5548. var _vbp = /*@__PURE__*/new Vector3();
  5549. var _vcp = /*@__PURE__*/new Vector3();
  5550. var Triangle = /*#__PURE__*/function () {
  5551. function Triangle(a, b, c) {
  5552. this.a = a !== undefined ? a : new Vector3();
  5553. this.b = b !== undefined ? b : new Vector3();
  5554. this.c = c !== undefined ? c : new Vector3();
  5555. }
  5556. Triangle.getNormal = function getNormal(a, b, c, target) {
  5557. if (target === undefined) {
  5558. console.warn('THREE.Triangle: .getNormal() target is now required');
  5559. target = new Vector3();
  5560. }
  5561. target.subVectors(c, b);
  5562. _v0$1.subVectors(a, b);
  5563. target.cross(_v0$1);
  5564. var targetLengthSq = target.lengthSq();
  5565. if (targetLengthSq > 0) {
  5566. return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
  5567. }
  5568. return target.set(0, 0, 0);
  5569. } // static/instance method to calculate barycentric coordinates
  5570. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  5571. ;
  5572. Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
  5573. _v0$1.subVectors(c, a);
  5574. _v1$3.subVectors(b, a);
  5575. _v2$1.subVectors(point, a);
  5576. var dot00 = _v0$1.dot(_v0$1);
  5577. var dot01 = _v0$1.dot(_v1$3);
  5578. var dot02 = _v0$1.dot(_v2$1);
  5579. var dot11 = _v1$3.dot(_v1$3);
  5580. var dot12 = _v1$3.dot(_v2$1);
  5581. var denom = dot00 * dot11 - dot01 * dot01;
  5582. if (target === undefined) {
  5583. console.warn('THREE.Triangle: .getBarycoord() target is now required');
  5584. target = new Vector3();
  5585. } // collinear or singular triangle
  5586. if (denom === 0) {
  5587. // arbitrary location outside of triangle?
  5588. // not sure if this is the best idea, maybe should be returning undefined
  5589. return target.set(-2, -1, -1);
  5590. }
  5591. var invDenom = 1 / denom;
  5592. var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  5593. var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
  5594. return target.set(1 - u - v, v, u);
  5595. };
  5596. Triangle.containsPoint = function containsPoint(point, a, b, c) {
  5597. this.getBarycoord(point, a, b, c, _v3);
  5598. return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
  5599. };
  5600. Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
  5601. this.getBarycoord(point, p1, p2, p3, _v3);
  5602. target.set(0, 0);
  5603. target.addScaledVector(uv1, _v3.x);
  5604. target.addScaledVector(uv2, _v3.y);
  5605. target.addScaledVector(uv3, _v3.z);
  5606. return target;
  5607. };
  5608. Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
  5609. _v0$1.subVectors(c, b);
  5610. _v1$3.subVectors(a, b); // strictly front facing
  5611. return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
  5612. };
  5613. var _proto = Triangle.prototype;
  5614. _proto.set = function set(a, b, c) {
  5615. this.a.copy(a);
  5616. this.b.copy(b);
  5617. this.c.copy(c);
  5618. return this;
  5619. };
  5620. _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
  5621. this.a.copy(points[i0]);
  5622. this.b.copy(points[i1]);
  5623. this.c.copy(points[i2]);
  5624. return this;
  5625. };
  5626. _proto.clone = function clone() {
  5627. return new this.constructor().copy(this);
  5628. };
  5629. _proto.copy = function copy(triangle) {
  5630. this.a.copy(triangle.a);
  5631. this.b.copy(triangle.b);
  5632. this.c.copy(triangle.c);
  5633. return this;
  5634. };
  5635. _proto.getArea = function getArea() {
  5636. _v0$1.subVectors(this.c, this.b);
  5637. _v1$3.subVectors(this.a, this.b);
  5638. return _v0$1.cross(_v1$3).length() * 0.5;
  5639. };
  5640. _proto.getMidpoint = function getMidpoint(target) {
  5641. if (target === undefined) {
  5642. console.warn('THREE.Triangle: .getMidpoint() target is now required');
  5643. target = new Vector3();
  5644. }
  5645. return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  5646. };
  5647. _proto.getNormal = function getNormal(target) {
  5648. return Triangle.getNormal(this.a, this.b, this.c, target);
  5649. };
  5650. _proto.getPlane = function getPlane(target) {
  5651. if (target === undefined) {
  5652. console.warn('THREE.Triangle: .getPlane() target is now required');
  5653. target = new Plane();
  5654. }
  5655. return target.setFromCoplanarPoints(this.a, this.b, this.c);
  5656. };
  5657. _proto.getBarycoord = function getBarycoord(point, target) {
  5658. return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
  5659. };
  5660. _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
  5661. return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
  5662. };
  5663. _proto.containsPoint = function containsPoint(point) {
  5664. return Triangle.containsPoint(point, this.a, this.b, this.c);
  5665. };
  5666. _proto.isFrontFacing = function isFrontFacing(direction) {
  5667. return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
  5668. };
  5669. _proto.intersectsBox = function intersectsBox(box) {
  5670. return box.intersectsTriangle(this);
  5671. };
  5672. _proto.closestPointToPoint = function closestPointToPoint(p, target) {
  5673. if (target === undefined) {
  5674. console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
  5675. target = new Vector3();
  5676. }
  5677. var a = this.a,
  5678. b = this.b,
  5679. c = this.c;
  5680. var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  5681. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  5682. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  5683. // basically, we're distinguishing which of the voronoi regions of the triangle
  5684. // the point lies in with the minimum amount of redundant computation.
  5685. _vab.subVectors(b, a);
  5686. _vac.subVectors(c, a);
  5687. _vap.subVectors(p, a);
  5688. var d1 = _vab.dot(_vap);
  5689. var d2 = _vac.dot(_vap);
  5690. if (d1 <= 0 && d2 <= 0) {
  5691. // vertex region of A; barycentric coords (1, 0, 0)
  5692. return target.copy(a);
  5693. }
  5694. _vbp.subVectors(p, b);
  5695. var d3 = _vab.dot(_vbp);
  5696. var d4 = _vac.dot(_vbp);
  5697. if (d3 >= 0 && d4 <= d3) {
  5698. // vertex region of B; barycentric coords (0, 1, 0)
  5699. return target.copy(b);
  5700. }
  5701. var vc = d1 * d4 - d3 * d2;
  5702. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  5703. v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
  5704. return target.copy(a).addScaledVector(_vab, v);
  5705. }
  5706. _vcp.subVectors(p, c);
  5707. var d5 = _vab.dot(_vcp);
  5708. var d6 = _vac.dot(_vcp);
  5709. if (d6 >= 0 && d5 <= d6) {
  5710. // vertex region of C; barycentric coords (0, 0, 1)
  5711. return target.copy(c);
  5712. }
  5713. var vb = d5 * d2 - d1 * d6;
  5714. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  5715. w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
  5716. return target.copy(a).addScaledVector(_vac, w);
  5717. }
  5718. var va = d3 * d6 - d5 * d4;
  5719. if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
  5720. _vbc.subVectors(c, b);
  5721. w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
  5722. return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
  5723. } // face region
  5724. var denom = 1 / (va + vb + vc); // u = va * denom
  5725. v = vb * denom;
  5726. w = vc * denom;
  5727. return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
  5728. };
  5729. _proto.equals = function equals(triangle) {
  5730. return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
  5731. };
  5732. return Triangle;
  5733. }();
  5734. var _colorKeywords = {
  5735. 'aliceblue': 0xF0F8FF,
  5736. 'antiquewhite': 0xFAEBD7,
  5737. 'aqua': 0x00FFFF,
  5738. 'aquamarine': 0x7FFFD4,
  5739. 'azure': 0xF0FFFF,
  5740. 'beige': 0xF5F5DC,
  5741. 'bisque': 0xFFE4C4,
  5742. 'black': 0x000000,
  5743. 'blanchedalmond': 0xFFEBCD,
  5744. 'blue': 0x0000FF,
  5745. 'blueviolet': 0x8A2BE2,
  5746. 'brown': 0xA52A2A,
  5747. 'burlywood': 0xDEB887,
  5748. 'cadetblue': 0x5F9EA0,
  5749. 'chartreuse': 0x7FFF00,
  5750. 'chocolate': 0xD2691E,
  5751. 'coral': 0xFF7F50,
  5752. 'cornflowerblue': 0x6495ED,
  5753. 'cornsilk': 0xFFF8DC,
  5754. 'crimson': 0xDC143C,
  5755. 'cyan': 0x00FFFF,
  5756. 'darkblue': 0x00008B,
  5757. 'darkcyan': 0x008B8B,
  5758. 'darkgoldenrod': 0xB8860B,
  5759. 'darkgray': 0xA9A9A9,
  5760. 'darkgreen': 0x006400,
  5761. 'darkgrey': 0xA9A9A9,
  5762. 'darkkhaki': 0xBDB76B,
  5763. 'darkmagenta': 0x8B008B,
  5764. 'darkolivegreen': 0x556B2F,
  5765. 'darkorange': 0xFF8C00,
  5766. 'darkorchid': 0x9932CC,
  5767. 'darkred': 0x8B0000,
  5768. 'darksalmon': 0xE9967A,
  5769. 'darkseagreen': 0x8FBC8F,
  5770. 'darkslateblue': 0x483D8B,
  5771. 'darkslategray': 0x2F4F4F,
  5772. 'darkslategrey': 0x2F4F4F,
  5773. 'darkturquoise': 0x00CED1,
  5774. 'darkviolet': 0x9400D3,
  5775. 'deeppink': 0xFF1493,
  5776. 'deepskyblue': 0x00BFFF,
  5777. 'dimgray': 0x696969,
  5778. 'dimgrey': 0x696969,
  5779. 'dodgerblue': 0x1E90FF,
  5780. 'firebrick': 0xB22222,
  5781. 'floralwhite': 0xFFFAF0,
  5782. 'forestgreen': 0x228B22,
  5783. 'fuchsia': 0xFF00FF,
  5784. 'gainsboro': 0xDCDCDC,
  5785. 'ghostwhite': 0xF8F8FF,
  5786. 'gold': 0xFFD700,
  5787. 'goldenrod': 0xDAA520,
  5788. 'gray': 0x808080,
  5789. 'green': 0x008000,
  5790. 'greenyellow': 0xADFF2F,
  5791. 'grey': 0x808080,
  5792. 'honeydew': 0xF0FFF0,
  5793. 'hotpink': 0xFF69B4,
  5794. 'indianred': 0xCD5C5C,
  5795. 'indigo': 0x4B0082,
  5796. 'ivory': 0xFFFFF0,
  5797. 'khaki': 0xF0E68C,
  5798. 'lavender': 0xE6E6FA,
  5799. 'lavenderblush': 0xFFF0F5,
  5800. 'lawngreen': 0x7CFC00,
  5801. 'lemonchiffon': 0xFFFACD,
  5802. 'lightblue': 0xADD8E6,
  5803. 'lightcoral': 0xF08080,
  5804. 'lightcyan': 0xE0FFFF,
  5805. 'lightgoldenrodyellow': 0xFAFAD2,
  5806. 'lightgray': 0xD3D3D3,
  5807. 'lightgreen': 0x90EE90,
  5808. 'lightgrey': 0xD3D3D3,
  5809. 'lightpink': 0xFFB6C1,
  5810. 'lightsalmon': 0xFFA07A,
  5811. 'lightseagreen': 0x20B2AA,
  5812. 'lightskyblue': 0x87CEFA,
  5813. 'lightslategray': 0x778899,
  5814. 'lightslategrey': 0x778899,
  5815. 'lightsteelblue': 0xB0C4DE,
  5816. 'lightyellow': 0xFFFFE0,
  5817. 'lime': 0x00FF00,
  5818. 'limegreen': 0x32CD32,
  5819. 'linen': 0xFAF0E6,
  5820. 'magenta': 0xFF00FF,
  5821. 'maroon': 0x800000,
  5822. 'mediumaquamarine': 0x66CDAA,
  5823. 'mediumblue': 0x0000CD,
  5824. 'mediumorchid': 0xBA55D3,
  5825. 'mediumpurple': 0x9370DB,
  5826. 'mediumseagreen': 0x3CB371,
  5827. 'mediumslateblue': 0x7B68EE,
  5828. 'mediumspringgreen': 0x00FA9A,
  5829. 'mediumturquoise': 0x48D1CC,
  5830. 'mediumvioletred': 0xC71585,
  5831. 'midnightblue': 0x191970,
  5832. 'mintcream': 0xF5FFFA,
  5833. 'mistyrose': 0xFFE4E1,
  5834. 'moccasin': 0xFFE4B5,
  5835. 'navajowhite': 0xFFDEAD,
  5836. 'navy': 0x000080,
  5837. 'oldlace': 0xFDF5E6,
  5838. 'olive': 0x808000,
  5839. 'olivedrab': 0x6B8E23,
  5840. 'orange': 0xFFA500,
  5841. 'orangered': 0xFF4500,
  5842. 'orchid': 0xDA70D6,
  5843. 'palegoldenrod': 0xEEE8AA,
  5844. 'palegreen': 0x98FB98,
  5845. 'paleturquoise': 0xAFEEEE,
  5846. 'palevioletred': 0xDB7093,
  5847. 'papayawhip': 0xFFEFD5,
  5848. 'peachpuff': 0xFFDAB9,
  5849. 'peru': 0xCD853F,
  5850. 'pink': 0xFFC0CB,
  5851. 'plum': 0xDDA0DD,
  5852. 'powderblue': 0xB0E0E6,
  5853. 'purple': 0x800080,
  5854. 'rebeccapurple': 0x663399,
  5855. 'red': 0xFF0000,
  5856. 'rosybrown': 0xBC8F8F,
  5857. 'royalblue': 0x4169E1,
  5858. 'saddlebrown': 0x8B4513,
  5859. 'salmon': 0xFA8072,
  5860. 'sandybrown': 0xF4A460,
  5861. 'seagreen': 0x2E8B57,
  5862. 'seashell': 0xFFF5EE,
  5863. 'sienna': 0xA0522D,
  5864. 'silver': 0xC0C0C0,
  5865. 'skyblue': 0x87CEEB,
  5866. 'slateblue': 0x6A5ACD,
  5867. 'slategray': 0x708090,
  5868. 'slategrey': 0x708090,
  5869. 'snow': 0xFFFAFA,
  5870. 'springgreen': 0x00FF7F,
  5871. 'steelblue': 0x4682B4,
  5872. 'tan': 0xD2B48C,
  5873. 'teal': 0x008080,
  5874. 'thistle': 0xD8BFD8,
  5875. 'tomato': 0xFF6347,
  5876. 'turquoise': 0x40E0D0,
  5877. 'violet': 0xEE82EE,
  5878. 'wheat': 0xF5DEB3,
  5879. 'white': 0xFFFFFF,
  5880. 'whitesmoke': 0xF5F5F5,
  5881. 'yellow': 0xFFFF00,
  5882. 'yellowgreen': 0x9ACD32
  5883. };
  5884. var _hslA = {
  5885. h: 0,
  5886. s: 0,
  5887. l: 0
  5888. };
  5889. var _hslB = {
  5890. h: 0,
  5891. s: 0,
  5892. l: 0
  5893. };
  5894. function hue2rgb(p, q, t) {
  5895. if (t < 0) t += 1;
  5896. if (t > 1) t -= 1;
  5897. if (t < 1 / 6) return p + (q - p) * 6 * t;
  5898. if (t < 1 / 2) return q;
  5899. if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  5900. return p;
  5901. }
  5902. function SRGBToLinear(c) {
  5903. return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
  5904. }
  5905. function LinearToSRGB(c) {
  5906. return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
  5907. }
  5908. var Color = /*#__PURE__*/function () {
  5909. function Color(r, g, b) {
  5910. Object.defineProperty(this, 'isColor', {
  5911. value: true
  5912. });
  5913. if (g === undefined && b === undefined) {
  5914. // r is THREE.Color, hex or string
  5915. return this.set(r);
  5916. }
  5917. return this.setRGB(r, g, b);
  5918. }
  5919. var _proto = Color.prototype;
  5920. _proto.set = function set(value) {
  5921. if (value && value.isColor) {
  5922. this.copy(value);
  5923. } else if (typeof value === 'number') {
  5924. this.setHex(value);
  5925. } else if (typeof value === 'string') {
  5926. this.setStyle(value);
  5927. }
  5928. return this;
  5929. };
  5930. _proto.setScalar = function setScalar(scalar) {
  5931. this.r = scalar;
  5932. this.g = scalar;
  5933. this.b = scalar;
  5934. return this;
  5935. };
  5936. _proto.setHex = function setHex(hex) {
  5937. hex = Math.floor(hex);
  5938. this.r = (hex >> 16 & 255) / 255;
  5939. this.g = (hex >> 8 & 255) / 255;
  5940. this.b = (hex & 255) / 255;
  5941. return this;
  5942. };
  5943. _proto.setRGB = function setRGB(r, g, b) {
  5944. this.r = r;
  5945. this.g = g;
  5946. this.b = b;
  5947. return this;
  5948. };
  5949. _proto.setHSL = function setHSL(h, s, l) {
  5950. // h,s,l ranges are in 0.0 - 1.0
  5951. h = MathUtils.euclideanModulo(h, 1);
  5952. s = MathUtils.clamp(s, 0, 1);
  5953. l = MathUtils.clamp(l, 0, 1);
  5954. if (s === 0) {
  5955. this.r = this.g = this.b = l;
  5956. } else {
  5957. var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  5958. var q = 2 * l - p;
  5959. this.r = hue2rgb(q, p, h + 1 / 3);
  5960. this.g = hue2rgb(q, p, h);
  5961. this.b = hue2rgb(q, p, h - 1 / 3);
  5962. }
  5963. return this;
  5964. };
  5965. _proto.setStyle = function setStyle(style) {
  5966. function handleAlpha(string) {
  5967. if (string === undefined) return;
  5968. if (parseFloat(string) < 1) {
  5969. console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
  5970. }
  5971. }
  5972. var m;
  5973. if (m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(style)) {
  5974. // rgb / hsl
  5975. var color;
  5976. var name = m[1];
  5977. var components = m[2];
  5978. switch (name) {
  5979. case 'rgb':
  5980. case 'rgba':
  5981. if (color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  5982. // rgb(255,0,0) rgba(255,0,0,0.5)
  5983. this.r = Math.min(255, parseInt(color[1], 10)) / 255;
  5984. this.g = Math.min(255, parseInt(color[2], 10)) / 255;
  5985. this.b = Math.min(255, parseInt(color[3], 10)) / 255;
  5986. handleAlpha(color[4]);
  5987. return this;
  5988. }
  5989. if (color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  5990. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  5991. this.r = Math.min(100, parseInt(color[1], 10)) / 100;
  5992. this.g = Math.min(100, parseInt(color[2], 10)) / 100;
  5993. this.b = Math.min(100, parseInt(color[3], 10)) / 100;
  5994. handleAlpha(color[4]);
  5995. return this;
  5996. }
  5997. break;
  5998. case 'hsl':
  5999. case 'hsla':
  6000. if (color = /^(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6001. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  6002. var h = parseFloat(color[1]) / 360;
  6003. var s = parseInt(color[2], 10) / 100;
  6004. var l = parseInt(color[3], 10) / 100;
  6005. handleAlpha(color[4]);
  6006. return this.setHSL(h, s, l);
  6007. }
  6008. break;
  6009. }
  6010. } else if (m = /^\#([A-Fa-f\d]+)$/.exec(style)) {
  6011. // hex color
  6012. var hex = m[1];
  6013. var size = hex.length;
  6014. if (size === 3) {
  6015. // #ff0
  6016. this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
  6017. this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
  6018. this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
  6019. return this;
  6020. } else if (size === 6) {
  6021. // #ff0000
  6022. this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
  6023. this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
  6024. this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
  6025. return this;
  6026. }
  6027. }
  6028. if (style && style.length > 0) {
  6029. return this.setColorName(style);
  6030. }
  6031. return this;
  6032. };
  6033. _proto.setColorName = function setColorName(style) {
  6034. // color keywords
  6035. var hex = _colorKeywords[style];
  6036. if (hex !== undefined) {
  6037. // red
  6038. this.setHex(hex);
  6039. } else {
  6040. // unknown color
  6041. console.warn('THREE.Color: Unknown color ' + style);
  6042. }
  6043. return this;
  6044. };
  6045. _proto.clone = function clone() {
  6046. return new this.constructor(this.r, this.g, this.b);
  6047. };
  6048. _proto.copy = function copy(color) {
  6049. this.r = color.r;
  6050. this.g = color.g;
  6051. this.b = color.b;
  6052. return this;
  6053. };
  6054. _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
  6055. if (gammaFactor === void 0) {
  6056. gammaFactor = 2.0;
  6057. }
  6058. this.r = Math.pow(color.r, gammaFactor);
  6059. this.g = Math.pow(color.g, gammaFactor);
  6060. this.b = Math.pow(color.b, gammaFactor);
  6061. return this;
  6062. };
  6063. _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
  6064. if (gammaFactor === void 0) {
  6065. gammaFactor = 2.0;
  6066. }
  6067. var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
  6068. this.r = Math.pow(color.r, safeInverse);
  6069. this.g = Math.pow(color.g, safeInverse);
  6070. this.b = Math.pow(color.b, safeInverse);
  6071. return this;
  6072. };
  6073. _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
  6074. this.copyGammaToLinear(this, gammaFactor);
  6075. return this;
  6076. };
  6077. _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
  6078. this.copyLinearToGamma(this, gammaFactor);
  6079. return this;
  6080. };
  6081. _proto.copySRGBToLinear = function copySRGBToLinear(color) {
  6082. this.r = SRGBToLinear(color.r);
  6083. this.g = SRGBToLinear(color.g);
  6084. this.b = SRGBToLinear(color.b);
  6085. return this;
  6086. };
  6087. _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
  6088. this.r = LinearToSRGB(color.r);
  6089. this.g = LinearToSRGB(color.g);
  6090. this.b = LinearToSRGB(color.b);
  6091. return this;
  6092. };
  6093. _proto.convertSRGBToLinear = function convertSRGBToLinear() {
  6094. this.copySRGBToLinear(this);
  6095. return this;
  6096. };
  6097. _proto.convertLinearToSRGB = function convertLinearToSRGB() {
  6098. this.copyLinearToSRGB(this);
  6099. return this;
  6100. };
  6101. _proto.getHex = function getHex() {
  6102. return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
  6103. };
  6104. _proto.getHexString = function getHexString() {
  6105. return ('000000' + this.getHex().toString(16)).slice(-6);
  6106. };
  6107. _proto.getHSL = function getHSL(target) {
  6108. // h,s,l ranges are in 0.0 - 1.0
  6109. if (target === undefined) {
  6110. console.warn('THREE.Color: .getHSL() target is now required');
  6111. target = {
  6112. h: 0,
  6113. s: 0,
  6114. l: 0
  6115. };
  6116. }
  6117. var r = this.r,
  6118. g = this.g,
  6119. b = this.b;
  6120. var max = Math.max(r, g, b);
  6121. var min = Math.min(r, g, b);
  6122. var hue, saturation;
  6123. var lightness = (min + max) / 2.0;
  6124. if (min === max) {
  6125. hue = 0;
  6126. saturation = 0;
  6127. } else {
  6128. var delta = max - min;
  6129. saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
  6130. switch (max) {
  6131. case r:
  6132. hue = (g - b) / delta + (g < b ? 6 : 0);
  6133. break;
  6134. case g:
  6135. hue = (b - r) / delta + 2;
  6136. break;
  6137. case b:
  6138. hue = (r - g) / delta + 4;
  6139. break;
  6140. }
  6141. hue /= 6;
  6142. }
  6143. target.h = hue;
  6144. target.s = saturation;
  6145. target.l = lightness;
  6146. return target;
  6147. };
  6148. _proto.getStyle = function getStyle() {
  6149. return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
  6150. };
  6151. _proto.offsetHSL = function offsetHSL(h, s, l) {
  6152. this.getHSL(_hslA);
  6153. _hslA.h += h;
  6154. _hslA.s += s;
  6155. _hslA.l += l;
  6156. this.setHSL(_hslA.h, _hslA.s, _hslA.l);
  6157. return this;
  6158. };
  6159. _proto.add = function add(color) {
  6160. this.r += color.r;
  6161. this.g += color.g;
  6162. this.b += color.b;
  6163. return this;
  6164. };
  6165. _proto.addColors = function addColors(color1, color2) {
  6166. this.r = color1.r + color2.r;
  6167. this.g = color1.g + color2.g;
  6168. this.b = color1.b + color2.b;
  6169. return this;
  6170. };
  6171. _proto.addScalar = function addScalar(s) {
  6172. this.r += s;
  6173. this.g += s;
  6174. this.b += s;
  6175. return this;
  6176. };
  6177. _proto.sub = function sub(color) {
  6178. this.r = Math.max(0, this.r - color.r);
  6179. this.g = Math.max(0, this.g - color.g);
  6180. this.b = Math.max(0, this.b - color.b);
  6181. return this;
  6182. };
  6183. _proto.multiply = function multiply(color) {
  6184. this.r *= color.r;
  6185. this.g *= color.g;
  6186. this.b *= color.b;
  6187. return this;
  6188. };
  6189. _proto.multiplyScalar = function multiplyScalar(s) {
  6190. this.r *= s;
  6191. this.g *= s;
  6192. this.b *= s;
  6193. return this;
  6194. };
  6195. _proto.lerp = function lerp(color, alpha) {
  6196. this.r += (color.r - this.r) * alpha;
  6197. this.g += (color.g - this.g) * alpha;
  6198. this.b += (color.b - this.b) * alpha;
  6199. return this;
  6200. };
  6201. _proto.lerpColors = function lerpColors(color1, color2, alpha) {
  6202. this.r = color1.r + (color2.r - color1.r) * alpha;
  6203. this.g = color1.g + (color2.g - color1.g) * alpha;
  6204. this.b = color1.b + (color2.b - color1.b) * alpha;
  6205. return this;
  6206. };
  6207. _proto.lerpHSL = function lerpHSL(color, alpha) {
  6208. this.getHSL(_hslA);
  6209. color.getHSL(_hslB);
  6210. var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
  6211. var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
  6212. var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
  6213. this.setHSL(h, s, l);
  6214. return this;
  6215. };
  6216. _proto.equals = function equals(c) {
  6217. return c.r === this.r && c.g === this.g && c.b === this.b;
  6218. };
  6219. _proto.fromArray = function fromArray(array, offset) {
  6220. if (offset === void 0) {
  6221. offset = 0;
  6222. }
  6223. this.r = array[offset];
  6224. this.g = array[offset + 1];
  6225. this.b = array[offset + 2];
  6226. return this;
  6227. };
  6228. _proto.toArray = function toArray(array, offset) {
  6229. if (array === void 0) {
  6230. array = [];
  6231. }
  6232. if (offset === void 0) {
  6233. offset = 0;
  6234. }
  6235. array[offset] = this.r;
  6236. array[offset + 1] = this.g;
  6237. array[offset + 2] = this.b;
  6238. return array;
  6239. };
  6240. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  6241. this.r = attribute.getX(index);
  6242. this.g = attribute.getY(index);
  6243. this.b = attribute.getZ(index);
  6244. if (attribute.normalized === true) {
  6245. // assuming Uint8Array
  6246. this.r /= 255;
  6247. this.g /= 255;
  6248. this.b /= 255;
  6249. }
  6250. return this;
  6251. };
  6252. _proto.toJSON = function toJSON() {
  6253. return this.getHex();
  6254. };
  6255. return Color;
  6256. }();
  6257. Color.NAMES = _colorKeywords;
  6258. Color.prototype.r = 1;
  6259. Color.prototype.g = 1;
  6260. Color.prototype.b = 1;
  6261. var Face3 = /*#__PURE__*/function () {
  6262. function Face3(a, b, c, normal, color, materialIndex) {
  6263. if (materialIndex === void 0) {
  6264. materialIndex = 0;
  6265. }
  6266. this.a = a;
  6267. this.b = b;
  6268. this.c = c;
  6269. this.normal = normal && normal.isVector3 ? normal : new Vector3();
  6270. this.vertexNormals = Array.isArray(normal) ? normal : [];
  6271. this.color = color && color.isColor ? color : new Color();
  6272. this.vertexColors = Array.isArray(color) ? color : [];
  6273. this.materialIndex = materialIndex;
  6274. }
  6275. var _proto = Face3.prototype;
  6276. _proto.clone = function clone() {
  6277. return new this.constructor().copy(this);
  6278. };
  6279. _proto.copy = function copy(source) {
  6280. this.a = source.a;
  6281. this.b = source.b;
  6282. this.c = source.c;
  6283. this.normal.copy(source.normal);
  6284. this.color.copy(source.color);
  6285. this.materialIndex = source.materialIndex;
  6286. for (var i = 0, il = source.vertexNormals.length; i < il; i++) {
  6287. this.vertexNormals[i] = source.vertexNormals[i].clone();
  6288. }
  6289. for (var _i = 0, _il = source.vertexColors.length; _i < _il; _i++) {
  6290. this.vertexColors[_i] = source.vertexColors[_i].clone();
  6291. }
  6292. return this;
  6293. };
  6294. return Face3;
  6295. }();
  6296. var materialId = 0;
  6297. function Material() {
  6298. Object.defineProperty(this, 'id', {
  6299. value: materialId++
  6300. });
  6301. this.uuid = MathUtils.generateUUID();
  6302. this.name = '';
  6303. this.type = 'Material';
  6304. this.fog = true;
  6305. this.blending = NormalBlending;
  6306. this.side = FrontSide;
  6307. this.flatShading = false;
  6308. this.vertexColors = false;
  6309. this.opacity = 1;
  6310. this.transparent = false;
  6311. this.blendSrc = SrcAlphaFactor;
  6312. this.blendDst = OneMinusSrcAlphaFactor;
  6313. this.blendEquation = AddEquation;
  6314. this.blendSrcAlpha = null;
  6315. this.blendDstAlpha = null;
  6316. this.blendEquationAlpha = null;
  6317. this.depthFunc = LessEqualDepth;
  6318. this.depthTest = true;
  6319. this.depthWrite = true;
  6320. this.stencilWriteMask = 0xff;
  6321. this.stencilFunc = AlwaysStencilFunc;
  6322. this.stencilRef = 0;
  6323. this.stencilFuncMask = 0xff;
  6324. this.stencilFail = KeepStencilOp;
  6325. this.stencilZFail = KeepStencilOp;
  6326. this.stencilZPass = KeepStencilOp;
  6327. this.stencilWrite = false;
  6328. this.clippingPlanes = null;
  6329. this.clipIntersection = false;
  6330. this.clipShadows = false;
  6331. this.shadowSide = null;
  6332. this.colorWrite = true;
  6333. this.precision = null; // override the renderer's default precision for this material
  6334. this.polygonOffset = false;
  6335. this.polygonOffsetFactor = 0;
  6336. this.polygonOffsetUnits = 0;
  6337. this.dithering = false;
  6338. this.alphaTest = 0;
  6339. this.premultipliedAlpha = false;
  6340. this.visible = true;
  6341. this.toneMapped = true;
  6342. this.userData = {};
  6343. this.version = 0;
  6344. }
  6345. Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  6346. constructor: Material,
  6347. isMaterial: true,
  6348. onBeforeCompile: function onBeforeCompile()
  6349. /* shaderobject, renderer */
  6350. {},
  6351. customProgramCacheKey: function customProgramCacheKey() {
  6352. return this.onBeforeCompile.toString();
  6353. },
  6354. setValues: function setValues(values) {
  6355. if (values === undefined) return;
  6356. for (var key in values) {
  6357. var newValue = values[key];
  6358. if (newValue === undefined) {
  6359. console.warn('THREE.Material: \'' + key + '\' parameter is undefined.');
  6360. continue;
  6361. } // for backward compatability if shading is set in the constructor
  6362. if (key === 'shading') {
  6363. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  6364. this.flatShading = newValue === FlatShading ? true : false;
  6365. continue;
  6366. }
  6367. var currentValue = this[key];
  6368. if (currentValue === undefined) {
  6369. console.warn('THREE.' + this.type + ': \'' + key + '\' is not a property of this material.');
  6370. continue;
  6371. }
  6372. if (currentValue && currentValue.isColor) {
  6373. currentValue.set(newValue);
  6374. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  6375. currentValue.copy(newValue);
  6376. } else {
  6377. this[key] = newValue;
  6378. }
  6379. }
  6380. },
  6381. toJSON: function toJSON(meta) {
  6382. var isRoot = meta === undefined || typeof meta === 'string';
  6383. if (isRoot) {
  6384. meta = {
  6385. textures: {},
  6386. images: {}
  6387. };
  6388. }
  6389. var data = {
  6390. metadata: {
  6391. version: 4.5,
  6392. type: 'Material',
  6393. generator: 'Material.toJSON'
  6394. }
  6395. }; // standard Material serialization
  6396. data.uuid = this.uuid;
  6397. data.type = this.type;
  6398. if (this.name !== '') data.name = this.name;
  6399. if (this.color && this.color.isColor) data.color = this.color.getHex();
  6400. if (this.roughness !== undefined) data.roughness = this.roughness;
  6401. if (this.metalness !== undefined) data.metalness = this.metalness;
  6402. if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
  6403. if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
  6404. if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
  6405. if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
  6406. if (this.shininess !== undefined) data.shininess = this.shininess;
  6407. if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
  6408. if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
  6409. if (this.clearcoatMap && this.clearcoatMap.isTexture) {
  6410. data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
  6411. }
  6412. if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
  6413. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
  6414. }
  6415. if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
  6416. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
  6417. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  6418. }
  6419. if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
  6420. if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
  6421. if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
  6422. if (this.lightMap && this.lightMap.isTexture) data.lightMap = this.lightMap.toJSON(meta).uuid;
  6423. if (this.aoMap && this.aoMap.isTexture) {
  6424. data.aoMap = this.aoMap.toJSON(meta).uuid;
  6425. data.aoMapIntensity = this.aoMapIntensity;
  6426. }
  6427. if (this.bumpMap && this.bumpMap.isTexture) {
  6428. data.bumpMap = this.bumpMap.toJSON(meta).uuid;
  6429. data.bumpScale = this.bumpScale;
  6430. }
  6431. if (this.normalMap && this.normalMap.isTexture) {
  6432. data.normalMap = this.normalMap.toJSON(meta).uuid;
  6433. data.normalMapType = this.normalMapType;
  6434. data.normalScale = this.normalScale.toArray();
  6435. }
  6436. if (this.displacementMap && this.displacementMap.isTexture) {
  6437. data.displacementMap = this.displacementMap.toJSON(meta).uuid;
  6438. data.displacementScale = this.displacementScale;
  6439. data.displacementBias = this.displacementBias;
  6440. }
  6441. if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
  6442. if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
  6443. if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
  6444. if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
  6445. if (this.envMap && this.envMap.isTexture) {
  6446. data.envMap = this.envMap.toJSON(meta).uuid;
  6447. data.reflectivity = this.reflectivity; // Scale behind envMap
  6448. data.refractionRatio = this.refractionRatio;
  6449. if (this.combine !== undefined) data.combine = this.combine;
  6450. if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
  6451. }
  6452. if (this.gradientMap && this.gradientMap.isTexture) {
  6453. data.gradientMap = this.gradientMap.toJSON(meta).uuid;
  6454. }
  6455. if (this.size !== undefined) data.size = this.size;
  6456. if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
  6457. if (this.blending !== NormalBlending) data.blending = this.blending;
  6458. if (this.flatShading === true) data.flatShading = this.flatShading;
  6459. if (this.side !== FrontSide) data.side = this.side;
  6460. if (this.vertexColors) data.vertexColors = true;
  6461. if (this.opacity < 1) data.opacity = this.opacity;
  6462. if (this.transparent === true) data.transparent = this.transparent;
  6463. data.depthFunc = this.depthFunc;
  6464. data.depthTest = this.depthTest;
  6465. data.depthWrite = this.depthWrite;
  6466. data.stencilWrite = this.stencilWrite;
  6467. data.stencilWriteMask = this.stencilWriteMask;
  6468. data.stencilFunc = this.stencilFunc;
  6469. data.stencilRef = this.stencilRef;
  6470. data.stencilFuncMask = this.stencilFuncMask;
  6471. data.stencilFail = this.stencilFail;
  6472. data.stencilZFail = this.stencilZFail;
  6473. data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
  6474. if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
  6475. if (this.polygonOffset === true) data.polygonOffset = true;
  6476. if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
  6477. if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
  6478. if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
  6479. if (this.dashSize !== undefined) data.dashSize = this.dashSize;
  6480. if (this.gapSize !== undefined) data.gapSize = this.gapSize;
  6481. if (this.scale !== undefined) data.scale = this.scale;
  6482. if (this.dithering === true) data.dithering = true;
  6483. if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
  6484. if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
  6485. if (this.wireframe === true) data.wireframe = this.wireframe;
  6486. if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
  6487. if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
  6488. if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
  6489. if (this.morphTargets === true) data.morphTargets = true;
  6490. if (this.morphNormals === true) data.morphNormals = true;
  6491. if (this.skinning === true) data.skinning = true;
  6492. if (this.visible === false) data.visible = false;
  6493. if (this.toneMapped === false) data.toneMapped = false;
  6494. if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
  6495. function extractFromCache(cache) {
  6496. var values = [];
  6497. for (var key in cache) {
  6498. var _data = cache[key];
  6499. delete _data.metadata;
  6500. values.push(_data);
  6501. }
  6502. return values;
  6503. }
  6504. if (isRoot) {
  6505. var textures = extractFromCache(meta.textures);
  6506. var images = extractFromCache(meta.images);
  6507. if (textures.length > 0) data.textures = textures;
  6508. if (images.length > 0) data.images = images;
  6509. }
  6510. return data;
  6511. },
  6512. clone: function clone() {
  6513. return new this.constructor().copy(this);
  6514. },
  6515. copy: function copy(source) {
  6516. this.name = source.name;
  6517. this.fog = source.fog;
  6518. this.blending = source.blending;
  6519. this.side = source.side;
  6520. this.flatShading = source.flatShading;
  6521. this.vertexColors = source.vertexColors;
  6522. this.opacity = source.opacity;
  6523. this.transparent = source.transparent;
  6524. this.blendSrc = source.blendSrc;
  6525. this.blendDst = source.blendDst;
  6526. this.blendEquation = source.blendEquation;
  6527. this.blendSrcAlpha = source.blendSrcAlpha;
  6528. this.blendDstAlpha = source.blendDstAlpha;
  6529. this.blendEquationAlpha = source.blendEquationAlpha;
  6530. this.depthFunc = source.depthFunc;
  6531. this.depthTest = source.depthTest;
  6532. this.depthWrite = source.depthWrite;
  6533. this.stencilWriteMask = source.stencilWriteMask;
  6534. this.stencilFunc = source.stencilFunc;
  6535. this.stencilRef = source.stencilRef;
  6536. this.stencilFuncMask = source.stencilFuncMask;
  6537. this.stencilFail = source.stencilFail;
  6538. this.stencilZFail = source.stencilZFail;
  6539. this.stencilZPass = source.stencilZPass;
  6540. this.stencilWrite = source.stencilWrite;
  6541. var srcPlanes = source.clippingPlanes;
  6542. var dstPlanes = null;
  6543. if (srcPlanes !== null) {
  6544. var n = srcPlanes.length;
  6545. dstPlanes = new Array(n);
  6546. for (var i = 0; i !== n; ++i) {
  6547. dstPlanes[i] = srcPlanes[i].clone();
  6548. }
  6549. }
  6550. this.clippingPlanes = dstPlanes;
  6551. this.clipIntersection = source.clipIntersection;
  6552. this.clipShadows = source.clipShadows;
  6553. this.shadowSide = source.shadowSide;
  6554. this.colorWrite = source.colorWrite;
  6555. this.precision = source.precision;
  6556. this.polygonOffset = source.polygonOffset;
  6557. this.polygonOffsetFactor = source.polygonOffsetFactor;
  6558. this.polygonOffsetUnits = source.polygonOffsetUnits;
  6559. this.dithering = source.dithering;
  6560. this.alphaTest = source.alphaTest;
  6561. this.premultipliedAlpha = source.premultipliedAlpha;
  6562. this.visible = source.visible;
  6563. this.toneMapped = source.toneMapped;
  6564. this.userData = JSON.parse(JSON.stringify(source.userData));
  6565. return this;
  6566. },
  6567. dispose: function dispose() {
  6568. this.dispatchEvent({
  6569. type: 'dispose'
  6570. });
  6571. }
  6572. });
  6573. Object.defineProperty(Material.prototype, 'needsUpdate', {
  6574. set: function set(value) {
  6575. if (value === true) this.version++;
  6576. }
  6577. });
  6578. /**
  6579. * parameters = {
  6580. * color: <hex>,
  6581. * opacity: <float>,
  6582. * map: new THREE.Texture( <Image> ),
  6583. *
  6584. * lightMap: new THREE.Texture( <Image> ),
  6585. * lightMapIntensity: <float>
  6586. *
  6587. * aoMap: new THREE.Texture( <Image> ),
  6588. * aoMapIntensity: <float>
  6589. *
  6590. * specularMap: new THREE.Texture( <Image> ),
  6591. *
  6592. * alphaMap: new THREE.Texture( <Image> ),
  6593. *
  6594. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  6595. * combine: THREE.Multiply,
  6596. * reflectivity: <float>,
  6597. * refractionRatio: <float>,
  6598. *
  6599. * depthTest: <bool>,
  6600. * depthWrite: <bool>,
  6601. *
  6602. * wireframe: <boolean>,
  6603. * wireframeLinewidth: <float>,
  6604. *
  6605. * skinning: <bool>,
  6606. * morphTargets: <bool>
  6607. * }
  6608. */
  6609. function MeshBasicMaterial(parameters) {
  6610. Material.call(this);
  6611. this.type = 'MeshBasicMaterial';
  6612. this.color = new Color(0xffffff); // emissive
  6613. this.map = null;
  6614. this.lightMap = null;
  6615. this.lightMapIntensity = 1.0;
  6616. this.aoMap = null;
  6617. this.aoMapIntensity = 1.0;
  6618. this.specularMap = null;
  6619. this.alphaMap = null;
  6620. this.envMap = null;
  6621. this.combine = MultiplyOperation;
  6622. this.reflectivity = 1;
  6623. this.refractionRatio = 0.98;
  6624. this.wireframe = false;
  6625. this.wireframeLinewidth = 1;
  6626. this.wireframeLinecap = 'round';
  6627. this.wireframeLinejoin = 'round';
  6628. this.skinning = false;
  6629. this.morphTargets = false;
  6630. this.setValues(parameters);
  6631. }
  6632. MeshBasicMaterial.prototype = Object.create(Material.prototype);
  6633. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  6634. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  6635. MeshBasicMaterial.prototype.copy = function (source) {
  6636. Material.prototype.copy.call(this, source);
  6637. this.color.copy(source.color);
  6638. this.map = source.map;
  6639. this.lightMap = source.lightMap;
  6640. this.lightMapIntensity = source.lightMapIntensity;
  6641. this.aoMap = source.aoMap;
  6642. this.aoMapIntensity = source.aoMapIntensity;
  6643. this.specularMap = source.specularMap;
  6644. this.alphaMap = source.alphaMap;
  6645. this.envMap = source.envMap;
  6646. this.combine = source.combine;
  6647. this.reflectivity = source.reflectivity;
  6648. this.refractionRatio = source.refractionRatio;
  6649. this.wireframe = source.wireframe;
  6650. this.wireframeLinewidth = source.wireframeLinewidth;
  6651. this.wireframeLinecap = source.wireframeLinecap;
  6652. this.wireframeLinejoin = source.wireframeLinejoin;
  6653. this.skinning = source.skinning;
  6654. this.morphTargets = source.morphTargets;
  6655. return this;
  6656. };
  6657. var _vector$3 = new Vector3();
  6658. var _vector2$1 = new Vector2();
  6659. function BufferAttribute(array, itemSize, normalized) {
  6660. if (Array.isArray(array)) {
  6661. throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
  6662. }
  6663. this.name = '';
  6664. this.array = array;
  6665. this.itemSize = itemSize;
  6666. this.count = array !== undefined ? array.length / itemSize : 0;
  6667. this.normalized = normalized === true;
  6668. this.usage = StaticDrawUsage;
  6669. this.updateRange = {
  6670. offset: 0,
  6671. count: -1
  6672. };
  6673. this.version = 0;
  6674. }
  6675. Object.defineProperty(BufferAttribute.prototype, 'needsUpdate', {
  6676. set: function set(value) {
  6677. if (value === true) this.version++;
  6678. }
  6679. });
  6680. Object.assign(BufferAttribute.prototype, {
  6681. isBufferAttribute: true,
  6682. onUploadCallback: function onUploadCallback() {},
  6683. setUsage: function setUsage(value) {
  6684. this.usage = value;
  6685. return this;
  6686. },
  6687. copy: function copy(source) {
  6688. this.name = source.name;
  6689. this.array = new source.array.constructor(source.array);
  6690. this.itemSize = source.itemSize;
  6691. this.count = source.count;
  6692. this.normalized = source.normalized;
  6693. this.usage = source.usage;
  6694. return this;
  6695. },
  6696. copyAt: function copyAt(index1, attribute, index2) {
  6697. index1 *= this.itemSize;
  6698. index2 *= attribute.itemSize;
  6699. for (var i = 0, l = this.itemSize; i < l; i++) {
  6700. this.array[index1 + i] = attribute.array[index2 + i];
  6701. }
  6702. return this;
  6703. },
  6704. copyArray: function copyArray(array) {
  6705. this.array.set(array);
  6706. return this;
  6707. },
  6708. copyColorsArray: function copyColorsArray(colors) {
  6709. var array = this.array;
  6710. var offset = 0;
  6711. for (var i = 0, l = colors.length; i < l; i++) {
  6712. var color = colors[i];
  6713. if (color === undefined) {
  6714. console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
  6715. color = new Color();
  6716. }
  6717. array[offset++] = color.r;
  6718. array[offset++] = color.g;
  6719. array[offset++] = color.b;
  6720. }
  6721. return this;
  6722. },
  6723. copyVector2sArray: function copyVector2sArray(vectors) {
  6724. var array = this.array;
  6725. var offset = 0;
  6726. for (var i = 0, l = vectors.length; i < l; i++) {
  6727. var vector = vectors[i];
  6728. if (vector === undefined) {
  6729. console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
  6730. vector = new Vector2();
  6731. }
  6732. array[offset++] = vector.x;
  6733. array[offset++] = vector.y;
  6734. }
  6735. return this;
  6736. },
  6737. copyVector3sArray: function copyVector3sArray(vectors) {
  6738. var array = this.array;
  6739. var offset = 0;
  6740. for (var i = 0, l = vectors.length; i < l; i++) {
  6741. var vector = vectors[i];
  6742. if (vector === undefined) {
  6743. console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
  6744. vector = new Vector3();
  6745. }
  6746. array[offset++] = vector.x;
  6747. array[offset++] = vector.y;
  6748. array[offset++] = vector.z;
  6749. }
  6750. return this;
  6751. },
  6752. copyVector4sArray: function copyVector4sArray(vectors) {
  6753. var array = this.array;
  6754. var offset = 0;
  6755. for (var i = 0, l = vectors.length; i < l; i++) {
  6756. var vector = vectors[i];
  6757. if (vector === undefined) {
  6758. console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
  6759. vector = new Vector4();
  6760. }
  6761. array[offset++] = vector.x;
  6762. array[offset++] = vector.y;
  6763. array[offset++] = vector.z;
  6764. array[offset++] = vector.w;
  6765. }
  6766. return this;
  6767. },
  6768. applyMatrix3: function applyMatrix3(m) {
  6769. if (this.itemSize === 2) {
  6770. for (var i = 0, l = this.count; i < l; i++) {
  6771. _vector2$1.fromBufferAttribute(this, i);
  6772. _vector2$1.applyMatrix3(m);
  6773. this.setXY(i, _vector2$1.x, _vector2$1.y);
  6774. }
  6775. } else if (this.itemSize === 3) {
  6776. for (var _i = 0, _l = this.count; _i < _l; _i++) {
  6777. _vector$3.fromBufferAttribute(this, _i);
  6778. _vector$3.applyMatrix3(m);
  6779. this.setXYZ(_i, _vector$3.x, _vector$3.y, _vector$3.z);
  6780. }
  6781. }
  6782. return this;
  6783. },
  6784. applyMatrix4: function applyMatrix4(m) {
  6785. for (var i = 0, l = this.count; i < l; i++) {
  6786. _vector$3.x = this.getX(i);
  6787. _vector$3.y = this.getY(i);
  6788. _vector$3.z = this.getZ(i);
  6789. _vector$3.applyMatrix4(m);
  6790. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6791. }
  6792. return this;
  6793. },
  6794. applyNormalMatrix: function applyNormalMatrix(m) {
  6795. for (var i = 0, l = this.count; i < l; i++) {
  6796. _vector$3.x = this.getX(i);
  6797. _vector$3.y = this.getY(i);
  6798. _vector$3.z = this.getZ(i);
  6799. _vector$3.applyNormalMatrix(m);
  6800. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6801. }
  6802. return this;
  6803. },
  6804. transformDirection: function transformDirection(m) {
  6805. for (var i = 0, l = this.count; i < l; i++) {
  6806. _vector$3.x = this.getX(i);
  6807. _vector$3.y = this.getY(i);
  6808. _vector$3.z = this.getZ(i);
  6809. _vector$3.transformDirection(m);
  6810. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6811. }
  6812. return this;
  6813. },
  6814. set: function set(value, offset) {
  6815. if (offset === void 0) {
  6816. offset = 0;
  6817. }
  6818. this.array.set(value, offset);
  6819. return this;
  6820. },
  6821. getX: function getX(index) {
  6822. return this.array[index * this.itemSize];
  6823. },
  6824. setX: function setX(index, x) {
  6825. this.array[index * this.itemSize] = x;
  6826. return this;
  6827. },
  6828. getY: function getY(index) {
  6829. return this.array[index * this.itemSize + 1];
  6830. },
  6831. setY: function setY(index, y) {
  6832. this.array[index * this.itemSize + 1] = y;
  6833. return this;
  6834. },
  6835. getZ: function getZ(index) {
  6836. return this.array[index * this.itemSize + 2];
  6837. },
  6838. setZ: function setZ(index, z) {
  6839. this.array[index * this.itemSize + 2] = z;
  6840. return this;
  6841. },
  6842. getW: function getW(index) {
  6843. return this.array[index * this.itemSize + 3];
  6844. },
  6845. setW: function setW(index, w) {
  6846. this.array[index * this.itemSize + 3] = w;
  6847. return this;
  6848. },
  6849. setXY: function setXY(index, x, y) {
  6850. index *= this.itemSize;
  6851. this.array[index + 0] = x;
  6852. this.array[index + 1] = y;
  6853. return this;
  6854. },
  6855. setXYZ: function setXYZ(index, x, y, z) {
  6856. index *= this.itemSize;
  6857. this.array[index + 0] = x;
  6858. this.array[index + 1] = y;
  6859. this.array[index + 2] = z;
  6860. return this;
  6861. },
  6862. setXYZW: function setXYZW(index, x, y, z, w) {
  6863. index *= this.itemSize;
  6864. this.array[index + 0] = x;
  6865. this.array[index + 1] = y;
  6866. this.array[index + 2] = z;
  6867. this.array[index + 3] = w;
  6868. return this;
  6869. },
  6870. onUpload: function onUpload(callback) {
  6871. this.onUploadCallback = callback;
  6872. return this;
  6873. },
  6874. clone: function clone() {
  6875. return new this.constructor(this.array, this.itemSize).copy(this);
  6876. },
  6877. toJSON: function toJSON() {
  6878. return {
  6879. itemSize: this.itemSize,
  6880. type: this.array.constructor.name,
  6881. array: Array.prototype.slice.call(this.array),
  6882. normalized: this.normalized
  6883. };
  6884. }
  6885. }); //
  6886. function Int8BufferAttribute(array, itemSize, normalized) {
  6887. BufferAttribute.call(this, new Int8Array(array), itemSize, normalized);
  6888. }
  6889. Int8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6890. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6891. function Uint8BufferAttribute(array, itemSize, normalized) {
  6892. BufferAttribute.call(this, new Uint8Array(array), itemSize, normalized);
  6893. }
  6894. Uint8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6895. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6896. function Uint8ClampedBufferAttribute(array, itemSize, normalized) {
  6897. BufferAttribute.call(this, new Uint8ClampedArray(array), itemSize, normalized);
  6898. }
  6899. Uint8ClampedBufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6900. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6901. function Int16BufferAttribute(array, itemSize, normalized) {
  6902. BufferAttribute.call(this, new Int16Array(array), itemSize, normalized);
  6903. }
  6904. Int16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6905. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6906. function Uint16BufferAttribute(array, itemSize, normalized) {
  6907. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6908. }
  6909. Uint16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6910. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6911. function Int32BufferAttribute(array, itemSize, normalized) {
  6912. BufferAttribute.call(this, new Int32Array(array), itemSize, normalized);
  6913. }
  6914. Int32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6915. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6916. function Uint32BufferAttribute(array, itemSize, normalized) {
  6917. BufferAttribute.call(this, new Uint32Array(array), itemSize, normalized);
  6918. }
  6919. Uint32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6920. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6921. function Float16BufferAttribute(array, itemSize, normalized) {
  6922. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6923. }
  6924. Float16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6925. Float16BufferAttribute.prototype.constructor = Float16BufferAttribute;
  6926. Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
  6927. function Float32BufferAttribute(array, itemSize, normalized) {
  6928. BufferAttribute.call(this, new Float32Array(array), itemSize, normalized);
  6929. }
  6930. Float32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6931. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6932. function Float64BufferAttribute(array, itemSize, normalized) {
  6933. BufferAttribute.call(this, new Float64Array(array), itemSize, normalized);
  6934. }
  6935. Float64BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6936. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; //
  6937. function arrayMax(array) {
  6938. if (array.length === 0) return -Infinity;
  6939. var max = array[0];
  6940. for (var i = 1, l = array.length; i < l; ++i) {
  6941. if (array[i] > max) max = array[i];
  6942. }
  6943. return max;
  6944. }
  6945. var TYPED_ARRAYS = {
  6946. Int8Array: Int8Array,
  6947. Uint8Array: Uint8Array,
  6948. // Workaround for IE11 pre KB2929437. See #11440
  6949. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  6950. Int16Array: Int16Array,
  6951. Uint16Array: Uint16Array,
  6952. Int32Array: Int32Array,
  6953. Uint32Array: Uint32Array,
  6954. Float32Array: Float32Array,
  6955. Float64Array: Float64Array
  6956. };
  6957. function getTypedArray(type, buffer) {
  6958. return new TYPED_ARRAYS[type](buffer);
  6959. }
  6960. var _id = 0;
  6961. var _m1$2 = new Matrix4();
  6962. var _obj = new Object3D();
  6963. var _offset = new Vector3();
  6964. var _box$2 = new Box3();
  6965. var _boxMorphTargets = new Box3();
  6966. var _vector$4 = new Vector3();
  6967. function BufferGeometry() {
  6968. Object.defineProperty(this, 'id', {
  6969. value: _id++
  6970. });
  6971. this.uuid = MathUtils.generateUUID();
  6972. this.name = '';
  6973. this.type = 'BufferGeometry';
  6974. this.index = null;
  6975. this.attributes = {};
  6976. this.morphAttributes = {};
  6977. this.morphTargetsRelative = false;
  6978. this.groups = [];
  6979. this.boundingBox = null;
  6980. this.boundingSphere = null;
  6981. this.drawRange = {
  6982. start: 0,
  6983. count: Infinity
  6984. };
  6985. this.userData = {};
  6986. }
  6987. BufferGeometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  6988. constructor: BufferGeometry,
  6989. isBufferGeometry: true,
  6990. getIndex: function getIndex() {
  6991. return this.index;
  6992. },
  6993. setIndex: function setIndex(index) {
  6994. if (Array.isArray(index)) {
  6995. this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
  6996. } else {
  6997. this.index = index;
  6998. }
  6999. return this;
  7000. },
  7001. getAttribute: function getAttribute(name) {
  7002. return this.attributes[name];
  7003. },
  7004. setAttribute: function setAttribute(name, attribute) {
  7005. this.attributes[name] = attribute;
  7006. return this;
  7007. },
  7008. deleteAttribute: function deleteAttribute(name) {
  7009. delete this.attributes[name];
  7010. return this;
  7011. },
  7012. hasAttribute: function hasAttribute(name) {
  7013. return this.attributes[name] !== undefined;
  7014. },
  7015. addGroup: function addGroup(start, count, materialIndex) {
  7016. if (materialIndex === void 0) {
  7017. materialIndex = 0;
  7018. }
  7019. this.groups.push({
  7020. start: start,
  7021. count: count,
  7022. materialIndex: materialIndex
  7023. });
  7024. },
  7025. clearGroups: function clearGroups() {
  7026. this.groups = [];
  7027. },
  7028. setDrawRange: function setDrawRange(start, count) {
  7029. this.drawRange.start = start;
  7030. this.drawRange.count = count;
  7031. },
  7032. applyMatrix4: function applyMatrix4(matrix) {
  7033. var position = this.attributes.position;
  7034. if (position !== undefined) {
  7035. position.applyMatrix4(matrix);
  7036. position.needsUpdate = true;
  7037. }
  7038. var normal = this.attributes.normal;
  7039. if (normal !== undefined) {
  7040. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  7041. normal.applyNormalMatrix(normalMatrix);
  7042. normal.needsUpdate = true;
  7043. }
  7044. var tangent = this.attributes.tangent;
  7045. if (tangent !== undefined) {
  7046. tangent.transformDirection(matrix);
  7047. tangent.needsUpdate = true;
  7048. }
  7049. if (this.boundingBox !== null) {
  7050. this.computeBoundingBox();
  7051. }
  7052. if (this.boundingSphere !== null) {
  7053. this.computeBoundingSphere();
  7054. }
  7055. return this;
  7056. },
  7057. rotateX: function rotateX(angle) {
  7058. // rotate geometry around world x-axis
  7059. _m1$2.makeRotationX(angle);
  7060. this.applyMatrix4(_m1$2);
  7061. return this;
  7062. },
  7063. rotateY: function rotateY(angle) {
  7064. // rotate geometry around world y-axis
  7065. _m1$2.makeRotationY(angle);
  7066. this.applyMatrix4(_m1$2);
  7067. return this;
  7068. },
  7069. rotateZ: function rotateZ(angle) {
  7070. // rotate geometry around world z-axis
  7071. _m1$2.makeRotationZ(angle);
  7072. this.applyMatrix4(_m1$2);
  7073. return this;
  7074. },
  7075. translate: function translate(x, y, z) {
  7076. // translate geometry
  7077. _m1$2.makeTranslation(x, y, z);
  7078. this.applyMatrix4(_m1$2);
  7079. return this;
  7080. },
  7081. scale: function scale(x, y, z) {
  7082. // scale geometry
  7083. _m1$2.makeScale(x, y, z);
  7084. this.applyMatrix4(_m1$2);
  7085. return this;
  7086. },
  7087. lookAt: function lookAt(vector) {
  7088. _obj.lookAt(vector);
  7089. _obj.updateMatrix();
  7090. this.applyMatrix4(_obj.matrix);
  7091. return this;
  7092. },
  7093. center: function center() {
  7094. this.computeBoundingBox();
  7095. this.boundingBox.getCenter(_offset).negate();
  7096. this.translate(_offset.x, _offset.y, _offset.z);
  7097. return this;
  7098. },
  7099. setFromPoints: function setFromPoints(points) {
  7100. var position = [];
  7101. for (var i = 0, l = points.length; i < l; i++) {
  7102. var point = points[i];
  7103. position.push(point.x, point.y, point.z || 0);
  7104. }
  7105. this.setAttribute('position', new Float32BufferAttribute(position, 3));
  7106. return this;
  7107. },
  7108. computeBoundingBox: function computeBoundingBox() {
  7109. if (this.boundingBox === null) {
  7110. this.boundingBox = new Box3();
  7111. }
  7112. var position = this.attributes.position;
  7113. var morphAttributesPosition = this.morphAttributes.position;
  7114. if (position && position.isGLBufferAttribute) {
  7115. console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this);
  7116. this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
  7117. return;
  7118. }
  7119. if (position !== undefined) {
  7120. this.boundingBox.setFromBufferAttribute(position); // process morph attributes if present
  7121. if (morphAttributesPosition) {
  7122. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  7123. var morphAttribute = morphAttributesPosition[i];
  7124. _box$2.setFromBufferAttribute(morphAttribute);
  7125. if (this.morphTargetsRelative) {
  7126. _vector$4.addVectors(this.boundingBox.min, _box$2.min);
  7127. this.boundingBox.expandByPoint(_vector$4);
  7128. _vector$4.addVectors(this.boundingBox.max, _box$2.max);
  7129. this.boundingBox.expandByPoint(_vector$4);
  7130. } else {
  7131. this.boundingBox.expandByPoint(_box$2.min);
  7132. this.boundingBox.expandByPoint(_box$2.max);
  7133. }
  7134. }
  7135. }
  7136. } else {
  7137. this.boundingBox.makeEmpty();
  7138. }
  7139. if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
  7140. console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
  7141. }
  7142. },
  7143. computeBoundingSphere: function computeBoundingSphere() {
  7144. if (this.boundingSphere === null) {
  7145. this.boundingSphere = new Sphere();
  7146. }
  7147. var position = this.attributes.position;
  7148. var morphAttributesPosition = this.morphAttributes.position;
  7149. if (position && position.isGLBufferAttribute) {
  7150. console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this);
  7151. this.boundingSphere.set(new Vector3(), Infinity);
  7152. return;
  7153. }
  7154. if (position) {
  7155. // first, find the center of the bounding sphere
  7156. var center = this.boundingSphere.center;
  7157. _box$2.setFromBufferAttribute(position); // process morph attributes if present
  7158. if (morphAttributesPosition) {
  7159. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  7160. var morphAttribute = morphAttributesPosition[i];
  7161. _boxMorphTargets.setFromBufferAttribute(morphAttribute);
  7162. if (this.morphTargetsRelative) {
  7163. _vector$4.addVectors(_box$2.min, _boxMorphTargets.min);
  7164. _box$2.expandByPoint(_vector$4);
  7165. _vector$4.addVectors(_box$2.max, _boxMorphTargets.max);
  7166. _box$2.expandByPoint(_vector$4);
  7167. } else {
  7168. _box$2.expandByPoint(_boxMorphTargets.min);
  7169. _box$2.expandByPoint(_boxMorphTargets.max);
  7170. }
  7171. }
  7172. }
  7173. _box$2.getCenter(center); // second, try to find a boundingSphere with a radius smaller than the
  7174. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  7175. var maxRadiusSq = 0;
  7176. for (var _i = 0, _il = position.count; _i < _il; _i++) {
  7177. _vector$4.fromBufferAttribute(position, _i);
  7178. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  7179. } // process morph attributes if present
  7180. if (morphAttributesPosition) {
  7181. for (var _i2 = 0, _il2 = morphAttributesPosition.length; _i2 < _il2; _i2++) {
  7182. var _morphAttribute = morphAttributesPosition[_i2];
  7183. var morphTargetsRelative = this.morphTargetsRelative;
  7184. for (var j = 0, jl = _morphAttribute.count; j < jl; j++) {
  7185. _vector$4.fromBufferAttribute(_morphAttribute, j);
  7186. if (morphTargetsRelative) {
  7187. _offset.fromBufferAttribute(position, j);
  7188. _vector$4.add(_offset);
  7189. }
  7190. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  7191. }
  7192. }
  7193. }
  7194. this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
  7195. if (isNaN(this.boundingSphere.radius)) {
  7196. console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
  7197. }
  7198. }
  7199. },
  7200. computeFaceNormals: function computeFaceNormals() {// backwards compatibility
  7201. },
  7202. computeTangents: function computeTangents() {
  7203. var index = this.index;
  7204. var attributes = this.attributes; // based on http://www.terathon.com/code/tangent.html
  7205. // (per vertex tangents)
  7206. if (index === null || attributes.position === undefined || attributes.normal === undefined || attributes.uv === undefined) {
  7207. console.error('THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)');
  7208. return;
  7209. }
  7210. var indices = index.array;
  7211. var positions = attributes.position.array;
  7212. var normals = attributes.normal.array;
  7213. var uvs = attributes.uv.array;
  7214. var nVertices = positions.length / 3;
  7215. if (attributes.tangent === undefined) {
  7216. this.setAttribute('tangent', new BufferAttribute(new Float32Array(4 * nVertices), 4));
  7217. }
  7218. var tangents = attributes.tangent.array;
  7219. var tan1 = [],
  7220. tan2 = [];
  7221. for (var i = 0; i < nVertices; i++) {
  7222. tan1[i] = new Vector3();
  7223. tan2[i] = new Vector3();
  7224. }
  7225. var vA = new Vector3(),
  7226. vB = new Vector3(),
  7227. vC = new Vector3(),
  7228. uvA = new Vector2(),
  7229. uvB = new Vector2(),
  7230. uvC = new Vector2(),
  7231. sdir = new Vector3(),
  7232. tdir = new Vector3();
  7233. function handleTriangle(a, b, c) {
  7234. vA.fromArray(positions, a * 3);
  7235. vB.fromArray(positions, b * 3);
  7236. vC.fromArray(positions, c * 3);
  7237. uvA.fromArray(uvs, a * 2);
  7238. uvB.fromArray(uvs, b * 2);
  7239. uvC.fromArray(uvs, c * 2);
  7240. vB.sub(vA);
  7241. vC.sub(vA);
  7242. uvB.sub(uvA);
  7243. uvC.sub(uvA);
  7244. var r = 1.0 / (uvB.x * uvC.y - uvC.x * uvB.y); // silently ignore degenerate uv triangles having coincident or colinear vertices
  7245. if (!isFinite(r)) return;
  7246. sdir.copy(vB).multiplyScalar(uvC.y).addScaledVector(vC, -uvB.y).multiplyScalar(r);
  7247. tdir.copy(vC).multiplyScalar(uvB.x).addScaledVector(vB, -uvC.x).multiplyScalar(r);
  7248. tan1[a].add(sdir);
  7249. tan1[b].add(sdir);
  7250. tan1[c].add(sdir);
  7251. tan2[a].add(tdir);
  7252. tan2[b].add(tdir);
  7253. tan2[c].add(tdir);
  7254. }
  7255. var groups = this.groups;
  7256. if (groups.length === 0) {
  7257. groups = [{
  7258. start: 0,
  7259. count: indices.length
  7260. }];
  7261. }
  7262. for (var _i3 = 0, il = groups.length; _i3 < il; ++_i3) {
  7263. var group = groups[_i3];
  7264. var start = group.start;
  7265. var count = group.count;
  7266. for (var j = start, jl = start + count; j < jl; j += 3) {
  7267. handleTriangle(indices[j + 0], indices[j + 1], indices[j + 2]);
  7268. }
  7269. }
  7270. var tmp = new Vector3(),
  7271. tmp2 = new Vector3();
  7272. var n = new Vector3(),
  7273. n2 = new Vector3();
  7274. function handleVertex(v) {
  7275. n.fromArray(normals, v * 3);
  7276. n2.copy(n);
  7277. var t = tan1[v]; // Gram-Schmidt orthogonalize
  7278. tmp.copy(t);
  7279. tmp.sub(n.multiplyScalar(n.dot(t))).normalize(); // Calculate handedness
  7280. tmp2.crossVectors(n2, t);
  7281. var test = tmp2.dot(tan2[v]);
  7282. var w = test < 0.0 ? -1.0 : 1.0;
  7283. tangents[v * 4] = tmp.x;
  7284. tangents[v * 4 + 1] = tmp.y;
  7285. tangents[v * 4 + 2] = tmp.z;
  7286. tangents[v * 4 + 3] = w;
  7287. }
  7288. for (var _i4 = 0, _il3 = groups.length; _i4 < _il3; ++_i4) {
  7289. var _group = groups[_i4];
  7290. var _start = _group.start;
  7291. var _count = _group.count;
  7292. for (var _j = _start, _jl = _start + _count; _j < _jl; _j += 3) {
  7293. handleVertex(indices[_j + 0]);
  7294. handleVertex(indices[_j + 1]);
  7295. handleVertex(indices[_j + 2]);
  7296. }
  7297. }
  7298. },
  7299. computeVertexNormals: function computeVertexNormals() {
  7300. var index = this.index;
  7301. var positionAttribute = this.getAttribute('position');
  7302. if (positionAttribute !== undefined) {
  7303. var normalAttribute = this.getAttribute('normal');
  7304. if (normalAttribute === undefined) {
  7305. normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
  7306. this.setAttribute('normal', normalAttribute);
  7307. } else {
  7308. // reset existing normals to zero
  7309. for (var i = 0, il = normalAttribute.count; i < il; i++) {
  7310. normalAttribute.setXYZ(i, 0, 0, 0);
  7311. }
  7312. }
  7313. var pA = new Vector3(),
  7314. pB = new Vector3(),
  7315. pC = new Vector3();
  7316. var nA = new Vector3(),
  7317. nB = new Vector3(),
  7318. nC = new Vector3();
  7319. var cb = new Vector3(),
  7320. ab = new Vector3(); // indexed elements
  7321. if (index) {
  7322. for (var _i5 = 0, _il4 = index.count; _i5 < _il4; _i5 += 3) {
  7323. var vA = index.getX(_i5 + 0);
  7324. var vB = index.getX(_i5 + 1);
  7325. var vC = index.getX(_i5 + 2);
  7326. pA.fromBufferAttribute(positionAttribute, vA);
  7327. pB.fromBufferAttribute(positionAttribute, vB);
  7328. pC.fromBufferAttribute(positionAttribute, vC);
  7329. cb.subVectors(pC, pB);
  7330. ab.subVectors(pA, pB);
  7331. cb.cross(ab);
  7332. nA.fromBufferAttribute(normalAttribute, vA);
  7333. nB.fromBufferAttribute(normalAttribute, vB);
  7334. nC.fromBufferAttribute(normalAttribute, vC);
  7335. nA.add(cb);
  7336. nB.add(cb);
  7337. nC.add(cb);
  7338. normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
  7339. normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
  7340. normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
  7341. }
  7342. } else {
  7343. // non-indexed elements (unconnected triangle soup)
  7344. for (var _i6 = 0, _il5 = positionAttribute.count; _i6 < _il5; _i6 += 3) {
  7345. pA.fromBufferAttribute(positionAttribute, _i6 + 0);
  7346. pB.fromBufferAttribute(positionAttribute, _i6 + 1);
  7347. pC.fromBufferAttribute(positionAttribute, _i6 + 2);
  7348. cb.subVectors(pC, pB);
  7349. ab.subVectors(pA, pB);
  7350. cb.cross(ab);
  7351. normalAttribute.setXYZ(_i6 + 0, cb.x, cb.y, cb.z);
  7352. normalAttribute.setXYZ(_i6 + 1, cb.x, cb.y, cb.z);
  7353. normalAttribute.setXYZ(_i6 + 2, cb.x, cb.y, cb.z);
  7354. }
  7355. }
  7356. this.normalizeNormals();
  7357. normalAttribute.needsUpdate = true;
  7358. }
  7359. },
  7360. merge: function merge(geometry, offset) {
  7361. if (!(geometry && geometry.isBufferGeometry)) {
  7362. console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
  7363. return;
  7364. }
  7365. if (offset === undefined) {
  7366. offset = 0;
  7367. console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');
  7368. }
  7369. var attributes = this.attributes;
  7370. for (var key in attributes) {
  7371. if (geometry.attributes[key] === undefined) continue;
  7372. var attribute1 = attributes[key];
  7373. var attributeArray1 = attribute1.array;
  7374. var attribute2 = geometry.attributes[key];
  7375. var attributeArray2 = attribute2.array;
  7376. var attributeOffset = attribute2.itemSize * offset;
  7377. var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
  7378. for (var i = 0, j = attributeOffset; i < length; i++, j++) {
  7379. attributeArray1[j] = attributeArray2[i];
  7380. }
  7381. }
  7382. return this;
  7383. },
  7384. normalizeNormals: function normalizeNormals() {
  7385. var normals = this.attributes.normal;
  7386. for (var i = 0, il = normals.count; i < il; i++) {
  7387. _vector$4.fromBufferAttribute(normals, i);
  7388. _vector$4.normalize();
  7389. normals.setXYZ(i, _vector$4.x, _vector$4.y, _vector$4.z);
  7390. }
  7391. },
  7392. toNonIndexed: function toNonIndexed() {
  7393. function convertBufferAttribute(attribute, indices) {
  7394. var array = attribute.array;
  7395. var itemSize = attribute.itemSize;
  7396. var normalized = attribute.normalized;
  7397. var array2 = new array.constructor(indices.length * itemSize);
  7398. var index = 0,
  7399. index2 = 0;
  7400. for (var i = 0, l = indices.length; i < l; i++) {
  7401. index = indices[i] * itemSize;
  7402. for (var j = 0; j < itemSize; j++) {
  7403. array2[index2++] = array[index++];
  7404. }
  7405. }
  7406. return new BufferAttribute(array2, itemSize, normalized);
  7407. } //
  7408. if (this.index === null) {
  7409. console.warn('THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.');
  7410. return this;
  7411. }
  7412. var geometry2 = new BufferGeometry();
  7413. var indices = this.index.array;
  7414. var attributes = this.attributes; // attributes
  7415. for (var name in attributes) {
  7416. var attribute = attributes[name];
  7417. var newAttribute = convertBufferAttribute(attribute, indices);
  7418. geometry2.setAttribute(name, newAttribute);
  7419. } // morph attributes
  7420. var morphAttributes = this.morphAttributes;
  7421. for (var _name in morphAttributes) {
  7422. var morphArray = [];
  7423. var morphAttribute = morphAttributes[_name]; // morphAttribute: array of Float32BufferAttributes
  7424. for (var i = 0, il = morphAttribute.length; i < il; i++) {
  7425. var _attribute = morphAttribute[i];
  7426. var _newAttribute = convertBufferAttribute(_attribute, indices);
  7427. morphArray.push(_newAttribute);
  7428. }
  7429. geometry2.morphAttributes[_name] = morphArray;
  7430. }
  7431. geometry2.morphTargetsRelative = this.morphTargetsRelative; // groups
  7432. var groups = this.groups;
  7433. for (var _i7 = 0, l = groups.length; _i7 < l; _i7++) {
  7434. var group = groups[_i7];
  7435. geometry2.addGroup(group.start, group.count, group.materialIndex);
  7436. }
  7437. return geometry2;
  7438. },
  7439. toJSON: function toJSON() {
  7440. var data = {
  7441. metadata: {
  7442. version: 4.5,
  7443. type: 'BufferGeometry',
  7444. generator: 'BufferGeometry.toJSON'
  7445. }
  7446. }; // standard BufferGeometry serialization
  7447. data.uuid = this.uuid;
  7448. data.type = this.type;
  7449. if (this.name !== '') data.name = this.name;
  7450. if (Object.keys(this.userData).length > 0) data.userData = this.userData;
  7451. if (this.parameters !== undefined) {
  7452. var parameters = this.parameters;
  7453. for (var key in parameters) {
  7454. if (parameters[key] !== undefined) data[key] = parameters[key];
  7455. }
  7456. return data;
  7457. }
  7458. data.data = {
  7459. attributes: {}
  7460. };
  7461. var index = this.index;
  7462. if (index !== null) {
  7463. data.data.index = {
  7464. type: index.array.constructor.name,
  7465. array: Array.prototype.slice.call(index.array)
  7466. };
  7467. }
  7468. var attributes = this.attributes;
  7469. for (var _key in attributes) {
  7470. var attribute = attributes[_key];
  7471. var attributeData = attribute.toJSON(data.data);
  7472. if (attribute.name !== '') attributeData.name = attribute.name;
  7473. data.data.attributes[_key] = attributeData;
  7474. }
  7475. var morphAttributes = {};
  7476. var hasMorphAttributes = false;
  7477. for (var _key2 in this.morphAttributes) {
  7478. var attributeArray = this.morphAttributes[_key2];
  7479. var array = [];
  7480. for (var i = 0, il = attributeArray.length; i < il; i++) {
  7481. var _attribute2 = attributeArray[i];
  7482. var _attributeData = _attribute2.toJSON(data.data);
  7483. if (_attribute2.name !== '') _attributeData.name = _attribute2.name;
  7484. array.push(_attributeData);
  7485. }
  7486. if (array.length > 0) {
  7487. morphAttributes[_key2] = array;
  7488. hasMorphAttributes = true;
  7489. }
  7490. }
  7491. if (hasMorphAttributes) {
  7492. data.data.morphAttributes = morphAttributes;
  7493. data.data.morphTargetsRelative = this.morphTargetsRelative;
  7494. }
  7495. var groups = this.groups;
  7496. if (groups.length > 0) {
  7497. data.data.groups = JSON.parse(JSON.stringify(groups));
  7498. }
  7499. var boundingSphere = this.boundingSphere;
  7500. if (boundingSphere !== null) {
  7501. data.data.boundingSphere = {
  7502. center: boundingSphere.center.toArray(),
  7503. radius: boundingSphere.radius
  7504. };
  7505. }
  7506. return data;
  7507. },
  7508. clone: function clone() {
  7509. /*
  7510. // Handle primitives
  7511. const parameters = this.parameters;
  7512. if ( parameters !== undefined ) {
  7513. const values = [];
  7514. for ( const key in parameters ) {
  7515. values.push( parameters[ key ] );
  7516. }
  7517. const geometry = Object.create( this.constructor.prototype );
  7518. this.constructor.apply( geometry, values );
  7519. return geometry;
  7520. }
  7521. return new this.constructor().copy( this );
  7522. */
  7523. return new BufferGeometry().copy(this);
  7524. },
  7525. copy: function copy(source) {
  7526. // reset
  7527. this.index = null;
  7528. this.attributes = {};
  7529. this.morphAttributes = {};
  7530. this.groups = [];
  7531. this.boundingBox = null;
  7532. this.boundingSphere = null; // used for storing cloned, shared data
  7533. var data = {}; // name
  7534. this.name = source.name; // index
  7535. var index = source.index;
  7536. if (index !== null) {
  7537. this.setIndex(index.clone(data));
  7538. } // attributes
  7539. var attributes = source.attributes;
  7540. for (var name in attributes) {
  7541. var attribute = attributes[name];
  7542. this.setAttribute(name, attribute.clone(data));
  7543. } // morph attributes
  7544. var morphAttributes = source.morphAttributes;
  7545. for (var _name2 in morphAttributes) {
  7546. var array = [];
  7547. var morphAttribute = morphAttributes[_name2]; // morphAttribute: array of Float32BufferAttributes
  7548. for (var i = 0, l = morphAttribute.length; i < l; i++) {
  7549. array.push(morphAttribute[i].clone(data));
  7550. }
  7551. this.morphAttributes[_name2] = array;
  7552. }
  7553. this.morphTargetsRelative = source.morphTargetsRelative; // groups
  7554. var groups = source.groups;
  7555. for (var _i8 = 0, _l = groups.length; _i8 < _l; _i8++) {
  7556. var group = groups[_i8];
  7557. this.addGroup(group.start, group.count, group.materialIndex);
  7558. } // bounding box
  7559. var boundingBox = source.boundingBox;
  7560. if (boundingBox !== null) {
  7561. this.boundingBox = boundingBox.clone();
  7562. } // bounding sphere
  7563. var boundingSphere = source.boundingSphere;
  7564. if (boundingSphere !== null) {
  7565. this.boundingSphere = boundingSphere.clone();
  7566. } // draw range
  7567. this.drawRange.start = source.drawRange.start;
  7568. this.drawRange.count = source.drawRange.count; // user data
  7569. this.userData = source.userData;
  7570. return this;
  7571. },
  7572. dispose: function dispose() {
  7573. this.dispatchEvent({
  7574. type: 'dispose'
  7575. });
  7576. }
  7577. });
  7578. var _inverseMatrix = new Matrix4();
  7579. var _ray = new Ray();
  7580. var _sphere = new Sphere();
  7581. var _vA = new Vector3();
  7582. var _vB = new Vector3();
  7583. var _vC = new Vector3();
  7584. var _tempA = new Vector3();
  7585. var _tempB = new Vector3();
  7586. var _tempC = new Vector3();
  7587. var _morphA = new Vector3();
  7588. var _morphB = new Vector3();
  7589. var _morphC = new Vector3();
  7590. var _uvA = new Vector2();
  7591. var _uvB = new Vector2();
  7592. var _uvC = new Vector2();
  7593. var _intersectionPoint = new Vector3();
  7594. var _intersectionPointWorld = new Vector3();
  7595. function Mesh(geometry, material) {
  7596. if (geometry === void 0) {
  7597. geometry = new BufferGeometry();
  7598. }
  7599. if (material === void 0) {
  7600. material = new MeshBasicMaterial();
  7601. }
  7602. Object3D.call(this);
  7603. this.type = 'Mesh';
  7604. this.geometry = geometry;
  7605. this.material = material;
  7606. this.updateMorphTargets();
  7607. }
  7608. Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
  7609. constructor: Mesh,
  7610. isMesh: true,
  7611. copy: function copy(source) {
  7612. Object3D.prototype.copy.call(this, source);
  7613. if (source.morphTargetInfluences !== undefined) {
  7614. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  7615. }
  7616. if (source.morphTargetDictionary !== undefined) {
  7617. this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
  7618. }
  7619. this.material = source.material;
  7620. this.geometry = source.geometry;
  7621. return this;
  7622. },
  7623. updateMorphTargets: function updateMorphTargets() {
  7624. var geometry = this.geometry;
  7625. if (geometry.isBufferGeometry) {
  7626. var morphAttributes = geometry.morphAttributes;
  7627. var keys = Object.keys(morphAttributes);
  7628. if (keys.length > 0) {
  7629. var morphAttribute = morphAttributes[keys[0]];
  7630. if (morphAttribute !== undefined) {
  7631. this.morphTargetInfluences = [];
  7632. this.morphTargetDictionary = {};
  7633. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  7634. var name = morphAttribute[m].name || String(m);
  7635. this.morphTargetInfluences.push(0);
  7636. this.morphTargetDictionary[name] = m;
  7637. }
  7638. }
  7639. }
  7640. } else {
  7641. var morphTargets = geometry.morphTargets;
  7642. if (morphTargets !== undefined && morphTargets.length > 0) {
  7643. console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7644. }
  7645. }
  7646. },
  7647. raycast: function raycast(raycaster, intersects) {
  7648. var geometry = this.geometry;
  7649. var material = this.material;
  7650. var matrixWorld = this.matrixWorld;
  7651. if (material === undefined) return; // Checking boundingSphere distance to ray
  7652. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7653. _sphere.copy(geometry.boundingSphere);
  7654. _sphere.applyMatrix4(matrixWorld);
  7655. if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
  7656. _inverseMatrix.copy(matrixWorld).invert();
  7657. _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
  7658. if (geometry.boundingBox !== null) {
  7659. if (_ray.intersectsBox(geometry.boundingBox) === false) return;
  7660. }
  7661. var intersection;
  7662. if (geometry.isBufferGeometry) {
  7663. var index = geometry.index;
  7664. var position = geometry.attributes.position;
  7665. var morphPosition = geometry.morphAttributes.position;
  7666. var morphTargetsRelative = geometry.morphTargetsRelative;
  7667. var uv = geometry.attributes.uv;
  7668. var uv2 = geometry.attributes.uv2;
  7669. var groups = geometry.groups;
  7670. var drawRange = geometry.drawRange;
  7671. if (index !== null) {
  7672. // indexed buffer geometry
  7673. if (Array.isArray(material)) {
  7674. for (var i = 0, il = groups.length; i < il; i++) {
  7675. var group = groups[i];
  7676. var groupMaterial = material[group.materialIndex];
  7677. var start = Math.max(group.start, drawRange.start);
  7678. var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
  7679. for (var j = start, jl = end; j < jl; j += 3) {
  7680. var a = index.getX(j);
  7681. var b = index.getX(j + 1);
  7682. var c = index.getX(j + 2);
  7683. intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
  7684. if (intersection) {
  7685. intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
  7686. intersection.face.materialIndex = group.materialIndex;
  7687. intersects.push(intersection);
  7688. }
  7689. }
  7690. }
  7691. } else {
  7692. var _start = Math.max(0, drawRange.start);
  7693. var _end = Math.min(index.count, drawRange.start + drawRange.count);
  7694. for (var _i = _start, _il = _end; _i < _il; _i += 3) {
  7695. var _a = index.getX(_i);
  7696. var _b = index.getX(_i + 1);
  7697. var _c = index.getX(_i + 2);
  7698. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
  7699. if (intersection) {
  7700. intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
  7701. intersects.push(intersection);
  7702. }
  7703. }
  7704. }
  7705. } else if (position !== undefined) {
  7706. // non-indexed buffer geometry
  7707. if (Array.isArray(material)) {
  7708. for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
  7709. var _group = groups[_i2];
  7710. var _groupMaterial = material[_group.materialIndex];
  7711. var _start2 = Math.max(_group.start, drawRange.start);
  7712. var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
  7713. for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
  7714. var _a2 = _j;
  7715. var _b2 = _j + 1;
  7716. var _c2 = _j + 2;
  7717. intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
  7718. if (intersection) {
  7719. intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
  7720. intersection.face.materialIndex = _group.materialIndex;
  7721. intersects.push(intersection);
  7722. }
  7723. }
  7724. }
  7725. } else {
  7726. var _start3 = Math.max(0, drawRange.start);
  7727. var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
  7728. for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
  7729. var _a3 = _i3;
  7730. var _b3 = _i3 + 1;
  7731. var _c3 = _i3 + 2;
  7732. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
  7733. if (intersection) {
  7734. intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
  7735. intersects.push(intersection);
  7736. }
  7737. }
  7738. }
  7739. }
  7740. } else if (geometry.isGeometry) {
  7741. console.error('THREE.Mesh.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7742. }
  7743. }
  7744. });
  7745. function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
  7746. var intersect;
  7747. if (material.side === BackSide) {
  7748. intersect = ray.intersectTriangle(pC, pB, pA, true, point);
  7749. } else {
  7750. intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
  7751. }
  7752. if (intersect === null) return null;
  7753. _intersectionPointWorld.copy(point);
  7754. _intersectionPointWorld.applyMatrix4(object.matrixWorld);
  7755. var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
  7756. if (distance < raycaster.near || distance > raycaster.far) return null;
  7757. return {
  7758. distance: distance,
  7759. point: _intersectionPointWorld.clone(),
  7760. object: object
  7761. };
  7762. }
  7763. function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
  7764. _vA.fromBufferAttribute(position, a);
  7765. _vB.fromBufferAttribute(position, b);
  7766. _vC.fromBufferAttribute(position, c);
  7767. var morphInfluences = object.morphTargetInfluences;
  7768. if (material.morphTargets && morphPosition && morphInfluences) {
  7769. _morphA.set(0, 0, 0);
  7770. _morphB.set(0, 0, 0);
  7771. _morphC.set(0, 0, 0);
  7772. for (var i = 0, il = morphPosition.length; i < il; i++) {
  7773. var influence = morphInfluences[i];
  7774. var morphAttribute = morphPosition[i];
  7775. if (influence === 0) continue;
  7776. _tempA.fromBufferAttribute(morphAttribute, a);
  7777. _tempB.fromBufferAttribute(morphAttribute, b);
  7778. _tempC.fromBufferAttribute(morphAttribute, c);
  7779. if (morphTargetsRelative) {
  7780. _morphA.addScaledVector(_tempA, influence);
  7781. _morphB.addScaledVector(_tempB, influence);
  7782. _morphC.addScaledVector(_tempC, influence);
  7783. } else {
  7784. _morphA.addScaledVector(_tempA.sub(_vA), influence);
  7785. _morphB.addScaledVector(_tempB.sub(_vB), influence);
  7786. _morphC.addScaledVector(_tempC.sub(_vC), influence);
  7787. }
  7788. }
  7789. _vA.add(_morphA);
  7790. _vB.add(_morphB);
  7791. _vC.add(_morphC);
  7792. }
  7793. if (object.isSkinnedMesh) {
  7794. object.boneTransform(a, _vA);
  7795. object.boneTransform(b, _vB);
  7796. object.boneTransform(c, _vC);
  7797. }
  7798. var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
  7799. if (intersection) {
  7800. if (uv) {
  7801. _uvA.fromBufferAttribute(uv, a);
  7802. _uvB.fromBufferAttribute(uv, b);
  7803. _uvC.fromBufferAttribute(uv, c);
  7804. intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7805. }
  7806. if (uv2) {
  7807. _uvA.fromBufferAttribute(uv2, a);
  7808. _uvB.fromBufferAttribute(uv2, b);
  7809. _uvC.fromBufferAttribute(uv2, c);
  7810. intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7811. }
  7812. var face = new Face3(a, b, c);
  7813. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7814. intersection.face = face;
  7815. }
  7816. return intersection;
  7817. }
  7818. var BoxGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7819. _inheritsLoose(BoxGeometry, _BufferGeometry);
  7820. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7821. var _this;
  7822. if (width === void 0) {
  7823. width = 1;
  7824. }
  7825. if (height === void 0) {
  7826. height = 1;
  7827. }
  7828. if (depth === void 0) {
  7829. depth = 1;
  7830. }
  7831. if (widthSegments === void 0) {
  7832. widthSegments = 1;
  7833. }
  7834. if (heightSegments === void 0) {
  7835. heightSegments = 1;
  7836. }
  7837. if (depthSegments === void 0) {
  7838. depthSegments = 1;
  7839. }
  7840. _this = _BufferGeometry.call(this) || this;
  7841. _this.type = 'BoxGeometry';
  7842. _this.parameters = {
  7843. width: width,
  7844. height: height,
  7845. depth: depth,
  7846. widthSegments: widthSegments,
  7847. heightSegments: heightSegments,
  7848. depthSegments: depthSegments
  7849. };
  7850. var scope = _assertThisInitialized(_this); // segments
  7851. widthSegments = Math.floor(widthSegments);
  7852. heightSegments = Math.floor(heightSegments);
  7853. depthSegments = Math.floor(depthSegments); // buffers
  7854. var indices = [];
  7855. var vertices = [];
  7856. var normals = [];
  7857. var uvs = []; // helper variables
  7858. var numberOfVertices = 0;
  7859. var groupStart = 0; // build each side of the box geometry
  7860. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7861. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7862. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7863. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7864. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7865. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7866. // build geometry
  7867. _this.setIndex(indices);
  7868. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7869. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7870. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7871. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7872. var segmentWidth = width / gridX;
  7873. var segmentHeight = height / gridY;
  7874. var widthHalf = width / 2;
  7875. var heightHalf = height / 2;
  7876. var depthHalf = depth / 2;
  7877. var gridX1 = gridX + 1;
  7878. var gridY1 = gridY + 1;
  7879. var vertexCounter = 0;
  7880. var groupCount = 0;
  7881. var vector = new Vector3(); // generate vertices, normals and uvs
  7882. for (var iy = 0; iy < gridY1; iy++) {
  7883. var y = iy * segmentHeight - heightHalf;
  7884. for (var ix = 0; ix < gridX1; ix++) {
  7885. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7886. vector[u] = x * udir;
  7887. vector[v] = y * vdir;
  7888. vector[w] = depthHalf; // now apply vector to vertex buffer
  7889. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7890. vector[u] = 0;
  7891. vector[v] = 0;
  7892. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7893. normals.push(vector.x, vector.y, vector.z); // uvs
  7894. uvs.push(ix / gridX);
  7895. uvs.push(1 - iy / gridY); // counters
  7896. vertexCounter += 1;
  7897. }
  7898. } // indices
  7899. // 1. you need three indices to draw a single face
  7900. // 2. a single segment consists of two faces
  7901. // 3. so we need to generate six (2*3) indices per segment
  7902. for (var _iy = 0; _iy < gridY; _iy++) {
  7903. for (var _ix = 0; _ix < gridX; _ix++) {
  7904. var a = numberOfVertices + _ix + gridX1 * _iy;
  7905. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7906. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7907. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7908. indices.push(a, b, d);
  7909. indices.push(b, c, d); // increase counter
  7910. groupCount += 6;
  7911. }
  7912. } // add a group to the geometry. this will ensure multi material support
  7913. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7914. groupStart += groupCount; // update total number of vertices
  7915. numberOfVertices += vertexCounter;
  7916. }
  7917. return _this;
  7918. }
  7919. return BoxGeometry;
  7920. }(BufferGeometry);
  7921. /**
  7922. * Uniform Utilities
  7923. */
  7924. function cloneUniforms(src) {
  7925. var dst = {};
  7926. for (var u in src) {
  7927. dst[u] = {};
  7928. for (var p in src[u]) {
  7929. var property = src[u][p];
  7930. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture)) {
  7931. dst[u][p] = property.clone();
  7932. } else if (Array.isArray(property)) {
  7933. dst[u][p] = property.slice();
  7934. } else {
  7935. dst[u][p] = property;
  7936. }
  7937. }
  7938. }
  7939. return dst;
  7940. }
  7941. function mergeUniforms(uniforms) {
  7942. var merged = {};
  7943. for (var u = 0; u < uniforms.length; u++) {
  7944. var tmp = cloneUniforms(uniforms[u]);
  7945. for (var p in tmp) {
  7946. merged[p] = tmp[p];
  7947. }
  7948. }
  7949. return merged;
  7950. } // Legacy
  7951. var UniformsUtils = {
  7952. clone: cloneUniforms,
  7953. merge: mergeUniforms
  7954. };
  7955. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7956. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7957. /**
  7958. * parameters = {
  7959. * defines: { "label" : "value" },
  7960. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7961. *
  7962. * fragmentShader: <string>,
  7963. * vertexShader: <string>,
  7964. *
  7965. * wireframe: <boolean>,
  7966. * wireframeLinewidth: <float>,
  7967. *
  7968. * lights: <bool>,
  7969. *
  7970. * skinning: <bool>,
  7971. * morphTargets: <bool>,
  7972. * morphNormals: <bool>
  7973. * }
  7974. */
  7975. function ShaderMaterial(parameters) {
  7976. Material.call(this);
  7977. this.type = 'ShaderMaterial';
  7978. this.defines = {};
  7979. this.uniforms = {};
  7980. this.vertexShader = default_vertex;
  7981. this.fragmentShader = default_fragment;
  7982. this.linewidth = 1;
  7983. this.wireframe = false;
  7984. this.wireframeLinewidth = 1;
  7985. this.fog = false; // set to use scene fog
  7986. this.lights = false; // set to use scene lights
  7987. this.clipping = false; // set to use user-defined clipping planes
  7988. this.skinning = false; // set to use skinning attribute streams
  7989. this.morphTargets = false; // set to use morph targets
  7990. this.morphNormals = false; // set to use morph normals
  7991. this.extensions = {
  7992. derivatives: false,
  7993. // set to use derivatives
  7994. fragDepth: false,
  7995. // set to use fragment depth values
  7996. drawBuffers: false,
  7997. // set to use draw buffers
  7998. shaderTextureLOD: false // set to use shader texture LOD
  7999. }; // When rendered geometry doesn't include these attributes but the material does,
  8000. // use these default values in WebGL. This avoids errors when buffer data is missing.
  8001. this.defaultAttributeValues = {
  8002. 'color': [1, 1, 1],
  8003. 'uv': [0, 0],
  8004. 'uv2': [0, 0]
  8005. };
  8006. this.index0AttributeName = undefined;
  8007. this.uniformsNeedUpdate = false;
  8008. this.glslVersion = null;
  8009. if (parameters !== undefined) {
  8010. if (parameters.attributes !== undefined) {
  8011. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  8012. }
  8013. this.setValues(parameters);
  8014. }
  8015. }
  8016. ShaderMaterial.prototype = Object.create(Material.prototype);
  8017. ShaderMaterial.prototype.constructor = ShaderMaterial;
  8018. ShaderMaterial.prototype.isShaderMaterial = true;
  8019. ShaderMaterial.prototype.copy = function (source) {
  8020. Material.prototype.copy.call(this, source);
  8021. this.fragmentShader = source.fragmentShader;
  8022. this.vertexShader = source.vertexShader;
  8023. this.uniforms = cloneUniforms(source.uniforms);
  8024. this.defines = Object.assign({}, source.defines);
  8025. this.wireframe = source.wireframe;
  8026. this.wireframeLinewidth = source.wireframeLinewidth;
  8027. this.lights = source.lights;
  8028. this.clipping = source.clipping;
  8029. this.skinning = source.skinning;
  8030. this.morphTargets = source.morphTargets;
  8031. this.morphNormals = source.morphNormals;
  8032. this.extensions = Object.assign({}, source.extensions);
  8033. this.glslVersion = source.glslVersion;
  8034. return this;
  8035. };
  8036. ShaderMaterial.prototype.toJSON = function (meta) {
  8037. var data = Material.prototype.toJSON.call(this, meta);
  8038. data.glslVersion = this.glslVersion;
  8039. data.uniforms = {};
  8040. for (var name in this.uniforms) {
  8041. var uniform = this.uniforms[name];
  8042. var value = uniform.value;
  8043. if (value && value.isTexture) {
  8044. data.uniforms[name] = {
  8045. type: 't',
  8046. value: value.toJSON(meta).uuid
  8047. };
  8048. } else if (value && value.isColor) {
  8049. data.uniforms[name] = {
  8050. type: 'c',
  8051. value: value.getHex()
  8052. };
  8053. } else if (value && value.isVector2) {
  8054. data.uniforms[name] = {
  8055. type: 'v2',
  8056. value: value.toArray()
  8057. };
  8058. } else if (value && value.isVector3) {
  8059. data.uniforms[name] = {
  8060. type: 'v3',
  8061. value: value.toArray()
  8062. };
  8063. } else if (value && value.isVector4) {
  8064. data.uniforms[name] = {
  8065. type: 'v4',
  8066. value: value.toArray()
  8067. };
  8068. } else if (value && value.isMatrix3) {
  8069. data.uniforms[name] = {
  8070. type: 'm3',
  8071. value: value.toArray()
  8072. };
  8073. } else if (value && value.isMatrix4) {
  8074. data.uniforms[name] = {
  8075. type: 'm4',
  8076. value: value.toArray()
  8077. };
  8078. } else {
  8079. data.uniforms[name] = {
  8080. value: value
  8081. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  8082. }
  8083. }
  8084. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  8085. data.vertexShader = this.vertexShader;
  8086. data.fragmentShader = this.fragmentShader;
  8087. var extensions = {};
  8088. for (var key in this.extensions) {
  8089. if (this.extensions[key] === true) extensions[key] = true;
  8090. }
  8091. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  8092. return data;
  8093. };
  8094. function Camera() {
  8095. Object3D.call(this);
  8096. this.type = 'Camera';
  8097. this.matrixWorldInverse = new Matrix4();
  8098. this.projectionMatrix = new Matrix4();
  8099. this.projectionMatrixInverse = new Matrix4();
  8100. }
  8101. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  8102. constructor: Camera,
  8103. isCamera: true,
  8104. copy: function copy(source, recursive) {
  8105. Object3D.prototype.copy.call(this, source, recursive);
  8106. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  8107. this.projectionMatrix.copy(source.projectionMatrix);
  8108. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  8109. return this;
  8110. },
  8111. getWorldDirection: function getWorldDirection(target) {
  8112. if (target === undefined) {
  8113. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  8114. target = new Vector3();
  8115. }
  8116. this.updateWorldMatrix(true, false);
  8117. var e = this.matrixWorld.elements;
  8118. return target.set(-e[8], -e[9], -e[10]).normalize();
  8119. },
  8120. updateMatrixWorld: function updateMatrixWorld(force) {
  8121. Object3D.prototype.updateMatrixWorld.call(this, force);
  8122. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  8123. },
  8124. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  8125. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  8126. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  8127. },
  8128. clone: function clone() {
  8129. return new this.constructor().copy(this);
  8130. }
  8131. });
  8132. function PerspectiveCamera(fov, aspect, near, far) {
  8133. if (fov === void 0) {
  8134. fov = 50;
  8135. }
  8136. if (aspect === void 0) {
  8137. aspect = 1;
  8138. }
  8139. if (near === void 0) {
  8140. near = 0.1;
  8141. }
  8142. if (far === void 0) {
  8143. far = 2000;
  8144. }
  8145. Camera.call(this);
  8146. this.type = 'PerspectiveCamera';
  8147. this.fov = fov;
  8148. this.zoom = 1;
  8149. this.near = near;
  8150. this.far = far;
  8151. this.focus = 10;
  8152. this.aspect = aspect;
  8153. this.view = null;
  8154. this.filmGauge = 35; // width of the film (default in millimeters)
  8155. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  8156. this.updateProjectionMatrix();
  8157. }
  8158. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  8159. constructor: PerspectiveCamera,
  8160. isPerspectiveCamera: true,
  8161. copy: function copy(source, recursive) {
  8162. Camera.prototype.copy.call(this, source, recursive);
  8163. this.fov = source.fov;
  8164. this.zoom = source.zoom;
  8165. this.near = source.near;
  8166. this.far = source.far;
  8167. this.focus = source.focus;
  8168. this.aspect = source.aspect;
  8169. this.view = source.view === null ? null : Object.assign({}, source.view);
  8170. this.filmGauge = source.filmGauge;
  8171. this.filmOffset = source.filmOffset;
  8172. return this;
  8173. },
  8174. /**
  8175. * Sets the FOV by focal length in respect to the current .filmGauge.
  8176. *
  8177. * The default film gauge is 35, so that the focal length can be specified for
  8178. * a 35mm (full frame) camera.
  8179. *
  8180. * Values for focal length and film gauge must have the same unit.
  8181. */
  8182. setFocalLength: function setFocalLength(focalLength) {
  8183. /** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
  8184. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  8185. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  8186. this.updateProjectionMatrix();
  8187. },
  8188. /**
  8189. * Calculates the focal length from the current .fov and .filmGauge.
  8190. */
  8191. getFocalLength: function getFocalLength() {
  8192. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  8193. return 0.5 * this.getFilmHeight() / vExtentSlope;
  8194. },
  8195. getEffectiveFOV: function getEffectiveFOV() {
  8196. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  8197. },
  8198. getFilmWidth: function getFilmWidth() {
  8199. // film not completely covered in portrait format (aspect < 1)
  8200. return this.filmGauge * Math.min(this.aspect, 1);
  8201. },
  8202. getFilmHeight: function getFilmHeight() {
  8203. // film not completely covered in landscape format (aspect > 1)
  8204. return this.filmGauge / Math.max(this.aspect, 1);
  8205. },
  8206. /**
  8207. * Sets an offset in a larger frustum. This is useful for multi-window or
  8208. * multi-monitor/multi-machine setups.
  8209. *
  8210. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  8211. * the monitors are in grid like this
  8212. *
  8213. * +---+---+---+
  8214. * | A | B | C |
  8215. * +---+---+---+
  8216. * | D | E | F |
  8217. * +---+---+---+
  8218. *
  8219. * then for each monitor you would call it like this
  8220. *
  8221. * const w = 1920;
  8222. * const h = 1080;
  8223. * const fullWidth = w * 3;
  8224. * const fullHeight = h * 2;
  8225. *
  8226. * --A--
  8227. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8228. * --B--
  8229. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8230. * --C--
  8231. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8232. * --D--
  8233. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8234. * --E--
  8235. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8236. * --F--
  8237. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8238. *
  8239. * Note there is no reason monitors have to be the same size or in a grid.
  8240. */
  8241. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  8242. this.aspect = fullWidth / fullHeight;
  8243. if (this.view === null) {
  8244. this.view = {
  8245. enabled: true,
  8246. fullWidth: 1,
  8247. fullHeight: 1,
  8248. offsetX: 0,
  8249. offsetY: 0,
  8250. width: 1,
  8251. height: 1
  8252. };
  8253. }
  8254. this.view.enabled = true;
  8255. this.view.fullWidth = fullWidth;
  8256. this.view.fullHeight = fullHeight;
  8257. this.view.offsetX = x;
  8258. this.view.offsetY = y;
  8259. this.view.width = width;
  8260. this.view.height = height;
  8261. this.updateProjectionMatrix();
  8262. },
  8263. clearViewOffset: function clearViewOffset() {
  8264. if (this.view !== null) {
  8265. this.view.enabled = false;
  8266. }
  8267. this.updateProjectionMatrix();
  8268. },
  8269. updateProjectionMatrix: function updateProjectionMatrix() {
  8270. var near = this.near;
  8271. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  8272. var height = 2 * top;
  8273. var width = this.aspect * height;
  8274. var left = -0.5 * width;
  8275. var view = this.view;
  8276. if (this.view !== null && this.view.enabled) {
  8277. var fullWidth = view.fullWidth,
  8278. fullHeight = view.fullHeight;
  8279. left += view.offsetX * width / fullWidth;
  8280. top -= view.offsetY * height / fullHeight;
  8281. width *= view.width / fullWidth;
  8282. height *= view.height / fullHeight;
  8283. }
  8284. var skew = this.filmOffset;
  8285. if (skew !== 0) left += near * skew / this.getFilmWidth();
  8286. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  8287. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  8288. },
  8289. toJSON: function toJSON(meta) {
  8290. var data = Object3D.prototype.toJSON.call(this, meta);
  8291. data.object.fov = this.fov;
  8292. data.object.zoom = this.zoom;
  8293. data.object.near = this.near;
  8294. data.object.far = this.far;
  8295. data.object.focus = this.focus;
  8296. data.object.aspect = this.aspect;
  8297. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  8298. data.object.filmGauge = this.filmGauge;
  8299. data.object.filmOffset = this.filmOffset;
  8300. return data;
  8301. }
  8302. });
  8303. var fov = 90,
  8304. aspect = 1;
  8305. function CubeCamera(near, far, renderTarget) {
  8306. Object3D.call(this);
  8307. this.type = 'CubeCamera';
  8308. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  8309. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  8310. return;
  8311. }
  8312. this.renderTarget = renderTarget;
  8313. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  8314. cameraPX.layers = this.layers;
  8315. cameraPX.up.set(0, -1, 0);
  8316. cameraPX.lookAt(new Vector3(1, 0, 0));
  8317. this.add(cameraPX);
  8318. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  8319. cameraNX.layers = this.layers;
  8320. cameraNX.up.set(0, -1, 0);
  8321. cameraNX.lookAt(new Vector3(-1, 0, 0));
  8322. this.add(cameraNX);
  8323. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  8324. cameraPY.layers = this.layers;
  8325. cameraPY.up.set(0, 0, 1);
  8326. cameraPY.lookAt(new Vector3(0, 1, 0));
  8327. this.add(cameraPY);
  8328. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  8329. cameraNY.layers = this.layers;
  8330. cameraNY.up.set(0, 0, -1);
  8331. cameraNY.lookAt(new Vector3(0, -1, 0));
  8332. this.add(cameraNY);
  8333. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  8334. cameraPZ.layers = this.layers;
  8335. cameraPZ.up.set(0, -1, 0);
  8336. cameraPZ.lookAt(new Vector3(0, 0, 1));
  8337. this.add(cameraPZ);
  8338. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  8339. cameraNZ.layers = this.layers;
  8340. cameraNZ.up.set(0, -1, 0);
  8341. cameraNZ.lookAt(new Vector3(0, 0, -1));
  8342. this.add(cameraNZ);
  8343. this.update = function (renderer, scene) {
  8344. if (this.parent === null) this.updateMatrixWorld();
  8345. var currentXrEnabled = renderer.xr.enabled;
  8346. var currentRenderTarget = renderer.getRenderTarget();
  8347. renderer.xr.enabled = false;
  8348. var generateMipmaps = renderTarget.texture.generateMipmaps;
  8349. renderTarget.texture.generateMipmaps = false;
  8350. renderer.setRenderTarget(renderTarget, 0);
  8351. renderer.render(scene, cameraPX);
  8352. renderer.setRenderTarget(renderTarget, 1);
  8353. renderer.render(scene, cameraNX);
  8354. renderer.setRenderTarget(renderTarget, 2);
  8355. renderer.render(scene, cameraPY);
  8356. renderer.setRenderTarget(renderTarget, 3);
  8357. renderer.render(scene, cameraNY);
  8358. renderer.setRenderTarget(renderTarget, 4);
  8359. renderer.render(scene, cameraPZ);
  8360. renderTarget.texture.generateMipmaps = generateMipmaps;
  8361. renderer.setRenderTarget(renderTarget, 5);
  8362. renderer.render(scene, cameraNZ);
  8363. renderer.setRenderTarget(currentRenderTarget);
  8364. renderer.xr.enabled = currentXrEnabled;
  8365. };
  8366. }
  8367. CubeCamera.prototype = Object.create(Object3D.prototype);
  8368. CubeCamera.prototype.constructor = CubeCamera;
  8369. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  8370. images = images !== undefined ? images : [];
  8371. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  8372. format = format !== undefined ? format : RGBFormat;
  8373. Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8374. this.flipY = false; // Why CubeTexture._needsFlipEnvMap is necessary:
  8375. //
  8376. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  8377. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  8378. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  8379. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  8380. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  8381. // when using WebGLCubeRenderTarget.texture as a cube texture.
  8382. this._needsFlipEnvMap = true;
  8383. }
  8384. CubeTexture.prototype = Object.create(Texture.prototype);
  8385. CubeTexture.prototype.constructor = CubeTexture;
  8386. CubeTexture.prototype.isCubeTexture = true;
  8387. Object.defineProperty(CubeTexture.prototype, 'images', {
  8388. get: function get() {
  8389. return this.image;
  8390. },
  8391. set: function set(value) {
  8392. this.image = value;
  8393. }
  8394. });
  8395. var WebGLCubeRenderTarget = /*#__PURE__*/function (_WebGLRenderTarget) {
  8396. _inheritsLoose(WebGLCubeRenderTarget, _WebGLRenderTarget);
  8397. function WebGLCubeRenderTarget(size, options, dummy) {
  8398. var _this;
  8399. if (Number.isInteger(options)) {
  8400. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  8401. options = dummy;
  8402. }
  8403. _this = _WebGLRenderTarget.call(this, size, size, options) || this;
  8404. Object.defineProperty(_assertThisInitialized(_this), 'isWebGLCubeRenderTarget', {
  8405. value: true
  8406. });
  8407. options = options || {};
  8408. _this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  8409. _this.texture._needsFlipEnvMap = false;
  8410. return _this;
  8411. }
  8412. var _proto = WebGLCubeRenderTarget.prototype;
  8413. _proto.fromEquirectangularTexture = function fromEquirectangularTexture(renderer, texture) {
  8414. this.texture.type = texture.type;
  8415. this.texture.format = RGBAFormat; // see #18859
  8416. this.texture.encoding = texture.encoding;
  8417. this.texture.generateMipmaps = texture.generateMipmaps;
  8418. this.texture.minFilter = texture.minFilter;
  8419. this.texture.magFilter = texture.magFilter;
  8420. var shader = {
  8421. uniforms: {
  8422. tEquirect: {
  8423. value: null
  8424. }
  8425. },
  8426. vertexShader:
  8427. /* glsl */
  8428. "\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",
  8429. fragmentShader:
  8430. /* glsl */
  8431. "\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"
  8432. };
  8433. var geometry = new BoxGeometry(5, 5, 5);
  8434. var material = new ShaderMaterial({
  8435. name: 'CubemapFromEquirect',
  8436. uniforms: cloneUniforms(shader.uniforms),
  8437. vertexShader: shader.vertexShader,
  8438. fragmentShader: shader.fragmentShader,
  8439. side: BackSide,
  8440. blending: NoBlending
  8441. });
  8442. material.uniforms.tEquirect.value = texture;
  8443. var mesh = new Mesh(geometry, material);
  8444. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  8445. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  8446. var camera = new CubeCamera(1, 10, this);
  8447. camera.update(renderer, mesh);
  8448. texture.minFilter = currentMinFilter;
  8449. mesh.geometry.dispose();
  8450. mesh.material.dispose();
  8451. return this;
  8452. };
  8453. _proto.clear = function clear(renderer, color, depth, stencil) {
  8454. var currentRenderTarget = renderer.getRenderTarget();
  8455. for (var i = 0; i < 6; i++) {
  8456. renderer.setRenderTarget(this, i);
  8457. renderer.clear(color, depth, stencil);
  8458. }
  8459. renderer.setRenderTarget(currentRenderTarget);
  8460. };
  8461. return WebGLCubeRenderTarget;
  8462. }(WebGLRenderTarget);
  8463. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  8464. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8465. this.image = {
  8466. data: data || null,
  8467. width: width || 1,
  8468. height: height || 1
  8469. };
  8470. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8471. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8472. this.generateMipmaps = false;
  8473. this.flipY = false;
  8474. this.unpackAlignment = 1;
  8475. this.needsUpdate = true;
  8476. }
  8477. DataTexture.prototype = Object.create(Texture.prototype);
  8478. DataTexture.prototype.constructor = DataTexture;
  8479. DataTexture.prototype.isDataTexture = true;
  8480. var _sphere$1 = /*@__PURE__*/new Sphere();
  8481. var _vector$5 = /*@__PURE__*/new Vector3();
  8482. var Frustum = /*#__PURE__*/function () {
  8483. function Frustum(p0, p1, p2, p3, p4, p5) {
  8484. 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()];
  8485. }
  8486. var _proto = Frustum.prototype;
  8487. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  8488. var planes = this.planes;
  8489. planes[0].copy(p0);
  8490. planes[1].copy(p1);
  8491. planes[2].copy(p2);
  8492. planes[3].copy(p3);
  8493. planes[4].copy(p4);
  8494. planes[5].copy(p5);
  8495. return this;
  8496. };
  8497. _proto.clone = function clone() {
  8498. return new this.constructor().copy(this);
  8499. };
  8500. _proto.copy = function copy(frustum) {
  8501. var planes = this.planes;
  8502. for (var i = 0; i < 6; i++) {
  8503. planes[i].copy(frustum.planes[i]);
  8504. }
  8505. return this;
  8506. };
  8507. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  8508. var planes = this.planes;
  8509. var me = m.elements;
  8510. var me0 = me[0],
  8511. me1 = me[1],
  8512. me2 = me[2],
  8513. me3 = me[3];
  8514. var me4 = me[4],
  8515. me5 = me[5],
  8516. me6 = me[6],
  8517. me7 = me[7];
  8518. var me8 = me[8],
  8519. me9 = me[9],
  8520. me10 = me[10],
  8521. me11 = me[11];
  8522. var me12 = me[12],
  8523. me13 = me[13],
  8524. me14 = me[14],
  8525. me15 = me[15];
  8526. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  8527. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  8528. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  8529. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  8530. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  8531. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  8532. return this;
  8533. };
  8534. _proto.intersectsObject = function intersectsObject(object) {
  8535. var geometry = object.geometry;
  8536. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  8537. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  8538. return this.intersectsSphere(_sphere$1);
  8539. };
  8540. _proto.intersectsSprite = function intersectsSprite(sprite) {
  8541. _sphere$1.center.set(0, 0, 0);
  8542. _sphere$1.radius = 0.7071067811865476;
  8543. _sphere$1.applyMatrix4(sprite.matrixWorld);
  8544. return this.intersectsSphere(_sphere$1);
  8545. };
  8546. _proto.intersectsSphere = function intersectsSphere(sphere) {
  8547. var planes = this.planes;
  8548. var center = sphere.center;
  8549. var negRadius = -sphere.radius;
  8550. for (var i = 0; i < 6; i++) {
  8551. var distance = planes[i].distanceToPoint(center);
  8552. if (distance < negRadius) {
  8553. return false;
  8554. }
  8555. }
  8556. return true;
  8557. };
  8558. _proto.intersectsBox = function intersectsBox(box) {
  8559. var planes = this.planes;
  8560. for (var i = 0; i < 6; i++) {
  8561. var plane = planes[i]; // corner at max distance
  8562. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8563. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8564. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8565. if (plane.distanceToPoint(_vector$5) < 0) {
  8566. return false;
  8567. }
  8568. }
  8569. return true;
  8570. };
  8571. _proto.containsPoint = function containsPoint(point) {
  8572. var planes = this.planes;
  8573. for (var i = 0; i < 6; i++) {
  8574. if (planes[i].distanceToPoint(point) < 0) {
  8575. return false;
  8576. }
  8577. }
  8578. return true;
  8579. };
  8580. return Frustum;
  8581. }();
  8582. function WebGLAnimation() {
  8583. var context = null;
  8584. var isAnimating = false;
  8585. var animationLoop = null;
  8586. var requestId = null;
  8587. function onAnimationFrame(time, frame) {
  8588. animationLoop(time, frame);
  8589. requestId = context.requestAnimationFrame(onAnimationFrame);
  8590. }
  8591. return {
  8592. start: function start() {
  8593. if (isAnimating === true) return;
  8594. if (animationLoop === null) return;
  8595. requestId = context.requestAnimationFrame(onAnimationFrame);
  8596. isAnimating = true;
  8597. },
  8598. stop: function stop() {
  8599. context.cancelAnimationFrame(requestId);
  8600. isAnimating = false;
  8601. },
  8602. setAnimationLoop: function setAnimationLoop(callback) {
  8603. animationLoop = callback;
  8604. },
  8605. setContext: function setContext(value) {
  8606. context = value;
  8607. }
  8608. };
  8609. }
  8610. function WebGLAttributes(gl, capabilities) {
  8611. var isWebGL2 = capabilities.isWebGL2;
  8612. var buffers = new WeakMap();
  8613. function createBuffer(attribute, bufferType) {
  8614. var array = attribute.array;
  8615. var usage = attribute.usage;
  8616. var buffer = gl.createBuffer();
  8617. gl.bindBuffer(bufferType, buffer);
  8618. gl.bufferData(bufferType, array, usage);
  8619. attribute.onUploadCallback();
  8620. var type = 5126;
  8621. if (array instanceof Float32Array) {
  8622. type = 5126;
  8623. } else if (array instanceof Float64Array) {
  8624. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  8625. } else if (array instanceof Uint16Array) {
  8626. if (attribute.isFloat16BufferAttribute) {
  8627. if (isWebGL2) {
  8628. type = 5131;
  8629. } else {
  8630. console.warn('THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.');
  8631. }
  8632. } else {
  8633. type = 5123;
  8634. }
  8635. } else if (array instanceof Int16Array) {
  8636. type = 5122;
  8637. } else if (array instanceof Uint32Array) {
  8638. type = 5125;
  8639. } else if (array instanceof Int32Array) {
  8640. type = 5124;
  8641. } else if (array instanceof Int8Array) {
  8642. type = 5120;
  8643. } else if (array instanceof Uint8Array) {
  8644. type = 5121;
  8645. }
  8646. return {
  8647. buffer: buffer,
  8648. type: type,
  8649. bytesPerElement: array.BYTES_PER_ELEMENT,
  8650. version: attribute.version
  8651. };
  8652. }
  8653. function updateBuffer(buffer, attribute, bufferType) {
  8654. var array = attribute.array;
  8655. var updateRange = attribute.updateRange;
  8656. gl.bindBuffer(bufferType, buffer);
  8657. if (updateRange.count === -1) {
  8658. // Not using update ranges
  8659. gl.bufferSubData(bufferType, 0, array);
  8660. } else {
  8661. if (isWebGL2) {
  8662. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8663. } else {
  8664. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8665. }
  8666. updateRange.count = -1; // reset range
  8667. }
  8668. } //
  8669. function get(attribute) {
  8670. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8671. return buffers.get(attribute);
  8672. }
  8673. function remove(attribute) {
  8674. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8675. var data = buffers.get(attribute);
  8676. if (data) {
  8677. gl.deleteBuffer(data.buffer);
  8678. buffers.delete(attribute);
  8679. }
  8680. }
  8681. function update(attribute, bufferType) {
  8682. if (attribute.isGLBufferAttribute) {
  8683. var cached = buffers.get(attribute);
  8684. if (!cached || cached.version < attribute.version) {
  8685. buffers.set(attribute, {
  8686. buffer: attribute.buffer,
  8687. type: attribute.type,
  8688. bytesPerElement: attribute.elementSize,
  8689. version: attribute.version
  8690. });
  8691. }
  8692. return;
  8693. }
  8694. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8695. var data = buffers.get(attribute);
  8696. if (data === undefined) {
  8697. buffers.set(attribute, createBuffer(attribute, bufferType));
  8698. } else if (data.version < attribute.version) {
  8699. updateBuffer(data.buffer, attribute, bufferType);
  8700. data.version = attribute.version;
  8701. }
  8702. }
  8703. return {
  8704. get: get,
  8705. remove: remove,
  8706. update: update
  8707. };
  8708. }
  8709. var PlaneGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8710. _inheritsLoose(PlaneGeometry, _BufferGeometry);
  8711. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  8712. var _this;
  8713. if (width === void 0) {
  8714. width = 1;
  8715. }
  8716. if (height === void 0) {
  8717. height = 1;
  8718. }
  8719. if (widthSegments === void 0) {
  8720. widthSegments = 1;
  8721. }
  8722. if (heightSegments === void 0) {
  8723. heightSegments = 1;
  8724. }
  8725. _this = _BufferGeometry.call(this) || this;
  8726. _this.type = 'PlaneGeometry';
  8727. _this.parameters = {
  8728. width: width,
  8729. height: height,
  8730. widthSegments: widthSegments,
  8731. heightSegments: heightSegments
  8732. };
  8733. var width_half = width / 2;
  8734. var height_half = height / 2;
  8735. var gridX = Math.floor(widthSegments);
  8736. var gridY = Math.floor(heightSegments);
  8737. var gridX1 = gridX + 1;
  8738. var gridY1 = gridY + 1;
  8739. var segment_width = width / gridX;
  8740. var segment_height = height / gridY; //
  8741. var indices = [];
  8742. var vertices = [];
  8743. var normals = [];
  8744. var uvs = [];
  8745. for (var iy = 0; iy < gridY1; iy++) {
  8746. var y = iy * segment_height - height_half;
  8747. for (var ix = 0; ix < gridX1; ix++) {
  8748. var x = ix * segment_width - width_half;
  8749. vertices.push(x, -y, 0);
  8750. normals.push(0, 0, 1);
  8751. uvs.push(ix / gridX);
  8752. uvs.push(1 - iy / gridY);
  8753. }
  8754. }
  8755. for (var _iy = 0; _iy < gridY; _iy++) {
  8756. for (var _ix = 0; _ix < gridX; _ix++) {
  8757. var a = _ix + gridX1 * _iy;
  8758. var b = _ix + gridX1 * (_iy + 1);
  8759. var c = _ix + 1 + gridX1 * (_iy + 1);
  8760. var d = _ix + 1 + gridX1 * _iy;
  8761. indices.push(a, b, d);
  8762. indices.push(b, c, d);
  8763. }
  8764. }
  8765. _this.setIndex(indices);
  8766. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8767. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8768. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8769. return _this;
  8770. }
  8771. return PlaneGeometry;
  8772. }(BufferGeometry);
  8773. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8774. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8775. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8776. 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";
  8777. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8778. var begin_vertex = "vec3 transformed = vec3( position );";
  8779. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8780. 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";
  8781. var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 );\n\t\tfDet *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif";
  8782. 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";
  8783. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8784. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8785. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8786. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8787. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8788. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8789. 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";
  8790. 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}";
  8791. 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";
  8792. 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";
  8793. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8794. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8795. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8796. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8797. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8798. 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}";
  8799. 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";
  8800. 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";
  8801. 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";
  8802. 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";
  8803. 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";
  8804. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8805. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8806. 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";
  8807. 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";
  8808. 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}";
  8809. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8810. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8811. 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";
  8812. 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";
  8813. 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";
  8814. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8815. 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)";
  8816. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8817. 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)";
  8818. 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";
  8819. 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}";
  8820. 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";
  8821. 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";
  8822. 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";
  8823. 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";
  8824. 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";
  8825. 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";
  8826. 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";
  8827. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8828. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8829. 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";
  8830. 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";
  8831. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8832. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8833. 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";
  8834. 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";
  8835. 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";
  8836. var normal_fragment_begin = "#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t#endif\n\t#ifdef USE_TANGENT\n\t\tvec3 tangent = normalize( vTangent );\n\t\tvec3 bitangent = normalize( vBitangent );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\ttangent = tangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t\tbitangent = bitangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t#endif\n\t\t#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t#endif\n\t#endif\n#endif\nvec3 geometryNormal = normal;";
  8837. var normal_fragment_maps = "#ifdef OBJECTSPACE_NORMALMAP\n\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( TANGENTSPACE_NORMALMAP )\n\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\t#ifdef USE_TANGENT\n\t\tnormal = normalize( vTBN * mapN );\n\t#else\n\t\tnormal = perturbNormal2Arb( -vViewPosition, normal, mapN );\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif";
  8838. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( TANGENTSPACE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP ) )\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 mapN ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\n\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\tvec3 N = normalize( surf_norm );\n\t\tmat3 tsn = mat3( S, T, N );\n\t\tmapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif";
  8839. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8840. var clearcoat_normal_fragment_maps = "#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\t#ifdef USE_TANGENT\n\t\tclearcoatNormal = normalize( vTBN * clearcoatMapN );\n\t#else\n\t\tclearcoatNormal = perturbNormal2Arb( - vViewPosition, clearcoatNormal, clearcoatMapN );\n\t#endif\n#endif";
  8841. 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";
  8842. 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}";
  8843. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8844. 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;";
  8845. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8846. 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";
  8847. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8848. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8849. 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";
  8850. 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";
  8851. 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";
  8852. 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}";
  8853. 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";
  8854. 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";
  8855. 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";
  8856. 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";
  8857. 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";
  8858. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8859. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8860. 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; }";
  8861. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8862. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8863. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8864. 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";
  8865. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8866. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8867. 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";
  8868. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8869. 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";
  8870. 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}";
  8871. 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}";
  8872. 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}";
  8873. 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}";
  8874. 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}";
  8875. 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}";
  8876. 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}";
  8877. 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}";
  8878. 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}";
  8879. 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}";
  8880. 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}";
  8881. 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}";
  8882. 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}";
  8883. 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}";
  8884. 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}";
  8885. 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}";
  8886. 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}";
  8887. 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}";
  8888. 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}";
  8889. 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}";
  8890. 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}";
  8891. 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}";
  8892. 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}";
  8893. 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}";
  8894. 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}";
  8895. 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}";
  8896. 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}";
  8897. 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}";
  8898. 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}";
  8899. 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}";
  8900. 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}";
  8901. 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}";
  8902. var ShaderChunk = {
  8903. alphamap_fragment: alphamap_fragment,
  8904. alphamap_pars_fragment: alphamap_pars_fragment,
  8905. alphatest_fragment: alphatest_fragment,
  8906. aomap_fragment: aomap_fragment,
  8907. aomap_pars_fragment: aomap_pars_fragment,
  8908. begin_vertex: begin_vertex,
  8909. beginnormal_vertex: beginnormal_vertex,
  8910. bsdfs: bsdfs,
  8911. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8912. clipping_planes_fragment: clipping_planes_fragment,
  8913. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8914. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8915. clipping_planes_vertex: clipping_planes_vertex,
  8916. color_fragment: color_fragment,
  8917. color_pars_fragment: color_pars_fragment,
  8918. color_pars_vertex: color_pars_vertex,
  8919. color_vertex: color_vertex,
  8920. common: common,
  8921. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8922. defaultnormal_vertex: defaultnormal_vertex,
  8923. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8924. displacementmap_vertex: displacementmap_vertex,
  8925. emissivemap_fragment: emissivemap_fragment,
  8926. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8927. encodings_fragment: encodings_fragment,
  8928. encodings_pars_fragment: encodings_pars_fragment,
  8929. envmap_fragment: envmap_fragment,
  8930. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8931. envmap_pars_fragment: envmap_pars_fragment,
  8932. envmap_pars_vertex: envmap_pars_vertex,
  8933. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8934. envmap_vertex: envmap_vertex,
  8935. fog_vertex: fog_vertex,
  8936. fog_pars_vertex: fog_pars_vertex,
  8937. fog_fragment: fog_fragment,
  8938. fog_pars_fragment: fog_pars_fragment,
  8939. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8940. lightmap_fragment: lightmap_fragment,
  8941. lightmap_pars_fragment: lightmap_pars_fragment,
  8942. lights_lambert_vertex: lights_lambert_vertex,
  8943. lights_pars_begin: lights_pars_begin,
  8944. lights_toon_fragment: lights_toon_fragment,
  8945. lights_toon_pars_fragment: lights_toon_pars_fragment,
  8946. lights_phong_fragment: lights_phong_fragment,
  8947. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8948. lights_physical_fragment: lights_physical_fragment,
  8949. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8950. lights_fragment_begin: lights_fragment_begin,
  8951. lights_fragment_maps: lights_fragment_maps,
  8952. lights_fragment_end: lights_fragment_end,
  8953. logdepthbuf_fragment: logdepthbuf_fragment,
  8954. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  8955. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  8956. logdepthbuf_vertex: logdepthbuf_vertex,
  8957. map_fragment: map_fragment,
  8958. map_pars_fragment: map_pars_fragment,
  8959. map_particle_fragment: map_particle_fragment,
  8960. map_particle_pars_fragment: map_particle_pars_fragment,
  8961. metalnessmap_fragment: metalnessmap_fragment,
  8962. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  8963. morphnormal_vertex: morphnormal_vertex,
  8964. morphtarget_pars_vertex: morphtarget_pars_vertex,
  8965. morphtarget_vertex: morphtarget_vertex,
  8966. normal_fragment_begin: normal_fragment_begin,
  8967. normal_fragment_maps: normal_fragment_maps,
  8968. normalmap_pars_fragment: normalmap_pars_fragment,
  8969. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  8970. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  8971. clearcoat_pars_fragment: clearcoat_pars_fragment,
  8972. packing: packing,
  8973. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  8974. project_vertex: project_vertex,
  8975. dithering_fragment: dithering_fragment,
  8976. dithering_pars_fragment: dithering_pars_fragment,
  8977. roughnessmap_fragment: roughnessmap_fragment,
  8978. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  8979. shadowmap_pars_fragment: shadowmap_pars_fragment,
  8980. shadowmap_pars_vertex: shadowmap_pars_vertex,
  8981. shadowmap_vertex: shadowmap_vertex,
  8982. shadowmask_pars_fragment: shadowmask_pars_fragment,
  8983. skinbase_vertex: skinbase_vertex,
  8984. skinning_pars_vertex: skinning_pars_vertex,
  8985. skinning_vertex: skinning_vertex,
  8986. skinnormal_vertex: skinnormal_vertex,
  8987. specularmap_fragment: specularmap_fragment,
  8988. specularmap_pars_fragment: specularmap_pars_fragment,
  8989. tonemapping_fragment: tonemapping_fragment,
  8990. tonemapping_pars_fragment: tonemapping_pars_fragment,
  8991. transmissionmap_fragment: transmissionmap_fragment,
  8992. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  8993. uv_pars_fragment: uv_pars_fragment,
  8994. uv_pars_vertex: uv_pars_vertex,
  8995. uv_vertex: uv_vertex,
  8996. uv2_pars_fragment: uv2_pars_fragment,
  8997. uv2_pars_vertex: uv2_pars_vertex,
  8998. uv2_vertex: uv2_vertex,
  8999. worldpos_vertex: worldpos_vertex,
  9000. background_frag: background_frag,
  9001. background_vert: background_vert,
  9002. cube_frag: cube_frag,
  9003. cube_vert: cube_vert,
  9004. depth_frag: depth_frag,
  9005. depth_vert: depth_vert,
  9006. distanceRGBA_frag: distanceRGBA_frag,
  9007. distanceRGBA_vert: distanceRGBA_vert,
  9008. equirect_frag: equirect_frag,
  9009. equirect_vert: equirect_vert,
  9010. linedashed_frag: linedashed_frag,
  9011. linedashed_vert: linedashed_vert,
  9012. meshbasic_frag: meshbasic_frag,
  9013. meshbasic_vert: meshbasic_vert,
  9014. meshlambert_frag: meshlambert_frag,
  9015. meshlambert_vert: meshlambert_vert,
  9016. meshmatcap_frag: meshmatcap_frag,
  9017. meshmatcap_vert: meshmatcap_vert,
  9018. meshtoon_frag: meshtoon_frag,
  9019. meshtoon_vert: meshtoon_vert,
  9020. meshphong_frag: meshphong_frag,
  9021. meshphong_vert: meshphong_vert,
  9022. meshphysical_frag: meshphysical_frag,
  9023. meshphysical_vert: meshphysical_vert,
  9024. normal_frag: normal_frag,
  9025. normal_vert: normal_vert,
  9026. points_frag: points_frag,
  9027. points_vert: points_vert,
  9028. shadow_frag: shadow_frag,
  9029. shadow_vert: shadow_vert,
  9030. sprite_frag: sprite_frag,
  9031. sprite_vert: sprite_vert
  9032. };
  9033. /**
  9034. * Uniforms library for shared webgl shaders
  9035. */
  9036. var UniformsLib = {
  9037. common: {
  9038. diffuse: {
  9039. value: new Color(0xeeeeee)
  9040. },
  9041. opacity: {
  9042. value: 1.0
  9043. },
  9044. map: {
  9045. value: null
  9046. },
  9047. uvTransform: {
  9048. value: new Matrix3()
  9049. },
  9050. uv2Transform: {
  9051. value: new Matrix3()
  9052. },
  9053. alphaMap: {
  9054. value: null
  9055. }
  9056. },
  9057. specularmap: {
  9058. specularMap: {
  9059. value: null
  9060. }
  9061. },
  9062. envmap: {
  9063. envMap: {
  9064. value: null
  9065. },
  9066. flipEnvMap: {
  9067. value: -1
  9068. },
  9069. reflectivity: {
  9070. value: 1.0
  9071. },
  9072. refractionRatio: {
  9073. value: 0.98
  9074. },
  9075. maxMipLevel: {
  9076. value: 0
  9077. }
  9078. },
  9079. aomap: {
  9080. aoMap: {
  9081. value: null
  9082. },
  9083. aoMapIntensity: {
  9084. value: 1
  9085. }
  9086. },
  9087. lightmap: {
  9088. lightMap: {
  9089. value: null
  9090. },
  9091. lightMapIntensity: {
  9092. value: 1
  9093. }
  9094. },
  9095. emissivemap: {
  9096. emissiveMap: {
  9097. value: null
  9098. }
  9099. },
  9100. bumpmap: {
  9101. bumpMap: {
  9102. value: null
  9103. },
  9104. bumpScale: {
  9105. value: 1
  9106. }
  9107. },
  9108. normalmap: {
  9109. normalMap: {
  9110. value: null
  9111. },
  9112. normalScale: {
  9113. value: new Vector2(1, 1)
  9114. }
  9115. },
  9116. displacementmap: {
  9117. displacementMap: {
  9118. value: null
  9119. },
  9120. displacementScale: {
  9121. value: 1
  9122. },
  9123. displacementBias: {
  9124. value: 0
  9125. }
  9126. },
  9127. roughnessmap: {
  9128. roughnessMap: {
  9129. value: null
  9130. }
  9131. },
  9132. metalnessmap: {
  9133. metalnessMap: {
  9134. value: null
  9135. }
  9136. },
  9137. gradientmap: {
  9138. gradientMap: {
  9139. value: null
  9140. }
  9141. },
  9142. fog: {
  9143. fogDensity: {
  9144. value: 0.00025
  9145. },
  9146. fogNear: {
  9147. value: 1
  9148. },
  9149. fogFar: {
  9150. value: 2000
  9151. },
  9152. fogColor: {
  9153. value: new Color(0xffffff)
  9154. }
  9155. },
  9156. lights: {
  9157. ambientLightColor: {
  9158. value: []
  9159. },
  9160. lightProbe: {
  9161. value: []
  9162. },
  9163. directionalLights: {
  9164. value: [],
  9165. properties: {
  9166. direction: {},
  9167. color: {}
  9168. }
  9169. },
  9170. directionalLightShadows: {
  9171. value: [],
  9172. properties: {
  9173. shadowBias: {},
  9174. shadowNormalBias: {},
  9175. shadowRadius: {},
  9176. shadowMapSize: {}
  9177. }
  9178. },
  9179. directionalShadowMap: {
  9180. value: []
  9181. },
  9182. directionalShadowMatrix: {
  9183. value: []
  9184. },
  9185. spotLights: {
  9186. value: [],
  9187. properties: {
  9188. color: {},
  9189. position: {},
  9190. direction: {},
  9191. distance: {},
  9192. coneCos: {},
  9193. penumbraCos: {},
  9194. decay: {}
  9195. }
  9196. },
  9197. spotLightShadows: {
  9198. value: [],
  9199. properties: {
  9200. shadowBias: {},
  9201. shadowNormalBias: {},
  9202. shadowRadius: {},
  9203. shadowMapSize: {}
  9204. }
  9205. },
  9206. spotShadowMap: {
  9207. value: []
  9208. },
  9209. spotShadowMatrix: {
  9210. value: []
  9211. },
  9212. pointLights: {
  9213. value: [],
  9214. properties: {
  9215. color: {},
  9216. position: {},
  9217. decay: {},
  9218. distance: {}
  9219. }
  9220. },
  9221. pointLightShadows: {
  9222. value: [],
  9223. properties: {
  9224. shadowBias: {},
  9225. shadowNormalBias: {},
  9226. shadowRadius: {},
  9227. shadowMapSize: {},
  9228. shadowCameraNear: {},
  9229. shadowCameraFar: {}
  9230. }
  9231. },
  9232. pointShadowMap: {
  9233. value: []
  9234. },
  9235. pointShadowMatrix: {
  9236. value: []
  9237. },
  9238. hemisphereLights: {
  9239. value: [],
  9240. properties: {
  9241. direction: {},
  9242. skyColor: {},
  9243. groundColor: {}
  9244. }
  9245. },
  9246. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  9247. rectAreaLights: {
  9248. value: [],
  9249. properties: {
  9250. color: {},
  9251. position: {},
  9252. width: {},
  9253. height: {}
  9254. }
  9255. },
  9256. ltc_1: {
  9257. value: null
  9258. },
  9259. ltc_2: {
  9260. value: null
  9261. }
  9262. },
  9263. points: {
  9264. diffuse: {
  9265. value: new Color(0xeeeeee)
  9266. },
  9267. opacity: {
  9268. value: 1.0
  9269. },
  9270. size: {
  9271. value: 1.0
  9272. },
  9273. scale: {
  9274. value: 1.0
  9275. },
  9276. map: {
  9277. value: null
  9278. },
  9279. alphaMap: {
  9280. value: null
  9281. },
  9282. uvTransform: {
  9283. value: new Matrix3()
  9284. }
  9285. },
  9286. sprite: {
  9287. diffuse: {
  9288. value: new Color(0xeeeeee)
  9289. },
  9290. opacity: {
  9291. value: 1.0
  9292. },
  9293. center: {
  9294. value: new Vector2(0.5, 0.5)
  9295. },
  9296. rotation: {
  9297. value: 0.0
  9298. },
  9299. map: {
  9300. value: null
  9301. },
  9302. alphaMap: {
  9303. value: null
  9304. },
  9305. uvTransform: {
  9306. value: new Matrix3()
  9307. }
  9308. }
  9309. };
  9310. var ShaderLib = {
  9311. basic: {
  9312. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  9313. vertexShader: ShaderChunk.meshbasic_vert,
  9314. fragmentShader: ShaderChunk.meshbasic_frag
  9315. },
  9316. lambert: {
  9317. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  9318. emissive: {
  9319. value: new Color(0x000000)
  9320. }
  9321. }]),
  9322. vertexShader: ShaderChunk.meshlambert_vert,
  9323. fragmentShader: ShaderChunk.meshlambert_frag
  9324. },
  9325. phong: {
  9326. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  9327. emissive: {
  9328. value: new Color(0x000000)
  9329. },
  9330. specular: {
  9331. value: new Color(0x111111)
  9332. },
  9333. shininess: {
  9334. value: 30
  9335. }
  9336. }]),
  9337. vertexShader: ShaderChunk.meshphong_vert,
  9338. fragmentShader: ShaderChunk.meshphong_frag
  9339. },
  9340. standard: {
  9341. 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, {
  9342. emissive: {
  9343. value: new Color(0x000000)
  9344. },
  9345. roughness: {
  9346. value: 1.0
  9347. },
  9348. metalness: {
  9349. value: 0.0
  9350. },
  9351. envMapIntensity: {
  9352. value: 1
  9353. } // temporary
  9354. }]),
  9355. vertexShader: ShaderChunk.meshphysical_vert,
  9356. fragmentShader: ShaderChunk.meshphysical_frag
  9357. },
  9358. toon: {
  9359. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  9360. emissive: {
  9361. value: new Color(0x000000)
  9362. }
  9363. }]),
  9364. vertexShader: ShaderChunk.meshtoon_vert,
  9365. fragmentShader: ShaderChunk.meshtoon_frag
  9366. },
  9367. matcap: {
  9368. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  9369. matcap: {
  9370. value: null
  9371. }
  9372. }]),
  9373. vertexShader: ShaderChunk.meshmatcap_vert,
  9374. fragmentShader: ShaderChunk.meshmatcap_frag
  9375. },
  9376. points: {
  9377. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  9378. vertexShader: ShaderChunk.points_vert,
  9379. fragmentShader: ShaderChunk.points_frag
  9380. },
  9381. dashed: {
  9382. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  9383. scale: {
  9384. value: 1
  9385. },
  9386. dashSize: {
  9387. value: 1
  9388. },
  9389. totalSize: {
  9390. value: 2
  9391. }
  9392. }]),
  9393. vertexShader: ShaderChunk.linedashed_vert,
  9394. fragmentShader: ShaderChunk.linedashed_frag
  9395. },
  9396. depth: {
  9397. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  9398. vertexShader: ShaderChunk.depth_vert,
  9399. fragmentShader: ShaderChunk.depth_frag
  9400. },
  9401. normal: {
  9402. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  9403. opacity: {
  9404. value: 1.0
  9405. }
  9406. }]),
  9407. vertexShader: ShaderChunk.normal_vert,
  9408. fragmentShader: ShaderChunk.normal_frag
  9409. },
  9410. sprite: {
  9411. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  9412. vertexShader: ShaderChunk.sprite_vert,
  9413. fragmentShader: ShaderChunk.sprite_frag
  9414. },
  9415. background: {
  9416. uniforms: {
  9417. uvTransform: {
  9418. value: new Matrix3()
  9419. },
  9420. t2D: {
  9421. value: null
  9422. }
  9423. },
  9424. vertexShader: ShaderChunk.background_vert,
  9425. fragmentShader: ShaderChunk.background_frag
  9426. },
  9427. /* -------------------------------------------------------------------------
  9428. // Cube map shader
  9429. ------------------------------------------------------------------------- */
  9430. cube: {
  9431. uniforms: mergeUniforms([UniformsLib.envmap, {
  9432. opacity: {
  9433. value: 1.0
  9434. }
  9435. }]),
  9436. vertexShader: ShaderChunk.cube_vert,
  9437. fragmentShader: ShaderChunk.cube_frag
  9438. },
  9439. equirect: {
  9440. uniforms: {
  9441. tEquirect: {
  9442. value: null
  9443. }
  9444. },
  9445. vertexShader: ShaderChunk.equirect_vert,
  9446. fragmentShader: ShaderChunk.equirect_frag
  9447. },
  9448. distanceRGBA: {
  9449. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  9450. referencePosition: {
  9451. value: new Vector3()
  9452. },
  9453. nearDistance: {
  9454. value: 1
  9455. },
  9456. farDistance: {
  9457. value: 1000
  9458. }
  9459. }]),
  9460. vertexShader: ShaderChunk.distanceRGBA_vert,
  9461. fragmentShader: ShaderChunk.distanceRGBA_frag
  9462. },
  9463. shadow: {
  9464. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  9465. color: {
  9466. value: new Color(0x00000)
  9467. },
  9468. opacity: {
  9469. value: 1.0
  9470. }
  9471. }]),
  9472. vertexShader: ShaderChunk.shadow_vert,
  9473. fragmentShader: ShaderChunk.shadow_frag
  9474. }
  9475. };
  9476. ShaderLib.physical = {
  9477. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  9478. clearcoat: {
  9479. value: 0
  9480. },
  9481. clearcoatMap: {
  9482. value: null
  9483. },
  9484. clearcoatRoughness: {
  9485. value: 0
  9486. },
  9487. clearcoatRoughnessMap: {
  9488. value: null
  9489. },
  9490. clearcoatNormalScale: {
  9491. value: new Vector2(1, 1)
  9492. },
  9493. clearcoatNormalMap: {
  9494. value: null
  9495. },
  9496. sheen: {
  9497. value: new Color(0x000000)
  9498. },
  9499. transmission: {
  9500. value: 0
  9501. },
  9502. transmissionMap: {
  9503. value: null
  9504. }
  9505. }]),
  9506. vertexShader: ShaderChunk.meshphysical_vert,
  9507. fragmentShader: ShaderChunk.meshphysical_frag
  9508. };
  9509. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  9510. var clearColor = new Color(0x000000);
  9511. var clearAlpha = 0;
  9512. var planeMesh;
  9513. var boxMesh;
  9514. var currentBackground = null;
  9515. var currentBackgroundVersion = 0;
  9516. var currentTonemapping = null;
  9517. function render(renderList, scene, camera, forceClear) {
  9518. var background = scene.isScene === true ? scene.background : null;
  9519. if (background && background.isTexture) {
  9520. background = cubemaps.get(background);
  9521. } // Ignore background in AR
  9522. // TODO: Reconsider this.
  9523. var xr = renderer.xr;
  9524. var session = xr.getSession && xr.getSession();
  9525. if (session && session.environmentBlendMode === 'additive') {
  9526. background = null;
  9527. }
  9528. if (background === null) {
  9529. setClear(clearColor, clearAlpha);
  9530. } else if (background && background.isColor) {
  9531. setClear(background, 1);
  9532. forceClear = true;
  9533. }
  9534. if (renderer.autoClear || forceClear) {
  9535. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  9536. }
  9537. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  9538. if (boxMesh === undefined) {
  9539. boxMesh = new Mesh(new BoxGeometry(1, 1, 1), new ShaderMaterial({
  9540. name: 'BackgroundCubeMaterial',
  9541. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  9542. vertexShader: ShaderLib.cube.vertexShader,
  9543. fragmentShader: ShaderLib.cube.fragmentShader,
  9544. side: BackSide,
  9545. depthTest: false,
  9546. depthWrite: false,
  9547. fog: false
  9548. }));
  9549. boxMesh.geometry.deleteAttribute('normal');
  9550. boxMesh.geometry.deleteAttribute('uv');
  9551. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  9552. this.matrixWorld.copyPosition(camera.matrixWorld);
  9553. }; // enable code injection for non-built-in material
  9554. Object.defineProperty(boxMesh.material, 'envMap', {
  9555. get: function get() {
  9556. return this.uniforms.envMap.value;
  9557. }
  9558. });
  9559. objects.update(boxMesh);
  9560. }
  9561. if (background.isWebGLCubeRenderTarget) {
  9562. // TODO Deprecate
  9563. background = background.texture;
  9564. }
  9565. boxMesh.material.uniforms.envMap.value = background;
  9566. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  9567. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9568. boxMesh.material.needsUpdate = true;
  9569. currentBackground = background;
  9570. currentBackgroundVersion = background.version;
  9571. currentTonemapping = renderer.toneMapping;
  9572. } // push to the pre-sorted opaque render list
  9573. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  9574. } else if (background && background.isTexture) {
  9575. if (planeMesh === undefined) {
  9576. planeMesh = new Mesh(new PlaneGeometry(2, 2), new ShaderMaterial({
  9577. name: 'BackgroundMaterial',
  9578. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  9579. vertexShader: ShaderLib.background.vertexShader,
  9580. fragmentShader: ShaderLib.background.fragmentShader,
  9581. side: FrontSide,
  9582. depthTest: false,
  9583. depthWrite: false,
  9584. fog: false
  9585. }));
  9586. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  9587. Object.defineProperty(planeMesh.material, 'map', {
  9588. get: function get() {
  9589. return this.uniforms.t2D.value;
  9590. }
  9591. });
  9592. objects.update(planeMesh);
  9593. }
  9594. planeMesh.material.uniforms.t2D.value = background;
  9595. if (background.matrixAutoUpdate === true) {
  9596. background.updateMatrix();
  9597. }
  9598. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  9599. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9600. planeMesh.material.needsUpdate = true;
  9601. currentBackground = background;
  9602. currentBackgroundVersion = background.version;
  9603. currentTonemapping = renderer.toneMapping;
  9604. } // push to the pre-sorted opaque render list
  9605. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  9606. }
  9607. }
  9608. function setClear(color, alpha) {
  9609. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  9610. }
  9611. return {
  9612. getClearColor: function getClearColor() {
  9613. return clearColor;
  9614. },
  9615. setClearColor: function setClearColor(color, alpha) {
  9616. if (alpha === void 0) {
  9617. alpha = 1;
  9618. }
  9619. clearColor.set(color);
  9620. clearAlpha = alpha;
  9621. setClear(clearColor, clearAlpha);
  9622. },
  9623. getClearAlpha: function getClearAlpha() {
  9624. return clearAlpha;
  9625. },
  9626. setClearAlpha: function setClearAlpha(alpha) {
  9627. clearAlpha = alpha;
  9628. setClear(clearColor, clearAlpha);
  9629. },
  9630. render: render
  9631. };
  9632. }
  9633. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  9634. var maxVertexAttributes = gl.getParameter(34921);
  9635. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  9636. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9637. var bindingStates = {};
  9638. var defaultState = createBindingState(null);
  9639. var currentState = defaultState;
  9640. function setup(object, material, program, geometry, index) {
  9641. var updateBuffers = false;
  9642. if (vaoAvailable) {
  9643. var state = getBindingState(geometry, program, material);
  9644. if (currentState !== state) {
  9645. currentState = state;
  9646. bindVertexArrayObject(currentState.object);
  9647. }
  9648. updateBuffers = needsUpdate(geometry, index);
  9649. if (updateBuffers) saveCache(geometry, index);
  9650. } else {
  9651. var wireframe = material.wireframe === true;
  9652. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9653. currentState.geometry = geometry.id;
  9654. currentState.program = program.id;
  9655. currentState.wireframe = wireframe;
  9656. updateBuffers = true;
  9657. }
  9658. }
  9659. if (object.isInstancedMesh === true) {
  9660. updateBuffers = true;
  9661. }
  9662. if (index !== null) {
  9663. attributes.update(index, 34963);
  9664. }
  9665. if (updateBuffers) {
  9666. setupVertexAttributes(object, material, program, geometry);
  9667. if (index !== null) {
  9668. gl.bindBuffer(34963, attributes.get(index).buffer);
  9669. }
  9670. }
  9671. }
  9672. function createVertexArrayObject() {
  9673. if (capabilities.isWebGL2) return gl.createVertexArray();
  9674. return extension.createVertexArrayOES();
  9675. }
  9676. function bindVertexArrayObject(vao) {
  9677. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9678. return extension.bindVertexArrayOES(vao);
  9679. }
  9680. function deleteVertexArrayObject(vao) {
  9681. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9682. return extension.deleteVertexArrayOES(vao);
  9683. }
  9684. function getBindingState(geometry, program, material) {
  9685. var wireframe = material.wireframe === true;
  9686. var programMap = bindingStates[geometry.id];
  9687. if (programMap === undefined) {
  9688. programMap = {};
  9689. bindingStates[geometry.id] = programMap;
  9690. }
  9691. var stateMap = programMap[program.id];
  9692. if (stateMap === undefined) {
  9693. stateMap = {};
  9694. programMap[program.id] = stateMap;
  9695. }
  9696. var state = stateMap[wireframe];
  9697. if (state === undefined) {
  9698. state = createBindingState(createVertexArrayObject());
  9699. stateMap[wireframe] = state;
  9700. }
  9701. return state;
  9702. }
  9703. function createBindingState(vao) {
  9704. var newAttributes = [];
  9705. var enabledAttributes = [];
  9706. var attributeDivisors = [];
  9707. for (var i = 0; i < maxVertexAttributes; i++) {
  9708. newAttributes[i] = 0;
  9709. enabledAttributes[i] = 0;
  9710. attributeDivisors[i] = 0;
  9711. }
  9712. return {
  9713. // for backward compatibility on non-VAO support browser
  9714. geometry: null,
  9715. program: null,
  9716. wireframe: false,
  9717. newAttributes: newAttributes,
  9718. enabledAttributes: enabledAttributes,
  9719. attributeDivisors: attributeDivisors,
  9720. object: vao,
  9721. attributes: {},
  9722. index: null
  9723. };
  9724. }
  9725. function needsUpdate(geometry, index) {
  9726. var cachedAttributes = currentState.attributes;
  9727. var geometryAttributes = geometry.attributes;
  9728. var attributesNum = 0;
  9729. for (var key in geometryAttributes) {
  9730. var cachedAttribute = cachedAttributes[key];
  9731. var geometryAttribute = geometryAttributes[key];
  9732. if (cachedAttribute === undefined) return true;
  9733. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9734. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9735. attributesNum++;
  9736. }
  9737. if (currentState.attributesNum !== attributesNum) return true;
  9738. if (currentState.index !== index) return true;
  9739. return false;
  9740. }
  9741. function saveCache(geometry, index) {
  9742. var cache = {};
  9743. var attributes = geometry.attributes;
  9744. var attributesNum = 0;
  9745. for (var key in attributes) {
  9746. var attribute = attributes[key];
  9747. var data = {};
  9748. data.attribute = attribute;
  9749. if (attribute.data) {
  9750. data.data = attribute.data;
  9751. }
  9752. cache[key] = data;
  9753. attributesNum++;
  9754. }
  9755. currentState.attributes = cache;
  9756. currentState.attributesNum = attributesNum;
  9757. currentState.index = index;
  9758. }
  9759. function initAttributes() {
  9760. var newAttributes = currentState.newAttributes;
  9761. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9762. newAttributes[i] = 0;
  9763. }
  9764. }
  9765. function enableAttribute(attribute) {
  9766. enableAttributeAndDivisor(attribute, 0);
  9767. }
  9768. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9769. var newAttributes = currentState.newAttributes;
  9770. var enabledAttributes = currentState.enabledAttributes;
  9771. var attributeDivisors = currentState.attributeDivisors;
  9772. newAttributes[attribute] = 1;
  9773. if (enabledAttributes[attribute] === 0) {
  9774. gl.enableVertexAttribArray(attribute);
  9775. enabledAttributes[attribute] = 1;
  9776. }
  9777. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9778. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9779. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9780. attributeDivisors[attribute] = meshPerAttribute;
  9781. }
  9782. }
  9783. function disableUnusedAttributes() {
  9784. var newAttributes = currentState.newAttributes;
  9785. var enabledAttributes = currentState.enabledAttributes;
  9786. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9787. if (enabledAttributes[i] !== newAttributes[i]) {
  9788. gl.disableVertexAttribArray(i);
  9789. enabledAttributes[i] = 0;
  9790. }
  9791. }
  9792. }
  9793. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9794. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9795. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9796. } else {
  9797. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9798. }
  9799. }
  9800. function setupVertexAttributes(object, material, program, geometry) {
  9801. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9802. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9803. }
  9804. initAttributes();
  9805. var geometryAttributes = geometry.attributes;
  9806. var programAttributes = program.getAttributes();
  9807. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9808. for (var name in programAttributes) {
  9809. var programAttribute = programAttributes[name];
  9810. if (programAttribute >= 0) {
  9811. var geometryAttribute = geometryAttributes[name];
  9812. if (geometryAttribute !== undefined) {
  9813. var normalized = geometryAttribute.normalized;
  9814. var size = geometryAttribute.itemSize;
  9815. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9816. if (attribute === undefined) continue;
  9817. var buffer = attribute.buffer;
  9818. var type = attribute.type;
  9819. var bytesPerElement = attribute.bytesPerElement;
  9820. if (geometryAttribute.isInterleavedBufferAttribute) {
  9821. var data = geometryAttribute.data;
  9822. var stride = data.stride;
  9823. var offset = geometryAttribute.offset;
  9824. if (data && data.isInstancedInterleavedBuffer) {
  9825. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9826. if (geometry._maxInstanceCount === undefined) {
  9827. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9828. }
  9829. } else {
  9830. enableAttribute(programAttribute);
  9831. }
  9832. gl.bindBuffer(34962, buffer);
  9833. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9834. } else {
  9835. if (geometryAttribute.isInstancedBufferAttribute) {
  9836. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9837. if (geometry._maxInstanceCount === undefined) {
  9838. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9839. }
  9840. } else {
  9841. enableAttribute(programAttribute);
  9842. }
  9843. gl.bindBuffer(34962, buffer);
  9844. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9845. }
  9846. } else if (name === 'instanceMatrix') {
  9847. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9848. if (_attribute === undefined) continue;
  9849. var _buffer = _attribute.buffer;
  9850. var _type = _attribute.type;
  9851. enableAttributeAndDivisor(programAttribute + 0, 1);
  9852. enableAttributeAndDivisor(programAttribute + 1, 1);
  9853. enableAttributeAndDivisor(programAttribute + 2, 1);
  9854. enableAttributeAndDivisor(programAttribute + 3, 1);
  9855. gl.bindBuffer(34962, _buffer);
  9856. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9857. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9858. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9859. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9860. } else if (name === 'instanceColor') {
  9861. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9862. if (_attribute2 === undefined) continue;
  9863. var _buffer2 = _attribute2.buffer;
  9864. var _type2 = _attribute2.type;
  9865. enableAttributeAndDivisor(programAttribute, 1);
  9866. gl.bindBuffer(34962, _buffer2);
  9867. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9868. } else if (materialDefaultAttributeValues !== undefined) {
  9869. var value = materialDefaultAttributeValues[name];
  9870. if (value !== undefined) {
  9871. switch (value.length) {
  9872. case 2:
  9873. gl.vertexAttrib2fv(programAttribute, value);
  9874. break;
  9875. case 3:
  9876. gl.vertexAttrib3fv(programAttribute, value);
  9877. break;
  9878. case 4:
  9879. gl.vertexAttrib4fv(programAttribute, value);
  9880. break;
  9881. default:
  9882. gl.vertexAttrib1fv(programAttribute, value);
  9883. }
  9884. }
  9885. }
  9886. }
  9887. }
  9888. disableUnusedAttributes();
  9889. }
  9890. function dispose() {
  9891. reset();
  9892. for (var geometryId in bindingStates) {
  9893. var programMap = bindingStates[geometryId];
  9894. for (var programId in programMap) {
  9895. var stateMap = programMap[programId];
  9896. for (var wireframe in stateMap) {
  9897. deleteVertexArrayObject(stateMap[wireframe].object);
  9898. delete stateMap[wireframe];
  9899. }
  9900. delete programMap[programId];
  9901. }
  9902. delete bindingStates[geometryId];
  9903. }
  9904. }
  9905. function releaseStatesOfGeometry(geometry) {
  9906. if (bindingStates[geometry.id] === undefined) return;
  9907. var programMap = bindingStates[geometry.id];
  9908. for (var programId in programMap) {
  9909. var stateMap = programMap[programId];
  9910. for (var wireframe in stateMap) {
  9911. deleteVertexArrayObject(stateMap[wireframe].object);
  9912. delete stateMap[wireframe];
  9913. }
  9914. delete programMap[programId];
  9915. }
  9916. delete bindingStates[geometry.id];
  9917. }
  9918. function releaseStatesOfProgram(program) {
  9919. for (var geometryId in bindingStates) {
  9920. var programMap = bindingStates[geometryId];
  9921. if (programMap[program.id] === undefined) continue;
  9922. var stateMap = programMap[program.id];
  9923. for (var wireframe in stateMap) {
  9924. deleteVertexArrayObject(stateMap[wireframe].object);
  9925. delete stateMap[wireframe];
  9926. }
  9927. delete programMap[program.id];
  9928. }
  9929. }
  9930. function reset() {
  9931. resetDefaultState();
  9932. if (currentState === defaultState) return;
  9933. currentState = defaultState;
  9934. bindVertexArrayObject(currentState.object);
  9935. } // for backward-compatilibity
  9936. function resetDefaultState() {
  9937. defaultState.geometry = null;
  9938. defaultState.program = null;
  9939. defaultState.wireframe = false;
  9940. }
  9941. return {
  9942. setup: setup,
  9943. reset: reset,
  9944. resetDefaultState: resetDefaultState,
  9945. dispose: dispose,
  9946. releaseStatesOfGeometry: releaseStatesOfGeometry,
  9947. releaseStatesOfProgram: releaseStatesOfProgram,
  9948. initAttributes: initAttributes,
  9949. enableAttribute: enableAttribute,
  9950. disableUnusedAttributes: disableUnusedAttributes
  9951. };
  9952. }
  9953. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  9954. var isWebGL2 = capabilities.isWebGL2;
  9955. var mode;
  9956. function setMode(value) {
  9957. mode = value;
  9958. }
  9959. function render(start, count) {
  9960. gl.drawArrays(mode, start, count);
  9961. info.update(count, mode, 1);
  9962. }
  9963. function renderInstances(start, count, primcount) {
  9964. if (primcount === 0) return;
  9965. var extension, methodName;
  9966. if (isWebGL2) {
  9967. extension = gl;
  9968. methodName = 'drawArraysInstanced';
  9969. } else {
  9970. extension = extensions.get('ANGLE_instanced_arrays');
  9971. methodName = 'drawArraysInstancedANGLE';
  9972. if (extension === null) {
  9973. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9974. return;
  9975. }
  9976. }
  9977. extension[methodName](mode, start, count, primcount);
  9978. info.update(count, mode, primcount);
  9979. } //
  9980. this.setMode = setMode;
  9981. this.render = render;
  9982. this.renderInstances = renderInstances;
  9983. }
  9984. function WebGLCapabilities(gl, extensions, parameters) {
  9985. var maxAnisotropy;
  9986. function getMaxAnisotropy() {
  9987. if (maxAnisotropy !== undefined) return maxAnisotropy;
  9988. var extension = extensions.get('EXT_texture_filter_anisotropic');
  9989. if (extension !== null) {
  9990. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  9991. } else {
  9992. maxAnisotropy = 0;
  9993. }
  9994. return maxAnisotropy;
  9995. }
  9996. function getMaxPrecision(precision) {
  9997. if (precision === 'highp') {
  9998. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  9999. return 'highp';
  10000. }
  10001. precision = 'mediump';
  10002. }
  10003. if (precision === 'mediump') {
  10004. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  10005. return 'mediump';
  10006. }
  10007. }
  10008. return 'lowp';
  10009. }
  10010. /* eslint-disable no-undef */
  10011. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  10012. /* eslint-enable no-undef */
  10013. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  10014. var maxPrecision = getMaxPrecision(precision);
  10015. if (maxPrecision !== precision) {
  10016. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  10017. precision = maxPrecision;
  10018. }
  10019. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  10020. var maxTextures = gl.getParameter(34930);
  10021. var maxVertexTextures = gl.getParameter(35660);
  10022. var maxTextureSize = gl.getParameter(3379);
  10023. var maxCubemapSize = gl.getParameter(34076);
  10024. var maxAttributes = gl.getParameter(34921);
  10025. var maxVertexUniforms = gl.getParameter(36347);
  10026. var maxVaryings = gl.getParameter(36348);
  10027. var maxFragmentUniforms = gl.getParameter(36349);
  10028. var vertexTextures = maxVertexTextures > 0;
  10029. var floatFragmentTextures = isWebGL2 || !!extensions.get('OES_texture_float');
  10030. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  10031. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  10032. return {
  10033. isWebGL2: isWebGL2,
  10034. getMaxAnisotropy: getMaxAnisotropy,
  10035. getMaxPrecision: getMaxPrecision,
  10036. precision: precision,
  10037. logarithmicDepthBuffer: logarithmicDepthBuffer,
  10038. maxTextures: maxTextures,
  10039. maxVertexTextures: maxVertexTextures,
  10040. maxTextureSize: maxTextureSize,
  10041. maxCubemapSize: maxCubemapSize,
  10042. maxAttributes: maxAttributes,
  10043. maxVertexUniforms: maxVertexUniforms,
  10044. maxVaryings: maxVaryings,
  10045. maxFragmentUniforms: maxFragmentUniforms,
  10046. vertexTextures: vertexTextures,
  10047. floatFragmentTextures: floatFragmentTextures,
  10048. floatVertexTextures: floatVertexTextures,
  10049. maxSamples: maxSamples
  10050. };
  10051. }
  10052. function WebGLClipping(properties) {
  10053. var scope = this;
  10054. var globalState = null,
  10055. numGlobalPlanes = 0,
  10056. localClippingEnabled = false,
  10057. renderingShadows = false;
  10058. var plane = new Plane(),
  10059. viewNormalMatrix = new Matrix3(),
  10060. uniform = {
  10061. value: null,
  10062. needsUpdate: false
  10063. };
  10064. this.uniform = uniform;
  10065. this.numPlanes = 0;
  10066. this.numIntersection = 0;
  10067. this.init = function (planes, enableLocalClipping, camera) {
  10068. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  10069. // run another frame in order to reset the state:
  10070. numGlobalPlanes !== 0 || localClippingEnabled;
  10071. localClippingEnabled = enableLocalClipping;
  10072. globalState = projectPlanes(planes, camera, 0);
  10073. numGlobalPlanes = planes.length;
  10074. return enabled;
  10075. };
  10076. this.beginShadows = function () {
  10077. renderingShadows = true;
  10078. projectPlanes(null);
  10079. };
  10080. this.endShadows = function () {
  10081. renderingShadows = false;
  10082. resetGlobalState();
  10083. };
  10084. this.setState = function (material, camera, useCache) {
  10085. var planes = material.clippingPlanes,
  10086. clipIntersection = material.clipIntersection,
  10087. clipShadows = material.clipShadows;
  10088. var materialProperties = properties.get(material);
  10089. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  10090. // there's no local clipping
  10091. if (renderingShadows) {
  10092. // there's no global clipping
  10093. projectPlanes(null);
  10094. } else {
  10095. resetGlobalState();
  10096. }
  10097. } else {
  10098. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  10099. lGlobal = nGlobal * 4;
  10100. var dstArray = materialProperties.clippingState || null;
  10101. uniform.value = dstArray; // ensure unique state
  10102. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  10103. for (var i = 0; i !== lGlobal; ++i) {
  10104. dstArray[i] = globalState[i];
  10105. }
  10106. materialProperties.clippingState = dstArray;
  10107. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  10108. this.numPlanes += nGlobal;
  10109. }
  10110. };
  10111. function resetGlobalState() {
  10112. if (uniform.value !== globalState) {
  10113. uniform.value = globalState;
  10114. uniform.needsUpdate = numGlobalPlanes > 0;
  10115. }
  10116. scope.numPlanes = numGlobalPlanes;
  10117. scope.numIntersection = 0;
  10118. }
  10119. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  10120. var nPlanes = planes !== null ? planes.length : 0;
  10121. var dstArray = null;
  10122. if (nPlanes !== 0) {
  10123. dstArray = uniform.value;
  10124. if (skipTransform !== true || dstArray === null) {
  10125. var flatSize = dstOffset + nPlanes * 4,
  10126. viewMatrix = camera.matrixWorldInverse;
  10127. viewNormalMatrix.getNormalMatrix(viewMatrix);
  10128. if (dstArray === null || dstArray.length < flatSize) {
  10129. dstArray = new Float32Array(flatSize);
  10130. }
  10131. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  10132. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  10133. plane.normal.toArray(dstArray, i4);
  10134. dstArray[i4 + 3] = plane.constant;
  10135. }
  10136. }
  10137. uniform.value = dstArray;
  10138. uniform.needsUpdate = true;
  10139. }
  10140. scope.numPlanes = nPlanes;
  10141. scope.numIntersection = 0;
  10142. return dstArray;
  10143. }
  10144. }
  10145. function WebGLCubeMaps(renderer) {
  10146. var cubemaps = new WeakMap();
  10147. function mapTextureMapping(texture, mapping) {
  10148. if (mapping === EquirectangularReflectionMapping) {
  10149. texture.mapping = CubeReflectionMapping;
  10150. } else if (mapping === EquirectangularRefractionMapping) {
  10151. texture.mapping = CubeRefractionMapping;
  10152. }
  10153. return texture;
  10154. }
  10155. function get(texture) {
  10156. if (texture && texture.isTexture) {
  10157. var mapping = texture.mapping;
  10158. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  10159. if (cubemaps.has(texture)) {
  10160. var cubemap = cubemaps.get(texture).texture;
  10161. return mapTextureMapping(cubemap, texture.mapping);
  10162. } else {
  10163. var image = texture.image;
  10164. if (image && image.height > 0) {
  10165. var currentRenderList = renderer.getRenderList();
  10166. var currentRenderTarget = renderer.getRenderTarget();
  10167. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  10168. renderTarget.fromEquirectangularTexture(renderer, texture);
  10169. cubemaps.set(texture, renderTarget);
  10170. renderer.setRenderTarget(currentRenderTarget);
  10171. renderer.setRenderList(currentRenderList);
  10172. texture.addEventListener('dispose', onTextureDispose);
  10173. return mapTextureMapping(renderTarget.texture, texture.mapping);
  10174. } else {
  10175. // image not yet ready. try the conversion next frame
  10176. return null;
  10177. }
  10178. }
  10179. }
  10180. }
  10181. return texture;
  10182. }
  10183. function onTextureDispose(event) {
  10184. var texture = event.target;
  10185. texture.removeEventListener('dispose', onTextureDispose);
  10186. var cubemap = cubemaps.get(texture);
  10187. if (cubemap !== undefined) {
  10188. cubemaps.delete(texture);
  10189. cubemap.dispose();
  10190. }
  10191. }
  10192. function dispose() {
  10193. cubemaps = new WeakMap();
  10194. }
  10195. return {
  10196. get: get,
  10197. dispose: dispose
  10198. };
  10199. }
  10200. function WebGLExtensions(gl) {
  10201. var extensions = {};
  10202. function getExtension(name) {
  10203. if (extensions[name] !== undefined) {
  10204. return extensions[name];
  10205. }
  10206. var extension;
  10207. switch (name) {
  10208. case 'WEBGL_depth_texture':
  10209. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  10210. break;
  10211. case 'EXT_texture_filter_anisotropic':
  10212. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  10213. break;
  10214. case 'WEBGL_compressed_texture_s3tc':
  10215. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  10216. break;
  10217. case 'WEBGL_compressed_texture_pvrtc':
  10218. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  10219. break;
  10220. default:
  10221. extension = gl.getExtension(name);
  10222. }
  10223. extensions[name] = extension;
  10224. return extension;
  10225. }
  10226. return {
  10227. has: function has(name) {
  10228. return getExtension(name) !== null;
  10229. },
  10230. init: function init(capabilities) {
  10231. if (capabilities.isWebGL2) {
  10232. getExtension('EXT_color_buffer_float');
  10233. } else {
  10234. getExtension('WEBGL_depth_texture');
  10235. getExtension('OES_texture_float');
  10236. getExtension('OES_texture_half_float');
  10237. getExtension('OES_texture_half_float_linear');
  10238. getExtension('OES_standard_derivatives');
  10239. getExtension('OES_element_index_uint');
  10240. getExtension('OES_vertex_array_object');
  10241. getExtension('ANGLE_instanced_arrays');
  10242. }
  10243. getExtension('OES_texture_float_linear');
  10244. getExtension('EXT_color_buffer_half_float');
  10245. },
  10246. get: function get(name) {
  10247. var extension = getExtension(name);
  10248. if (extension === null) {
  10249. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  10250. }
  10251. return extension;
  10252. }
  10253. };
  10254. }
  10255. function WebGLGeometries(gl, attributes, info, bindingStates) {
  10256. var geometries = {};
  10257. var wireframeAttributes = new WeakMap();
  10258. function onGeometryDispose(event) {
  10259. var geometry = event.target;
  10260. if (geometry.index !== null) {
  10261. attributes.remove(geometry.index);
  10262. }
  10263. for (var name in geometry.attributes) {
  10264. attributes.remove(geometry.attributes[name]);
  10265. }
  10266. geometry.removeEventListener('dispose', onGeometryDispose);
  10267. delete geometries[geometry.id];
  10268. var attribute = wireframeAttributes.get(geometry);
  10269. if (attribute) {
  10270. attributes.remove(attribute);
  10271. wireframeAttributes.delete(geometry);
  10272. }
  10273. bindingStates.releaseStatesOfGeometry(geometry);
  10274. if (geometry.isInstancedBufferGeometry === true) {
  10275. delete geometry._maxInstanceCount;
  10276. } //
  10277. info.memory.geometries--;
  10278. }
  10279. function get(object, geometry) {
  10280. if (geometries[geometry.id] === true) return geometry;
  10281. geometry.addEventListener('dispose', onGeometryDispose);
  10282. geometries[geometry.id] = true;
  10283. info.memory.geometries++;
  10284. return geometry;
  10285. }
  10286. function update(geometry) {
  10287. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  10288. for (var name in geometryAttributes) {
  10289. attributes.update(geometryAttributes[name], 34962);
  10290. } // morph targets
  10291. var morphAttributes = geometry.morphAttributes;
  10292. for (var _name in morphAttributes) {
  10293. var array = morphAttributes[_name];
  10294. for (var i = 0, l = array.length; i < l; i++) {
  10295. attributes.update(array[i], 34962);
  10296. }
  10297. }
  10298. }
  10299. function updateWireframeAttribute(geometry) {
  10300. var indices = [];
  10301. var geometryIndex = geometry.index;
  10302. var geometryPosition = geometry.attributes.position;
  10303. var version = 0;
  10304. if (geometryIndex !== null) {
  10305. var array = geometryIndex.array;
  10306. version = geometryIndex.version;
  10307. for (var i = 0, l = array.length; i < l; i += 3) {
  10308. var a = array[i + 0];
  10309. var b = array[i + 1];
  10310. var c = array[i + 2];
  10311. indices.push(a, b, b, c, c, a);
  10312. }
  10313. } else {
  10314. var _array = geometryPosition.array;
  10315. version = geometryPosition.version;
  10316. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  10317. var _a = _i + 0;
  10318. var _b = _i + 1;
  10319. var _c = _i + 2;
  10320. indices.push(_a, _b, _b, _c, _c, _a);
  10321. }
  10322. }
  10323. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  10324. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  10325. //
  10326. var previousAttribute = wireframeAttributes.get(geometry);
  10327. if (previousAttribute) attributes.remove(previousAttribute); //
  10328. wireframeAttributes.set(geometry, attribute);
  10329. }
  10330. function getWireframeAttribute(geometry) {
  10331. var currentAttribute = wireframeAttributes.get(geometry);
  10332. if (currentAttribute) {
  10333. var geometryIndex = geometry.index;
  10334. if (geometryIndex !== null) {
  10335. // if the attribute is obsolete, create a new one
  10336. if (currentAttribute.version < geometryIndex.version) {
  10337. updateWireframeAttribute(geometry);
  10338. }
  10339. }
  10340. } else {
  10341. updateWireframeAttribute(geometry);
  10342. }
  10343. return wireframeAttributes.get(geometry);
  10344. }
  10345. return {
  10346. get: get,
  10347. update: update,
  10348. getWireframeAttribute: getWireframeAttribute
  10349. };
  10350. }
  10351. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  10352. var isWebGL2 = capabilities.isWebGL2;
  10353. var mode;
  10354. function setMode(value) {
  10355. mode = value;
  10356. }
  10357. var type, bytesPerElement;
  10358. function setIndex(value) {
  10359. type = value.type;
  10360. bytesPerElement = value.bytesPerElement;
  10361. }
  10362. function render(start, count) {
  10363. gl.drawElements(mode, count, type, start * bytesPerElement);
  10364. info.update(count, mode, 1);
  10365. }
  10366. function renderInstances(start, count, primcount) {
  10367. if (primcount === 0) return;
  10368. var extension, methodName;
  10369. if (isWebGL2) {
  10370. extension = gl;
  10371. methodName = 'drawElementsInstanced';
  10372. } else {
  10373. extension = extensions.get('ANGLE_instanced_arrays');
  10374. methodName = 'drawElementsInstancedANGLE';
  10375. if (extension === null) {
  10376. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  10377. return;
  10378. }
  10379. }
  10380. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  10381. info.update(count, mode, primcount);
  10382. } //
  10383. this.setMode = setMode;
  10384. this.setIndex = setIndex;
  10385. this.render = render;
  10386. this.renderInstances = renderInstances;
  10387. }
  10388. function WebGLInfo(gl) {
  10389. var memory = {
  10390. geometries: 0,
  10391. textures: 0
  10392. };
  10393. var render = {
  10394. frame: 0,
  10395. calls: 0,
  10396. triangles: 0,
  10397. points: 0,
  10398. lines: 0
  10399. };
  10400. function update(count, mode, instanceCount) {
  10401. render.calls++;
  10402. switch (mode) {
  10403. case 4:
  10404. render.triangles += instanceCount * (count / 3);
  10405. break;
  10406. case 1:
  10407. render.lines += instanceCount * (count / 2);
  10408. break;
  10409. case 3:
  10410. render.lines += instanceCount * (count - 1);
  10411. break;
  10412. case 2:
  10413. render.lines += instanceCount * count;
  10414. break;
  10415. case 0:
  10416. render.points += instanceCount * count;
  10417. break;
  10418. default:
  10419. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  10420. break;
  10421. }
  10422. }
  10423. function reset() {
  10424. render.frame++;
  10425. render.calls = 0;
  10426. render.triangles = 0;
  10427. render.points = 0;
  10428. render.lines = 0;
  10429. }
  10430. return {
  10431. memory: memory,
  10432. render: render,
  10433. programs: null,
  10434. autoReset: true,
  10435. reset: reset,
  10436. update: update
  10437. };
  10438. }
  10439. function numericalSort(a, b) {
  10440. return a[0] - b[0];
  10441. }
  10442. function absNumericalSort(a, b) {
  10443. return Math.abs(b[1]) - Math.abs(a[1]);
  10444. }
  10445. function WebGLMorphtargets(gl) {
  10446. var influencesList = {};
  10447. var morphInfluences = new Float32Array(8);
  10448. var workInfluences = [];
  10449. for (var i = 0; i < 8; i++) {
  10450. workInfluences[i] = [i, 0];
  10451. }
  10452. function update(object, geometry, material, program) {
  10453. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  10454. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  10455. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  10456. var influences = influencesList[geometry.id];
  10457. if (influences === undefined) {
  10458. // initialise list
  10459. influences = [];
  10460. for (var _i = 0; _i < length; _i++) {
  10461. influences[_i] = [_i, 0];
  10462. }
  10463. influencesList[geometry.id] = influences;
  10464. } // Collect influences
  10465. for (var _i2 = 0; _i2 < length; _i2++) {
  10466. var influence = influences[_i2];
  10467. influence[0] = _i2;
  10468. influence[1] = objectInfluences[_i2];
  10469. }
  10470. influences.sort(absNumericalSort);
  10471. for (var _i3 = 0; _i3 < 8; _i3++) {
  10472. if (_i3 < length && influences[_i3][1]) {
  10473. workInfluences[_i3][0] = influences[_i3][0];
  10474. workInfluences[_i3][1] = influences[_i3][1];
  10475. } else {
  10476. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  10477. workInfluences[_i3][1] = 0;
  10478. }
  10479. }
  10480. workInfluences.sort(numericalSort);
  10481. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  10482. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  10483. var morphInfluencesSum = 0;
  10484. for (var _i4 = 0; _i4 < 8; _i4++) {
  10485. var _influence = workInfluences[_i4];
  10486. var index = _influence[0];
  10487. var value = _influence[1];
  10488. if (index !== Number.MAX_SAFE_INTEGER && value) {
  10489. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  10490. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  10491. }
  10492. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  10493. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  10494. }
  10495. morphInfluences[_i4] = value;
  10496. morphInfluencesSum += value;
  10497. } else {
  10498. if (morphTargets && geometry.hasAttribute('morphTarget' + _i4) === true) {
  10499. geometry.deleteAttribute('morphTarget' + _i4);
  10500. }
  10501. if (morphNormals && geometry.hasAttribute('morphNormal' + _i4) === true) {
  10502. geometry.deleteAttribute('morphNormal' + _i4);
  10503. }
  10504. morphInfluences[_i4] = 0;
  10505. }
  10506. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  10507. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  10508. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  10509. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  10510. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  10511. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  10512. }
  10513. return {
  10514. update: update
  10515. };
  10516. }
  10517. function WebGLObjects(gl, geometries, attributes, info) {
  10518. var updateMap = new WeakMap();
  10519. function update(object) {
  10520. var frame = info.render.frame;
  10521. var geometry = object.geometry;
  10522. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  10523. if (updateMap.get(buffergeometry) !== frame) {
  10524. geometries.update(buffergeometry);
  10525. updateMap.set(buffergeometry, frame);
  10526. }
  10527. if (object.isInstancedMesh) {
  10528. if (object.hasEventListener('dispose', onInstancedMeshDispose) === false) {
  10529. object.addEventListener('dispose', onInstancedMeshDispose);
  10530. }
  10531. attributes.update(object.instanceMatrix, 34962);
  10532. if (object.instanceColor !== null) {
  10533. attributes.update(object.instanceColor, 34962);
  10534. }
  10535. }
  10536. return buffergeometry;
  10537. }
  10538. function dispose() {
  10539. updateMap = new WeakMap();
  10540. }
  10541. function onInstancedMeshDispose(event) {
  10542. var instancedMesh = event.target;
  10543. instancedMesh.removeEventListener('dispose', onInstancedMeshDispose);
  10544. attributes.remove(instancedMesh.instanceMatrix);
  10545. if (instancedMesh.instanceColor !== null) attributes.remove(instancedMesh.instanceColor);
  10546. }
  10547. return {
  10548. update: update,
  10549. dispose: dispose
  10550. };
  10551. }
  10552. function DataTexture2DArray(data, width, height, depth) {
  10553. if (data === void 0) {
  10554. data = null;
  10555. }
  10556. if (width === void 0) {
  10557. width = 1;
  10558. }
  10559. if (height === void 0) {
  10560. height = 1;
  10561. }
  10562. if (depth === void 0) {
  10563. depth = 1;
  10564. }
  10565. Texture.call(this, null);
  10566. this.image = {
  10567. data: data,
  10568. width: width,
  10569. height: height,
  10570. depth: depth
  10571. };
  10572. this.magFilter = NearestFilter;
  10573. this.minFilter = NearestFilter;
  10574. this.wrapR = ClampToEdgeWrapping;
  10575. this.generateMipmaps = false;
  10576. this.flipY = false;
  10577. this.needsUpdate = true;
  10578. }
  10579. DataTexture2DArray.prototype = Object.create(Texture.prototype);
  10580. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  10581. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  10582. function DataTexture3D(data, width, height, depth) {
  10583. if (data === void 0) {
  10584. data = null;
  10585. }
  10586. if (width === void 0) {
  10587. width = 1;
  10588. }
  10589. if (height === void 0) {
  10590. height = 1;
  10591. }
  10592. if (depth === void 0) {
  10593. depth = 1;
  10594. }
  10595. // We're going to add .setXXX() methods for setting properties later.
  10596. // Users can still set in DataTexture3D directly.
  10597. //
  10598. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  10599. // texture.anisotropy = 16;
  10600. //
  10601. // See #14839
  10602. Texture.call(this, null);
  10603. this.image = {
  10604. data: data,
  10605. width: width,
  10606. height: height,
  10607. depth: depth
  10608. };
  10609. this.magFilter = NearestFilter;
  10610. this.minFilter = NearestFilter;
  10611. this.wrapR = ClampToEdgeWrapping;
  10612. this.generateMipmaps = false;
  10613. this.flipY = false;
  10614. this.needsUpdate = true;
  10615. }
  10616. DataTexture3D.prototype = Object.create(Texture.prototype);
  10617. DataTexture3D.prototype.constructor = DataTexture3D;
  10618. DataTexture3D.prototype.isDataTexture3D = true;
  10619. /**
  10620. * Uniforms of a program.
  10621. * Those form a tree structure with a special top-level container for the root,
  10622. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10623. *
  10624. *
  10625. * Properties of inner nodes including the top-level container:
  10626. *
  10627. * .seq - array of nested uniforms
  10628. * .map - nested uniforms by name
  10629. *
  10630. *
  10631. * Methods of all nodes except the top-level container:
  10632. *
  10633. * .setValue( gl, value, [textures] )
  10634. *
  10635. * uploads a uniform value(s)
  10636. * the 'textures' parameter is needed for sampler uniforms
  10637. *
  10638. *
  10639. * Static methods of the top-level container (textures factorizations):
  10640. *
  10641. * .upload( gl, seq, values, textures )
  10642. *
  10643. * sets uniforms in 'seq' to 'values[id].value'
  10644. *
  10645. * .seqWithValue( seq, values ) : filteredSeq
  10646. *
  10647. * filters 'seq' entries with corresponding entry in values
  10648. *
  10649. *
  10650. * Methods of the top-level container (textures factorizations):
  10651. *
  10652. * .setValue( gl, name, value, textures )
  10653. *
  10654. * sets uniform with name 'name' to 'value'
  10655. *
  10656. * .setOptional( gl, obj, prop )
  10657. *
  10658. * like .set for an optional property of the object
  10659. *
  10660. */
  10661. var emptyTexture = new Texture();
  10662. var emptyTexture2dArray = new DataTexture2DArray();
  10663. var emptyTexture3d = new DataTexture3D();
  10664. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  10665. // Array Caches (provide typed arrays for temporary by size)
  10666. var arrayCacheF32 = [];
  10667. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  10668. var mat4array = new Float32Array(16);
  10669. var mat3array = new Float32Array(9);
  10670. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  10671. function flatten(array, nBlocks, blockSize) {
  10672. var firstElem = array[0];
  10673. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  10674. // see http://jacksondunstan.com/articles/983
  10675. var n = nBlocks * blockSize;
  10676. var r = arrayCacheF32[n];
  10677. if (r === undefined) {
  10678. r = new Float32Array(n);
  10679. arrayCacheF32[n] = r;
  10680. }
  10681. if (nBlocks !== 0) {
  10682. firstElem.toArray(r, 0);
  10683. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  10684. offset += blockSize;
  10685. array[i].toArray(r, offset);
  10686. }
  10687. }
  10688. return r;
  10689. }
  10690. function arraysEqual(a, b) {
  10691. if (a.length !== b.length) return false;
  10692. for (var i = 0, l = a.length; i < l; i++) {
  10693. if (a[i] !== b[i]) return false;
  10694. }
  10695. return true;
  10696. }
  10697. function copyArray(a, b) {
  10698. for (var i = 0, l = b.length; i < l; i++) {
  10699. a[i] = b[i];
  10700. }
  10701. } // Texture unit allocation
  10702. function allocTexUnits(textures, n) {
  10703. var r = arrayCacheI32[n];
  10704. if (r === undefined) {
  10705. r = new Int32Array(n);
  10706. arrayCacheI32[n] = r;
  10707. }
  10708. for (var i = 0; i !== n; ++i) {
  10709. r[i] = textures.allocateTextureUnit();
  10710. }
  10711. return r;
  10712. } // --- Setters ---
  10713. // Note: Defining these methods externally, because they come in a bunch
  10714. // and this way their names minify.
  10715. // Single scalar
  10716. function setValueV1f(gl, v) {
  10717. var cache = this.cache;
  10718. if (cache[0] === v) return;
  10719. gl.uniform1f(this.addr, v);
  10720. cache[0] = v;
  10721. } // Single float vector (from flat array or THREE.VectorN)
  10722. function setValueV2f(gl, v) {
  10723. var cache = this.cache;
  10724. if (v.x !== undefined) {
  10725. if (cache[0] !== v.x || cache[1] !== v.y) {
  10726. gl.uniform2f(this.addr, v.x, v.y);
  10727. cache[0] = v.x;
  10728. cache[1] = v.y;
  10729. }
  10730. } else {
  10731. if (arraysEqual(cache, v)) return;
  10732. gl.uniform2fv(this.addr, v);
  10733. copyArray(cache, v);
  10734. }
  10735. }
  10736. function setValueV3f(gl, v) {
  10737. var cache = this.cache;
  10738. if (v.x !== undefined) {
  10739. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10740. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10741. cache[0] = v.x;
  10742. cache[1] = v.y;
  10743. cache[2] = v.z;
  10744. }
  10745. } else if (v.r !== undefined) {
  10746. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10747. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10748. cache[0] = v.r;
  10749. cache[1] = v.g;
  10750. cache[2] = v.b;
  10751. }
  10752. } else {
  10753. if (arraysEqual(cache, v)) return;
  10754. gl.uniform3fv(this.addr, v);
  10755. copyArray(cache, v);
  10756. }
  10757. }
  10758. function setValueV4f(gl, v) {
  10759. var cache = this.cache;
  10760. if (v.x !== undefined) {
  10761. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10762. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10763. cache[0] = v.x;
  10764. cache[1] = v.y;
  10765. cache[2] = v.z;
  10766. cache[3] = v.w;
  10767. }
  10768. } else {
  10769. if (arraysEqual(cache, v)) return;
  10770. gl.uniform4fv(this.addr, v);
  10771. copyArray(cache, v);
  10772. }
  10773. } // Single matrix (from flat array or MatrixN)
  10774. function setValueM2(gl, v) {
  10775. var cache = this.cache;
  10776. var elements = v.elements;
  10777. if (elements === undefined) {
  10778. if (arraysEqual(cache, v)) return;
  10779. gl.uniformMatrix2fv(this.addr, false, v);
  10780. copyArray(cache, v);
  10781. } else {
  10782. if (arraysEqual(cache, elements)) return;
  10783. mat2array.set(elements);
  10784. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10785. copyArray(cache, elements);
  10786. }
  10787. }
  10788. function setValueM3(gl, v) {
  10789. var cache = this.cache;
  10790. var elements = v.elements;
  10791. if (elements === undefined) {
  10792. if (arraysEqual(cache, v)) return;
  10793. gl.uniformMatrix3fv(this.addr, false, v);
  10794. copyArray(cache, v);
  10795. } else {
  10796. if (arraysEqual(cache, elements)) return;
  10797. mat3array.set(elements);
  10798. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10799. copyArray(cache, elements);
  10800. }
  10801. }
  10802. function setValueM4(gl, v) {
  10803. var cache = this.cache;
  10804. var elements = v.elements;
  10805. if (elements === undefined) {
  10806. if (arraysEqual(cache, v)) return;
  10807. gl.uniformMatrix4fv(this.addr, false, v);
  10808. copyArray(cache, v);
  10809. } else {
  10810. if (arraysEqual(cache, elements)) return;
  10811. mat4array.set(elements);
  10812. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10813. copyArray(cache, elements);
  10814. }
  10815. } // Single texture (2D / Cube)
  10816. function setValueT1(gl, v, textures) {
  10817. var cache = this.cache;
  10818. var unit = textures.allocateTextureUnit();
  10819. if (cache[0] !== unit) {
  10820. gl.uniform1i(this.addr, unit);
  10821. cache[0] = unit;
  10822. }
  10823. textures.safeSetTexture2D(v || emptyTexture, unit);
  10824. }
  10825. function setValueT2DArray1(gl, v, textures) {
  10826. var cache = this.cache;
  10827. var unit = textures.allocateTextureUnit();
  10828. if (cache[0] !== unit) {
  10829. gl.uniform1i(this.addr, unit);
  10830. cache[0] = unit;
  10831. }
  10832. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10833. }
  10834. function setValueT3D1(gl, v, textures) {
  10835. var cache = this.cache;
  10836. var unit = textures.allocateTextureUnit();
  10837. if (cache[0] !== unit) {
  10838. gl.uniform1i(this.addr, unit);
  10839. cache[0] = unit;
  10840. }
  10841. textures.setTexture3D(v || emptyTexture3d, unit);
  10842. }
  10843. function setValueT6(gl, v, textures) {
  10844. var cache = this.cache;
  10845. var unit = textures.allocateTextureUnit();
  10846. if (cache[0] !== unit) {
  10847. gl.uniform1i(this.addr, unit);
  10848. cache[0] = unit;
  10849. }
  10850. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10851. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10852. function setValueV1i(gl, v) {
  10853. var cache = this.cache;
  10854. if (cache[0] === v) return;
  10855. gl.uniform1i(this.addr, v);
  10856. cache[0] = v;
  10857. }
  10858. function setValueV2i(gl, v) {
  10859. var cache = this.cache;
  10860. if (arraysEqual(cache, v)) return;
  10861. gl.uniform2iv(this.addr, v);
  10862. copyArray(cache, v);
  10863. }
  10864. function setValueV3i(gl, v) {
  10865. var cache = this.cache;
  10866. if (arraysEqual(cache, v)) return;
  10867. gl.uniform3iv(this.addr, v);
  10868. copyArray(cache, v);
  10869. }
  10870. function setValueV4i(gl, v) {
  10871. var cache = this.cache;
  10872. if (arraysEqual(cache, v)) return;
  10873. gl.uniform4iv(this.addr, v);
  10874. copyArray(cache, v);
  10875. } // uint
  10876. function setValueV1ui(gl, v) {
  10877. var cache = this.cache;
  10878. if (cache[0] === v) return;
  10879. gl.uniform1ui(this.addr, v);
  10880. cache[0] = v;
  10881. } // Helper to pick the right setter for the singular case
  10882. function getSingularSetter(type) {
  10883. switch (type) {
  10884. case 0x1406:
  10885. return setValueV1f;
  10886. // FLOAT
  10887. case 0x8b50:
  10888. return setValueV2f;
  10889. // _VEC2
  10890. case 0x8b51:
  10891. return setValueV3f;
  10892. // _VEC3
  10893. case 0x8b52:
  10894. return setValueV4f;
  10895. // _VEC4
  10896. case 0x8b5a:
  10897. return setValueM2;
  10898. // _MAT2
  10899. case 0x8b5b:
  10900. return setValueM3;
  10901. // _MAT3
  10902. case 0x8b5c:
  10903. return setValueM4;
  10904. // _MAT4
  10905. case 0x1404:
  10906. case 0x8b56:
  10907. return setValueV1i;
  10908. // INT, BOOL
  10909. case 0x8b53:
  10910. case 0x8b57:
  10911. return setValueV2i;
  10912. // _VEC2
  10913. case 0x8b54:
  10914. case 0x8b58:
  10915. return setValueV3i;
  10916. // _VEC3
  10917. case 0x8b55:
  10918. case 0x8b59:
  10919. return setValueV4i;
  10920. // _VEC4
  10921. case 0x1405:
  10922. return setValueV1ui;
  10923. // UINT
  10924. case 0x8b5e: // SAMPLER_2D
  10925. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10926. case 0x8dca: // INT_SAMPLER_2D
  10927. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10928. case 0x8b62:
  10929. // SAMPLER_2D_SHADOW
  10930. return setValueT1;
  10931. case 0x8b5f: // SAMPLER_3D
  10932. case 0x8dcb: // INT_SAMPLER_3D
  10933. case 0x8dd3:
  10934. // UNSIGNED_INT_SAMPLER_3D
  10935. return setValueT3D1;
  10936. case 0x8b60: // SAMPLER_CUBE
  10937. case 0x8dcc: // INT_SAMPLER_CUBE
  10938. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10939. case 0x8dc5:
  10940. // SAMPLER_CUBE_SHADOW
  10941. return setValueT6;
  10942. case 0x8dc1: // SAMPLER_2D_ARRAY
  10943. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10944. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10945. case 0x8dc4:
  10946. // SAMPLER_2D_ARRAY_SHADOW
  10947. return setValueT2DArray1;
  10948. }
  10949. } // Array of scalars
  10950. function setValueV1fArray(gl, v) {
  10951. gl.uniform1fv(this.addr, v);
  10952. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10953. function setValueV1iArray(gl, v) {
  10954. gl.uniform1iv(this.addr, v);
  10955. }
  10956. function setValueV2iArray(gl, v) {
  10957. gl.uniform2iv(this.addr, v);
  10958. }
  10959. function setValueV3iArray(gl, v) {
  10960. gl.uniform3iv(this.addr, v);
  10961. }
  10962. function setValueV4iArray(gl, v) {
  10963. gl.uniform4iv(this.addr, v);
  10964. } // Array of vectors (flat or from THREE classes)
  10965. function setValueV2fArray(gl, v) {
  10966. var data = flatten(v, this.size, 2);
  10967. gl.uniform2fv(this.addr, data);
  10968. }
  10969. function setValueV3fArray(gl, v) {
  10970. var data = flatten(v, this.size, 3);
  10971. gl.uniform3fv(this.addr, data);
  10972. }
  10973. function setValueV4fArray(gl, v) {
  10974. var data = flatten(v, this.size, 4);
  10975. gl.uniform4fv(this.addr, data);
  10976. } // Array of matrices (flat or from THREE clases)
  10977. function setValueM2Array(gl, v) {
  10978. var data = flatten(v, this.size, 4);
  10979. gl.uniformMatrix2fv(this.addr, false, data);
  10980. }
  10981. function setValueM3Array(gl, v) {
  10982. var data = flatten(v, this.size, 9);
  10983. gl.uniformMatrix3fv(this.addr, false, data);
  10984. }
  10985. function setValueM4Array(gl, v) {
  10986. var data = flatten(v, this.size, 16);
  10987. gl.uniformMatrix4fv(this.addr, false, data);
  10988. } // Array of textures (2D / Cube)
  10989. function setValueT1Array(gl, v, textures) {
  10990. var n = v.length;
  10991. var units = allocTexUnits(textures, n);
  10992. gl.uniform1iv(this.addr, units);
  10993. for (var i = 0; i !== n; ++i) {
  10994. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  10995. }
  10996. }
  10997. function setValueT6Array(gl, v, textures) {
  10998. var n = v.length;
  10999. var units = allocTexUnits(textures, n);
  11000. gl.uniform1iv(this.addr, units);
  11001. for (var i = 0; i !== n; ++i) {
  11002. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  11003. }
  11004. } // Helper to pick the right setter for a pure (bottom-level) array
  11005. function getPureArraySetter(type) {
  11006. switch (type) {
  11007. case 0x1406:
  11008. return setValueV1fArray;
  11009. // FLOAT
  11010. case 0x8b50:
  11011. return setValueV2fArray;
  11012. // _VEC2
  11013. case 0x8b51:
  11014. return setValueV3fArray;
  11015. // _VEC3
  11016. case 0x8b52:
  11017. return setValueV4fArray;
  11018. // _VEC4
  11019. case 0x8b5a:
  11020. return setValueM2Array;
  11021. // _MAT2
  11022. case 0x8b5b:
  11023. return setValueM3Array;
  11024. // _MAT3
  11025. case 0x8b5c:
  11026. return setValueM4Array;
  11027. // _MAT4
  11028. case 0x1404:
  11029. case 0x8b56:
  11030. return setValueV1iArray;
  11031. // INT, BOOL
  11032. case 0x8b53:
  11033. case 0x8b57:
  11034. return setValueV2iArray;
  11035. // _VEC2
  11036. case 0x8b54:
  11037. case 0x8b58:
  11038. return setValueV3iArray;
  11039. // _VEC3
  11040. case 0x8b55:
  11041. case 0x8b59:
  11042. return setValueV4iArray;
  11043. // _VEC4
  11044. case 0x8b5e: // SAMPLER_2D
  11045. case 0x8d66: // SAMPLER_EXTERNAL_OES
  11046. case 0x8dca: // INT_SAMPLER_2D
  11047. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  11048. case 0x8b62:
  11049. // SAMPLER_2D_SHADOW
  11050. return setValueT1Array;
  11051. case 0x8b60: // SAMPLER_CUBE
  11052. case 0x8dcc: // INT_SAMPLER_CUBE
  11053. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  11054. case 0x8dc5:
  11055. // SAMPLER_CUBE_SHADOW
  11056. return setValueT6Array;
  11057. }
  11058. } // --- Uniform Classes ---
  11059. function SingleUniform(id, activeInfo, addr) {
  11060. this.id = id;
  11061. this.addr = addr;
  11062. this.cache = [];
  11063. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  11064. }
  11065. function PureArrayUniform(id, activeInfo, addr) {
  11066. this.id = id;
  11067. this.addr = addr;
  11068. this.cache = [];
  11069. this.size = activeInfo.size;
  11070. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  11071. }
  11072. PureArrayUniform.prototype.updateCache = function (data) {
  11073. var cache = this.cache;
  11074. if (data instanceof Float32Array && cache.length !== data.length) {
  11075. this.cache = new Float32Array(data.length);
  11076. }
  11077. copyArray(cache, data);
  11078. };
  11079. function StructuredUniform(id) {
  11080. this.id = id;
  11081. this.seq = [];
  11082. this.map = {};
  11083. }
  11084. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  11085. var seq = this.seq;
  11086. for (var i = 0, n = seq.length; i !== n; ++i) {
  11087. var u = seq[i];
  11088. u.setValue(gl, value[u.id], textures);
  11089. }
  11090. }; // --- Top-level ---
  11091. // Parser - builds up the property tree from the path strings
  11092. var RePathPart = /(\w+)(\])?(\[|\.)?/g; // extracts
  11093. // - the identifier (member name or array index)
  11094. // - followed by an optional right bracket (found when array index)
  11095. // - followed by an optional left bracket or dot (type of subscript)
  11096. //
  11097. // Note: These portions can be read in a non-overlapping fashion and
  11098. // allow straightforward parsing of the hierarchy that WebGL encodes
  11099. // in the uniform names.
  11100. function addUniform(container, uniformObject) {
  11101. container.seq.push(uniformObject);
  11102. container.map[uniformObject.id] = uniformObject;
  11103. }
  11104. function parseUniform(activeInfo, addr, container) {
  11105. var path = activeInfo.name,
  11106. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  11107. RePathPart.lastIndex = 0;
  11108. while (true) {
  11109. var match = RePathPart.exec(path),
  11110. matchEnd = RePathPart.lastIndex;
  11111. var id = match[1];
  11112. var idIsIndex = match[2] === ']',
  11113. subscript = match[3];
  11114. if (idIsIndex) id = id | 0; // convert to integer
  11115. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  11116. // bare name or "pure" bottom-level array "[0]" suffix
  11117. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  11118. break;
  11119. } else {
  11120. // step into inner node / create it in case it doesn't exist
  11121. var map = container.map;
  11122. var next = map[id];
  11123. if (next === undefined) {
  11124. next = new StructuredUniform(id);
  11125. addUniform(container, next);
  11126. }
  11127. container = next;
  11128. }
  11129. }
  11130. } // Root Container
  11131. function WebGLUniforms(gl, program) {
  11132. this.seq = [];
  11133. this.map = {};
  11134. var n = gl.getProgramParameter(program, 35718);
  11135. for (var i = 0; i < n; ++i) {
  11136. var info = gl.getActiveUniform(program, i),
  11137. addr = gl.getUniformLocation(program, info.name);
  11138. parseUniform(info, addr, this);
  11139. }
  11140. }
  11141. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  11142. var u = this.map[name];
  11143. if (u !== undefined) u.setValue(gl, value, textures);
  11144. };
  11145. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  11146. var v = object[name];
  11147. if (v !== undefined) this.setValue(gl, name, v);
  11148. }; // Static interface
  11149. WebGLUniforms.upload = function (gl, seq, values, textures) {
  11150. for (var i = 0, n = seq.length; i !== n; ++i) {
  11151. var u = seq[i],
  11152. v = values[u.id];
  11153. if (v.needsUpdate !== false) {
  11154. // note: always updating when .needsUpdate is undefined
  11155. u.setValue(gl, v.value, textures);
  11156. }
  11157. }
  11158. };
  11159. WebGLUniforms.seqWithValue = function (seq, values) {
  11160. var r = [];
  11161. for (var i = 0, n = seq.length; i !== n; ++i) {
  11162. var u = seq[i];
  11163. if (u.id in values) r.push(u);
  11164. }
  11165. return r;
  11166. };
  11167. function WebGLShader(gl, type, string) {
  11168. var shader = gl.createShader(type);
  11169. gl.shaderSource(shader, string);
  11170. gl.compileShader(shader);
  11171. return shader;
  11172. }
  11173. var programIdCount = 0;
  11174. function addLineNumbers(string) {
  11175. var lines = string.split('\n');
  11176. for (var i = 0; i < lines.length; i++) {
  11177. lines[i] = i + 1 + ': ' + lines[i];
  11178. }
  11179. return lines.join('\n');
  11180. }
  11181. function getEncodingComponents(encoding) {
  11182. switch (encoding) {
  11183. case LinearEncoding:
  11184. return ['Linear', '( value )'];
  11185. case sRGBEncoding:
  11186. return ['sRGB', '( value )'];
  11187. case RGBEEncoding:
  11188. return ['RGBE', '( value )'];
  11189. case RGBM7Encoding:
  11190. return ['RGBM', '( value, 7.0 )'];
  11191. case RGBM16Encoding:
  11192. return ['RGBM', '( value, 16.0 )'];
  11193. case RGBDEncoding:
  11194. return ['RGBD', '( value, 256.0 )'];
  11195. case GammaEncoding:
  11196. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  11197. case LogLuvEncoding:
  11198. return ['LogLuv', '( value )'];
  11199. default:
  11200. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  11201. return ['Linear', '( value )'];
  11202. }
  11203. }
  11204. function getShaderErrors(gl, shader, type) {
  11205. var status = gl.getShaderParameter(shader, 35713);
  11206. var log = gl.getShaderInfoLog(shader).trim();
  11207. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  11208. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  11209. var source = gl.getShaderSource(shader);
  11210. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  11211. }
  11212. function getTexelDecodingFunction(functionName, encoding) {
  11213. var components = getEncodingComponents(encoding);
  11214. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  11215. }
  11216. function getTexelEncodingFunction(functionName, encoding) {
  11217. var components = getEncodingComponents(encoding);
  11218. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  11219. }
  11220. function getToneMappingFunction(functionName, toneMapping) {
  11221. var toneMappingName;
  11222. switch (toneMapping) {
  11223. case LinearToneMapping:
  11224. toneMappingName = 'Linear';
  11225. break;
  11226. case ReinhardToneMapping:
  11227. toneMappingName = 'Reinhard';
  11228. break;
  11229. case CineonToneMapping:
  11230. toneMappingName = 'OptimizedCineon';
  11231. break;
  11232. case ACESFilmicToneMapping:
  11233. toneMappingName = 'ACESFilmic';
  11234. break;
  11235. case CustomToneMapping:
  11236. toneMappingName = 'Custom';
  11237. break;
  11238. default:
  11239. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  11240. toneMappingName = 'Linear';
  11241. }
  11242. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  11243. }
  11244. function generateExtensions(parameters) {
  11245. 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' : ''];
  11246. return chunks.filter(filterEmptyLine).join('\n');
  11247. }
  11248. function generateDefines(defines) {
  11249. var chunks = [];
  11250. for (var name in defines) {
  11251. var value = defines[name];
  11252. if (value === false) continue;
  11253. chunks.push('#define ' + name + ' ' + value);
  11254. }
  11255. return chunks.join('\n');
  11256. }
  11257. function fetchAttributeLocations(gl, program) {
  11258. var attributes = {};
  11259. var n = gl.getProgramParameter(program, 35721);
  11260. for (var i = 0; i < n; i++) {
  11261. var info = gl.getActiveAttrib(program, i);
  11262. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  11263. attributes[name] = gl.getAttribLocation(program, name);
  11264. }
  11265. return attributes;
  11266. }
  11267. function filterEmptyLine(string) {
  11268. return string !== '';
  11269. }
  11270. function replaceLightNums(string, parameters) {
  11271. 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);
  11272. }
  11273. function replaceClippingPlaneNums(string, parameters) {
  11274. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  11275. } // Resolve Includes
  11276. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  11277. function resolveIncludes(string) {
  11278. return string.replace(includePattern, includeReplacer);
  11279. }
  11280. function includeReplacer(match, include) {
  11281. var string = ShaderChunk[include];
  11282. if (string === undefined) {
  11283. throw new Error('Can not resolve #include <' + include + '>');
  11284. }
  11285. return resolveIncludes(string);
  11286. } // Unroll Loops
  11287. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  11288. 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;
  11289. function unrollLoops(string) {
  11290. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  11291. }
  11292. function deprecatedLoopReplacer(match, start, end, snippet) {
  11293. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  11294. return loopReplacer(match, start, end, snippet);
  11295. }
  11296. function loopReplacer(match, start, end, snippet) {
  11297. var string = '';
  11298. for (var i = parseInt(start); i < parseInt(end); i++) {
  11299. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  11300. }
  11301. return string;
  11302. } //
  11303. function generatePrecision(parameters) {
  11304. var precisionstring = 'precision ' + parameters.precision + ' float;\nprecision ' + parameters.precision + ' int;';
  11305. if (parameters.precision === 'highp') {
  11306. precisionstring += '\n#define HIGH_PRECISION';
  11307. } else if (parameters.precision === 'mediump') {
  11308. precisionstring += '\n#define MEDIUM_PRECISION';
  11309. } else if (parameters.precision === 'lowp') {
  11310. precisionstring += '\n#define LOW_PRECISION';
  11311. }
  11312. return precisionstring;
  11313. }
  11314. function generateShadowMapTypeDefine(parameters) {
  11315. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  11316. if (parameters.shadowMapType === PCFShadowMap) {
  11317. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  11318. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  11319. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  11320. } else if (parameters.shadowMapType === VSMShadowMap) {
  11321. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  11322. }
  11323. return shadowMapTypeDefine;
  11324. }
  11325. function generateEnvMapTypeDefine(parameters) {
  11326. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11327. if (parameters.envMap) {
  11328. switch (parameters.envMapMode) {
  11329. case CubeReflectionMapping:
  11330. case CubeRefractionMapping:
  11331. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11332. break;
  11333. case CubeUVReflectionMapping:
  11334. case CubeUVRefractionMapping:
  11335. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  11336. break;
  11337. }
  11338. }
  11339. return envMapTypeDefine;
  11340. }
  11341. function generateEnvMapModeDefine(parameters) {
  11342. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  11343. if (parameters.envMap) {
  11344. switch (parameters.envMapMode) {
  11345. case CubeRefractionMapping:
  11346. case CubeUVRefractionMapping:
  11347. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  11348. break;
  11349. }
  11350. }
  11351. return envMapModeDefine;
  11352. }
  11353. function generateEnvMapBlendingDefine(parameters) {
  11354. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  11355. if (parameters.envMap) {
  11356. switch (parameters.combine) {
  11357. case MultiplyOperation:
  11358. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  11359. break;
  11360. case MixOperation:
  11361. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  11362. break;
  11363. case AddOperation:
  11364. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  11365. break;
  11366. }
  11367. }
  11368. return envMapBlendingDefine;
  11369. }
  11370. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  11371. var gl = renderer.getContext();
  11372. var defines = parameters.defines;
  11373. var vertexShader = parameters.vertexShader;
  11374. var fragmentShader = parameters.fragmentShader;
  11375. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  11376. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  11377. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  11378. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  11379. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  11380. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  11381. var customDefines = generateDefines(defines);
  11382. var program = gl.createProgram();
  11383. var prefixVertex, prefixFragment;
  11384. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : '';
  11385. if (parameters.isRawShaderMaterial) {
  11386. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  11387. if (prefixVertex.length > 0) {
  11388. prefixVertex += '\n';
  11389. }
  11390. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  11391. if (prefixFragment.length > 0) {
  11392. prefixFragment += '\n';
  11393. }
  11394. } else {
  11395. 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');
  11396. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  11397. '#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
  11398. 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
  11399. 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');
  11400. }
  11401. vertexShader = resolveIncludes(vertexShader);
  11402. vertexShader = replaceLightNums(vertexShader, parameters);
  11403. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  11404. fragmentShader = resolveIncludes(fragmentShader);
  11405. fragmentShader = replaceLightNums(fragmentShader, parameters);
  11406. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  11407. vertexShader = unrollLoops(vertexShader);
  11408. fragmentShader = unrollLoops(fragmentShader);
  11409. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  11410. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  11411. versionString = '#version 300 es\n';
  11412. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  11413. 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;
  11414. }
  11415. var vertexGlsl = versionString + prefixVertex + vertexShader;
  11416. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  11417. // console.log( '*FRAGMENT*', fragmentGlsl );
  11418. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  11419. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  11420. gl.attachShader(program, glVertexShader);
  11421. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  11422. if (parameters.index0AttributeName !== undefined) {
  11423. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  11424. } else if (parameters.morphTargets === true) {
  11425. // programs with morphTargets displace position out of attribute 0
  11426. gl.bindAttribLocation(program, 0, 'position');
  11427. }
  11428. gl.linkProgram(program); // check for link errors
  11429. if (renderer.debug.checkShaderErrors) {
  11430. var programLog = gl.getProgramInfoLog(program).trim();
  11431. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  11432. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  11433. var runnable = true;
  11434. var haveDiagnostics = true;
  11435. if (gl.getProgramParameter(program, 35714) === false) {
  11436. runnable = false;
  11437. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  11438. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  11439. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  11440. } else if (programLog !== '') {
  11441. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  11442. } else if (vertexLog === '' || fragmentLog === '') {
  11443. haveDiagnostics = false;
  11444. }
  11445. if (haveDiagnostics) {
  11446. this.diagnostics = {
  11447. runnable: runnable,
  11448. programLog: programLog,
  11449. vertexShader: {
  11450. log: vertexLog,
  11451. prefix: prefixVertex
  11452. },
  11453. fragmentShader: {
  11454. log: fragmentLog,
  11455. prefix: prefixFragment
  11456. }
  11457. };
  11458. }
  11459. } // Clean up
  11460. // Crashes in iOS9 and iOS10. #18402
  11461. // gl.detachShader( program, glVertexShader );
  11462. // gl.detachShader( program, glFragmentShader );
  11463. gl.deleteShader(glVertexShader);
  11464. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  11465. var cachedUniforms;
  11466. this.getUniforms = function () {
  11467. if (cachedUniforms === undefined) {
  11468. cachedUniforms = new WebGLUniforms(gl, program);
  11469. }
  11470. return cachedUniforms;
  11471. }; // set up caching for attribute locations
  11472. var cachedAttributes;
  11473. this.getAttributes = function () {
  11474. if (cachedAttributes === undefined) {
  11475. cachedAttributes = fetchAttributeLocations(gl, program);
  11476. }
  11477. return cachedAttributes;
  11478. }; // free resource
  11479. this.destroy = function () {
  11480. bindingStates.releaseStatesOfProgram(this);
  11481. gl.deleteProgram(program);
  11482. this.program = undefined;
  11483. }; //
  11484. this.name = parameters.shaderName;
  11485. this.id = programIdCount++;
  11486. this.cacheKey = cacheKey;
  11487. this.usedTimes = 1;
  11488. this.program = program;
  11489. this.vertexShader = glVertexShader;
  11490. this.fragmentShader = glFragmentShader;
  11491. return this;
  11492. }
  11493. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  11494. var programs = [];
  11495. var isWebGL2 = capabilities.isWebGL2;
  11496. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  11497. var floatVertexTextures = capabilities.floatVertexTextures;
  11498. var maxVertexUniforms = capabilities.maxVertexUniforms;
  11499. var vertexTextures = capabilities.vertexTextures;
  11500. var precision = capabilities.precision;
  11501. var shaderIDs = {
  11502. MeshDepthMaterial: 'depth',
  11503. MeshDistanceMaterial: 'distanceRGBA',
  11504. MeshNormalMaterial: 'normal',
  11505. MeshBasicMaterial: 'basic',
  11506. MeshLambertMaterial: 'lambert',
  11507. MeshPhongMaterial: 'phong',
  11508. MeshToonMaterial: 'toon',
  11509. MeshStandardMaterial: 'physical',
  11510. MeshPhysicalMaterial: 'physical',
  11511. MeshMatcapMaterial: 'matcap',
  11512. LineBasicMaterial: 'basic',
  11513. LineDashedMaterial: 'dashed',
  11514. PointsMaterial: 'points',
  11515. ShadowMaterial: 'shadow',
  11516. SpriteMaterial: 'sprite'
  11517. };
  11518. 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'];
  11519. function getMaxBones(object) {
  11520. var skeleton = object.skeleton;
  11521. var bones = skeleton.bones;
  11522. if (floatVertexTextures) {
  11523. return 1024;
  11524. } else {
  11525. // default for when object is not specified
  11526. // ( for example when prebuilding shader to be used with multiple objects )
  11527. //
  11528. // - leave some extra space for other uniforms
  11529. // - limit here is ANGLE's 254 max uniform vectors
  11530. // (up to 54 should be safe)
  11531. var nVertexUniforms = maxVertexUniforms;
  11532. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  11533. var maxBones = Math.min(nVertexMatrices, bones.length);
  11534. if (maxBones < bones.length) {
  11535. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  11536. return 0;
  11537. }
  11538. return maxBones;
  11539. }
  11540. }
  11541. function getTextureEncodingFromMap(map) {
  11542. var encoding;
  11543. if (map && map.isTexture) {
  11544. encoding = map.encoding;
  11545. } else if (map && map.isWebGLRenderTarget) {
  11546. console.warn('THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.');
  11547. encoding = map.texture.encoding;
  11548. } else {
  11549. encoding = LinearEncoding;
  11550. }
  11551. return encoding;
  11552. }
  11553. function getParameters(material, lights, shadows, scene, object) {
  11554. var fog = scene.fog;
  11555. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  11556. var envMap = cubemaps.get(material.envMap || environment);
  11557. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  11558. // (not to blow over maxLights budget)
  11559. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  11560. if (material.precision !== null) {
  11561. precision = capabilities.getMaxPrecision(material.precision);
  11562. if (precision !== material.precision) {
  11563. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  11564. }
  11565. }
  11566. var vertexShader, fragmentShader;
  11567. if (shaderID) {
  11568. var shader = ShaderLib[shaderID];
  11569. vertexShader = shader.vertexShader;
  11570. fragmentShader = shader.fragmentShader;
  11571. } else {
  11572. vertexShader = material.vertexShader;
  11573. fragmentShader = material.fragmentShader;
  11574. }
  11575. var currentRenderTarget = renderer.getRenderTarget();
  11576. var parameters = {
  11577. isWebGL2: isWebGL2,
  11578. shaderID: shaderID,
  11579. shaderName: material.type,
  11580. vertexShader: vertexShader,
  11581. fragmentShader: fragmentShader,
  11582. defines: material.defines,
  11583. isRawShaderMaterial: material.isRawShaderMaterial === true,
  11584. glslVersion: material.glslVersion,
  11585. precision: precision,
  11586. instancing: object.isInstancedMesh === true,
  11587. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  11588. supportsVertexTextures: vertexTextures,
  11589. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  11590. map: !!material.map,
  11591. mapEncoding: getTextureEncodingFromMap(material.map),
  11592. matcap: !!material.matcap,
  11593. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  11594. envMap: !!envMap,
  11595. envMapMode: envMap && envMap.mapping,
  11596. envMapEncoding: getTextureEncodingFromMap(envMap),
  11597. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  11598. lightMap: !!material.lightMap,
  11599. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  11600. aoMap: !!material.aoMap,
  11601. emissiveMap: !!material.emissiveMap,
  11602. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  11603. bumpMap: !!material.bumpMap,
  11604. normalMap: !!material.normalMap,
  11605. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11606. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11607. clearcoatMap: !!material.clearcoatMap,
  11608. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  11609. clearcoatNormalMap: !!material.clearcoatNormalMap,
  11610. displacementMap: !!material.displacementMap,
  11611. roughnessMap: !!material.roughnessMap,
  11612. metalnessMap: !!material.metalnessMap,
  11613. specularMap: !!material.specularMap,
  11614. alphaMap: !!material.alphaMap,
  11615. gradientMap: !!material.gradientMap,
  11616. sheen: !!material.sheen,
  11617. transmissionMap: !!material.transmissionMap,
  11618. combine: material.combine,
  11619. vertexTangents: material.normalMap && material.vertexTangents,
  11620. vertexColors: material.vertexColors,
  11621. 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,
  11622. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  11623. fog: !!fog,
  11624. useFog: material.fog,
  11625. fogExp2: fog && fog.isFogExp2,
  11626. flatShading: material.flatShading,
  11627. sizeAttenuation: material.sizeAttenuation,
  11628. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11629. skinning: material.skinning && maxBones > 0,
  11630. maxBones: maxBones,
  11631. useVertexTexture: floatVertexTextures,
  11632. morphTargets: material.morphTargets,
  11633. morphNormals: material.morphNormals,
  11634. maxMorphTargets: renderer.maxMorphTargets,
  11635. maxMorphNormals: renderer.maxMorphNormals,
  11636. numDirLights: lights.directional.length,
  11637. numPointLights: lights.point.length,
  11638. numSpotLights: lights.spot.length,
  11639. numRectAreaLights: lights.rectArea.length,
  11640. numHemiLights: lights.hemi.length,
  11641. numDirLightShadows: lights.directionalShadowMap.length,
  11642. numPointLightShadows: lights.pointShadowMap.length,
  11643. numSpotLightShadows: lights.spotShadowMap.length,
  11644. numClippingPlanes: clipping.numPlanes,
  11645. numClipIntersection: clipping.numIntersection,
  11646. dithering: material.dithering,
  11647. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11648. shadowMapType: renderer.shadowMap.type,
  11649. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11650. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11651. premultipliedAlpha: material.premultipliedAlpha,
  11652. alphaTest: material.alphaTest,
  11653. doubleSided: material.side === DoubleSide,
  11654. flipSided: material.side === BackSide,
  11655. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  11656. index0AttributeName: material.index0AttributeName,
  11657. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11658. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11659. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11660. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11661. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  11662. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  11663. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  11664. customProgramCacheKey: material.customProgramCacheKey()
  11665. };
  11666. return parameters;
  11667. }
  11668. function getProgramCacheKey(parameters) {
  11669. var array = [];
  11670. if (parameters.shaderID) {
  11671. array.push(parameters.shaderID);
  11672. } else {
  11673. array.push(parameters.fragmentShader);
  11674. array.push(parameters.vertexShader);
  11675. }
  11676. if (parameters.defines !== undefined) {
  11677. for (var name in parameters.defines) {
  11678. array.push(name);
  11679. array.push(parameters.defines[name]);
  11680. }
  11681. }
  11682. if (parameters.isRawShaderMaterial === false) {
  11683. for (var i = 0; i < parameterNames.length; i++) {
  11684. array.push(parameters[parameterNames[i]]);
  11685. }
  11686. array.push(renderer.outputEncoding);
  11687. array.push(renderer.gammaFactor);
  11688. }
  11689. array.push(parameters.customProgramCacheKey);
  11690. return array.join();
  11691. }
  11692. function getUniforms(material) {
  11693. var shaderID = shaderIDs[material.type];
  11694. var uniforms;
  11695. if (shaderID) {
  11696. var shader = ShaderLib[shaderID];
  11697. uniforms = UniformsUtils.clone(shader.uniforms);
  11698. } else {
  11699. uniforms = material.uniforms;
  11700. }
  11701. return uniforms;
  11702. }
  11703. function acquireProgram(parameters, cacheKey) {
  11704. var program; // Check if code has been already compiled
  11705. for (var p = 0, pl = programs.length; p < pl; p++) {
  11706. var preexistingProgram = programs[p];
  11707. if (preexistingProgram.cacheKey === cacheKey) {
  11708. program = preexistingProgram;
  11709. ++program.usedTimes;
  11710. break;
  11711. }
  11712. }
  11713. if (program === undefined) {
  11714. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11715. programs.push(program);
  11716. }
  11717. return program;
  11718. }
  11719. function releaseProgram(program) {
  11720. if (--program.usedTimes === 0) {
  11721. // Remove from unordered set
  11722. var i = programs.indexOf(program);
  11723. programs[i] = programs[programs.length - 1];
  11724. programs.pop(); // Free WebGL resources
  11725. program.destroy();
  11726. }
  11727. }
  11728. return {
  11729. getParameters: getParameters,
  11730. getProgramCacheKey: getProgramCacheKey,
  11731. getUniforms: getUniforms,
  11732. acquireProgram: acquireProgram,
  11733. releaseProgram: releaseProgram,
  11734. // Exposed for resource monitoring & error feedback via renderer.info:
  11735. programs: programs
  11736. };
  11737. }
  11738. function WebGLProperties() {
  11739. var properties = new WeakMap();
  11740. function get(object) {
  11741. var map = properties.get(object);
  11742. if (map === undefined) {
  11743. map = {};
  11744. properties.set(object, map);
  11745. }
  11746. return map;
  11747. }
  11748. function remove(object) {
  11749. properties.delete(object);
  11750. }
  11751. function update(object, key, value) {
  11752. properties.get(object)[key] = value;
  11753. }
  11754. function dispose() {
  11755. properties = new WeakMap();
  11756. }
  11757. return {
  11758. get: get,
  11759. remove: remove,
  11760. update: update,
  11761. dispose: dispose
  11762. };
  11763. }
  11764. function painterSortStable(a, b) {
  11765. if (a.groupOrder !== b.groupOrder) {
  11766. return a.groupOrder - b.groupOrder;
  11767. } else if (a.renderOrder !== b.renderOrder) {
  11768. return a.renderOrder - b.renderOrder;
  11769. } else if (a.program !== b.program) {
  11770. return a.program.id - b.program.id;
  11771. } else if (a.material.id !== b.material.id) {
  11772. return a.material.id - b.material.id;
  11773. } else if (a.z !== b.z) {
  11774. return a.z - b.z;
  11775. } else {
  11776. return a.id - b.id;
  11777. }
  11778. }
  11779. function reversePainterSortStable(a, b) {
  11780. if (a.groupOrder !== b.groupOrder) {
  11781. return a.groupOrder - b.groupOrder;
  11782. } else if (a.renderOrder !== b.renderOrder) {
  11783. return a.renderOrder - b.renderOrder;
  11784. } else if (a.z !== b.z) {
  11785. return b.z - a.z;
  11786. } else {
  11787. return a.id - b.id;
  11788. }
  11789. }
  11790. function WebGLRenderList(properties) {
  11791. var renderItems = [];
  11792. var renderItemsIndex = 0;
  11793. var opaque = [];
  11794. var transparent = [];
  11795. var defaultProgram = {
  11796. id: -1
  11797. };
  11798. function init() {
  11799. renderItemsIndex = 0;
  11800. opaque.length = 0;
  11801. transparent.length = 0;
  11802. }
  11803. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11804. var renderItem = renderItems[renderItemsIndex];
  11805. var materialProperties = properties.get(material);
  11806. if (renderItem === undefined) {
  11807. renderItem = {
  11808. id: object.id,
  11809. object: object,
  11810. geometry: geometry,
  11811. material: material,
  11812. program: materialProperties.program || defaultProgram,
  11813. groupOrder: groupOrder,
  11814. renderOrder: object.renderOrder,
  11815. z: z,
  11816. group: group
  11817. };
  11818. renderItems[renderItemsIndex] = renderItem;
  11819. } else {
  11820. renderItem.id = object.id;
  11821. renderItem.object = object;
  11822. renderItem.geometry = geometry;
  11823. renderItem.material = material;
  11824. renderItem.program = materialProperties.program || defaultProgram;
  11825. renderItem.groupOrder = groupOrder;
  11826. renderItem.renderOrder = object.renderOrder;
  11827. renderItem.z = z;
  11828. renderItem.group = group;
  11829. }
  11830. renderItemsIndex++;
  11831. return renderItem;
  11832. }
  11833. function push(object, geometry, material, groupOrder, z, group) {
  11834. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11835. (material.transparent === true ? transparent : opaque).push(renderItem);
  11836. }
  11837. function unshift(object, geometry, material, groupOrder, z, group) {
  11838. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11839. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11840. }
  11841. function sort(customOpaqueSort, customTransparentSort) {
  11842. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11843. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11844. }
  11845. function finish() {
  11846. // Clear references from inactive renderItems in the list
  11847. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11848. var renderItem = renderItems[i];
  11849. if (renderItem.id === null) break;
  11850. renderItem.id = null;
  11851. renderItem.object = null;
  11852. renderItem.geometry = null;
  11853. renderItem.material = null;
  11854. renderItem.program = null;
  11855. renderItem.group = null;
  11856. }
  11857. }
  11858. return {
  11859. opaque: opaque,
  11860. transparent: transparent,
  11861. init: init,
  11862. push: push,
  11863. unshift: unshift,
  11864. finish: finish,
  11865. sort: sort
  11866. };
  11867. }
  11868. function WebGLRenderLists(properties) {
  11869. var lists = new WeakMap();
  11870. function get(scene, camera) {
  11871. var cameras = lists.get(scene);
  11872. var list;
  11873. if (cameras === undefined) {
  11874. list = new WebGLRenderList(properties);
  11875. lists.set(scene, new WeakMap());
  11876. lists.get(scene).set(camera, list);
  11877. } else {
  11878. list = cameras.get(camera);
  11879. if (list === undefined) {
  11880. list = new WebGLRenderList(properties);
  11881. cameras.set(camera, list);
  11882. }
  11883. }
  11884. return list;
  11885. }
  11886. function dispose() {
  11887. lists = new WeakMap();
  11888. }
  11889. return {
  11890. get: get,
  11891. dispose: dispose
  11892. };
  11893. }
  11894. function UniformsCache() {
  11895. var lights = {};
  11896. return {
  11897. get: function get(light) {
  11898. if (lights[light.id] !== undefined) {
  11899. return lights[light.id];
  11900. }
  11901. var uniforms;
  11902. switch (light.type) {
  11903. case 'DirectionalLight':
  11904. uniforms = {
  11905. direction: new Vector3(),
  11906. color: new Color()
  11907. };
  11908. break;
  11909. case 'SpotLight':
  11910. uniforms = {
  11911. position: new Vector3(),
  11912. direction: new Vector3(),
  11913. color: new Color(),
  11914. distance: 0,
  11915. coneCos: 0,
  11916. penumbraCos: 0,
  11917. decay: 0
  11918. };
  11919. break;
  11920. case 'PointLight':
  11921. uniforms = {
  11922. position: new Vector3(),
  11923. color: new Color(),
  11924. distance: 0,
  11925. decay: 0
  11926. };
  11927. break;
  11928. case 'HemisphereLight':
  11929. uniforms = {
  11930. direction: new Vector3(),
  11931. skyColor: new Color(),
  11932. groundColor: new Color()
  11933. };
  11934. break;
  11935. case 'RectAreaLight':
  11936. uniforms = {
  11937. color: new Color(),
  11938. position: new Vector3(),
  11939. halfWidth: new Vector3(),
  11940. halfHeight: new Vector3()
  11941. };
  11942. break;
  11943. }
  11944. lights[light.id] = uniforms;
  11945. return uniforms;
  11946. }
  11947. };
  11948. }
  11949. function ShadowUniformsCache() {
  11950. var lights = {};
  11951. return {
  11952. get: function get(light) {
  11953. if (lights[light.id] !== undefined) {
  11954. return lights[light.id];
  11955. }
  11956. var uniforms;
  11957. switch (light.type) {
  11958. case 'DirectionalLight':
  11959. uniforms = {
  11960. shadowBias: 0,
  11961. shadowNormalBias: 0,
  11962. shadowRadius: 1,
  11963. shadowMapSize: new Vector2()
  11964. };
  11965. break;
  11966. case 'SpotLight':
  11967. uniforms = {
  11968. shadowBias: 0,
  11969. shadowNormalBias: 0,
  11970. shadowRadius: 1,
  11971. shadowMapSize: new Vector2()
  11972. };
  11973. break;
  11974. case 'PointLight':
  11975. uniforms = {
  11976. shadowBias: 0,
  11977. shadowNormalBias: 0,
  11978. shadowRadius: 1,
  11979. shadowMapSize: new Vector2(),
  11980. shadowCameraNear: 1,
  11981. shadowCameraFar: 1000
  11982. };
  11983. break;
  11984. // TODO (abelnation): set RectAreaLight shadow uniforms
  11985. }
  11986. lights[light.id] = uniforms;
  11987. return uniforms;
  11988. }
  11989. };
  11990. }
  11991. var nextVersion = 0;
  11992. function shadowCastingLightsFirst(lightA, lightB) {
  11993. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  11994. }
  11995. function WebGLLights(extensions, capabilities) {
  11996. var cache = new UniformsCache();
  11997. var shadowCache = ShadowUniformsCache();
  11998. var state = {
  11999. version: 0,
  12000. hash: {
  12001. directionalLength: -1,
  12002. pointLength: -1,
  12003. spotLength: -1,
  12004. rectAreaLength: -1,
  12005. hemiLength: -1,
  12006. numDirectionalShadows: -1,
  12007. numPointShadows: -1,
  12008. numSpotShadows: -1
  12009. },
  12010. ambient: [0, 0, 0],
  12011. probe: [],
  12012. directional: [],
  12013. directionalShadow: [],
  12014. directionalShadowMap: [],
  12015. directionalShadowMatrix: [],
  12016. spot: [],
  12017. spotShadow: [],
  12018. spotShadowMap: [],
  12019. spotShadowMatrix: [],
  12020. rectArea: [],
  12021. rectAreaLTC1: null,
  12022. rectAreaLTC2: null,
  12023. point: [],
  12024. pointShadow: [],
  12025. pointShadowMap: [],
  12026. pointShadowMatrix: [],
  12027. hemi: []
  12028. };
  12029. for (var i = 0; i < 9; i++) {
  12030. state.probe.push(new Vector3());
  12031. }
  12032. var vector3 = new Vector3();
  12033. var matrix4 = new Matrix4();
  12034. var matrix42 = new Matrix4();
  12035. function setup(lights) {
  12036. var r = 0,
  12037. g = 0,
  12038. b = 0;
  12039. for (var _i = 0; _i < 9; _i++) {
  12040. state.probe[_i].set(0, 0, 0);
  12041. }
  12042. var directionalLength = 0;
  12043. var pointLength = 0;
  12044. var spotLength = 0;
  12045. var rectAreaLength = 0;
  12046. var hemiLength = 0;
  12047. var numDirectionalShadows = 0;
  12048. var numPointShadows = 0;
  12049. var numSpotShadows = 0;
  12050. lights.sort(shadowCastingLightsFirst);
  12051. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  12052. var light = lights[_i2];
  12053. var color = light.color;
  12054. var intensity = light.intensity;
  12055. var distance = light.distance;
  12056. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  12057. if (light.isAmbientLight) {
  12058. r += color.r * intensity;
  12059. g += color.g * intensity;
  12060. b += color.b * intensity;
  12061. } else if (light.isLightProbe) {
  12062. for (var j = 0; j < 9; j++) {
  12063. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  12064. }
  12065. } else if (light.isDirectionalLight) {
  12066. var uniforms = cache.get(light);
  12067. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  12068. if (light.castShadow) {
  12069. var shadow = light.shadow;
  12070. var shadowUniforms = shadowCache.get(light);
  12071. shadowUniforms.shadowBias = shadow.bias;
  12072. shadowUniforms.shadowNormalBias = shadow.normalBias;
  12073. shadowUniforms.shadowRadius = shadow.radius;
  12074. shadowUniforms.shadowMapSize = shadow.mapSize;
  12075. state.directionalShadow[directionalLength] = shadowUniforms;
  12076. state.directionalShadowMap[directionalLength] = shadowMap;
  12077. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  12078. numDirectionalShadows++;
  12079. }
  12080. state.directional[directionalLength] = uniforms;
  12081. directionalLength++;
  12082. } else if (light.isSpotLight) {
  12083. var _uniforms = cache.get(light);
  12084. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  12085. _uniforms.color.copy(color).multiplyScalar(intensity);
  12086. _uniforms.distance = distance;
  12087. _uniforms.coneCos = Math.cos(light.angle);
  12088. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  12089. _uniforms.decay = light.decay;
  12090. if (light.castShadow) {
  12091. var _shadow = light.shadow;
  12092. var _shadowUniforms = shadowCache.get(light);
  12093. _shadowUniforms.shadowBias = _shadow.bias;
  12094. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  12095. _shadowUniforms.shadowRadius = _shadow.radius;
  12096. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  12097. state.spotShadow[spotLength] = _shadowUniforms;
  12098. state.spotShadowMap[spotLength] = shadowMap;
  12099. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  12100. numSpotShadows++;
  12101. }
  12102. state.spot[spotLength] = _uniforms;
  12103. spotLength++;
  12104. } else if (light.isRectAreaLight) {
  12105. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  12106. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  12107. // (b) intensity is the brightness of the light
  12108. _uniforms2.color.copy(color).multiplyScalar(intensity);
  12109. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  12110. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  12111. state.rectArea[rectAreaLength] = _uniforms2;
  12112. rectAreaLength++;
  12113. } else if (light.isPointLight) {
  12114. var _uniforms3 = cache.get(light);
  12115. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  12116. _uniforms3.distance = light.distance;
  12117. _uniforms3.decay = light.decay;
  12118. if (light.castShadow) {
  12119. var _shadow2 = light.shadow;
  12120. var _shadowUniforms2 = shadowCache.get(light);
  12121. _shadowUniforms2.shadowBias = _shadow2.bias;
  12122. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  12123. _shadowUniforms2.shadowRadius = _shadow2.radius;
  12124. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  12125. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  12126. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  12127. state.pointShadow[pointLength] = _shadowUniforms2;
  12128. state.pointShadowMap[pointLength] = shadowMap;
  12129. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  12130. numPointShadows++;
  12131. }
  12132. state.point[pointLength] = _uniforms3;
  12133. pointLength++;
  12134. } else if (light.isHemisphereLight) {
  12135. var _uniforms4 = cache.get(light);
  12136. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  12137. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  12138. state.hemi[hemiLength] = _uniforms4;
  12139. hemiLength++;
  12140. }
  12141. }
  12142. if (rectAreaLength > 0) {
  12143. if (capabilities.isWebGL2) {
  12144. // WebGL 2
  12145. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12146. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12147. } else {
  12148. // WebGL 1
  12149. if (extensions.has('OES_texture_float_linear') === true) {
  12150. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12151. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12152. } else if (extensions.has('OES_texture_half_float_linear') === true) {
  12153. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  12154. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  12155. } else {
  12156. console.error('THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.');
  12157. }
  12158. }
  12159. }
  12160. state.ambient[0] = r;
  12161. state.ambient[1] = g;
  12162. state.ambient[2] = b;
  12163. var hash = state.hash;
  12164. 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) {
  12165. state.directional.length = directionalLength;
  12166. state.spot.length = spotLength;
  12167. state.rectArea.length = rectAreaLength;
  12168. state.point.length = pointLength;
  12169. state.hemi.length = hemiLength;
  12170. state.directionalShadow.length = numDirectionalShadows;
  12171. state.directionalShadowMap.length = numDirectionalShadows;
  12172. state.pointShadow.length = numPointShadows;
  12173. state.pointShadowMap.length = numPointShadows;
  12174. state.spotShadow.length = numSpotShadows;
  12175. state.spotShadowMap.length = numSpotShadows;
  12176. state.directionalShadowMatrix.length = numDirectionalShadows;
  12177. state.pointShadowMatrix.length = numPointShadows;
  12178. state.spotShadowMatrix.length = numSpotShadows;
  12179. hash.directionalLength = directionalLength;
  12180. hash.pointLength = pointLength;
  12181. hash.spotLength = spotLength;
  12182. hash.rectAreaLength = rectAreaLength;
  12183. hash.hemiLength = hemiLength;
  12184. hash.numDirectionalShadows = numDirectionalShadows;
  12185. hash.numPointShadows = numPointShadows;
  12186. hash.numSpotShadows = numSpotShadows;
  12187. state.version = nextVersion++;
  12188. }
  12189. }
  12190. function setupView(lights, camera) {
  12191. var directionalLength = 0;
  12192. var pointLength = 0;
  12193. var spotLength = 0;
  12194. var rectAreaLength = 0;
  12195. var hemiLength = 0;
  12196. var viewMatrix = camera.matrixWorldInverse;
  12197. for (var _i3 = 0, l = lights.length; _i3 < l; _i3++) {
  12198. var light = lights[_i3];
  12199. if (light.isDirectionalLight) {
  12200. var uniforms = state.directional[directionalLength];
  12201. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  12202. vector3.setFromMatrixPosition(light.target.matrixWorld);
  12203. uniforms.direction.sub(vector3);
  12204. uniforms.direction.transformDirection(viewMatrix);
  12205. directionalLength++;
  12206. } else if (light.isSpotLight) {
  12207. var _uniforms5 = state.spot[spotLength];
  12208. _uniforms5.position.setFromMatrixPosition(light.matrixWorld);
  12209. _uniforms5.position.applyMatrix4(viewMatrix);
  12210. _uniforms5.direction.setFromMatrixPosition(light.matrixWorld);
  12211. vector3.setFromMatrixPosition(light.target.matrixWorld);
  12212. _uniforms5.direction.sub(vector3);
  12213. _uniforms5.direction.transformDirection(viewMatrix);
  12214. spotLength++;
  12215. } else if (light.isRectAreaLight) {
  12216. var _uniforms6 = state.rectArea[rectAreaLength];
  12217. _uniforms6.position.setFromMatrixPosition(light.matrixWorld);
  12218. _uniforms6.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  12219. matrix42.identity();
  12220. matrix4.copy(light.matrixWorld);
  12221. matrix4.premultiply(viewMatrix);
  12222. matrix42.extractRotation(matrix4);
  12223. _uniforms6.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  12224. _uniforms6.halfHeight.set(0.0, light.height * 0.5, 0.0);
  12225. _uniforms6.halfWidth.applyMatrix4(matrix42);
  12226. _uniforms6.halfHeight.applyMatrix4(matrix42);
  12227. rectAreaLength++;
  12228. } else if (light.isPointLight) {
  12229. var _uniforms7 = state.point[pointLength];
  12230. _uniforms7.position.setFromMatrixPosition(light.matrixWorld);
  12231. _uniforms7.position.applyMatrix4(viewMatrix);
  12232. pointLength++;
  12233. } else if (light.isHemisphereLight) {
  12234. var _uniforms8 = state.hemi[hemiLength];
  12235. _uniforms8.direction.setFromMatrixPosition(light.matrixWorld);
  12236. _uniforms8.direction.transformDirection(viewMatrix);
  12237. _uniforms8.direction.normalize();
  12238. hemiLength++;
  12239. }
  12240. }
  12241. }
  12242. return {
  12243. setup: setup,
  12244. setupView: setupView,
  12245. state: state
  12246. };
  12247. }
  12248. function WebGLRenderState(extensions, capabilities) {
  12249. var lights = new WebGLLights(extensions, capabilities);
  12250. var lightsArray = [];
  12251. var shadowsArray = [];
  12252. function init() {
  12253. lightsArray.length = 0;
  12254. shadowsArray.length = 0;
  12255. }
  12256. function pushLight(light) {
  12257. lightsArray.push(light);
  12258. }
  12259. function pushShadow(shadowLight) {
  12260. shadowsArray.push(shadowLight);
  12261. }
  12262. function setupLights() {
  12263. lights.setup(lightsArray);
  12264. }
  12265. function setupLightsView(camera) {
  12266. lights.setupView(lightsArray, camera);
  12267. }
  12268. var state = {
  12269. lightsArray: lightsArray,
  12270. shadowsArray: shadowsArray,
  12271. lights: lights
  12272. };
  12273. return {
  12274. init: init,
  12275. state: state,
  12276. setupLights: setupLights,
  12277. setupLightsView: setupLightsView,
  12278. pushLight: pushLight,
  12279. pushShadow: pushShadow
  12280. };
  12281. }
  12282. function WebGLRenderStates(extensions, capabilities) {
  12283. var renderStates = new WeakMap();
  12284. function get(scene, renderCallDepth) {
  12285. if (renderCallDepth === void 0) {
  12286. renderCallDepth = 0;
  12287. }
  12288. var renderState;
  12289. if (renderStates.has(scene) === false) {
  12290. renderState = new WebGLRenderState(extensions, capabilities);
  12291. renderStates.set(scene, []);
  12292. renderStates.get(scene).push(renderState);
  12293. } else {
  12294. if (renderCallDepth >= renderStates.get(scene).length) {
  12295. renderState = new WebGLRenderState(extensions, capabilities);
  12296. renderStates.get(scene).push(renderState);
  12297. } else {
  12298. renderState = renderStates.get(scene)[renderCallDepth];
  12299. }
  12300. }
  12301. return renderState;
  12302. }
  12303. function dispose() {
  12304. renderStates = new WeakMap();
  12305. }
  12306. return {
  12307. get: get,
  12308. dispose: dispose
  12309. };
  12310. }
  12311. /**
  12312. * parameters = {
  12313. *
  12314. * opacity: <float>,
  12315. *
  12316. * map: new THREE.Texture( <Image> ),
  12317. *
  12318. * alphaMap: new THREE.Texture( <Image> ),
  12319. *
  12320. * displacementMap: new THREE.Texture( <Image> ),
  12321. * displacementScale: <float>,
  12322. * displacementBias: <float>,
  12323. *
  12324. * wireframe: <boolean>,
  12325. * wireframeLinewidth: <float>
  12326. * }
  12327. */
  12328. function MeshDepthMaterial(parameters) {
  12329. Material.call(this);
  12330. this.type = 'MeshDepthMaterial';
  12331. this.depthPacking = BasicDepthPacking;
  12332. this.skinning = false;
  12333. this.morphTargets = false;
  12334. this.map = null;
  12335. this.alphaMap = null;
  12336. this.displacementMap = null;
  12337. this.displacementScale = 1;
  12338. this.displacementBias = 0;
  12339. this.wireframe = false;
  12340. this.wireframeLinewidth = 1;
  12341. this.fog = false;
  12342. this.setValues(parameters);
  12343. }
  12344. MeshDepthMaterial.prototype = Object.create(Material.prototype);
  12345. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  12346. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  12347. MeshDepthMaterial.prototype.copy = function (source) {
  12348. Material.prototype.copy.call(this, source);
  12349. this.depthPacking = source.depthPacking;
  12350. this.skinning = source.skinning;
  12351. this.morphTargets = source.morphTargets;
  12352. this.map = source.map;
  12353. this.alphaMap = source.alphaMap;
  12354. this.displacementMap = source.displacementMap;
  12355. this.displacementScale = source.displacementScale;
  12356. this.displacementBias = source.displacementBias;
  12357. this.wireframe = source.wireframe;
  12358. this.wireframeLinewidth = source.wireframeLinewidth;
  12359. return this;
  12360. };
  12361. /**
  12362. * parameters = {
  12363. *
  12364. * referencePosition: <float>,
  12365. * nearDistance: <float>,
  12366. * farDistance: <float>,
  12367. *
  12368. * skinning: <bool>,
  12369. * morphTargets: <bool>,
  12370. *
  12371. * map: new THREE.Texture( <Image> ),
  12372. *
  12373. * alphaMap: new THREE.Texture( <Image> ),
  12374. *
  12375. * displacementMap: new THREE.Texture( <Image> ),
  12376. * displacementScale: <float>,
  12377. * displacementBias: <float>
  12378. *
  12379. * }
  12380. */
  12381. function MeshDistanceMaterial(parameters) {
  12382. Material.call(this);
  12383. this.type = 'MeshDistanceMaterial';
  12384. this.referencePosition = new Vector3();
  12385. this.nearDistance = 1;
  12386. this.farDistance = 1000;
  12387. this.skinning = false;
  12388. this.morphTargets = false;
  12389. this.map = null;
  12390. this.alphaMap = null;
  12391. this.displacementMap = null;
  12392. this.displacementScale = 1;
  12393. this.displacementBias = 0;
  12394. this.fog = false;
  12395. this.setValues(parameters);
  12396. }
  12397. MeshDistanceMaterial.prototype = Object.create(Material.prototype);
  12398. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  12399. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  12400. MeshDistanceMaterial.prototype.copy = function (source) {
  12401. Material.prototype.copy.call(this, source);
  12402. this.referencePosition.copy(source.referencePosition);
  12403. this.nearDistance = source.nearDistance;
  12404. this.farDistance = source.farDistance;
  12405. this.skinning = source.skinning;
  12406. this.morphTargets = source.morphTargets;
  12407. this.map = source.map;
  12408. this.alphaMap = source.alphaMap;
  12409. this.displacementMap = source.displacementMap;
  12410. this.displacementScale = source.displacementScale;
  12411. this.displacementBias = source.displacementBias;
  12412. return this;
  12413. };
  12414. 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}";
  12415. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  12416. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  12417. var _frustum = new Frustum();
  12418. var _shadowMapSize = new Vector2(),
  12419. _viewportSize = new Vector2(),
  12420. _viewport = new Vector4(),
  12421. _depthMaterials = [],
  12422. _distanceMaterials = [],
  12423. _materialCache = {};
  12424. var shadowSide = {
  12425. 0: BackSide,
  12426. 1: FrontSide,
  12427. 2: DoubleSide
  12428. };
  12429. var shadowMaterialVertical = new ShaderMaterial({
  12430. defines: {
  12431. SAMPLE_RATE: 2.0 / 8.0,
  12432. HALF_SAMPLE_RATE: 1.0 / 8.0
  12433. },
  12434. uniforms: {
  12435. shadow_pass: {
  12436. value: null
  12437. },
  12438. resolution: {
  12439. value: new Vector2()
  12440. },
  12441. radius: {
  12442. value: 4.0
  12443. }
  12444. },
  12445. vertexShader: vsm_vert,
  12446. fragmentShader: vsm_frag
  12447. });
  12448. var shadowMaterialHorizontal = shadowMaterialVertical.clone();
  12449. shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1;
  12450. var fullScreenTri = new BufferGeometry();
  12451. fullScreenTri.setAttribute('position', new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  12452. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  12453. var scope = this;
  12454. this.enabled = false;
  12455. this.autoUpdate = true;
  12456. this.needsUpdate = false;
  12457. this.type = PCFShadowMap;
  12458. this.render = function (lights, scene, camera) {
  12459. if (scope.enabled === false) return;
  12460. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  12461. if (lights.length === 0) return;
  12462. var currentRenderTarget = _renderer.getRenderTarget();
  12463. var activeCubeFace = _renderer.getActiveCubeFace();
  12464. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  12465. var _state = _renderer.state; // Set GL state for depth map.
  12466. _state.setBlending(NoBlending);
  12467. _state.buffers.color.setClear(1, 1, 1, 1);
  12468. _state.buffers.depth.setTest(true);
  12469. _state.setScissorTest(false); // render depth map
  12470. for (var i = 0, il = lights.length; i < il; i++) {
  12471. var light = lights[i];
  12472. var shadow = light.shadow;
  12473. if (shadow === undefined) {
  12474. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  12475. continue;
  12476. }
  12477. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  12478. _shadowMapSize.copy(shadow.mapSize);
  12479. var shadowFrameExtents = shadow.getFrameExtents();
  12480. _shadowMapSize.multiply(shadowFrameExtents);
  12481. _viewportSize.copy(shadow.mapSize);
  12482. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  12483. if (_shadowMapSize.x > maxTextureSize) {
  12484. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  12485. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  12486. shadow.mapSize.x = _viewportSize.x;
  12487. }
  12488. if (_shadowMapSize.y > maxTextureSize) {
  12489. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  12490. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  12491. shadow.mapSize.y = _viewportSize.y;
  12492. }
  12493. }
  12494. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12495. var pars = {
  12496. minFilter: LinearFilter,
  12497. magFilter: LinearFilter,
  12498. format: RGBAFormat
  12499. };
  12500. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12501. shadow.map.texture.name = light.name + '.shadowMap';
  12502. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12503. shadow.camera.updateProjectionMatrix();
  12504. }
  12505. if (shadow.map === null) {
  12506. var _pars = {
  12507. minFilter: NearestFilter,
  12508. magFilter: NearestFilter,
  12509. format: RGBAFormat
  12510. };
  12511. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  12512. shadow.map.texture.name = light.name + '.shadowMap';
  12513. shadow.camera.updateProjectionMatrix();
  12514. }
  12515. _renderer.setRenderTarget(shadow.map);
  12516. _renderer.clear();
  12517. var viewportCount = shadow.getViewportCount();
  12518. for (var vp = 0; vp < viewportCount; vp++) {
  12519. var viewport = shadow.getViewport(vp);
  12520. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  12521. _state.viewport(_viewport);
  12522. shadow.updateMatrices(light, vp);
  12523. _frustum = shadow.getFrustum();
  12524. renderObject(scene, camera, shadow.camera, light, this.type);
  12525. } // do blur pass for VSM
  12526. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12527. VSMPass(shadow, camera);
  12528. }
  12529. shadow.needsUpdate = false;
  12530. }
  12531. scope.needsUpdate = false;
  12532. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  12533. };
  12534. function VSMPass(shadow, camera) {
  12535. var geometry = _objects.update(fullScreenMesh); // vertical pass
  12536. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  12537. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  12538. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  12539. _renderer.setRenderTarget(shadow.mapPass);
  12540. _renderer.clear();
  12541. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizontal pass
  12542. shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  12543. shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize;
  12544. shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;
  12545. _renderer.setRenderTarget(shadow.map);
  12546. _renderer.clear();
  12547. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null);
  12548. }
  12549. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12550. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12551. var material = _depthMaterials[index];
  12552. if (material === undefined) {
  12553. material = new MeshDepthMaterial({
  12554. depthPacking: RGBADepthPacking,
  12555. morphTargets: useMorphing,
  12556. skinning: useSkinning
  12557. });
  12558. _depthMaterials[index] = material;
  12559. }
  12560. return material;
  12561. }
  12562. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12563. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12564. var material = _distanceMaterials[index];
  12565. if (material === undefined) {
  12566. material = new MeshDistanceMaterial({
  12567. morphTargets: useMorphing,
  12568. skinning: useSkinning
  12569. });
  12570. _distanceMaterials[index] = material;
  12571. }
  12572. return material;
  12573. }
  12574. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  12575. var result = null;
  12576. var getMaterialVariant = getDepthMaterialVariant;
  12577. var customMaterial = object.customDepthMaterial;
  12578. if (light.isPointLight === true) {
  12579. getMaterialVariant = getDistanceMaterialVariant;
  12580. customMaterial = object.customDistanceMaterial;
  12581. }
  12582. if (customMaterial === undefined) {
  12583. var useMorphing = false;
  12584. if (material.morphTargets === true) {
  12585. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  12586. }
  12587. var useSkinning = false;
  12588. if (object.isSkinnedMesh === true) {
  12589. if (material.skinning === true) {
  12590. useSkinning = true;
  12591. } else {
  12592. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  12593. }
  12594. }
  12595. var useInstancing = object.isInstancedMesh === true;
  12596. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  12597. } else {
  12598. result = customMaterial;
  12599. }
  12600. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  12601. // in this case we need a unique material instance reflecting the
  12602. // appropriate state
  12603. var keyA = result.uuid,
  12604. keyB = material.uuid;
  12605. var materialsForVariant = _materialCache[keyA];
  12606. if (materialsForVariant === undefined) {
  12607. materialsForVariant = {};
  12608. _materialCache[keyA] = materialsForVariant;
  12609. }
  12610. var cachedMaterial = materialsForVariant[keyB];
  12611. if (cachedMaterial === undefined) {
  12612. cachedMaterial = result.clone();
  12613. materialsForVariant[keyB] = cachedMaterial;
  12614. }
  12615. result = cachedMaterial;
  12616. }
  12617. result.visible = material.visible;
  12618. result.wireframe = material.wireframe;
  12619. if (type === VSMShadowMap) {
  12620. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  12621. } else {
  12622. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  12623. }
  12624. result.clipShadows = material.clipShadows;
  12625. result.clippingPlanes = material.clippingPlanes;
  12626. result.clipIntersection = material.clipIntersection;
  12627. result.wireframeLinewidth = material.wireframeLinewidth;
  12628. result.linewidth = material.linewidth;
  12629. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  12630. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  12631. result.nearDistance = shadowCameraNear;
  12632. result.farDistance = shadowCameraFar;
  12633. }
  12634. return result;
  12635. }
  12636. function renderObject(object, camera, shadowCamera, light, type) {
  12637. if (object.visible === false) return;
  12638. var visible = object.layers.test(camera.layers);
  12639. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  12640. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  12641. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  12642. var geometry = _objects.update(object);
  12643. var material = object.material;
  12644. if (Array.isArray(material)) {
  12645. var groups = geometry.groups;
  12646. for (var k = 0, kl = groups.length; k < kl; k++) {
  12647. var group = groups[k];
  12648. var groupMaterial = material[group.materialIndex];
  12649. if (groupMaterial && groupMaterial.visible) {
  12650. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  12651. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  12652. }
  12653. }
  12654. } else if (material.visible) {
  12655. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  12656. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  12657. }
  12658. }
  12659. }
  12660. var children = object.children;
  12661. for (var i = 0, l = children.length; i < l; i++) {
  12662. renderObject(children[i], camera, shadowCamera, light, type);
  12663. }
  12664. }
  12665. }
  12666. function WebGLState(gl, extensions, capabilities) {
  12667. var _equationToGL, _factorToGL;
  12668. var isWebGL2 = capabilities.isWebGL2;
  12669. function ColorBuffer() {
  12670. var locked = false;
  12671. var color = new Vector4();
  12672. var currentColorMask = null;
  12673. var currentColorClear = new Vector4(0, 0, 0, 0);
  12674. return {
  12675. setMask: function setMask(colorMask) {
  12676. if (currentColorMask !== colorMask && !locked) {
  12677. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  12678. currentColorMask = colorMask;
  12679. }
  12680. },
  12681. setLocked: function setLocked(lock) {
  12682. locked = lock;
  12683. },
  12684. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  12685. if (premultipliedAlpha === true) {
  12686. r *= a;
  12687. g *= a;
  12688. b *= a;
  12689. }
  12690. color.set(r, g, b, a);
  12691. if (currentColorClear.equals(color) === false) {
  12692. gl.clearColor(r, g, b, a);
  12693. currentColorClear.copy(color);
  12694. }
  12695. },
  12696. reset: function reset() {
  12697. locked = false;
  12698. currentColorMask = null;
  12699. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  12700. }
  12701. };
  12702. }
  12703. function DepthBuffer() {
  12704. var locked = false;
  12705. var currentDepthMask = null;
  12706. var currentDepthFunc = null;
  12707. var currentDepthClear = null;
  12708. return {
  12709. setTest: function setTest(depthTest) {
  12710. if (depthTest) {
  12711. enable(2929);
  12712. } else {
  12713. disable(2929);
  12714. }
  12715. },
  12716. setMask: function setMask(depthMask) {
  12717. if (currentDepthMask !== depthMask && !locked) {
  12718. gl.depthMask(depthMask);
  12719. currentDepthMask = depthMask;
  12720. }
  12721. },
  12722. setFunc: function setFunc(depthFunc) {
  12723. if (currentDepthFunc !== depthFunc) {
  12724. if (depthFunc) {
  12725. switch (depthFunc) {
  12726. case NeverDepth:
  12727. gl.depthFunc(512);
  12728. break;
  12729. case AlwaysDepth:
  12730. gl.depthFunc(519);
  12731. break;
  12732. case LessDepth:
  12733. gl.depthFunc(513);
  12734. break;
  12735. case LessEqualDepth:
  12736. gl.depthFunc(515);
  12737. break;
  12738. case EqualDepth:
  12739. gl.depthFunc(514);
  12740. break;
  12741. case GreaterEqualDepth:
  12742. gl.depthFunc(518);
  12743. break;
  12744. case GreaterDepth:
  12745. gl.depthFunc(516);
  12746. break;
  12747. case NotEqualDepth:
  12748. gl.depthFunc(517);
  12749. break;
  12750. default:
  12751. gl.depthFunc(515);
  12752. }
  12753. } else {
  12754. gl.depthFunc(515);
  12755. }
  12756. currentDepthFunc = depthFunc;
  12757. }
  12758. },
  12759. setLocked: function setLocked(lock) {
  12760. locked = lock;
  12761. },
  12762. setClear: function setClear(depth) {
  12763. if (currentDepthClear !== depth) {
  12764. gl.clearDepth(depth);
  12765. currentDepthClear = depth;
  12766. }
  12767. },
  12768. reset: function reset() {
  12769. locked = false;
  12770. currentDepthMask = null;
  12771. currentDepthFunc = null;
  12772. currentDepthClear = null;
  12773. }
  12774. };
  12775. }
  12776. function StencilBuffer() {
  12777. var locked = false;
  12778. var currentStencilMask = null;
  12779. var currentStencilFunc = null;
  12780. var currentStencilRef = null;
  12781. var currentStencilFuncMask = null;
  12782. var currentStencilFail = null;
  12783. var currentStencilZFail = null;
  12784. var currentStencilZPass = null;
  12785. var currentStencilClear = null;
  12786. return {
  12787. setTest: function setTest(stencilTest) {
  12788. if (!locked) {
  12789. if (stencilTest) {
  12790. enable(2960);
  12791. } else {
  12792. disable(2960);
  12793. }
  12794. }
  12795. },
  12796. setMask: function setMask(stencilMask) {
  12797. if (currentStencilMask !== stencilMask && !locked) {
  12798. gl.stencilMask(stencilMask);
  12799. currentStencilMask = stencilMask;
  12800. }
  12801. },
  12802. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12803. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12804. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12805. currentStencilFunc = stencilFunc;
  12806. currentStencilRef = stencilRef;
  12807. currentStencilFuncMask = stencilMask;
  12808. }
  12809. },
  12810. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12811. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12812. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12813. currentStencilFail = stencilFail;
  12814. currentStencilZFail = stencilZFail;
  12815. currentStencilZPass = stencilZPass;
  12816. }
  12817. },
  12818. setLocked: function setLocked(lock) {
  12819. locked = lock;
  12820. },
  12821. setClear: function setClear(stencil) {
  12822. if (currentStencilClear !== stencil) {
  12823. gl.clearStencil(stencil);
  12824. currentStencilClear = stencil;
  12825. }
  12826. },
  12827. reset: function reset() {
  12828. locked = false;
  12829. currentStencilMask = null;
  12830. currentStencilFunc = null;
  12831. currentStencilRef = null;
  12832. currentStencilFuncMask = null;
  12833. currentStencilFail = null;
  12834. currentStencilZFail = null;
  12835. currentStencilZPass = null;
  12836. currentStencilClear = null;
  12837. }
  12838. };
  12839. } //
  12840. var colorBuffer = new ColorBuffer();
  12841. var depthBuffer = new DepthBuffer();
  12842. var stencilBuffer = new StencilBuffer();
  12843. var enabledCapabilities = {};
  12844. var currentProgram = null;
  12845. var currentBlendingEnabled = null;
  12846. var currentBlending = null;
  12847. var currentBlendEquation = null;
  12848. var currentBlendSrc = null;
  12849. var currentBlendDst = null;
  12850. var currentBlendEquationAlpha = null;
  12851. var currentBlendSrcAlpha = null;
  12852. var currentBlendDstAlpha = null;
  12853. var currentPremultipledAlpha = false;
  12854. var currentFlipSided = null;
  12855. var currentCullFace = null;
  12856. var currentLineWidth = null;
  12857. var currentPolygonOffsetFactor = null;
  12858. var currentPolygonOffsetUnits = null;
  12859. var maxTextures = gl.getParameter(35661);
  12860. var lineWidthAvailable = false;
  12861. var version = 0;
  12862. var glVersion = gl.getParameter(7938);
  12863. if (glVersion.indexOf('WebGL') !== -1) {
  12864. version = parseFloat(/^WebGL (\d)/.exec(glVersion)[1]);
  12865. lineWidthAvailable = version >= 1.0;
  12866. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12867. version = parseFloat(/^OpenGL ES (\d)/.exec(glVersion)[1]);
  12868. lineWidthAvailable = version >= 2.0;
  12869. }
  12870. var currentTextureSlot = null;
  12871. var currentBoundTextures = {};
  12872. var currentScissor = new Vector4();
  12873. var currentViewport = new Vector4();
  12874. function createTexture(type, target, count) {
  12875. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12876. var texture = gl.createTexture();
  12877. gl.bindTexture(type, texture);
  12878. gl.texParameteri(type, 10241, 9728);
  12879. gl.texParameteri(type, 10240, 9728);
  12880. for (var i = 0; i < count; i++) {
  12881. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12882. }
  12883. return texture;
  12884. }
  12885. var emptyTextures = {};
  12886. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12887. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12888. colorBuffer.setClear(0, 0, 0, 1);
  12889. depthBuffer.setClear(1);
  12890. stencilBuffer.setClear(0);
  12891. enable(2929);
  12892. depthBuffer.setFunc(LessEqualDepth);
  12893. setFlipSided(false);
  12894. setCullFace(CullFaceBack);
  12895. enable(2884);
  12896. setBlending(NoBlending); //
  12897. function enable(id) {
  12898. if (enabledCapabilities[id] !== true) {
  12899. gl.enable(id);
  12900. enabledCapabilities[id] = true;
  12901. }
  12902. }
  12903. function disable(id) {
  12904. if (enabledCapabilities[id] !== false) {
  12905. gl.disable(id);
  12906. enabledCapabilities[id] = false;
  12907. }
  12908. }
  12909. function useProgram(program) {
  12910. if (currentProgram !== program) {
  12911. gl.useProgram(program);
  12912. currentProgram = program;
  12913. return true;
  12914. }
  12915. return false;
  12916. }
  12917. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  12918. if (isWebGL2) {
  12919. equationToGL[MinEquation] = 32775;
  12920. equationToGL[MaxEquation] = 32776;
  12921. } else {
  12922. var extension = extensions.get('EXT_blend_minmax');
  12923. if (extension !== null) {
  12924. equationToGL[MinEquation] = extension.MIN_EXT;
  12925. equationToGL[MaxEquation] = extension.MAX_EXT;
  12926. }
  12927. }
  12928. 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);
  12929. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  12930. if (blending === NoBlending) {
  12931. if (currentBlendingEnabled) {
  12932. disable(3042);
  12933. currentBlendingEnabled = false;
  12934. }
  12935. return;
  12936. }
  12937. if (!currentBlendingEnabled) {
  12938. enable(3042);
  12939. currentBlendingEnabled = true;
  12940. }
  12941. if (blending !== CustomBlending) {
  12942. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  12943. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  12944. gl.blendEquation(32774);
  12945. currentBlendEquation = AddEquation;
  12946. currentBlendEquationAlpha = AddEquation;
  12947. }
  12948. if (premultipliedAlpha) {
  12949. switch (blending) {
  12950. case NormalBlending:
  12951. gl.blendFuncSeparate(1, 771, 1, 771);
  12952. break;
  12953. case AdditiveBlending:
  12954. gl.blendFunc(1, 1);
  12955. break;
  12956. case SubtractiveBlending:
  12957. gl.blendFuncSeparate(0, 0, 769, 771);
  12958. break;
  12959. case MultiplyBlending:
  12960. gl.blendFuncSeparate(0, 768, 0, 770);
  12961. break;
  12962. default:
  12963. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12964. break;
  12965. }
  12966. } else {
  12967. switch (blending) {
  12968. case NormalBlending:
  12969. gl.blendFuncSeparate(770, 771, 1, 771);
  12970. break;
  12971. case AdditiveBlending:
  12972. gl.blendFunc(770, 1);
  12973. break;
  12974. case SubtractiveBlending:
  12975. gl.blendFunc(0, 769);
  12976. break;
  12977. case MultiplyBlending:
  12978. gl.blendFunc(0, 768);
  12979. break;
  12980. default:
  12981. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12982. break;
  12983. }
  12984. }
  12985. currentBlendSrc = null;
  12986. currentBlendDst = null;
  12987. currentBlendSrcAlpha = null;
  12988. currentBlendDstAlpha = null;
  12989. currentBlending = blending;
  12990. currentPremultipledAlpha = premultipliedAlpha;
  12991. }
  12992. return;
  12993. } // custom blending
  12994. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12995. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12996. blendDstAlpha = blendDstAlpha || blendDst;
  12997. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  12998. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  12999. currentBlendEquation = blendEquation;
  13000. currentBlendEquationAlpha = blendEquationAlpha;
  13001. }
  13002. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  13003. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  13004. currentBlendSrc = blendSrc;
  13005. currentBlendDst = blendDst;
  13006. currentBlendSrcAlpha = blendSrcAlpha;
  13007. currentBlendDstAlpha = blendDstAlpha;
  13008. }
  13009. currentBlending = blending;
  13010. currentPremultipledAlpha = null;
  13011. }
  13012. function setMaterial(material, frontFaceCW) {
  13013. material.side === DoubleSide ? disable(2884) : enable(2884);
  13014. var flipSided = material.side === BackSide;
  13015. if (frontFaceCW) flipSided = !flipSided;
  13016. setFlipSided(flipSided);
  13017. 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);
  13018. depthBuffer.setFunc(material.depthFunc);
  13019. depthBuffer.setTest(material.depthTest);
  13020. depthBuffer.setMask(material.depthWrite);
  13021. colorBuffer.setMask(material.colorWrite);
  13022. var stencilWrite = material.stencilWrite;
  13023. stencilBuffer.setTest(stencilWrite);
  13024. if (stencilWrite) {
  13025. stencilBuffer.setMask(material.stencilWriteMask);
  13026. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  13027. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  13028. }
  13029. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  13030. } //
  13031. function setFlipSided(flipSided) {
  13032. if (currentFlipSided !== flipSided) {
  13033. if (flipSided) {
  13034. gl.frontFace(2304);
  13035. } else {
  13036. gl.frontFace(2305);
  13037. }
  13038. currentFlipSided = flipSided;
  13039. }
  13040. }
  13041. function setCullFace(cullFace) {
  13042. if (cullFace !== CullFaceNone) {
  13043. enable(2884);
  13044. if (cullFace !== currentCullFace) {
  13045. if (cullFace === CullFaceBack) {
  13046. gl.cullFace(1029);
  13047. } else if (cullFace === CullFaceFront) {
  13048. gl.cullFace(1028);
  13049. } else {
  13050. gl.cullFace(1032);
  13051. }
  13052. }
  13053. } else {
  13054. disable(2884);
  13055. }
  13056. currentCullFace = cullFace;
  13057. }
  13058. function setLineWidth(width) {
  13059. if (width !== currentLineWidth) {
  13060. if (lineWidthAvailable) gl.lineWidth(width);
  13061. currentLineWidth = width;
  13062. }
  13063. }
  13064. function setPolygonOffset(polygonOffset, factor, units) {
  13065. if (polygonOffset) {
  13066. enable(32823);
  13067. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  13068. gl.polygonOffset(factor, units);
  13069. currentPolygonOffsetFactor = factor;
  13070. currentPolygonOffsetUnits = units;
  13071. }
  13072. } else {
  13073. disable(32823);
  13074. }
  13075. }
  13076. function setScissorTest(scissorTest) {
  13077. if (scissorTest) {
  13078. enable(3089);
  13079. } else {
  13080. disable(3089);
  13081. }
  13082. } // texture
  13083. function activeTexture(webglSlot) {
  13084. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  13085. if (currentTextureSlot !== webglSlot) {
  13086. gl.activeTexture(webglSlot);
  13087. currentTextureSlot = webglSlot;
  13088. }
  13089. }
  13090. function bindTexture(webglType, webglTexture) {
  13091. if (currentTextureSlot === null) {
  13092. activeTexture();
  13093. }
  13094. var boundTexture = currentBoundTextures[currentTextureSlot];
  13095. if (boundTexture === undefined) {
  13096. boundTexture = {
  13097. type: undefined,
  13098. texture: undefined
  13099. };
  13100. currentBoundTextures[currentTextureSlot] = boundTexture;
  13101. }
  13102. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  13103. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  13104. boundTexture.type = webglType;
  13105. boundTexture.texture = webglTexture;
  13106. }
  13107. }
  13108. function unbindTexture() {
  13109. var boundTexture = currentBoundTextures[currentTextureSlot];
  13110. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  13111. gl.bindTexture(boundTexture.type, null);
  13112. boundTexture.type = undefined;
  13113. boundTexture.texture = undefined;
  13114. }
  13115. }
  13116. function compressedTexImage2D() {
  13117. try {
  13118. gl.compressedTexImage2D.apply(gl, arguments);
  13119. } catch (error) {
  13120. console.error('THREE.WebGLState:', error);
  13121. }
  13122. }
  13123. function texImage2D() {
  13124. try {
  13125. gl.texImage2D.apply(gl, arguments);
  13126. } catch (error) {
  13127. console.error('THREE.WebGLState:', error);
  13128. }
  13129. }
  13130. function texImage3D() {
  13131. try {
  13132. gl.texImage3D.apply(gl, arguments);
  13133. } catch (error) {
  13134. console.error('THREE.WebGLState:', error);
  13135. }
  13136. } //
  13137. function scissor(scissor) {
  13138. if (currentScissor.equals(scissor) === false) {
  13139. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  13140. currentScissor.copy(scissor);
  13141. }
  13142. }
  13143. function viewport(viewport) {
  13144. if (currentViewport.equals(viewport) === false) {
  13145. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  13146. currentViewport.copy(viewport);
  13147. }
  13148. } //
  13149. function reset() {
  13150. enabledCapabilities = {};
  13151. currentTextureSlot = null;
  13152. currentBoundTextures = {};
  13153. currentProgram = null;
  13154. currentBlendingEnabled = null;
  13155. currentBlending = null;
  13156. currentBlendEquation = null;
  13157. currentBlendSrc = null;
  13158. currentBlendDst = null;
  13159. currentBlendEquationAlpha = null;
  13160. currentBlendSrcAlpha = null;
  13161. currentBlendDstAlpha = null;
  13162. currentPremultipledAlpha = false;
  13163. currentFlipSided = null;
  13164. currentCullFace = null;
  13165. currentLineWidth = null;
  13166. currentPolygonOffsetFactor = null;
  13167. currentPolygonOffsetUnits = null;
  13168. colorBuffer.reset();
  13169. depthBuffer.reset();
  13170. stencilBuffer.reset();
  13171. }
  13172. return {
  13173. buffers: {
  13174. color: colorBuffer,
  13175. depth: depthBuffer,
  13176. stencil: stencilBuffer
  13177. },
  13178. enable: enable,
  13179. disable: disable,
  13180. useProgram: useProgram,
  13181. setBlending: setBlending,
  13182. setMaterial: setMaterial,
  13183. setFlipSided: setFlipSided,
  13184. setCullFace: setCullFace,
  13185. setLineWidth: setLineWidth,
  13186. setPolygonOffset: setPolygonOffset,
  13187. setScissorTest: setScissorTest,
  13188. activeTexture: activeTexture,
  13189. bindTexture: bindTexture,
  13190. unbindTexture: unbindTexture,
  13191. compressedTexImage2D: compressedTexImage2D,
  13192. texImage2D: texImage2D,
  13193. texImage3D: texImage3D,
  13194. scissor: scissor,
  13195. viewport: viewport,
  13196. reset: reset
  13197. };
  13198. }
  13199. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  13200. var _wrappingToGL, _filterToGL;
  13201. var isWebGL2 = capabilities.isWebGL2;
  13202. var maxTextures = capabilities.maxTextures;
  13203. var maxCubemapSize = capabilities.maxCubemapSize;
  13204. var maxTextureSize = capabilities.maxTextureSize;
  13205. var maxSamples = capabilities.maxSamples;
  13206. var _videoTextures = new WeakMap();
  13207. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  13208. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  13209. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  13210. var useOffscreenCanvas = false;
  13211. try {
  13212. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext('2d') !== null;
  13213. } catch (err) {// Ignore any errors
  13214. }
  13215. function createCanvas(width, height) {
  13216. // Use OffscreenCanvas when available. Specially needed in web workers
  13217. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  13218. }
  13219. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  13220. var scale = 1; // handle case if texture exceeds max size
  13221. if (image.width > maxSize || image.height > maxSize) {
  13222. scale = maxSize / Math.max(image.width, image.height);
  13223. } // only perform resize if necessary
  13224. if (scale < 1 || needsPowerOfTwo === true) {
  13225. // only perform resize for certain image types
  13226. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  13227. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  13228. var width = floor(scale * image.width);
  13229. var height = floor(scale * image.height);
  13230. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  13231. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  13232. canvas.width = width;
  13233. canvas.height = height;
  13234. var context = canvas.getContext('2d');
  13235. context.drawImage(image, 0, 0, width, height);
  13236. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  13237. return canvas;
  13238. } else {
  13239. if ('data' in image) {
  13240. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  13241. }
  13242. return image;
  13243. }
  13244. }
  13245. return image;
  13246. }
  13247. function isPowerOfTwo(image) {
  13248. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  13249. }
  13250. function textureNeedsPowerOfTwo(texture) {
  13251. if (isWebGL2) return false;
  13252. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13253. }
  13254. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  13255. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13256. }
  13257. function generateMipmap(target, texture, width, height) {
  13258. _gl.generateMipmap(target);
  13259. var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  13260. textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
  13261. }
  13262. function getInternalFormat(internalFormatName, glFormat, glType) {
  13263. if (isWebGL2 === false) return glFormat;
  13264. if (internalFormatName !== null) {
  13265. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  13266. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  13267. }
  13268. var internalFormat = glFormat;
  13269. if (glFormat === 6403) {
  13270. if (glType === 5126) internalFormat = 33326;
  13271. if (glType === 5131) internalFormat = 33325;
  13272. if (glType === 5121) internalFormat = 33321;
  13273. }
  13274. if (glFormat === 6407) {
  13275. if (glType === 5126) internalFormat = 34837;
  13276. if (glType === 5131) internalFormat = 34843;
  13277. if (glType === 5121) internalFormat = 32849;
  13278. }
  13279. if (glFormat === 6408) {
  13280. if (glType === 5126) internalFormat = 34836;
  13281. if (glType === 5131) internalFormat = 34842;
  13282. if (glType === 5121) internalFormat = 32856;
  13283. }
  13284. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  13285. extensions.get('EXT_color_buffer_float');
  13286. }
  13287. return internalFormat;
  13288. } // Fallback filters for non-power-of-2 textures
  13289. function filterFallback(f) {
  13290. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  13291. return 9728;
  13292. }
  13293. return 9729;
  13294. } //
  13295. function onTextureDispose(event) {
  13296. var texture = event.target;
  13297. texture.removeEventListener('dispose', onTextureDispose);
  13298. deallocateTexture(texture);
  13299. if (texture.isVideoTexture) {
  13300. _videoTextures.delete(texture);
  13301. }
  13302. info.memory.textures--;
  13303. }
  13304. function onRenderTargetDispose(event) {
  13305. var renderTarget = event.target;
  13306. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  13307. deallocateRenderTarget(renderTarget);
  13308. info.memory.textures--;
  13309. } //
  13310. function deallocateTexture(texture) {
  13311. var textureProperties = properties.get(texture);
  13312. if (textureProperties.__webglInit === undefined) return;
  13313. _gl.deleteTexture(textureProperties.__webglTexture);
  13314. properties.remove(texture);
  13315. }
  13316. function deallocateRenderTarget(renderTarget) {
  13317. var renderTargetProperties = properties.get(renderTarget);
  13318. var textureProperties = properties.get(renderTarget.texture);
  13319. if (!renderTarget) return;
  13320. if (textureProperties.__webglTexture !== undefined) {
  13321. _gl.deleteTexture(textureProperties.__webglTexture);
  13322. }
  13323. if (renderTarget.depthTexture) {
  13324. renderTarget.depthTexture.dispose();
  13325. }
  13326. if (renderTarget.isWebGLCubeRenderTarget) {
  13327. for (var i = 0; i < 6; i++) {
  13328. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  13329. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  13330. }
  13331. } else {
  13332. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  13333. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  13334. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  13335. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  13336. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  13337. }
  13338. properties.remove(renderTarget.texture);
  13339. properties.remove(renderTarget);
  13340. } //
  13341. var textureUnits = 0;
  13342. function resetTextureUnits() {
  13343. textureUnits = 0;
  13344. }
  13345. function allocateTextureUnit() {
  13346. var textureUnit = textureUnits;
  13347. if (textureUnit >= maxTextures) {
  13348. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  13349. }
  13350. textureUnits += 1;
  13351. return textureUnit;
  13352. } //
  13353. function setTexture2D(texture, slot) {
  13354. var textureProperties = properties.get(texture);
  13355. if (texture.isVideoTexture) updateVideoTexture(texture);
  13356. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13357. var image = texture.image;
  13358. if (image === undefined) {
  13359. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  13360. } else if (image.complete === false) {
  13361. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  13362. } else {
  13363. uploadTexture(textureProperties, texture, slot);
  13364. return;
  13365. }
  13366. }
  13367. state.activeTexture(33984 + slot);
  13368. state.bindTexture(3553, textureProperties.__webglTexture);
  13369. }
  13370. function setTexture2DArray(texture, slot) {
  13371. var textureProperties = properties.get(texture);
  13372. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13373. uploadTexture(textureProperties, texture, slot);
  13374. return;
  13375. }
  13376. state.activeTexture(33984 + slot);
  13377. state.bindTexture(35866, textureProperties.__webglTexture);
  13378. }
  13379. function setTexture3D(texture, slot) {
  13380. var textureProperties = properties.get(texture);
  13381. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13382. uploadTexture(textureProperties, texture, slot);
  13383. return;
  13384. }
  13385. state.activeTexture(33984 + slot);
  13386. state.bindTexture(32879, textureProperties.__webglTexture);
  13387. }
  13388. function setTextureCube(texture, slot) {
  13389. var textureProperties = properties.get(texture);
  13390. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13391. uploadCubeTexture(textureProperties, texture, slot);
  13392. return;
  13393. }
  13394. state.activeTexture(33984 + slot);
  13395. state.bindTexture(34067, textureProperties.__webglTexture);
  13396. }
  13397. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  13398. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  13399. function setTextureParameters(textureType, texture, supportsMips) {
  13400. if (supportsMips) {
  13401. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  13402. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  13403. if (textureType === 32879 || textureType === 35866) {
  13404. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  13405. }
  13406. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  13407. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  13408. } else {
  13409. _gl.texParameteri(textureType, 10242, 33071);
  13410. _gl.texParameteri(textureType, 10243, 33071);
  13411. if (textureType === 32879 || textureType === 35866) {
  13412. _gl.texParameteri(textureType, 32882, 33071);
  13413. }
  13414. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  13415. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  13416. }
  13417. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  13418. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  13419. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  13420. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  13421. }
  13422. }
  13423. var extension = extensions.get('EXT_texture_filter_anisotropic');
  13424. if (extension) {
  13425. if (texture.type === FloatType && extensions.get('OES_texture_float_linear') === null) return;
  13426. if (texture.type === HalfFloatType && (isWebGL2 || extensions.get('OES_texture_half_float_linear')) === null) return;
  13427. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  13428. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  13429. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  13430. }
  13431. }
  13432. }
  13433. function initTexture(textureProperties, texture) {
  13434. if (textureProperties.__webglInit === undefined) {
  13435. textureProperties.__webglInit = true;
  13436. texture.addEventListener('dispose', onTextureDispose);
  13437. textureProperties.__webglTexture = _gl.createTexture();
  13438. info.memory.textures++;
  13439. }
  13440. }
  13441. function uploadTexture(textureProperties, texture, slot) {
  13442. var textureType = 3553;
  13443. if (texture.isDataTexture2DArray) textureType = 35866;
  13444. if (texture.isDataTexture3D) textureType = 32879;
  13445. initTexture(textureProperties, texture);
  13446. state.activeTexture(33984 + slot);
  13447. state.bindTexture(textureType, textureProperties.__webglTexture);
  13448. _gl.pixelStorei(37440, texture.flipY);
  13449. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13450. _gl.pixelStorei(3317, texture.unpackAlignment);
  13451. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  13452. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  13453. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  13454. glFormat = utils.convert(texture.format);
  13455. var glType = utils.convert(texture.type),
  13456. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13457. setTextureParameters(textureType, texture, supportsMips);
  13458. var mipmap;
  13459. var mipmaps = texture.mipmaps;
  13460. if (texture.isDepthTexture) {
  13461. // populate depth texture with dummy data
  13462. glInternalFormat = 6402;
  13463. if (isWebGL2) {
  13464. if (texture.type === FloatType) {
  13465. glInternalFormat = 36012;
  13466. } else if (texture.type === UnsignedIntType) {
  13467. glInternalFormat = 33190;
  13468. } else if (texture.type === UnsignedInt248Type) {
  13469. glInternalFormat = 35056;
  13470. } else {
  13471. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  13472. }
  13473. } else {
  13474. if (texture.type === FloatType) {
  13475. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  13476. }
  13477. } // validation checks for WebGL 1
  13478. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  13479. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13480. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  13481. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13482. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  13483. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  13484. texture.type = UnsignedShortType;
  13485. glType = utils.convert(texture.type);
  13486. }
  13487. }
  13488. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  13489. // Depth stencil textures need the DEPTH_STENCIL internal format
  13490. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13491. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13492. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  13493. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13494. if (texture.type !== UnsignedInt248Type) {
  13495. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  13496. texture.type = UnsignedInt248Type;
  13497. glType = utils.convert(texture.type);
  13498. }
  13499. } //
  13500. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  13501. } else if (texture.isDataTexture) {
  13502. // use manually created mipmaps if available
  13503. // if there are no manual mipmaps
  13504. // set 0 level mipmap and then use GL to generate other mipmap levels
  13505. if (mipmaps.length > 0 && supportsMips) {
  13506. for (var i = 0, il = mipmaps.length; i < il; i++) {
  13507. mipmap = mipmaps[i];
  13508. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13509. }
  13510. texture.generateMipmaps = false;
  13511. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13512. } else {
  13513. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  13514. textureProperties.__maxMipLevel = 0;
  13515. }
  13516. } else if (texture.isCompressedTexture) {
  13517. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  13518. mipmap = mipmaps[_i];
  13519. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13520. if (glFormat !== null) {
  13521. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13522. } else {
  13523. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  13524. }
  13525. } else {
  13526. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13527. }
  13528. }
  13529. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13530. } else if (texture.isDataTexture2DArray) {
  13531. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13532. textureProperties.__maxMipLevel = 0;
  13533. } else if (texture.isDataTexture3D) {
  13534. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13535. textureProperties.__maxMipLevel = 0;
  13536. } else {
  13537. // regular Texture (image, video, canvas)
  13538. // use manually created mipmaps if available
  13539. // if there are no manual mipmaps
  13540. // set 0 level mipmap and then use GL to generate other mipmap levels
  13541. if (mipmaps.length > 0 && supportsMips) {
  13542. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  13543. mipmap = mipmaps[_i2];
  13544. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  13545. }
  13546. texture.generateMipmaps = false;
  13547. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13548. } else {
  13549. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  13550. textureProperties.__maxMipLevel = 0;
  13551. }
  13552. }
  13553. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13554. generateMipmap(textureType, texture, image.width, image.height);
  13555. }
  13556. textureProperties.__version = texture.version;
  13557. if (texture.onUpdate) texture.onUpdate(texture);
  13558. }
  13559. function uploadCubeTexture(textureProperties, texture, slot) {
  13560. if (texture.image.length !== 6) return;
  13561. initTexture(textureProperties, texture);
  13562. state.activeTexture(33984 + slot);
  13563. state.bindTexture(34067, textureProperties.__webglTexture);
  13564. _gl.pixelStorei(37440, texture.flipY);
  13565. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13566. _gl.pixelStorei(3317, texture.unpackAlignment);
  13567. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  13568. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  13569. var cubeImage = [];
  13570. for (var i = 0; i < 6; i++) {
  13571. if (!isCompressed && !isDataTexture) {
  13572. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  13573. } else {
  13574. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  13575. }
  13576. }
  13577. var image = cubeImage[0],
  13578. supportsMips = isPowerOfTwo(image) || isWebGL2,
  13579. glFormat = utils.convert(texture.format),
  13580. glType = utils.convert(texture.type),
  13581. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13582. setTextureParameters(34067, texture, supportsMips);
  13583. var mipmaps;
  13584. if (isCompressed) {
  13585. for (var _i3 = 0; _i3 < 6; _i3++) {
  13586. mipmaps = cubeImage[_i3].mipmaps;
  13587. for (var j = 0; j < mipmaps.length; j++) {
  13588. var mipmap = mipmaps[j];
  13589. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13590. if (glFormat !== null) {
  13591. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13592. } else {
  13593. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  13594. }
  13595. } else {
  13596. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13597. }
  13598. }
  13599. }
  13600. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13601. } else {
  13602. mipmaps = texture.mipmaps;
  13603. for (var _i4 = 0; _i4 < 6; _i4++) {
  13604. if (isDataTexture) {
  13605. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  13606. for (var _j = 0; _j < mipmaps.length; _j++) {
  13607. var _mipmap = mipmaps[_j];
  13608. var mipmapImage = _mipmap.image[_i4].image;
  13609. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  13610. }
  13611. } else {
  13612. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  13613. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  13614. var _mipmap2 = mipmaps[_j2];
  13615. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  13616. }
  13617. }
  13618. }
  13619. textureProperties.__maxMipLevel = mipmaps.length;
  13620. }
  13621. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13622. // We assume images for cube map have the same size.
  13623. generateMipmap(34067, texture, image.width, image.height);
  13624. }
  13625. textureProperties.__version = texture.version;
  13626. if (texture.onUpdate) texture.onUpdate(texture);
  13627. } // Render targets
  13628. // Setup storage for target texture and bind it to correct framebuffer
  13629. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  13630. var glFormat = utils.convert(renderTarget.texture.format);
  13631. var glType = utils.convert(renderTarget.texture.type);
  13632. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13633. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  13634. _gl.bindFramebuffer(36160, framebuffer);
  13635. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(renderTarget.texture).__webglTexture, 0);
  13636. _gl.bindFramebuffer(36160, null);
  13637. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13638. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  13639. _gl.bindRenderbuffer(36161, renderbuffer);
  13640. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  13641. var glInternalFormat = 33189;
  13642. if (isMultisample) {
  13643. var depthTexture = renderTarget.depthTexture;
  13644. if (depthTexture && depthTexture.isDepthTexture) {
  13645. if (depthTexture.type === FloatType) {
  13646. glInternalFormat = 36012;
  13647. } else if (depthTexture.type === UnsignedIntType) {
  13648. glInternalFormat = 33190;
  13649. }
  13650. }
  13651. var samples = getRenderTargetSamples(renderTarget);
  13652. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13653. } else {
  13654. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  13655. }
  13656. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  13657. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  13658. if (isMultisample) {
  13659. var _samples = getRenderTargetSamples(renderTarget);
  13660. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  13661. } else {
  13662. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  13663. }
  13664. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  13665. } else {
  13666. var glFormat = utils.convert(renderTarget.texture.format);
  13667. var glType = utils.convert(renderTarget.texture.type);
  13668. var _glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13669. if (isMultisample) {
  13670. var _samples2 = getRenderTargetSamples(renderTarget);
  13671. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  13672. } else {
  13673. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  13674. }
  13675. }
  13676. _gl.bindRenderbuffer(36161, null);
  13677. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  13678. function setupDepthTexture(framebuffer, renderTarget) {
  13679. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  13680. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  13681. _gl.bindFramebuffer(36160, framebuffer);
  13682. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  13683. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  13684. } // upload an empty depth texture with framebuffer size
  13685. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  13686. renderTarget.depthTexture.image.width = renderTarget.width;
  13687. renderTarget.depthTexture.image.height = renderTarget.height;
  13688. renderTarget.depthTexture.needsUpdate = true;
  13689. }
  13690. setTexture2D(renderTarget.depthTexture, 0);
  13691. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  13692. if (renderTarget.depthTexture.format === DepthFormat) {
  13693. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  13694. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  13695. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  13696. } else {
  13697. throw new Error('Unknown depthTexture format');
  13698. }
  13699. } // Setup GL resources for a non-texture depth buffer
  13700. function setupDepthRenderbuffer(renderTarget) {
  13701. var renderTargetProperties = properties.get(renderTarget);
  13702. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13703. if (renderTarget.depthTexture) {
  13704. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  13705. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  13706. } else {
  13707. if (isCube) {
  13708. renderTargetProperties.__webglDepthbuffer = [];
  13709. for (var i = 0; i < 6; i++) {
  13710. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  13711. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  13712. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  13713. }
  13714. } else {
  13715. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  13716. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13717. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  13718. }
  13719. }
  13720. _gl.bindFramebuffer(36160, null);
  13721. } // Set up GL resources for the render target
  13722. function setupRenderTarget(renderTarget) {
  13723. var renderTargetProperties = properties.get(renderTarget);
  13724. var textureProperties = properties.get(renderTarget.texture);
  13725. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  13726. textureProperties.__webglTexture = _gl.createTexture();
  13727. info.memory.textures++;
  13728. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13729. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  13730. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  13731. if (isWebGL2 && renderTarget.texture.format === RGBFormat && (renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType)) {
  13732. renderTarget.texture.format = RGBAFormat;
  13733. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  13734. } // Setup framebuffer
  13735. if (isCube) {
  13736. renderTargetProperties.__webglFramebuffer = [];
  13737. for (var i = 0; i < 6; i++) {
  13738. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  13739. }
  13740. } else {
  13741. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13742. if (isMultisample) {
  13743. if (isWebGL2) {
  13744. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13745. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13746. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  13747. var glFormat = utils.convert(renderTarget.texture.format);
  13748. var glType = utils.convert(renderTarget.texture.type);
  13749. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13750. var samples = getRenderTargetSamples(renderTarget);
  13751. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13752. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13753. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13754. _gl.bindRenderbuffer(36161, null);
  13755. if (renderTarget.depthBuffer) {
  13756. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13757. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13758. }
  13759. _gl.bindFramebuffer(36160, null);
  13760. } else {
  13761. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13762. }
  13763. }
  13764. } // Setup color buffer
  13765. if (isCube) {
  13766. state.bindTexture(34067, textureProperties.__webglTexture);
  13767. setTextureParameters(34067, renderTarget.texture, supportsMips);
  13768. for (var _i5 = 0; _i5 < 6; _i5++) {
  13769. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13770. }
  13771. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13772. generateMipmap(34067, renderTarget.texture, renderTarget.width, renderTarget.height);
  13773. }
  13774. state.bindTexture(34067, null);
  13775. } else {
  13776. state.bindTexture(3553, textureProperties.__webglTexture);
  13777. setTextureParameters(3553, renderTarget.texture, supportsMips);
  13778. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553);
  13779. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13780. generateMipmap(3553, renderTarget.texture, renderTarget.width, renderTarget.height);
  13781. }
  13782. state.bindTexture(3553, null);
  13783. } // Setup depth and stencil buffers
  13784. if (renderTarget.depthBuffer) {
  13785. setupDepthRenderbuffer(renderTarget);
  13786. }
  13787. }
  13788. function updateRenderTargetMipmap(renderTarget) {
  13789. var texture = renderTarget.texture;
  13790. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13791. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13792. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13793. var webglTexture = properties.get(texture).__webglTexture;
  13794. state.bindTexture(target, webglTexture);
  13795. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13796. state.bindTexture(target, null);
  13797. }
  13798. }
  13799. function updateMultisampleRenderTarget(renderTarget) {
  13800. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13801. if (isWebGL2) {
  13802. var renderTargetProperties = properties.get(renderTarget);
  13803. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13804. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13805. var width = renderTarget.width;
  13806. var height = renderTarget.height;
  13807. var mask = 16384;
  13808. if (renderTarget.depthBuffer) mask |= 256;
  13809. if (renderTarget.stencilBuffer) mask |= 1024;
  13810. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13811. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13812. } else {
  13813. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13814. }
  13815. }
  13816. }
  13817. function getRenderTargetSamples(renderTarget) {
  13818. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13819. }
  13820. function updateVideoTexture(texture) {
  13821. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13822. if (_videoTextures.get(texture) !== frame) {
  13823. _videoTextures.set(texture, frame);
  13824. texture.update();
  13825. }
  13826. } // backwards compatibility
  13827. var warnedTexture2D = false;
  13828. var warnedTextureCube = false;
  13829. function safeSetTexture2D(texture, slot) {
  13830. if (texture && texture.isWebGLRenderTarget) {
  13831. if (warnedTexture2D === false) {
  13832. console.warn('THREE.WebGLTextures.safeSetTexture2D: don\'t use render targets as textures. Use their .texture property instead.');
  13833. warnedTexture2D = true;
  13834. }
  13835. texture = texture.texture;
  13836. }
  13837. setTexture2D(texture, slot);
  13838. }
  13839. function safeSetTextureCube(texture, slot) {
  13840. if (texture && texture.isWebGLCubeRenderTarget) {
  13841. if (warnedTextureCube === false) {
  13842. console.warn('THREE.WebGLTextures.safeSetTextureCube: don\'t use cube render targets as textures. Use their .texture property instead.');
  13843. warnedTextureCube = true;
  13844. }
  13845. texture = texture.texture;
  13846. }
  13847. setTextureCube(texture, slot);
  13848. } //
  13849. this.allocateTextureUnit = allocateTextureUnit;
  13850. this.resetTextureUnits = resetTextureUnits;
  13851. this.setTexture2D = setTexture2D;
  13852. this.setTexture2DArray = setTexture2DArray;
  13853. this.setTexture3D = setTexture3D;
  13854. this.setTextureCube = setTextureCube;
  13855. this.setupRenderTarget = setupRenderTarget;
  13856. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13857. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13858. this.safeSetTexture2D = safeSetTexture2D;
  13859. this.safeSetTextureCube = safeSetTextureCube;
  13860. }
  13861. function WebGLUtils(gl, extensions, capabilities) {
  13862. var isWebGL2 = capabilities.isWebGL2;
  13863. function convert(p) {
  13864. var extension;
  13865. if (p === UnsignedByteType) return 5121;
  13866. if (p === UnsignedShort4444Type) return 32819;
  13867. if (p === UnsignedShort5551Type) return 32820;
  13868. if (p === UnsignedShort565Type) return 33635;
  13869. if (p === ByteType) return 5120;
  13870. if (p === ShortType) return 5122;
  13871. if (p === UnsignedShortType) return 5123;
  13872. if (p === IntType) return 5124;
  13873. if (p === UnsignedIntType) return 5125;
  13874. if (p === FloatType) return 5126;
  13875. if (p === HalfFloatType) {
  13876. if (isWebGL2) return 5131;
  13877. extension = extensions.get('OES_texture_half_float');
  13878. if (extension !== null) {
  13879. return extension.HALF_FLOAT_OES;
  13880. } else {
  13881. return null;
  13882. }
  13883. }
  13884. if (p === AlphaFormat) return 6406;
  13885. if (p === RGBFormat) return 6407;
  13886. if (p === RGBAFormat) return 6408;
  13887. if (p === LuminanceFormat) return 6409;
  13888. if (p === LuminanceAlphaFormat) return 6410;
  13889. if (p === DepthFormat) return 6402;
  13890. if (p === DepthStencilFormat) return 34041;
  13891. if (p === RedFormat) return 6403; // WebGL2 formats.
  13892. if (p === RedIntegerFormat) return 36244;
  13893. if (p === RGFormat) return 33319;
  13894. if (p === RGIntegerFormat) return 33320;
  13895. if (p === RGBIntegerFormat) return 36248;
  13896. if (p === RGBAIntegerFormat) return 36249;
  13897. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  13898. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  13899. if (extension !== null) {
  13900. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13901. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13902. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13903. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13904. } else {
  13905. return null;
  13906. }
  13907. }
  13908. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  13909. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  13910. if (extension !== null) {
  13911. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13912. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13913. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13914. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13915. } else {
  13916. return null;
  13917. }
  13918. }
  13919. if (p === RGB_ETC1_Format) {
  13920. extension = extensions.get('WEBGL_compressed_texture_etc1');
  13921. if (extension !== null) {
  13922. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13923. } else {
  13924. return null;
  13925. }
  13926. }
  13927. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  13928. extension = extensions.get('WEBGL_compressed_texture_etc');
  13929. if (extension !== null) {
  13930. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  13931. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13932. }
  13933. }
  13934. 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) {
  13935. extension = extensions.get('WEBGL_compressed_texture_astc');
  13936. if (extension !== null) {
  13937. // TODO Complete?
  13938. return p;
  13939. } else {
  13940. return null;
  13941. }
  13942. }
  13943. if (p === RGBA_BPTC_Format) {
  13944. extension = extensions.get('EXT_texture_compression_bptc');
  13945. if (extension !== null) {
  13946. // TODO Complete?
  13947. return p;
  13948. } else {
  13949. return null;
  13950. }
  13951. }
  13952. if (p === UnsignedInt248Type) {
  13953. if (isWebGL2) return 34042;
  13954. extension = extensions.get('WEBGL_depth_texture');
  13955. if (extension !== null) {
  13956. return extension.UNSIGNED_INT_24_8_WEBGL;
  13957. } else {
  13958. return null;
  13959. }
  13960. }
  13961. }
  13962. return {
  13963. convert: convert
  13964. };
  13965. }
  13966. function ArrayCamera(array) {
  13967. if (array === void 0) {
  13968. array = [];
  13969. }
  13970. PerspectiveCamera.call(this);
  13971. this.cameras = array;
  13972. }
  13973. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  13974. constructor: ArrayCamera,
  13975. isArrayCamera: true
  13976. });
  13977. function Group() {
  13978. Object3D.call(this);
  13979. this.type = 'Group';
  13980. }
  13981. Group.prototype = Object.assign(Object.create(Object3D.prototype), {
  13982. constructor: Group,
  13983. isGroup: true
  13984. });
  13985. function WebXRController() {
  13986. this._targetRay = null;
  13987. this._grip = null;
  13988. this._hand = null;
  13989. }
  13990. Object.assign(WebXRController.prototype, {
  13991. constructor: WebXRController,
  13992. getHandSpace: function getHandSpace() {
  13993. if (this._hand === null) {
  13994. this._hand = new Group();
  13995. this._hand.matrixAutoUpdate = false;
  13996. this._hand.visible = false;
  13997. this._hand.joints = [];
  13998. this._hand.inputState = {
  13999. pinching: false
  14000. };
  14001. if (window.XRHand) {
  14002. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  14003. // The transform of this joint will be updated with the joint pose on each frame
  14004. var joint = new Group();
  14005. joint.matrixAutoUpdate = false;
  14006. joint.visible = false;
  14007. this._hand.joints.push(joint); // ??
  14008. this._hand.add(joint);
  14009. }
  14010. }
  14011. }
  14012. return this._hand;
  14013. },
  14014. getTargetRaySpace: function getTargetRaySpace() {
  14015. if (this._targetRay === null) {
  14016. this._targetRay = new Group();
  14017. this._targetRay.matrixAutoUpdate = false;
  14018. this._targetRay.visible = false;
  14019. }
  14020. return this._targetRay;
  14021. },
  14022. getGripSpace: function getGripSpace() {
  14023. if (this._grip === null) {
  14024. this._grip = new Group();
  14025. this._grip.matrixAutoUpdate = false;
  14026. this._grip.visible = false;
  14027. }
  14028. return this._grip;
  14029. },
  14030. dispatchEvent: function dispatchEvent(event) {
  14031. if (this._targetRay !== null) {
  14032. this._targetRay.dispatchEvent(event);
  14033. }
  14034. if (this._grip !== null) {
  14035. this._grip.dispatchEvent(event);
  14036. }
  14037. if (this._hand !== null) {
  14038. this._hand.dispatchEvent(event);
  14039. }
  14040. return this;
  14041. },
  14042. disconnect: function disconnect(inputSource) {
  14043. this.dispatchEvent({
  14044. type: 'disconnected',
  14045. data: inputSource
  14046. });
  14047. if (this._targetRay !== null) {
  14048. this._targetRay.visible = false;
  14049. }
  14050. if (this._grip !== null) {
  14051. this._grip.visible = false;
  14052. }
  14053. if (this._hand !== null) {
  14054. this._hand.visible = false;
  14055. }
  14056. return this;
  14057. },
  14058. update: function update(inputSource, frame, referenceSpace) {
  14059. var inputPose = null;
  14060. var gripPose = null;
  14061. var handPose = null;
  14062. var targetRay = this._targetRay;
  14063. var grip = this._grip;
  14064. var hand = this._hand;
  14065. if (inputSource && frame.session.visibilityState !== 'visible-blurred') {
  14066. if (hand && inputSource.hand) {
  14067. handPose = true;
  14068. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  14069. if (inputSource.hand[i]) {
  14070. // Update the joints groups with the XRJoint poses
  14071. var jointPose = frame.getJointPose(inputSource.hand[i], referenceSpace);
  14072. var joint = hand.joints[i];
  14073. if (jointPose !== null) {
  14074. joint.matrix.fromArray(jointPose.transform.matrix);
  14075. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  14076. joint.jointRadius = jointPose.radius;
  14077. }
  14078. joint.visible = jointPose !== null; // Custom events
  14079. // Check pinch
  14080. var indexTip = hand.joints[window.XRHand.INDEX_PHALANX_TIP];
  14081. var thumbTip = hand.joints[window.XRHand.THUMB_PHALANX_TIP];
  14082. var distance = indexTip.position.distanceTo(thumbTip.position);
  14083. var distanceToPinch = 0.02;
  14084. var threshold = 0.005;
  14085. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  14086. hand.inputState.pinching = false;
  14087. this.dispatchEvent({
  14088. type: 'pinchend',
  14089. handedness: inputSource.handedness,
  14090. target: this
  14091. });
  14092. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  14093. hand.inputState.pinching = true;
  14094. this.dispatchEvent({
  14095. type: 'pinchstart',
  14096. handedness: inputSource.handedness,
  14097. target: this
  14098. });
  14099. }
  14100. }
  14101. }
  14102. } else {
  14103. if (targetRay !== null) {
  14104. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  14105. if (inputPose !== null) {
  14106. targetRay.matrix.fromArray(inputPose.transform.matrix);
  14107. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  14108. }
  14109. }
  14110. if (grip !== null && inputSource.gripSpace) {
  14111. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  14112. if (gripPose !== null) {
  14113. grip.matrix.fromArray(gripPose.transform.matrix);
  14114. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  14115. }
  14116. }
  14117. }
  14118. }
  14119. if (targetRay !== null) {
  14120. targetRay.visible = inputPose !== null;
  14121. }
  14122. if (grip !== null) {
  14123. grip.visible = gripPose !== null;
  14124. }
  14125. if (hand !== null) {
  14126. hand.visible = handPose !== null;
  14127. }
  14128. return this;
  14129. }
  14130. });
  14131. function WebXRManager(renderer, gl) {
  14132. var scope = this;
  14133. var session = null;
  14134. var framebufferScaleFactor = 1.0;
  14135. var referenceSpace = null;
  14136. var referenceSpaceType = 'local-floor';
  14137. var pose = null;
  14138. var controllers = [];
  14139. var inputSourcesMap = new Map(); //
  14140. var cameraL = new PerspectiveCamera();
  14141. cameraL.layers.enable(1);
  14142. cameraL.viewport = new Vector4();
  14143. var cameraR = new PerspectiveCamera();
  14144. cameraR.layers.enable(2);
  14145. cameraR.viewport = new Vector4();
  14146. var cameras = [cameraL, cameraR];
  14147. var cameraVR = new ArrayCamera();
  14148. cameraVR.layers.enable(1);
  14149. cameraVR.layers.enable(2);
  14150. var _currentDepthNear = null;
  14151. var _currentDepthFar = null; //
  14152. this.enabled = false;
  14153. this.isPresenting = false;
  14154. this.getController = function (index) {
  14155. var controller = controllers[index];
  14156. if (controller === undefined) {
  14157. controller = new WebXRController();
  14158. controllers[index] = controller;
  14159. }
  14160. return controller.getTargetRaySpace();
  14161. };
  14162. this.getControllerGrip = function (index) {
  14163. var controller = controllers[index];
  14164. if (controller === undefined) {
  14165. controller = new WebXRController();
  14166. controllers[index] = controller;
  14167. }
  14168. return controller.getGripSpace();
  14169. };
  14170. this.getHand = function (index) {
  14171. var controller = controllers[index];
  14172. if (controller === undefined) {
  14173. controller = new WebXRController();
  14174. controllers[index] = controller;
  14175. }
  14176. return controller.getHandSpace();
  14177. }; //
  14178. function onSessionEvent(event) {
  14179. var controller = inputSourcesMap.get(event.inputSource);
  14180. if (controller) {
  14181. controller.dispatchEvent({
  14182. type: event.type,
  14183. data: event.inputSource
  14184. });
  14185. }
  14186. }
  14187. function onSessionEnd() {
  14188. inputSourcesMap.forEach(function (controller, inputSource) {
  14189. controller.disconnect(inputSource);
  14190. });
  14191. inputSourcesMap.clear(); //
  14192. renderer.setFramebuffer(null);
  14193. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  14194. animation.stop();
  14195. scope.isPresenting = false;
  14196. scope.dispatchEvent({
  14197. type: 'sessionend'
  14198. });
  14199. }
  14200. this.setFramebufferScaleFactor = function (value) {
  14201. framebufferScaleFactor = value;
  14202. if (scope.isPresenting === true) {
  14203. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  14204. }
  14205. };
  14206. this.setReferenceSpaceType = function (value) {
  14207. referenceSpaceType = value;
  14208. if (scope.isPresenting === true) {
  14209. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  14210. }
  14211. };
  14212. this.getReferenceSpace = function () {
  14213. return referenceSpace;
  14214. };
  14215. this.getSession = function () {
  14216. return session;
  14217. };
  14218. this.setSession = /*#__PURE__*/function () {
  14219. var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(value) {
  14220. var attributes, layerInit, baseLayer;
  14221. return regeneratorRuntime.wrap(function _callee$(_context) {
  14222. while (1) {
  14223. switch (_context.prev = _context.next) {
  14224. case 0:
  14225. session = value;
  14226. if (!(session !== null)) {
  14227. _context.next = 24;
  14228. break;
  14229. }
  14230. session.addEventListener('select', onSessionEvent);
  14231. session.addEventListener('selectstart', onSessionEvent);
  14232. session.addEventListener('selectend', onSessionEvent);
  14233. session.addEventListener('squeeze', onSessionEvent);
  14234. session.addEventListener('squeezestart', onSessionEvent);
  14235. session.addEventListener('squeezeend', onSessionEvent);
  14236. session.addEventListener('end', onSessionEnd);
  14237. session.addEventListener('inputsourceschange', onInputSourcesChange);
  14238. attributes = gl.getContextAttributes();
  14239. if (!(attributes.xrCompatible !== true)) {
  14240. _context.next = 14;
  14241. break;
  14242. }
  14243. _context.next = 14;
  14244. return gl.makeXRCompatible();
  14245. case 14:
  14246. layerInit = {
  14247. antialias: attributes.antialias,
  14248. alpha: attributes.alpha,
  14249. depth: attributes.depth,
  14250. stencil: attributes.stencil,
  14251. framebufferScaleFactor: framebufferScaleFactor
  14252. }; // eslint-disable-next-line no-undef
  14253. baseLayer = new XRWebGLLayer(session, gl, layerInit);
  14254. session.updateRenderState({
  14255. baseLayer: baseLayer
  14256. });
  14257. _context.next = 19;
  14258. return session.requestReferenceSpace(referenceSpaceType);
  14259. case 19:
  14260. referenceSpace = _context.sent;
  14261. animation.setContext(session);
  14262. animation.start();
  14263. scope.isPresenting = true;
  14264. scope.dispatchEvent({
  14265. type: 'sessionstart'
  14266. });
  14267. case 24:
  14268. case "end":
  14269. return _context.stop();
  14270. }
  14271. }
  14272. }, _callee);
  14273. }));
  14274. return function (_x) {
  14275. return _ref.apply(this, arguments);
  14276. };
  14277. }();
  14278. function onInputSourcesChange(event) {
  14279. var inputSources = session.inputSources; // Assign inputSources to available controllers
  14280. for (var i = 0; i < controllers.length; i++) {
  14281. inputSourcesMap.set(inputSources[i], controllers[i]);
  14282. } // Notify disconnected
  14283. for (var _i = 0; _i < event.removed.length; _i++) {
  14284. var inputSource = event.removed[_i];
  14285. var controller = inputSourcesMap.get(inputSource);
  14286. if (controller) {
  14287. controller.dispatchEvent({
  14288. type: 'disconnected',
  14289. data: inputSource
  14290. });
  14291. inputSourcesMap.delete(inputSource);
  14292. }
  14293. } // Notify connected
  14294. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  14295. var _inputSource = event.added[_i2];
  14296. var _controller = inputSourcesMap.get(_inputSource);
  14297. if (_controller) {
  14298. _controller.dispatchEvent({
  14299. type: 'connected',
  14300. data: _inputSource
  14301. });
  14302. }
  14303. }
  14304. } //
  14305. var cameraLPos = new Vector3();
  14306. var cameraRPos = new Vector3();
  14307. /**
  14308. * Assumes 2 cameras that are parallel and share an X-axis, and that
  14309. * the cameras' projection and world matrices have already been set.
  14310. * And that near and far planes are identical for both cameras.
  14311. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  14312. */
  14313. function setProjectionFromUnion(camera, cameraL, cameraR) {
  14314. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  14315. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  14316. var ipd = cameraLPos.distanceTo(cameraRPos);
  14317. var projL = cameraL.projectionMatrix.elements;
  14318. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  14319. // most likely identical top and bottom frustum extents.
  14320. // Use the left camera for these values.
  14321. var near = projL[14] / (projL[10] - 1);
  14322. var far = projL[14] / (projL[10] + 1);
  14323. var topFov = (projL[9] + 1) / projL[5];
  14324. var bottomFov = (projL[9] - 1) / projL[5];
  14325. var leftFov = (projL[8] - 1) / projL[0];
  14326. var rightFov = (projR[8] + 1) / projR[0];
  14327. var left = near * leftFov;
  14328. var right = near * rightFov; // Calculate the new camera's position offset from the
  14329. // left camera. xOffset should be roughly half `ipd`.
  14330. var zOffset = ipd / (-leftFov + rightFov);
  14331. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  14332. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  14333. camera.translateX(xOffset);
  14334. camera.translateZ(zOffset);
  14335. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  14336. camera.matrixWorldInverse.copy(camera.matrixWorld).invert(); // Find the union of the frustum values of the cameras and scale
  14337. // the values so that the near plane's position does not change in world space,
  14338. // although must now be relative to the new union camera.
  14339. var near2 = near + zOffset;
  14340. var far2 = far + zOffset;
  14341. var left2 = left - xOffset;
  14342. var right2 = right + (ipd - xOffset);
  14343. var top2 = topFov * far / far2 * near2;
  14344. var bottom2 = bottomFov * far / far2 * near2;
  14345. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  14346. }
  14347. function updateCamera(camera, parent) {
  14348. if (parent === null) {
  14349. camera.matrixWorld.copy(camera.matrix);
  14350. } else {
  14351. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  14352. }
  14353. camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
  14354. }
  14355. this.getCamera = function (camera) {
  14356. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  14357. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  14358. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  14359. // Note that the new renderState won't apply until the next frame. See #18320
  14360. session.updateRenderState({
  14361. depthNear: cameraVR.near,
  14362. depthFar: cameraVR.far
  14363. });
  14364. _currentDepthNear = cameraVR.near;
  14365. _currentDepthFar = cameraVR.far;
  14366. }
  14367. var parent = camera.parent;
  14368. var cameras = cameraVR.cameras;
  14369. updateCamera(cameraVR, parent);
  14370. for (var i = 0; i < cameras.length; i++) {
  14371. updateCamera(cameras[i], parent);
  14372. } // update camera and its children
  14373. camera.matrixWorld.copy(cameraVR.matrixWorld);
  14374. var children = camera.children;
  14375. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  14376. children[_i3].updateMatrixWorld(true);
  14377. } // update projection matrix for proper view frustum culling
  14378. if (cameras.length === 2) {
  14379. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  14380. } else {
  14381. // assume single camera setup (AR)
  14382. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  14383. }
  14384. return cameraVR;
  14385. }; // Animation Loop
  14386. var onAnimationFrameCallback = null;
  14387. function onAnimationFrame(time, frame) {
  14388. pose = frame.getViewerPose(referenceSpace);
  14389. if (pose !== null) {
  14390. var views = pose.views;
  14391. var baseLayer = session.renderState.baseLayer;
  14392. renderer.setFramebuffer(baseLayer.framebuffer);
  14393. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  14394. if (views.length !== cameraVR.cameras.length) {
  14395. cameraVR.cameras.length = 0;
  14396. cameraVRNeedsUpdate = true;
  14397. }
  14398. for (var i = 0; i < views.length; i++) {
  14399. var view = views[i];
  14400. var viewport = baseLayer.getViewport(view);
  14401. var camera = cameras[i];
  14402. camera.matrix.fromArray(view.transform.matrix);
  14403. camera.projectionMatrix.fromArray(view.projectionMatrix);
  14404. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  14405. if (i === 0) {
  14406. cameraVR.matrix.copy(camera.matrix);
  14407. }
  14408. if (cameraVRNeedsUpdate === true) {
  14409. cameraVR.cameras.push(camera);
  14410. }
  14411. }
  14412. } //
  14413. var inputSources = session.inputSources;
  14414. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  14415. var controller = controllers[_i4];
  14416. var inputSource = inputSources[_i4];
  14417. controller.update(inputSource, frame, referenceSpace);
  14418. }
  14419. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  14420. }
  14421. var animation = new WebGLAnimation();
  14422. animation.setAnimationLoop(onAnimationFrame);
  14423. this.setAnimationLoop = function (callback) {
  14424. onAnimationFrameCallback = callback;
  14425. };
  14426. this.dispose = function () {};
  14427. }
  14428. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  14429. function WebGLMaterials(properties) {
  14430. function refreshFogUniforms(uniforms, fog) {
  14431. uniforms.fogColor.value.copy(fog.color);
  14432. if (fog.isFog) {
  14433. uniforms.fogNear.value = fog.near;
  14434. uniforms.fogFar.value = fog.far;
  14435. } else if (fog.isFogExp2) {
  14436. uniforms.fogDensity.value = fog.density;
  14437. }
  14438. }
  14439. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  14440. if (material.isMeshBasicMaterial) {
  14441. refreshUniformsCommon(uniforms, material);
  14442. } else if (material.isMeshLambertMaterial) {
  14443. refreshUniformsCommon(uniforms, material);
  14444. refreshUniformsLambert(uniforms, material);
  14445. } else if (material.isMeshToonMaterial) {
  14446. refreshUniformsCommon(uniforms, material);
  14447. refreshUniformsToon(uniforms, material);
  14448. } else if (material.isMeshPhongMaterial) {
  14449. refreshUniformsCommon(uniforms, material);
  14450. refreshUniformsPhong(uniforms, material);
  14451. } else if (material.isMeshStandardMaterial) {
  14452. refreshUniformsCommon(uniforms, material);
  14453. if (material.isMeshPhysicalMaterial) {
  14454. refreshUniformsPhysical(uniforms, material);
  14455. } else {
  14456. refreshUniformsStandard(uniforms, material);
  14457. }
  14458. } else if (material.isMeshMatcapMaterial) {
  14459. refreshUniformsCommon(uniforms, material);
  14460. refreshUniformsMatcap(uniforms, material);
  14461. } else if (material.isMeshDepthMaterial) {
  14462. refreshUniformsCommon(uniforms, material);
  14463. refreshUniformsDepth(uniforms, material);
  14464. } else if (material.isMeshDistanceMaterial) {
  14465. refreshUniformsCommon(uniforms, material);
  14466. refreshUniformsDistance(uniforms, material);
  14467. } else if (material.isMeshNormalMaterial) {
  14468. refreshUniformsCommon(uniforms, material);
  14469. refreshUniformsNormal(uniforms, material);
  14470. } else if (material.isLineBasicMaterial) {
  14471. refreshUniformsLine(uniforms, material);
  14472. if (material.isLineDashedMaterial) {
  14473. refreshUniformsDash(uniforms, material);
  14474. }
  14475. } else if (material.isPointsMaterial) {
  14476. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  14477. } else if (material.isSpriteMaterial) {
  14478. refreshUniformsSprites(uniforms, material);
  14479. } else if (material.isShadowMaterial) {
  14480. uniforms.color.value.copy(material.color);
  14481. uniforms.opacity.value = material.opacity;
  14482. } else if (material.isShaderMaterial) {
  14483. material.uniformsNeedUpdate = false; // #15581
  14484. }
  14485. }
  14486. function refreshUniformsCommon(uniforms, material) {
  14487. uniforms.opacity.value = material.opacity;
  14488. if (material.color) {
  14489. uniforms.diffuse.value.copy(material.color);
  14490. }
  14491. if (material.emissive) {
  14492. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  14493. }
  14494. if (material.map) {
  14495. uniforms.map.value = material.map;
  14496. }
  14497. if (material.alphaMap) {
  14498. uniforms.alphaMap.value = material.alphaMap;
  14499. }
  14500. if (material.specularMap) {
  14501. uniforms.specularMap.value = material.specularMap;
  14502. }
  14503. var envMap = properties.get(material).envMap;
  14504. if (envMap) {
  14505. uniforms.envMap.value = envMap;
  14506. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  14507. uniforms.reflectivity.value = material.reflectivity;
  14508. uniforms.refractionRatio.value = material.refractionRatio;
  14509. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  14510. if (maxMipLevel !== undefined) {
  14511. uniforms.maxMipLevel.value = maxMipLevel;
  14512. }
  14513. }
  14514. if (material.lightMap) {
  14515. uniforms.lightMap.value = material.lightMap;
  14516. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14517. }
  14518. if (material.aoMap) {
  14519. uniforms.aoMap.value = material.aoMap;
  14520. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14521. } // uv repeat and offset setting priorities
  14522. // 1. color map
  14523. // 2. specular map
  14524. // 3. displacementMap map
  14525. // 4. normal map
  14526. // 5. bump map
  14527. // 6. roughnessMap map
  14528. // 7. metalnessMap map
  14529. // 8. alphaMap map
  14530. // 9. emissiveMap map
  14531. // 10. clearcoat map
  14532. // 11. clearcoat normal map
  14533. // 12. clearcoat roughnessMap map
  14534. var uvScaleMap;
  14535. if (material.map) {
  14536. uvScaleMap = material.map;
  14537. } else if (material.specularMap) {
  14538. uvScaleMap = material.specularMap;
  14539. } else if (material.displacementMap) {
  14540. uvScaleMap = material.displacementMap;
  14541. } else if (material.normalMap) {
  14542. uvScaleMap = material.normalMap;
  14543. } else if (material.bumpMap) {
  14544. uvScaleMap = material.bumpMap;
  14545. } else if (material.roughnessMap) {
  14546. uvScaleMap = material.roughnessMap;
  14547. } else if (material.metalnessMap) {
  14548. uvScaleMap = material.metalnessMap;
  14549. } else if (material.alphaMap) {
  14550. uvScaleMap = material.alphaMap;
  14551. } else if (material.emissiveMap) {
  14552. uvScaleMap = material.emissiveMap;
  14553. } else if (material.clearcoatMap) {
  14554. uvScaleMap = material.clearcoatMap;
  14555. } else if (material.clearcoatNormalMap) {
  14556. uvScaleMap = material.clearcoatNormalMap;
  14557. } else if (material.clearcoatRoughnessMap) {
  14558. uvScaleMap = material.clearcoatRoughnessMap;
  14559. }
  14560. if (uvScaleMap !== undefined) {
  14561. // backwards compatibility
  14562. if (uvScaleMap.isWebGLRenderTarget) {
  14563. uvScaleMap = uvScaleMap.texture;
  14564. }
  14565. if (uvScaleMap.matrixAutoUpdate === true) {
  14566. uvScaleMap.updateMatrix();
  14567. }
  14568. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14569. } // uv repeat and offset setting priorities for uv2
  14570. // 1. ao map
  14571. // 2. light map
  14572. var uv2ScaleMap;
  14573. if (material.aoMap) {
  14574. uv2ScaleMap = material.aoMap;
  14575. } else if (material.lightMap) {
  14576. uv2ScaleMap = material.lightMap;
  14577. }
  14578. if (uv2ScaleMap !== undefined) {
  14579. // backwards compatibility
  14580. if (uv2ScaleMap.isWebGLRenderTarget) {
  14581. uv2ScaleMap = uv2ScaleMap.texture;
  14582. }
  14583. if (uv2ScaleMap.matrixAutoUpdate === true) {
  14584. uv2ScaleMap.updateMatrix();
  14585. }
  14586. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  14587. }
  14588. }
  14589. function refreshUniformsLine(uniforms, material) {
  14590. uniforms.diffuse.value.copy(material.color);
  14591. uniforms.opacity.value = material.opacity;
  14592. }
  14593. function refreshUniformsDash(uniforms, material) {
  14594. uniforms.dashSize.value = material.dashSize;
  14595. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14596. uniforms.scale.value = material.scale;
  14597. }
  14598. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  14599. uniforms.diffuse.value.copy(material.color);
  14600. uniforms.opacity.value = material.opacity;
  14601. uniforms.size.value = material.size * pixelRatio;
  14602. uniforms.scale.value = height * 0.5;
  14603. if (material.map) {
  14604. uniforms.map.value = material.map;
  14605. }
  14606. if (material.alphaMap) {
  14607. uniforms.alphaMap.value = material.alphaMap;
  14608. } // uv repeat and offset setting priorities
  14609. // 1. color map
  14610. // 2. alpha map
  14611. var uvScaleMap;
  14612. if (material.map) {
  14613. uvScaleMap = material.map;
  14614. } else if (material.alphaMap) {
  14615. uvScaleMap = material.alphaMap;
  14616. }
  14617. if (uvScaleMap !== undefined) {
  14618. if (uvScaleMap.matrixAutoUpdate === true) {
  14619. uvScaleMap.updateMatrix();
  14620. }
  14621. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14622. }
  14623. }
  14624. function refreshUniformsSprites(uniforms, material) {
  14625. uniforms.diffuse.value.copy(material.color);
  14626. uniforms.opacity.value = material.opacity;
  14627. uniforms.rotation.value = material.rotation;
  14628. if (material.map) {
  14629. uniforms.map.value = material.map;
  14630. }
  14631. if (material.alphaMap) {
  14632. uniforms.alphaMap.value = material.alphaMap;
  14633. } // uv repeat and offset setting priorities
  14634. // 1. color map
  14635. // 2. alpha map
  14636. var uvScaleMap;
  14637. if (material.map) {
  14638. uvScaleMap = material.map;
  14639. } else if (material.alphaMap) {
  14640. uvScaleMap = material.alphaMap;
  14641. }
  14642. if (uvScaleMap !== undefined) {
  14643. if (uvScaleMap.matrixAutoUpdate === true) {
  14644. uvScaleMap.updateMatrix();
  14645. }
  14646. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14647. }
  14648. }
  14649. function refreshUniformsLambert(uniforms, material) {
  14650. if (material.emissiveMap) {
  14651. uniforms.emissiveMap.value = material.emissiveMap;
  14652. }
  14653. }
  14654. function refreshUniformsPhong(uniforms, material) {
  14655. uniforms.specular.value.copy(material.specular);
  14656. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  14657. if (material.emissiveMap) {
  14658. uniforms.emissiveMap.value = material.emissiveMap;
  14659. }
  14660. if (material.bumpMap) {
  14661. uniforms.bumpMap.value = material.bumpMap;
  14662. uniforms.bumpScale.value = material.bumpScale;
  14663. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14664. }
  14665. if (material.normalMap) {
  14666. uniforms.normalMap.value = material.normalMap;
  14667. uniforms.normalScale.value.copy(material.normalScale);
  14668. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14669. }
  14670. if (material.displacementMap) {
  14671. uniforms.displacementMap.value = material.displacementMap;
  14672. uniforms.displacementScale.value = material.displacementScale;
  14673. uniforms.displacementBias.value = material.displacementBias;
  14674. }
  14675. }
  14676. function refreshUniformsToon(uniforms, material) {
  14677. if (material.gradientMap) {
  14678. uniforms.gradientMap.value = material.gradientMap;
  14679. }
  14680. if (material.emissiveMap) {
  14681. uniforms.emissiveMap.value = material.emissiveMap;
  14682. }
  14683. if (material.bumpMap) {
  14684. uniforms.bumpMap.value = material.bumpMap;
  14685. uniforms.bumpScale.value = material.bumpScale;
  14686. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14687. }
  14688. if (material.normalMap) {
  14689. uniforms.normalMap.value = material.normalMap;
  14690. uniforms.normalScale.value.copy(material.normalScale);
  14691. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14692. }
  14693. if (material.displacementMap) {
  14694. uniforms.displacementMap.value = material.displacementMap;
  14695. uniforms.displacementScale.value = material.displacementScale;
  14696. uniforms.displacementBias.value = material.displacementBias;
  14697. }
  14698. }
  14699. function refreshUniformsStandard(uniforms, material) {
  14700. uniforms.roughness.value = material.roughness;
  14701. uniforms.metalness.value = material.metalness;
  14702. if (material.roughnessMap) {
  14703. uniforms.roughnessMap.value = material.roughnessMap;
  14704. }
  14705. if (material.metalnessMap) {
  14706. uniforms.metalnessMap.value = material.metalnessMap;
  14707. }
  14708. if (material.emissiveMap) {
  14709. uniforms.emissiveMap.value = material.emissiveMap;
  14710. }
  14711. if (material.bumpMap) {
  14712. uniforms.bumpMap.value = material.bumpMap;
  14713. uniforms.bumpScale.value = material.bumpScale;
  14714. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14715. }
  14716. if (material.normalMap) {
  14717. uniforms.normalMap.value = material.normalMap;
  14718. uniforms.normalScale.value.copy(material.normalScale);
  14719. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14720. }
  14721. if (material.displacementMap) {
  14722. uniforms.displacementMap.value = material.displacementMap;
  14723. uniforms.displacementScale.value = material.displacementScale;
  14724. uniforms.displacementBias.value = material.displacementBias;
  14725. }
  14726. var envMap = properties.get(material).envMap;
  14727. if (envMap) {
  14728. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14729. uniforms.envMapIntensity.value = material.envMapIntensity;
  14730. }
  14731. }
  14732. function refreshUniformsPhysical(uniforms, material) {
  14733. refreshUniformsStandard(uniforms, material);
  14734. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14735. uniforms.clearcoat.value = material.clearcoat;
  14736. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14737. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  14738. if (material.clearcoatMap) {
  14739. uniforms.clearcoatMap.value = material.clearcoatMap;
  14740. }
  14741. if (material.clearcoatRoughnessMap) {
  14742. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14743. }
  14744. if (material.clearcoatNormalMap) {
  14745. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  14746. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14747. if (material.side === BackSide) {
  14748. uniforms.clearcoatNormalScale.value.negate();
  14749. }
  14750. }
  14751. uniforms.transmission.value = material.transmission;
  14752. if (material.transmissionMap) {
  14753. uniforms.transmissionMap.value = material.transmissionMap;
  14754. }
  14755. }
  14756. function refreshUniformsMatcap(uniforms, material) {
  14757. if (material.matcap) {
  14758. uniforms.matcap.value = material.matcap;
  14759. }
  14760. if (material.bumpMap) {
  14761. uniforms.bumpMap.value = material.bumpMap;
  14762. uniforms.bumpScale.value = material.bumpScale;
  14763. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14764. }
  14765. if (material.normalMap) {
  14766. uniforms.normalMap.value = material.normalMap;
  14767. uniforms.normalScale.value.copy(material.normalScale);
  14768. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14769. }
  14770. if (material.displacementMap) {
  14771. uniforms.displacementMap.value = material.displacementMap;
  14772. uniforms.displacementScale.value = material.displacementScale;
  14773. uniforms.displacementBias.value = material.displacementBias;
  14774. }
  14775. }
  14776. function refreshUniformsDepth(uniforms, material) {
  14777. if (material.displacementMap) {
  14778. uniforms.displacementMap.value = material.displacementMap;
  14779. uniforms.displacementScale.value = material.displacementScale;
  14780. uniforms.displacementBias.value = material.displacementBias;
  14781. }
  14782. }
  14783. function refreshUniformsDistance(uniforms, material) {
  14784. if (material.displacementMap) {
  14785. uniforms.displacementMap.value = material.displacementMap;
  14786. uniforms.displacementScale.value = material.displacementScale;
  14787. uniforms.displacementBias.value = material.displacementBias;
  14788. }
  14789. uniforms.referencePosition.value.copy(material.referencePosition);
  14790. uniforms.nearDistance.value = material.nearDistance;
  14791. uniforms.farDistance.value = material.farDistance;
  14792. }
  14793. function refreshUniformsNormal(uniforms, material) {
  14794. if (material.bumpMap) {
  14795. uniforms.bumpMap.value = material.bumpMap;
  14796. uniforms.bumpScale.value = material.bumpScale;
  14797. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14798. }
  14799. if (material.normalMap) {
  14800. uniforms.normalMap.value = material.normalMap;
  14801. uniforms.normalScale.value.copy(material.normalScale);
  14802. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14803. }
  14804. if (material.displacementMap) {
  14805. uniforms.displacementMap.value = material.displacementMap;
  14806. uniforms.displacementScale.value = material.displacementScale;
  14807. uniforms.displacementBias.value = material.displacementBias;
  14808. }
  14809. }
  14810. return {
  14811. refreshFogUniforms: refreshFogUniforms,
  14812. refreshMaterialUniforms: refreshMaterialUniforms
  14813. };
  14814. }
  14815. function createCanvasElement() {
  14816. var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  14817. canvas.style.display = 'block';
  14818. return canvas;
  14819. }
  14820. function WebGLRenderer(parameters) {
  14821. parameters = parameters || {};
  14822. var _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  14823. _context = parameters.context !== undefined ? parameters.context : null,
  14824. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14825. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14826. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14827. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14828. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14829. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14830. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14831. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14832. var currentRenderList = null;
  14833. var currentRenderState = null; // render() can be called from within a callback triggered by another render.
  14834. // We track this so that the nested render call gets its state isolated from the parent render call.
  14835. var renderStateStack = []; // public properties
  14836. this.domElement = _canvas; // Debug configuration container
  14837. this.debug = {
  14838. /**
  14839. * Enables error checking and reporting when shader programs are being compiled
  14840. * @type {boolean}
  14841. */
  14842. checkShaderErrors: true
  14843. }; // clearing
  14844. this.autoClear = true;
  14845. this.autoClearColor = true;
  14846. this.autoClearDepth = true;
  14847. this.autoClearStencil = true; // scene graph
  14848. this.sortObjects = true; // user-defined clipping
  14849. this.clippingPlanes = [];
  14850. this.localClippingEnabled = false; // physically based shading
  14851. this.gammaFactor = 2.0; // for backwards compatibility
  14852. this.outputEncoding = LinearEncoding; // physical lights
  14853. this.physicallyCorrectLights = false; // tone mapping
  14854. this.toneMapping = NoToneMapping;
  14855. this.toneMappingExposure = 1.0; // morphs
  14856. this.maxMorphTargets = 8;
  14857. this.maxMorphNormals = 4; // internal properties
  14858. var _this = this;
  14859. var _isContextLost = false; // internal state cache
  14860. var _framebuffer = null;
  14861. var _currentActiveCubeFace = 0;
  14862. var _currentActiveMipmapLevel = 0;
  14863. var _currentRenderTarget = null;
  14864. var _currentFramebuffer = null;
  14865. var _currentMaterialId = -1;
  14866. var _currentCamera = null;
  14867. var _currentViewport = new Vector4();
  14868. var _currentScissor = new Vector4();
  14869. var _currentScissorTest = null; //
  14870. var _width = _canvas.width;
  14871. var _height = _canvas.height;
  14872. var _pixelRatio = 1;
  14873. var _opaqueSort = null;
  14874. var _transparentSort = null;
  14875. var _viewport = new Vector4(0, 0, _width, _height);
  14876. var _scissor = new Vector4(0, 0, _width, _height);
  14877. var _scissorTest = false; // frustum
  14878. var _frustum = new Frustum(); // clipping
  14879. var _clippingEnabled = false;
  14880. var _localClippingEnabled = false; // camera matrices cache
  14881. var _projScreenMatrix = new Matrix4();
  14882. var _vector3 = new Vector3();
  14883. var _emptyScene = {
  14884. background: null,
  14885. fog: null,
  14886. environment: null,
  14887. overrideMaterial: null,
  14888. isScene: true
  14889. };
  14890. function getTargetPixelRatio() {
  14891. return _currentRenderTarget === null ? _pixelRatio : 1;
  14892. } // initialize
  14893. var _gl = _context;
  14894. function getContext(contextNames, contextAttributes) {
  14895. for (var i = 0; i < contextNames.length; i++) {
  14896. var contextName = contextNames[i];
  14897. var context = _canvas.getContext(contextName, contextAttributes);
  14898. if (context !== null) return context;
  14899. }
  14900. return null;
  14901. }
  14902. try {
  14903. var contextAttributes = {
  14904. alpha: _alpha,
  14905. depth: _depth,
  14906. stencil: _stencil,
  14907. antialias: _antialias,
  14908. premultipliedAlpha: _premultipliedAlpha,
  14909. preserveDrawingBuffer: _preserveDrawingBuffer,
  14910. powerPreference: _powerPreference,
  14911. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  14912. }; // event listeners must be registered before WebGL context is created, see #12753
  14913. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  14914. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  14915. if (_gl === null) {
  14916. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  14917. if (_this.isWebGL1Renderer === true) {
  14918. contextNames.shift();
  14919. }
  14920. _gl = getContext(contextNames, contextAttributes);
  14921. if (_gl === null) {
  14922. if (getContext(contextNames)) {
  14923. throw new Error('Error creating WebGL context with your selected attributes.');
  14924. } else {
  14925. throw new Error('Error creating WebGL context.');
  14926. }
  14927. }
  14928. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14929. if (_gl.getShaderPrecisionFormat === undefined) {
  14930. _gl.getShaderPrecisionFormat = function () {
  14931. return {
  14932. 'rangeMin': 1,
  14933. 'rangeMax': 1,
  14934. 'precision': 1
  14935. };
  14936. };
  14937. }
  14938. } catch (error) {
  14939. console.error('THREE.WebGLRenderer: ' + error.message);
  14940. throw error;
  14941. }
  14942. var extensions, capabilities, state, info;
  14943. var properties, textures, cubemaps, attributes, geometries, objects;
  14944. var programCache, materials, renderLists, renderStates, clipping;
  14945. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14946. var utils, bindingStates;
  14947. function initGLContext() {
  14948. extensions = new WebGLExtensions(_gl);
  14949. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  14950. extensions.init(capabilities);
  14951. utils = new WebGLUtils(_gl, extensions, capabilities);
  14952. state = new WebGLState(_gl, extensions, capabilities);
  14953. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14954. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14955. info = new WebGLInfo(_gl);
  14956. properties = new WebGLProperties();
  14957. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  14958. cubemaps = new WebGLCubeMaps(_this);
  14959. attributes = new WebGLAttributes(_gl, capabilities);
  14960. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  14961. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  14962. objects = new WebGLObjects(_gl, geometries, attributes, info);
  14963. morphtargets = new WebGLMorphtargets(_gl);
  14964. clipping = new WebGLClipping(properties);
  14965. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  14966. materials = new WebGLMaterials(properties);
  14967. renderLists = new WebGLRenderLists(properties);
  14968. renderStates = new WebGLRenderStates(extensions, capabilities);
  14969. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  14970. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  14971. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  14972. info.programs = programCache.programs;
  14973. _this.capabilities = capabilities;
  14974. _this.extensions = extensions;
  14975. _this.properties = properties;
  14976. _this.renderLists = renderLists;
  14977. _this.state = state;
  14978. _this.info = info;
  14979. }
  14980. initGLContext(); // xr
  14981. var xr = new WebXRManager(_this, _gl);
  14982. this.xr = xr; // shadow map
  14983. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  14984. this.shadowMap = shadowMap; // API
  14985. this.getContext = function () {
  14986. return _gl;
  14987. };
  14988. this.getContextAttributes = function () {
  14989. return _gl.getContextAttributes();
  14990. };
  14991. this.forceContextLoss = function () {
  14992. var extension = extensions.get('WEBGL_lose_context');
  14993. if (extension) extension.loseContext();
  14994. };
  14995. this.forceContextRestore = function () {
  14996. var extension = extensions.get('WEBGL_lose_context');
  14997. if (extension) extension.restoreContext();
  14998. };
  14999. this.getPixelRatio = function () {
  15000. return _pixelRatio;
  15001. };
  15002. this.setPixelRatio = function (value) {
  15003. if (value === undefined) return;
  15004. _pixelRatio = value;
  15005. this.setSize(_width, _height, false);
  15006. };
  15007. this.getSize = function (target) {
  15008. if (target === undefined) {
  15009. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  15010. target = new Vector2();
  15011. }
  15012. return target.set(_width, _height);
  15013. };
  15014. this.setSize = function (width, height, updateStyle) {
  15015. if (xr.isPresenting) {
  15016. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  15017. return;
  15018. }
  15019. _width = width;
  15020. _height = height;
  15021. _canvas.width = Math.floor(width * _pixelRatio);
  15022. _canvas.height = Math.floor(height * _pixelRatio);
  15023. if (updateStyle !== false) {
  15024. _canvas.style.width = width + 'px';
  15025. _canvas.style.height = height + 'px';
  15026. }
  15027. this.setViewport(0, 0, width, height);
  15028. };
  15029. this.getDrawingBufferSize = function (target) {
  15030. if (target === undefined) {
  15031. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  15032. target = new Vector2();
  15033. }
  15034. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  15035. };
  15036. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  15037. _width = width;
  15038. _height = height;
  15039. _pixelRatio = pixelRatio;
  15040. _canvas.width = Math.floor(width * pixelRatio);
  15041. _canvas.height = Math.floor(height * pixelRatio);
  15042. this.setViewport(0, 0, width, height);
  15043. };
  15044. this.getCurrentViewport = function (target) {
  15045. if (target === undefined) {
  15046. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  15047. target = new Vector4();
  15048. }
  15049. return target.copy(_currentViewport);
  15050. };
  15051. this.getViewport = function (target) {
  15052. return target.copy(_viewport);
  15053. };
  15054. this.setViewport = function (x, y, width, height) {
  15055. if (x.isVector4) {
  15056. _viewport.set(x.x, x.y, x.z, x.w);
  15057. } else {
  15058. _viewport.set(x, y, width, height);
  15059. }
  15060. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  15061. };
  15062. this.getScissor = function (target) {
  15063. return target.copy(_scissor);
  15064. };
  15065. this.setScissor = function (x, y, width, height) {
  15066. if (x.isVector4) {
  15067. _scissor.set(x.x, x.y, x.z, x.w);
  15068. } else {
  15069. _scissor.set(x, y, width, height);
  15070. }
  15071. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  15072. };
  15073. this.getScissorTest = function () {
  15074. return _scissorTest;
  15075. };
  15076. this.setScissorTest = function (boolean) {
  15077. state.setScissorTest(_scissorTest = boolean);
  15078. };
  15079. this.setOpaqueSort = function (method) {
  15080. _opaqueSort = method;
  15081. };
  15082. this.setTransparentSort = function (method) {
  15083. _transparentSort = method;
  15084. }; // Clearing
  15085. this.getClearColor = function (target) {
  15086. if (target === undefined) {
  15087. console.warn('WebGLRenderer: .getClearColor() now requires a Color as an argument');
  15088. target = new Color();
  15089. }
  15090. return target.copy(background.getClearColor());
  15091. };
  15092. this.setClearColor = function () {
  15093. background.setClearColor.apply(background, arguments);
  15094. };
  15095. this.getClearAlpha = function () {
  15096. return background.getClearAlpha();
  15097. };
  15098. this.setClearAlpha = function () {
  15099. background.setClearAlpha.apply(background, arguments);
  15100. };
  15101. this.clear = function (color, depth, stencil) {
  15102. var bits = 0;
  15103. if (color === undefined || color) bits |= 16384;
  15104. if (depth === undefined || depth) bits |= 256;
  15105. if (stencil === undefined || stencil) bits |= 1024;
  15106. _gl.clear(bits);
  15107. };
  15108. this.clearColor = function () {
  15109. this.clear(true, false, false);
  15110. };
  15111. this.clearDepth = function () {
  15112. this.clear(false, true, false);
  15113. };
  15114. this.clearStencil = function () {
  15115. this.clear(false, false, true);
  15116. }; //
  15117. this.dispose = function () {
  15118. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  15119. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  15120. renderLists.dispose();
  15121. renderStates.dispose();
  15122. properties.dispose();
  15123. cubemaps.dispose();
  15124. objects.dispose();
  15125. bindingStates.dispose();
  15126. xr.dispose();
  15127. animation.stop();
  15128. }; // Events
  15129. function onContextLost(event) {
  15130. event.preventDefault();
  15131. console.log('THREE.WebGLRenderer: Context Lost.');
  15132. _isContextLost = true;
  15133. }
  15134. function onContextRestore()
  15135. /* event */
  15136. {
  15137. console.log('THREE.WebGLRenderer: Context Restored.');
  15138. _isContextLost = false;
  15139. initGLContext();
  15140. }
  15141. function onMaterialDispose(event) {
  15142. var material = event.target;
  15143. material.removeEventListener('dispose', onMaterialDispose);
  15144. deallocateMaterial(material);
  15145. } // Buffer deallocation
  15146. function deallocateMaterial(material) {
  15147. releaseMaterialProgramReference(material);
  15148. properties.remove(material);
  15149. }
  15150. function releaseMaterialProgramReference(material) {
  15151. var programInfo = properties.get(material).program;
  15152. if (programInfo !== undefined) {
  15153. programCache.releaseProgram(programInfo);
  15154. }
  15155. } // Buffer rendering
  15156. function renderObjectImmediate(object, program) {
  15157. object.render(function (object) {
  15158. _this.renderBufferImmediate(object, program);
  15159. });
  15160. }
  15161. this.renderBufferImmediate = function (object, program) {
  15162. bindingStates.initAttributes();
  15163. var buffers = properties.get(object);
  15164. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  15165. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  15166. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  15167. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  15168. var programAttributes = program.getAttributes();
  15169. if (object.hasPositions) {
  15170. _gl.bindBuffer(34962, buffers.position);
  15171. _gl.bufferData(34962, object.positionArray, 35048);
  15172. bindingStates.enableAttribute(programAttributes.position);
  15173. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  15174. }
  15175. if (object.hasNormals) {
  15176. _gl.bindBuffer(34962, buffers.normal);
  15177. _gl.bufferData(34962, object.normalArray, 35048);
  15178. bindingStates.enableAttribute(programAttributes.normal);
  15179. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  15180. }
  15181. if (object.hasUvs) {
  15182. _gl.bindBuffer(34962, buffers.uv);
  15183. _gl.bufferData(34962, object.uvArray, 35048);
  15184. bindingStates.enableAttribute(programAttributes.uv);
  15185. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  15186. }
  15187. if (object.hasColors) {
  15188. _gl.bindBuffer(34962, buffers.color);
  15189. _gl.bufferData(34962, object.colorArray, 35048);
  15190. bindingStates.enableAttribute(programAttributes.color);
  15191. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  15192. }
  15193. bindingStates.disableUnusedAttributes();
  15194. _gl.drawArrays(4, 0, object.count);
  15195. object.count = 0;
  15196. };
  15197. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  15198. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  15199. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  15200. var program = setProgram(camera, scene, material, object);
  15201. state.setMaterial(material, frontFaceCW); //
  15202. var index = geometry.index;
  15203. var position = geometry.attributes.position; //
  15204. if (index === null) {
  15205. if (position === undefined || position.count === 0) return;
  15206. } else if (index.count === 0) {
  15207. return;
  15208. } //
  15209. var rangeFactor = 1;
  15210. if (material.wireframe === true) {
  15211. index = geometries.getWireframeAttribute(geometry);
  15212. rangeFactor = 2;
  15213. }
  15214. if (material.morphTargets || material.morphNormals) {
  15215. morphtargets.update(object, geometry, material, program);
  15216. }
  15217. bindingStates.setup(object, material, program, geometry, index);
  15218. var attribute;
  15219. var renderer = bufferRenderer;
  15220. if (index !== null) {
  15221. attribute = attributes.get(index);
  15222. renderer = indexedBufferRenderer;
  15223. renderer.setIndex(attribute);
  15224. } //
  15225. var dataCount = index !== null ? index.count : position.count;
  15226. var rangeStart = geometry.drawRange.start * rangeFactor;
  15227. var rangeCount = geometry.drawRange.count * rangeFactor;
  15228. var groupStart = group !== null ? group.start * rangeFactor : 0;
  15229. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  15230. var drawStart = Math.max(rangeStart, groupStart);
  15231. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  15232. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  15233. if (drawCount === 0) return; //
  15234. if (object.isMesh) {
  15235. if (material.wireframe === true) {
  15236. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  15237. renderer.setMode(1);
  15238. } else {
  15239. renderer.setMode(4);
  15240. }
  15241. } else if (object.isLine) {
  15242. var lineWidth = material.linewidth;
  15243. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  15244. state.setLineWidth(lineWidth * getTargetPixelRatio());
  15245. if (object.isLineSegments) {
  15246. renderer.setMode(1);
  15247. } else if (object.isLineLoop) {
  15248. renderer.setMode(2);
  15249. } else {
  15250. renderer.setMode(3);
  15251. }
  15252. } else if (object.isPoints) {
  15253. renderer.setMode(0);
  15254. } else if (object.isSprite) {
  15255. renderer.setMode(4);
  15256. }
  15257. if (object.isInstancedMesh) {
  15258. renderer.renderInstances(drawStart, drawCount, object.count);
  15259. } else if (geometry.isInstancedBufferGeometry) {
  15260. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  15261. renderer.renderInstances(drawStart, drawCount, instanceCount);
  15262. } else {
  15263. renderer.render(drawStart, drawCount);
  15264. }
  15265. }; // Compile
  15266. this.compile = function (scene, camera) {
  15267. currentRenderState = renderStates.get(scene);
  15268. currentRenderState.init();
  15269. scene.traverseVisible(function (object) {
  15270. if (object.isLight && object.layers.test(camera.layers)) {
  15271. currentRenderState.pushLight(object);
  15272. if (object.castShadow) {
  15273. currentRenderState.pushShadow(object);
  15274. }
  15275. }
  15276. });
  15277. currentRenderState.setupLights();
  15278. var compiled = new WeakMap();
  15279. scene.traverse(function (object) {
  15280. var material = object.material;
  15281. if (material) {
  15282. if (Array.isArray(material)) {
  15283. for (var i = 0; i < material.length; i++) {
  15284. var material2 = material[i];
  15285. if (compiled.has(material2) === false) {
  15286. initMaterial(material2, scene, object);
  15287. compiled.set(material2);
  15288. }
  15289. }
  15290. } else if (compiled.has(material) === false) {
  15291. initMaterial(material, scene, object);
  15292. compiled.set(material);
  15293. }
  15294. }
  15295. });
  15296. }; // Animation Loop
  15297. var onAnimationFrameCallback = null;
  15298. function onAnimationFrame(time) {
  15299. if (xr.isPresenting) return;
  15300. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  15301. }
  15302. var animation = new WebGLAnimation();
  15303. animation.setAnimationLoop(onAnimationFrame);
  15304. if (typeof window !== 'undefined') animation.setContext(window);
  15305. this.setAnimationLoop = function (callback) {
  15306. onAnimationFrameCallback = callback;
  15307. xr.setAnimationLoop(callback);
  15308. callback === null ? animation.stop() : animation.start();
  15309. }; // Rendering
  15310. this.render = function (scene, camera) {
  15311. var renderTarget, forceClear;
  15312. if (arguments[2] !== undefined) {
  15313. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  15314. renderTarget = arguments[2];
  15315. }
  15316. if (arguments[3] !== undefined) {
  15317. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  15318. forceClear = arguments[3];
  15319. }
  15320. if (camera !== undefined && camera.isCamera !== true) {
  15321. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  15322. return;
  15323. }
  15324. if (_isContextLost === true) return; // reset caching for this frame
  15325. bindingStates.resetDefaultState();
  15326. _currentMaterialId = -1;
  15327. _currentCamera = null; // update scene graph
  15328. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  15329. if (camera.parent === null) camera.updateMatrixWorld();
  15330. if (xr.enabled === true && xr.isPresenting === true) {
  15331. camera = xr.getCamera(camera);
  15332. } //
  15333. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  15334. currentRenderState = renderStates.get(scene, renderStateStack.length);
  15335. currentRenderState.init();
  15336. renderStateStack.push(currentRenderState);
  15337. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  15338. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  15339. _localClippingEnabled = this.localClippingEnabled;
  15340. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  15341. currentRenderList = renderLists.get(scene, camera);
  15342. currentRenderList.init();
  15343. projectObject(scene, camera, 0, _this.sortObjects);
  15344. currentRenderList.finish();
  15345. if (_this.sortObjects === true) {
  15346. currentRenderList.sort(_opaqueSort, _transparentSort);
  15347. } //
  15348. if (_clippingEnabled === true) clipping.beginShadows();
  15349. var shadowsArray = currentRenderState.state.shadowsArray;
  15350. shadowMap.render(shadowsArray, scene, camera);
  15351. currentRenderState.setupLights();
  15352. currentRenderState.setupLightsView(camera);
  15353. if (_clippingEnabled === true) clipping.endShadows(); //
  15354. if (this.info.autoReset === true) this.info.reset();
  15355. if (renderTarget !== undefined) {
  15356. this.setRenderTarget(renderTarget);
  15357. } //
  15358. background.render(currentRenderList, scene, camera, forceClear); // render scene
  15359. var opaqueObjects = currentRenderList.opaque;
  15360. var transparentObjects = currentRenderList.transparent;
  15361. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  15362. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  15363. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  15364. if (_currentRenderTarget !== null) {
  15365. // Generate mipmap if we're using any kind of mipmap filtering
  15366. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  15367. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  15368. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  15369. state.buffers.depth.setTest(true);
  15370. state.buffers.depth.setMask(true);
  15371. state.buffers.color.setMask(true);
  15372. state.setPolygonOffset(false); // _gl.finish();
  15373. renderStateStack.pop();
  15374. if (renderStateStack.length > 0) {
  15375. currentRenderState = renderStateStack[renderStateStack.length - 1];
  15376. } else {
  15377. currentRenderState = null;
  15378. }
  15379. currentRenderList = null;
  15380. };
  15381. function projectObject(object, camera, groupOrder, sortObjects) {
  15382. if (object.visible === false) return;
  15383. var visible = object.layers.test(camera.layers);
  15384. if (visible) {
  15385. if (object.isGroup) {
  15386. groupOrder = object.renderOrder;
  15387. } else if (object.isLOD) {
  15388. if (object.autoUpdate === true) object.update(camera);
  15389. } else if (object.isLight) {
  15390. currentRenderState.pushLight(object);
  15391. if (object.castShadow) {
  15392. currentRenderState.pushShadow(object);
  15393. }
  15394. } else if (object.isSprite) {
  15395. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  15396. if (sortObjects) {
  15397. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15398. }
  15399. var geometry = objects.update(object);
  15400. var material = object.material;
  15401. if (material.visible) {
  15402. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  15403. }
  15404. }
  15405. } else if (object.isImmediateRenderObject) {
  15406. if (sortObjects) {
  15407. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15408. }
  15409. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  15410. } else if (object.isMesh || object.isLine || object.isPoints) {
  15411. if (object.isSkinnedMesh) {
  15412. // update skeleton only once in a frame
  15413. if (object.skeleton.frame !== info.render.frame) {
  15414. object.skeleton.update();
  15415. object.skeleton.frame = info.render.frame;
  15416. }
  15417. }
  15418. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  15419. if (sortObjects) {
  15420. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15421. }
  15422. var _geometry = objects.update(object);
  15423. var _material = object.material;
  15424. if (Array.isArray(_material)) {
  15425. var groups = _geometry.groups;
  15426. for (var i = 0, l = groups.length; i < l; i++) {
  15427. var group = groups[i];
  15428. var groupMaterial = _material[group.materialIndex];
  15429. if (groupMaterial && groupMaterial.visible) {
  15430. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  15431. }
  15432. }
  15433. } else if (_material.visible) {
  15434. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  15435. }
  15436. }
  15437. }
  15438. }
  15439. var children = object.children;
  15440. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  15441. projectObject(children[_i], camera, groupOrder, sortObjects);
  15442. }
  15443. }
  15444. function renderObjects(renderList, scene, camera) {
  15445. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  15446. for (var i = 0, l = renderList.length; i < l; i++) {
  15447. var renderItem = renderList[i];
  15448. var object = renderItem.object;
  15449. var geometry = renderItem.geometry;
  15450. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  15451. var group = renderItem.group;
  15452. if (camera.isArrayCamera) {
  15453. var cameras = camera.cameras;
  15454. for (var j = 0, jl = cameras.length; j < jl; j++) {
  15455. var camera2 = cameras[j];
  15456. if (object.layers.test(camera2.layers)) {
  15457. state.viewport(_currentViewport.copy(camera2.viewport));
  15458. currentRenderState.setupLightsView(camera2);
  15459. renderObject(object, scene, camera2, geometry, material, group);
  15460. }
  15461. }
  15462. } else {
  15463. renderObject(object, scene, camera, geometry, material, group);
  15464. }
  15465. }
  15466. }
  15467. function renderObject(object, scene, camera, geometry, material, group) {
  15468. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  15469. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  15470. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  15471. if (object.isImmediateRenderObject) {
  15472. var program = setProgram(camera, scene, material, object);
  15473. state.setMaterial(material);
  15474. bindingStates.reset();
  15475. renderObjectImmediate(object, program);
  15476. } else {
  15477. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  15478. }
  15479. object.onAfterRender(_this, scene, camera, geometry, material, group);
  15480. }
  15481. function initMaterial(material, scene, object) {
  15482. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15483. var materialProperties = properties.get(material);
  15484. var lights = currentRenderState.state.lights;
  15485. var shadowsArray = currentRenderState.state.shadowsArray;
  15486. var lightsStateVersion = lights.state.version;
  15487. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  15488. var programCacheKey = programCache.getProgramCacheKey(parameters);
  15489. var program = materialProperties.program;
  15490. var programChange = true; // always update environment and fog - changing these trigger an initMaterial call, but it's possible that the program doesn't change
  15491. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  15492. materialProperties.fog = scene.fog;
  15493. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment);
  15494. if (program === undefined) {
  15495. // new material
  15496. material.addEventListener('dispose', onMaterialDispose);
  15497. } else if (program.cacheKey !== programCacheKey) {
  15498. // changed glsl or parameters
  15499. releaseMaterialProgramReference(material);
  15500. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  15501. programChange = false;
  15502. } else if (parameters.shaderID !== undefined) {
  15503. // same glsl and uniform list
  15504. return;
  15505. } else {
  15506. // only rebuild uniform list
  15507. programChange = false;
  15508. }
  15509. if (programChange) {
  15510. parameters.uniforms = programCache.getUniforms(material);
  15511. material.onBeforeCompile(parameters, _this);
  15512. program = programCache.acquireProgram(parameters, programCacheKey);
  15513. materialProperties.program = program;
  15514. materialProperties.uniforms = parameters.uniforms;
  15515. materialProperties.outputEncoding = parameters.outputEncoding;
  15516. }
  15517. var uniforms = materialProperties.uniforms;
  15518. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  15519. materialProperties.numClippingPlanes = clipping.numPlanes;
  15520. materialProperties.numIntersection = clipping.numIntersection;
  15521. uniforms.clippingPlanes = clipping.uniform;
  15522. } // store the light setup it was created for
  15523. materialProperties.needsLights = materialNeedsLights(material);
  15524. materialProperties.lightsStateVersion = lightsStateVersion;
  15525. if (materialProperties.needsLights) {
  15526. // wire up the material to this renderer's lighting state
  15527. uniforms.ambientLightColor.value = lights.state.ambient;
  15528. uniforms.lightProbe.value = lights.state.probe;
  15529. uniforms.directionalLights.value = lights.state.directional;
  15530. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  15531. uniforms.spotLights.value = lights.state.spot;
  15532. uniforms.spotLightShadows.value = lights.state.spotShadow;
  15533. uniforms.rectAreaLights.value = lights.state.rectArea;
  15534. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  15535. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  15536. uniforms.pointLights.value = lights.state.point;
  15537. uniforms.pointLightShadows.value = lights.state.pointShadow;
  15538. uniforms.hemisphereLights.value = lights.state.hemi;
  15539. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  15540. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  15541. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  15542. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  15543. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  15544. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  15545. }
  15546. var progUniforms = materialProperties.program.getUniforms();
  15547. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  15548. materialProperties.uniformsList = uniformsList;
  15549. }
  15550. function setProgram(camera, scene, material, object) {
  15551. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15552. textures.resetTextureUnits();
  15553. var fog = scene.fog;
  15554. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  15555. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  15556. var envMap = cubemaps.get(material.envMap || environment);
  15557. var materialProperties = properties.get(material);
  15558. var lights = currentRenderState.state.lights;
  15559. if (_clippingEnabled === true) {
  15560. if (_localClippingEnabled === true || camera !== _currentCamera) {
  15561. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  15562. // object instead of the material, once it becomes feasible
  15563. // (#8465, #8379)
  15564. clipping.setState(material, camera, useCache);
  15565. }
  15566. }
  15567. if (material.version === materialProperties.__version) {
  15568. if (material.fog && materialProperties.fog !== fog) {
  15569. initMaterial(material, scene, object);
  15570. } else if (materialProperties.environment !== environment) {
  15571. initMaterial(material, scene, object);
  15572. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  15573. initMaterial(material, scene, object);
  15574. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  15575. initMaterial(material, scene, object);
  15576. } else if (materialProperties.outputEncoding !== encoding) {
  15577. initMaterial(material, scene, object);
  15578. } else if (materialProperties.envMap !== envMap) {
  15579. initMaterial(material, scene, object);
  15580. }
  15581. } else {
  15582. initMaterial(material, scene, object);
  15583. materialProperties.__version = material.version;
  15584. }
  15585. var refreshProgram = false;
  15586. var refreshMaterial = false;
  15587. var refreshLights = false;
  15588. var program = materialProperties.program,
  15589. p_uniforms = program.getUniforms(),
  15590. m_uniforms = materialProperties.uniforms;
  15591. if (state.useProgram(program.program)) {
  15592. refreshProgram = true;
  15593. refreshMaterial = true;
  15594. refreshLights = true;
  15595. }
  15596. if (material.id !== _currentMaterialId) {
  15597. _currentMaterialId = material.id;
  15598. refreshMaterial = true;
  15599. }
  15600. if (refreshProgram || _currentCamera !== camera) {
  15601. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  15602. if (capabilities.logarithmicDepthBuffer) {
  15603. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  15604. }
  15605. if (_currentCamera !== camera) {
  15606. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  15607. // now, in case this material supports lights - or later, when
  15608. // the next material that does gets activated:
  15609. refreshMaterial = true; // set to true on material change
  15610. refreshLights = true; // remains set until update done
  15611. } // load material specific uniforms
  15612. // (shader material also gets them for the sake of genericity)
  15613. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  15614. var uCamPos = p_uniforms.map.cameraPosition;
  15615. if (uCamPos !== undefined) {
  15616. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  15617. }
  15618. }
  15619. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  15620. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  15621. }
  15622. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  15623. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  15624. }
  15625. } // skinning uniforms must be set even if material didn't change
  15626. // auto-setting of texture unit for bone texture must go before other textures
  15627. // otherwise textures used for skinning can take over texture units reserved for other material textures
  15628. if (material.skinning) {
  15629. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  15630. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  15631. var skeleton = object.skeleton;
  15632. if (skeleton) {
  15633. var bones = skeleton.bones;
  15634. if (capabilities.floatVertexTextures) {
  15635. if (skeleton.boneTexture === null) {
  15636. // layout (1 matrix = 4 pixels)
  15637. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15638. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15639. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15640. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15641. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15642. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  15643. size = MathUtils.ceilPowerOfTwo(size);
  15644. size = Math.max(size, 4);
  15645. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  15646. boneMatrices.set(skeleton.boneMatrices); // copy current values
  15647. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  15648. skeleton.boneMatrices = boneMatrices;
  15649. skeleton.boneTexture = boneTexture;
  15650. skeleton.boneTextureSize = size;
  15651. }
  15652. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  15653. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  15654. } else {
  15655. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  15656. }
  15657. }
  15658. }
  15659. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  15660. materialProperties.receiveShadow = object.receiveShadow;
  15661. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  15662. }
  15663. if (refreshMaterial) {
  15664. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  15665. if (materialProperties.needsLights) {
  15666. // the current material requires lighting info
  15667. // note: all lighting uniforms are always set correctly
  15668. // they simply reference the renderer's state for their
  15669. // values
  15670. //
  15671. // use the current material's .needsUpdate flags to set
  15672. // the GL state when required
  15673. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  15674. } // refresh uniforms common to several materials
  15675. if (fog && material.fog) {
  15676. materials.refreshFogUniforms(m_uniforms, fog);
  15677. }
  15678. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  15679. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15680. }
  15681. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  15682. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15683. material.uniformsNeedUpdate = false;
  15684. }
  15685. if (material.isSpriteMaterial) {
  15686. p_uniforms.setValue(_gl, 'center', object.center);
  15687. } // common matrices
  15688. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  15689. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  15690. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  15691. return program;
  15692. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15693. function markUniformsLightsNeedsUpdate(uniforms, value) {
  15694. uniforms.ambientLightColor.needsUpdate = value;
  15695. uniforms.lightProbe.needsUpdate = value;
  15696. uniforms.directionalLights.needsUpdate = value;
  15697. uniforms.directionalLightShadows.needsUpdate = value;
  15698. uniforms.pointLights.needsUpdate = value;
  15699. uniforms.pointLightShadows.needsUpdate = value;
  15700. uniforms.spotLights.needsUpdate = value;
  15701. uniforms.spotLightShadows.needsUpdate = value;
  15702. uniforms.rectAreaLights.needsUpdate = value;
  15703. uniforms.hemisphereLights.needsUpdate = value;
  15704. }
  15705. function materialNeedsLights(material) {
  15706. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  15707. } //
  15708. this.setFramebuffer = function (value) {
  15709. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  15710. _framebuffer = value;
  15711. };
  15712. this.getActiveCubeFace = function () {
  15713. return _currentActiveCubeFace;
  15714. };
  15715. this.getActiveMipmapLevel = function () {
  15716. return _currentActiveMipmapLevel;
  15717. };
  15718. this.getRenderList = function () {
  15719. return currentRenderList;
  15720. };
  15721. this.setRenderList = function (renderList) {
  15722. currentRenderList = renderList;
  15723. };
  15724. this.getRenderTarget = function () {
  15725. return _currentRenderTarget;
  15726. };
  15727. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  15728. if (activeCubeFace === void 0) {
  15729. activeCubeFace = 0;
  15730. }
  15731. if (activeMipmapLevel === void 0) {
  15732. activeMipmapLevel = 0;
  15733. }
  15734. _currentRenderTarget = renderTarget;
  15735. _currentActiveCubeFace = activeCubeFace;
  15736. _currentActiveMipmapLevel = activeMipmapLevel;
  15737. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  15738. textures.setupRenderTarget(renderTarget);
  15739. }
  15740. var framebuffer = _framebuffer;
  15741. var isCube = false;
  15742. if (renderTarget) {
  15743. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  15744. if (renderTarget.isWebGLCubeRenderTarget) {
  15745. framebuffer = __webglFramebuffer[activeCubeFace];
  15746. isCube = true;
  15747. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  15748. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  15749. } else {
  15750. framebuffer = __webglFramebuffer;
  15751. }
  15752. _currentViewport.copy(renderTarget.viewport);
  15753. _currentScissor.copy(renderTarget.scissor);
  15754. _currentScissorTest = renderTarget.scissorTest;
  15755. } else {
  15756. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  15757. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  15758. _currentScissorTest = _scissorTest;
  15759. }
  15760. if (_currentFramebuffer !== framebuffer) {
  15761. _gl.bindFramebuffer(36160, framebuffer);
  15762. _currentFramebuffer = framebuffer;
  15763. }
  15764. state.viewport(_currentViewport);
  15765. state.scissor(_currentScissor);
  15766. state.setScissorTest(_currentScissorTest);
  15767. if (isCube) {
  15768. var textureProperties = properties.get(renderTarget.texture);
  15769. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  15770. }
  15771. };
  15772. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15773. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15774. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15775. return;
  15776. }
  15777. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15778. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15779. framebuffer = framebuffer[activeCubeFaceIndex];
  15780. }
  15781. if (framebuffer) {
  15782. var restore = false;
  15783. if (framebuffer !== _currentFramebuffer) {
  15784. _gl.bindFramebuffer(36160, framebuffer);
  15785. restore = true;
  15786. }
  15787. try {
  15788. var texture = renderTarget.texture;
  15789. var textureFormat = texture.format;
  15790. var textureType = texture.type;
  15791. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15792. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15793. return;
  15794. }
  15795. var halfFloatSupportedByExt = textureType === HalfFloatType && (extensions.has('EXT_color_buffer_half_float') || capabilities.isWebGL2 && extensions.has('EXT_color_buffer_float'));
  15796. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15797. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.has('OES_texture_float') || extensions.has('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15798. !halfFloatSupportedByExt) {
  15799. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15800. return;
  15801. }
  15802. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15803. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15804. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15805. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15806. }
  15807. } else {
  15808. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15809. }
  15810. } finally {
  15811. if (restore) {
  15812. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15813. }
  15814. }
  15815. }
  15816. };
  15817. this.copyFramebufferToTexture = function (position, texture, level) {
  15818. if (level === void 0) {
  15819. level = 0;
  15820. }
  15821. var levelScale = Math.pow(2, -level);
  15822. var width = Math.floor(texture.image.width * levelScale);
  15823. var height = Math.floor(texture.image.height * levelScale);
  15824. var glFormat = utils.convert(texture.format);
  15825. textures.setTexture2D(texture, 0);
  15826. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15827. state.unbindTexture();
  15828. };
  15829. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15830. if (level === void 0) {
  15831. level = 0;
  15832. }
  15833. var width = srcTexture.image.width;
  15834. var height = srcTexture.image.height;
  15835. var glFormat = utils.convert(dstTexture.format);
  15836. var glType = utils.convert(dstTexture.type);
  15837. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  15838. // parameters, make sure they are correct for the dstTexture
  15839. _gl.pixelStorei(37440, dstTexture.flipY);
  15840. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  15841. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  15842. if (srcTexture.isDataTexture) {
  15843. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  15844. } else {
  15845. if (srcTexture.isCompressedTexture) {
  15846. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  15847. } else {
  15848. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  15849. }
  15850. } // Generate mipmaps only when copying level 0
  15851. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  15852. state.unbindTexture();
  15853. };
  15854. this.initTexture = function (texture) {
  15855. textures.setTexture2D(texture, 0);
  15856. state.unbindTexture();
  15857. };
  15858. this.resetState = function () {
  15859. state.reset();
  15860. bindingStates.reset();
  15861. };
  15862. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15863. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15864. detail: this
  15865. })); // eslint-disable-line no-undef
  15866. }
  15867. }
  15868. function WebGL1Renderer(parameters) {
  15869. WebGLRenderer.call(this, parameters);
  15870. }
  15871. WebGL1Renderer.prototype = Object.assign(Object.create(WebGLRenderer.prototype), {
  15872. constructor: WebGL1Renderer,
  15873. isWebGL1Renderer: true
  15874. });
  15875. var FogExp2 = /*#__PURE__*/function () {
  15876. function FogExp2(color, density) {
  15877. Object.defineProperty(this, 'isFogExp2', {
  15878. value: true
  15879. });
  15880. this.name = '';
  15881. this.color = new Color(color);
  15882. this.density = density !== undefined ? density : 0.00025;
  15883. }
  15884. var _proto = FogExp2.prototype;
  15885. _proto.clone = function clone() {
  15886. return new FogExp2(this.color, this.density);
  15887. };
  15888. _proto.toJSON = function toJSON()
  15889. /* meta */
  15890. {
  15891. return {
  15892. type: 'FogExp2',
  15893. color: this.color.getHex(),
  15894. density: this.density
  15895. };
  15896. };
  15897. return FogExp2;
  15898. }();
  15899. var Fog = /*#__PURE__*/function () {
  15900. function Fog(color, near, far) {
  15901. Object.defineProperty(this, 'isFog', {
  15902. value: true
  15903. });
  15904. this.name = '';
  15905. this.color = new Color(color);
  15906. this.near = near !== undefined ? near : 1;
  15907. this.far = far !== undefined ? far : 1000;
  15908. }
  15909. var _proto = Fog.prototype;
  15910. _proto.clone = function clone() {
  15911. return new Fog(this.color, this.near, this.far);
  15912. };
  15913. _proto.toJSON = function toJSON()
  15914. /* meta */
  15915. {
  15916. return {
  15917. type: 'Fog',
  15918. color: this.color.getHex(),
  15919. near: this.near,
  15920. far: this.far
  15921. };
  15922. };
  15923. return Fog;
  15924. }();
  15925. var Scene = /*#__PURE__*/function (_Object3D) {
  15926. _inheritsLoose(Scene, _Object3D);
  15927. function Scene() {
  15928. var _this;
  15929. _this = _Object3D.call(this) || this;
  15930. Object.defineProperty(_assertThisInitialized(_this), 'isScene', {
  15931. value: true
  15932. });
  15933. _this.type = 'Scene';
  15934. _this.background = null;
  15935. _this.environment = null;
  15936. _this.fog = null;
  15937. _this.overrideMaterial = null;
  15938. _this.autoUpdate = true; // checked by the renderer
  15939. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15940. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15941. detail: _assertThisInitialized(_this)
  15942. })); // eslint-disable-line no-undef
  15943. }
  15944. return _this;
  15945. }
  15946. var _proto = Scene.prototype;
  15947. _proto.copy = function copy(source, recursive) {
  15948. _Object3D.prototype.copy.call(this, source, recursive);
  15949. if (source.background !== null) this.background = source.background.clone();
  15950. if (source.environment !== null) this.environment = source.environment.clone();
  15951. if (source.fog !== null) this.fog = source.fog.clone();
  15952. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  15953. this.autoUpdate = source.autoUpdate;
  15954. this.matrixAutoUpdate = source.matrixAutoUpdate;
  15955. return this;
  15956. };
  15957. _proto.toJSON = function toJSON(meta) {
  15958. var data = _Object3D.prototype.toJSON.call(this, meta);
  15959. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  15960. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  15961. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  15962. return data;
  15963. };
  15964. return Scene;
  15965. }(Object3D);
  15966. function InterleavedBuffer(array, stride) {
  15967. this.array = array;
  15968. this.stride = stride;
  15969. this.count = array !== undefined ? array.length / stride : 0;
  15970. this.usage = StaticDrawUsage;
  15971. this.updateRange = {
  15972. offset: 0,
  15973. count: -1
  15974. };
  15975. this.version = 0;
  15976. this.uuid = MathUtils.generateUUID();
  15977. }
  15978. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  15979. set: function set(value) {
  15980. if (value === true) this.version++;
  15981. }
  15982. });
  15983. Object.assign(InterleavedBuffer.prototype, {
  15984. isInterleavedBuffer: true,
  15985. onUploadCallback: function onUploadCallback() {},
  15986. setUsage: function setUsage(value) {
  15987. this.usage = value;
  15988. return this;
  15989. },
  15990. copy: function copy(source) {
  15991. this.array = new source.array.constructor(source.array);
  15992. this.count = source.count;
  15993. this.stride = source.stride;
  15994. this.usage = source.usage;
  15995. return this;
  15996. },
  15997. copyAt: function copyAt(index1, attribute, index2) {
  15998. index1 *= this.stride;
  15999. index2 *= attribute.stride;
  16000. for (var i = 0, l = this.stride; i < l; i++) {
  16001. this.array[index1 + i] = attribute.array[index2 + i];
  16002. }
  16003. return this;
  16004. },
  16005. set: function set(value, offset) {
  16006. if (offset === void 0) {
  16007. offset = 0;
  16008. }
  16009. this.array.set(value, offset);
  16010. return this;
  16011. },
  16012. clone: function clone(data) {
  16013. if (data.arrayBuffers === undefined) {
  16014. data.arrayBuffers = {};
  16015. }
  16016. if (this.array.buffer._uuid === undefined) {
  16017. this.array.buffer._uuid = MathUtils.generateUUID();
  16018. }
  16019. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  16020. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  16021. }
  16022. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  16023. var ib = new InterleavedBuffer(array, this.stride);
  16024. ib.setUsage(this.usage);
  16025. return ib;
  16026. },
  16027. onUpload: function onUpload(callback) {
  16028. this.onUploadCallback = callback;
  16029. return this;
  16030. },
  16031. toJSON: function toJSON(data) {
  16032. if (data.arrayBuffers === undefined) {
  16033. data.arrayBuffers = {};
  16034. } // generate UUID for array buffer if necessary
  16035. if (this.array.buffer._uuid === undefined) {
  16036. this.array.buffer._uuid = MathUtils.generateUUID();
  16037. }
  16038. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  16039. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  16040. } //
  16041. return {
  16042. uuid: this.uuid,
  16043. buffer: this.array.buffer._uuid,
  16044. type: this.array.constructor.name,
  16045. stride: this.stride
  16046. };
  16047. }
  16048. });
  16049. var _vector$6 = new Vector3();
  16050. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  16051. this.name = '';
  16052. this.data = interleavedBuffer;
  16053. this.itemSize = itemSize;
  16054. this.offset = offset;
  16055. this.normalized = normalized === true;
  16056. }
  16057. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  16058. count: {
  16059. get: function get() {
  16060. return this.data.count;
  16061. }
  16062. },
  16063. array: {
  16064. get: function get() {
  16065. return this.data.array;
  16066. }
  16067. },
  16068. needsUpdate: {
  16069. set: function set(value) {
  16070. this.data.needsUpdate = value;
  16071. }
  16072. }
  16073. });
  16074. Object.assign(InterleavedBufferAttribute.prototype, {
  16075. isInterleavedBufferAttribute: true,
  16076. applyMatrix4: function applyMatrix4(m) {
  16077. for (var i = 0, l = this.data.count; i < l; i++) {
  16078. _vector$6.x = this.getX(i);
  16079. _vector$6.y = this.getY(i);
  16080. _vector$6.z = this.getZ(i);
  16081. _vector$6.applyMatrix4(m);
  16082. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  16083. }
  16084. return this;
  16085. },
  16086. setX: function setX(index, x) {
  16087. this.data.array[index * this.data.stride + this.offset] = x;
  16088. return this;
  16089. },
  16090. setY: function setY(index, y) {
  16091. this.data.array[index * this.data.stride + this.offset + 1] = y;
  16092. return this;
  16093. },
  16094. setZ: function setZ(index, z) {
  16095. this.data.array[index * this.data.stride + this.offset + 2] = z;
  16096. return this;
  16097. },
  16098. setW: function setW(index, w) {
  16099. this.data.array[index * this.data.stride + this.offset + 3] = w;
  16100. return this;
  16101. },
  16102. getX: function getX(index) {
  16103. return this.data.array[index * this.data.stride + this.offset];
  16104. },
  16105. getY: function getY(index) {
  16106. return this.data.array[index * this.data.stride + this.offset + 1];
  16107. },
  16108. getZ: function getZ(index) {
  16109. return this.data.array[index * this.data.stride + this.offset + 2];
  16110. },
  16111. getW: function getW(index) {
  16112. return this.data.array[index * this.data.stride + this.offset + 3];
  16113. },
  16114. setXY: function setXY(index, x, y) {
  16115. index = index * this.data.stride + this.offset;
  16116. this.data.array[index + 0] = x;
  16117. this.data.array[index + 1] = y;
  16118. return this;
  16119. },
  16120. setXYZ: function setXYZ(index, x, y, z) {
  16121. index = index * this.data.stride + this.offset;
  16122. this.data.array[index + 0] = x;
  16123. this.data.array[index + 1] = y;
  16124. this.data.array[index + 2] = z;
  16125. return this;
  16126. },
  16127. setXYZW: function setXYZW(index, x, y, z, w) {
  16128. index = index * this.data.stride + this.offset;
  16129. this.data.array[index + 0] = x;
  16130. this.data.array[index + 1] = y;
  16131. this.data.array[index + 2] = z;
  16132. this.data.array[index + 3] = w;
  16133. return this;
  16134. },
  16135. clone: function clone(data) {
  16136. if (data === undefined) {
  16137. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  16138. var array = [];
  16139. for (var i = 0; i < this.count; i++) {
  16140. var index = i * this.data.stride + this.offset;
  16141. for (var j = 0; j < this.itemSize; j++) {
  16142. array.push(this.data.array[index + j]);
  16143. }
  16144. }
  16145. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  16146. } else {
  16147. if (data.interleavedBuffers === undefined) {
  16148. data.interleavedBuffers = {};
  16149. }
  16150. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  16151. data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
  16152. }
  16153. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  16154. }
  16155. },
  16156. toJSON: function toJSON(data) {
  16157. if (data === undefined) {
  16158. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  16159. var array = [];
  16160. for (var i = 0; i < this.count; i++) {
  16161. var index = i * this.data.stride + this.offset;
  16162. for (var j = 0; j < this.itemSize; j++) {
  16163. array.push(this.data.array[index + j]);
  16164. }
  16165. } // deinterleave data and save it as an ordinary buffer attribute for now
  16166. return {
  16167. itemSize: this.itemSize,
  16168. type: this.array.constructor.name,
  16169. array: array,
  16170. normalized: this.normalized
  16171. };
  16172. } else {
  16173. // save as true interlaved attribtue
  16174. if (data.interleavedBuffers === undefined) {
  16175. data.interleavedBuffers = {};
  16176. }
  16177. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  16178. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  16179. }
  16180. return {
  16181. isInterleavedBufferAttribute: true,
  16182. itemSize: this.itemSize,
  16183. data: this.data.uuid,
  16184. offset: this.offset,
  16185. normalized: this.normalized
  16186. };
  16187. }
  16188. }
  16189. });
  16190. /**
  16191. * parameters = {
  16192. * color: <hex>,
  16193. * map: new THREE.Texture( <Image> ),
  16194. * alphaMap: new THREE.Texture( <Image> ),
  16195. * rotation: <float>,
  16196. * sizeAttenuation: <bool>
  16197. * }
  16198. */
  16199. function SpriteMaterial(parameters) {
  16200. Material.call(this);
  16201. this.type = 'SpriteMaterial';
  16202. this.color = new Color(0xffffff);
  16203. this.map = null;
  16204. this.alphaMap = null;
  16205. this.rotation = 0;
  16206. this.sizeAttenuation = true;
  16207. this.transparent = true;
  16208. this.setValues(parameters);
  16209. }
  16210. SpriteMaterial.prototype = Object.create(Material.prototype);
  16211. SpriteMaterial.prototype.constructor = SpriteMaterial;
  16212. SpriteMaterial.prototype.isSpriteMaterial = true;
  16213. SpriteMaterial.prototype.copy = function (source) {
  16214. Material.prototype.copy.call(this, source);
  16215. this.color.copy(source.color);
  16216. this.map = source.map;
  16217. this.alphaMap = source.alphaMap;
  16218. this.rotation = source.rotation;
  16219. this.sizeAttenuation = source.sizeAttenuation;
  16220. return this;
  16221. };
  16222. var _geometry;
  16223. var _intersectPoint = new Vector3();
  16224. var _worldScale = new Vector3();
  16225. var _mvPosition = new Vector3();
  16226. var _alignedPosition = new Vector2();
  16227. var _rotatedPosition = new Vector2();
  16228. var _viewWorldMatrix = new Matrix4();
  16229. var _vA$1 = new Vector3();
  16230. var _vB$1 = new Vector3();
  16231. var _vC$1 = new Vector3();
  16232. var _uvA$1 = new Vector2();
  16233. var _uvB$1 = new Vector2();
  16234. var _uvC$1 = new Vector2();
  16235. function Sprite(material) {
  16236. Object3D.call(this);
  16237. this.type = 'Sprite';
  16238. if (_geometry === undefined) {
  16239. _geometry = new BufferGeometry();
  16240. 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]);
  16241. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  16242. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  16243. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  16244. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  16245. }
  16246. this.geometry = _geometry;
  16247. this.material = material !== undefined ? material : new SpriteMaterial();
  16248. this.center = new Vector2(0.5, 0.5);
  16249. }
  16250. Sprite.prototype = Object.assign(Object.create(Object3D.prototype), {
  16251. constructor: Sprite,
  16252. isSprite: true,
  16253. raycast: function raycast(raycaster, intersects) {
  16254. if (raycaster.camera === null) {
  16255. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  16256. }
  16257. _worldScale.setFromMatrixScale(this.matrixWorld);
  16258. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  16259. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  16260. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  16261. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  16262. _worldScale.multiplyScalar(-_mvPosition.z);
  16263. }
  16264. var rotation = this.material.rotation;
  16265. var sin, cos;
  16266. if (rotation !== 0) {
  16267. cos = Math.cos(rotation);
  16268. sin = Math.sin(rotation);
  16269. }
  16270. var center = this.center;
  16271. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16272. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16273. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16274. _uvA$1.set(0, 0);
  16275. _uvB$1.set(1, 0);
  16276. _uvC$1.set(1, 1); // check first triangle
  16277. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  16278. if (intersect === null) {
  16279. // check second triangle
  16280. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16281. _uvB$1.set(0, 1);
  16282. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  16283. if (intersect === null) {
  16284. return;
  16285. }
  16286. }
  16287. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  16288. if (distance < raycaster.near || distance > raycaster.far) return;
  16289. intersects.push({
  16290. distance: distance,
  16291. point: _intersectPoint.clone(),
  16292. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  16293. face: null,
  16294. object: this
  16295. });
  16296. },
  16297. copy: function copy(source) {
  16298. Object3D.prototype.copy.call(this, source);
  16299. if (source.center !== undefined) this.center.copy(source.center);
  16300. this.material = source.material;
  16301. return this;
  16302. }
  16303. });
  16304. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  16305. // compute position in camera space
  16306. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  16307. if (sin !== undefined) {
  16308. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  16309. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  16310. } else {
  16311. _rotatedPosition.copy(_alignedPosition);
  16312. }
  16313. vertexPosition.copy(mvPosition);
  16314. vertexPosition.x += _rotatedPosition.x;
  16315. vertexPosition.y += _rotatedPosition.y; // transform to world space
  16316. vertexPosition.applyMatrix4(_viewWorldMatrix);
  16317. }
  16318. var _v1$4 = new Vector3();
  16319. var _v2$2 = new Vector3();
  16320. function LOD() {
  16321. Object3D.call(this);
  16322. this._currentLevel = 0;
  16323. this.type = 'LOD';
  16324. Object.defineProperties(this, {
  16325. levels: {
  16326. enumerable: true,
  16327. value: []
  16328. }
  16329. });
  16330. this.autoUpdate = true;
  16331. }
  16332. LOD.prototype = Object.assign(Object.create(Object3D.prototype), {
  16333. constructor: LOD,
  16334. isLOD: true,
  16335. copy: function copy(source) {
  16336. Object3D.prototype.copy.call(this, source, false);
  16337. var levels = source.levels;
  16338. for (var i = 0, l = levels.length; i < l; i++) {
  16339. var level = levels[i];
  16340. this.addLevel(level.object.clone(), level.distance);
  16341. }
  16342. this.autoUpdate = source.autoUpdate;
  16343. return this;
  16344. },
  16345. addLevel: function addLevel(object, distance) {
  16346. if (distance === void 0) {
  16347. distance = 0;
  16348. }
  16349. distance = Math.abs(distance);
  16350. var levels = this.levels;
  16351. var l;
  16352. for (l = 0; l < levels.length; l++) {
  16353. if (distance < levels[l].distance) {
  16354. break;
  16355. }
  16356. }
  16357. levels.splice(l, 0, {
  16358. distance: distance,
  16359. object: object
  16360. });
  16361. this.add(object);
  16362. return this;
  16363. },
  16364. getCurrentLevel: function getCurrentLevel() {
  16365. return this._currentLevel;
  16366. },
  16367. getObjectForDistance: function getObjectForDistance(distance) {
  16368. var levels = this.levels;
  16369. if (levels.length > 0) {
  16370. var i, l;
  16371. for (i = 1, l = levels.length; i < l; i++) {
  16372. if (distance < levels[i].distance) {
  16373. break;
  16374. }
  16375. }
  16376. return levels[i - 1].object;
  16377. }
  16378. return null;
  16379. },
  16380. raycast: function raycast(raycaster, intersects) {
  16381. var levels = this.levels;
  16382. if (levels.length > 0) {
  16383. _v1$4.setFromMatrixPosition(this.matrixWorld);
  16384. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  16385. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  16386. }
  16387. },
  16388. update: function update(camera) {
  16389. var levels = this.levels;
  16390. if (levels.length > 1) {
  16391. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  16392. _v2$2.setFromMatrixPosition(this.matrixWorld);
  16393. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  16394. levels[0].object.visible = true;
  16395. var i, l;
  16396. for (i = 1, l = levels.length; i < l; i++) {
  16397. if (distance >= levels[i].distance) {
  16398. levels[i - 1].object.visible = false;
  16399. levels[i].object.visible = true;
  16400. } else {
  16401. break;
  16402. }
  16403. }
  16404. this._currentLevel = i - 1;
  16405. for (; i < l; i++) {
  16406. levels[i].object.visible = false;
  16407. }
  16408. }
  16409. },
  16410. toJSON: function toJSON(meta) {
  16411. var data = Object3D.prototype.toJSON.call(this, meta);
  16412. if (this.autoUpdate === false) data.object.autoUpdate = false;
  16413. data.object.levels = [];
  16414. var levels = this.levels;
  16415. for (var i = 0, l = levels.length; i < l; i++) {
  16416. var level = levels[i];
  16417. data.object.levels.push({
  16418. object: level.object.uuid,
  16419. distance: level.distance
  16420. });
  16421. }
  16422. return data;
  16423. }
  16424. });
  16425. var _basePosition = new Vector3();
  16426. var _skinIndex = new Vector4();
  16427. var _skinWeight = new Vector4();
  16428. var _vector$7 = new Vector3();
  16429. var _matrix$1 = new Matrix4();
  16430. function SkinnedMesh(geometry, material) {
  16431. if (geometry && geometry.isGeometry) {
  16432. console.error('THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16433. }
  16434. Mesh.call(this, geometry, material);
  16435. this.type = 'SkinnedMesh';
  16436. this.bindMode = 'attached';
  16437. this.bindMatrix = new Matrix4();
  16438. this.bindMatrixInverse = new Matrix4();
  16439. }
  16440. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16441. constructor: SkinnedMesh,
  16442. isSkinnedMesh: true,
  16443. copy: function copy(source) {
  16444. Mesh.prototype.copy.call(this, source);
  16445. this.bindMode = source.bindMode;
  16446. this.bindMatrix.copy(source.bindMatrix);
  16447. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  16448. this.skeleton = source.skeleton;
  16449. return this;
  16450. },
  16451. bind: function bind(skeleton, bindMatrix) {
  16452. this.skeleton = skeleton;
  16453. if (bindMatrix === undefined) {
  16454. this.updateMatrixWorld(true);
  16455. this.skeleton.calculateInverses();
  16456. bindMatrix = this.matrixWorld;
  16457. }
  16458. this.bindMatrix.copy(bindMatrix);
  16459. this.bindMatrixInverse.copy(bindMatrix).invert();
  16460. },
  16461. pose: function pose() {
  16462. this.skeleton.pose();
  16463. },
  16464. normalizeSkinWeights: function normalizeSkinWeights() {
  16465. var vector = new Vector4();
  16466. var skinWeight = this.geometry.attributes.skinWeight;
  16467. for (var i = 0, l = skinWeight.count; i < l; i++) {
  16468. vector.x = skinWeight.getX(i);
  16469. vector.y = skinWeight.getY(i);
  16470. vector.z = skinWeight.getZ(i);
  16471. vector.w = skinWeight.getW(i);
  16472. var scale = 1.0 / vector.manhattanLength();
  16473. if (scale !== Infinity) {
  16474. vector.multiplyScalar(scale);
  16475. } else {
  16476. vector.set(1, 0, 0, 0); // do something reasonable
  16477. }
  16478. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  16479. }
  16480. },
  16481. updateMatrixWorld: function updateMatrixWorld(force) {
  16482. Mesh.prototype.updateMatrixWorld.call(this, force);
  16483. if (this.bindMode === 'attached') {
  16484. this.bindMatrixInverse.copy(this.matrixWorld).invert();
  16485. } else if (this.bindMode === 'detached') {
  16486. this.bindMatrixInverse.copy(this.bindMatrix).invert();
  16487. } else {
  16488. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  16489. }
  16490. },
  16491. boneTransform: function boneTransform(index, target) {
  16492. var skeleton = this.skeleton;
  16493. var geometry = this.geometry;
  16494. _skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  16495. _skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  16496. _basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  16497. target.set(0, 0, 0);
  16498. for (var i = 0; i < 4; i++) {
  16499. var weight = _skinWeight.getComponent(i);
  16500. if (weight !== 0) {
  16501. var boneIndex = _skinIndex.getComponent(i);
  16502. _matrix$1.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  16503. target.addScaledVector(_vector$7.copy(_basePosition).applyMatrix4(_matrix$1), weight);
  16504. }
  16505. }
  16506. return target.applyMatrix4(this.bindMatrixInverse);
  16507. }
  16508. });
  16509. function Bone() {
  16510. Object3D.call(this);
  16511. this.type = 'Bone';
  16512. }
  16513. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  16514. constructor: Bone,
  16515. isBone: true
  16516. });
  16517. var _offsetMatrix = new Matrix4();
  16518. var _identityMatrix = new Matrix4();
  16519. function Skeleton(bones, boneInverses) {
  16520. if (bones === void 0) {
  16521. bones = [];
  16522. }
  16523. if (boneInverses === void 0) {
  16524. boneInverses = [];
  16525. }
  16526. this.uuid = MathUtils.generateUUID();
  16527. this.bones = bones.slice(0);
  16528. this.boneInverses = boneInverses;
  16529. this.boneMatrices = null;
  16530. this.boneTexture = null;
  16531. this.boneTextureSize = 0;
  16532. this.frame = -1;
  16533. this.init();
  16534. }
  16535. Object.assign(Skeleton.prototype, {
  16536. init: function init() {
  16537. var bones = this.bones;
  16538. var boneInverses = this.boneInverses;
  16539. this.boneMatrices = new Float32Array(bones.length * 16); // calculate inverse bone matrices if necessary
  16540. if (boneInverses.length === 0) {
  16541. this.calculateInverses();
  16542. } else {
  16543. // handle special case
  16544. if (bones.length !== boneInverses.length) {
  16545. console.warn('THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.');
  16546. this.boneInverses = [];
  16547. for (var i = 0, il = this.bones.length; i < il; i++) {
  16548. this.boneInverses.push(new Matrix4());
  16549. }
  16550. }
  16551. }
  16552. },
  16553. calculateInverses: function calculateInverses() {
  16554. this.boneInverses.length = 0;
  16555. for (var i = 0, il = this.bones.length; i < il; i++) {
  16556. var inverse = new Matrix4();
  16557. if (this.bones[i]) {
  16558. inverse.copy(this.bones[i].matrixWorld).invert();
  16559. }
  16560. this.boneInverses.push(inverse);
  16561. }
  16562. },
  16563. pose: function pose() {
  16564. // recover the bind-time world matrices
  16565. for (var i = 0, il = this.bones.length; i < il; i++) {
  16566. var bone = this.bones[i];
  16567. if (bone) {
  16568. bone.matrixWorld.copy(this.boneInverses[i]).invert();
  16569. }
  16570. } // compute the local matrices, positions, rotations and scales
  16571. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  16572. var _bone = this.bones[_i];
  16573. if (_bone) {
  16574. if (_bone.parent && _bone.parent.isBone) {
  16575. _bone.matrix.copy(_bone.parent.matrixWorld).invert();
  16576. _bone.matrix.multiply(_bone.matrixWorld);
  16577. } else {
  16578. _bone.matrix.copy(_bone.matrixWorld);
  16579. }
  16580. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  16581. }
  16582. }
  16583. },
  16584. update: function update() {
  16585. var bones = this.bones;
  16586. var boneInverses = this.boneInverses;
  16587. var boneMatrices = this.boneMatrices;
  16588. var boneTexture = this.boneTexture; // flatten bone matrices to array
  16589. for (var i = 0, il = bones.length; i < il; i++) {
  16590. // compute the offset between the current and the original transform
  16591. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  16592. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  16593. _offsetMatrix.toArray(boneMatrices, i * 16);
  16594. }
  16595. if (boneTexture !== null) {
  16596. boneTexture.needsUpdate = true;
  16597. }
  16598. },
  16599. clone: function clone() {
  16600. return new Skeleton(this.bones, this.boneInverses);
  16601. },
  16602. getBoneByName: function getBoneByName(name) {
  16603. for (var i = 0, il = this.bones.length; i < il; i++) {
  16604. var bone = this.bones[i];
  16605. if (bone.name === name) {
  16606. return bone;
  16607. }
  16608. }
  16609. return undefined;
  16610. },
  16611. dispose: function dispose() {
  16612. if (this.boneTexture !== null) {
  16613. this.boneTexture.dispose();
  16614. this.boneTexture = null;
  16615. }
  16616. },
  16617. fromJSON: function fromJSON(json, bones) {
  16618. this.uuid = json.uuid;
  16619. for (var i = 0, l = json.bones.length; i < l; i++) {
  16620. var uuid = json.bones[i];
  16621. var bone = bones[uuid];
  16622. if (bone === undefined) {
  16623. console.warn('THREE.Skeleton: No bone found with UUID:', uuid);
  16624. bone = new Bone();
  16625. }
  16626. this.bones.push(bone);
  16627. this.boneInverses.push(new Matrix4().fromArray(json.boneInverses[i]));
  16628. }
  16629. this.init();
  16630. return this;
  16631. },
  16632. toJSON: function toJSON() {
  16633. var data = {
  16634. metadata: {
  16635. version: 4.5,
  16636. type: 'Skeleton',
  16637. generator: 'Skeleton.toJSON'
  16638. },
  16639. bones: [],
  16640. boneInverses: []
  16641. };
  16642. data.uuid = this.uuid;
  16643. var bones = this.bones;
  16644. var boneInverses = this.boneInverses;
  16645. for (var i = 0, l = bones.length; i < l; i++) {
  16646. var bone = bones[i];
  16647. data.bones.push(bone.uuid);
  16648. var boneInverse = boneInverses[i];
  16649. data.boneInverses.push(boneInverse.toArray());
  16650. }
  16651. return data;
  16652. }
  16653. });
  16654. var _instanceLocalMatrix = new Matrix4();
  16655. var _instanceWorldMatrix = new Matrix4();
  16656. var _instanceIntersects = [];
  16657. var _mesh = new Mesh();
  16658. function InstancedMesh(geometry, material, count) {
  16659. Mesh.call(this, geometry, material);
  16660. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  16661. this.instanceColor = null;
  16662. this.count = count;
  16663. this.frustumCulled = false;
  16664. }
  16665. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16666. constructor: InstancedMesh,
  16667. isInstancedMesh: true,
  16668. copy: function copy(source) {
  16669. Mesh.prototype.copy.call(this, source);
  16670. this.instanceMatrix.copy(source.instanceMatrix);
  16671. if (source.instanceColor !== null) this.instanceColor = source.instanceColor.clone();
  16672. this.count = source.count;
  16673. return this;
  16674. },
  16675. getColorAt: function getColorAt(index, color) {
  16676. color.fromArray(this.instanceColor.array, index * 3);
  16677. },
  16678. getMatrixAt: function getMatrixAt(index, matrix) {
  16679. matrix.fromArray(this.instanceMatrix.array, index * 16);
  16680. },
  16681. raycast: function raycast(raycaster, intersects) {
  16682. var matrixWorld = this.matrixWorld;
  16683. var raycastTimes = this.count;
  16684. _mesh.geometry = this.geometry;
  16685. _mesh.material = this.material;
  16686. if (_mesh.material === undefined) return;
  16687. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  16688. // calculate the world matrix for each instance
  16689. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  16690. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  16691. _mesh.matrixWorld = _instanceWorldMatrix;
  16692. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  16693. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  16694. var intersect = _instanceIntersects[i];
  16695. intersect.instanceId = instanceId;
  16696. intersect.object = this;
  16697. intersects.push(intersect);
  16698. }
  16699. _instanceIntersects.length = 0;
  16700. }
  16701. },
  16702. setColorAt: function setColorAt(index, color) {
  16703. if (this.instanceColor === null) {
  16704. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  16705. }
  16706. color.toArray(this.instanceColor.array, index * 3);
  16707. },
  16708. setMatrixAt: function setMatrixAt(index, matrix) {
  16709. matrix.toArray(this.instanceMatrix.array, index * 16);
  16710. },
  16711. updateMorphTargets: function updateMorphTargets() {},
  16712. dispose: function dispose() {
  16713. this.dispatchEvent({
  16714. type: 'dispose'
  16715. });
  16716. }
  16717. });
  16718. /**
  16719. * parameters = {
  16720. * color: <hex>,
  16721. * opacity: <float>,
  16722. *
  16723. * linewidth: <float>,
  16724. * linecap: "round",
  16725. * linejoin: "round"
  16726. * }
  16727. */
  16728. function LineBasicMaterial(parameters) {
  16729. Material.call(this);
  16730. this.type = 'LineBasicMaterial';
  16731. this.color = new Color(0xffffff);
  16732. this.linewidth = 1;
  16733. this.linecap = 'round';
  16734. this.linejoin = 'round';
  16735. this.morphTargets = false;
  16736. this.setValues(parameters);
  16737. }
  16738. LineBasicMaterial.prototype = Object.create(Material.prototype);
  16739. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  16740. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16741. LineBasicMaterial.prototype.copy = function (source) {
  16742. Material.prototype.copy.call(this, source);
  16743. this.color.copy(source.color);
  16744. this.linewidth = source.linewidth;
  16745. this.linecap = source.linecap;
  16746. this.linejoin = source.linejoin;
  16747. this.morphTargets = source.morphTargets;
  16748. return this;
  16749. };
  16750. var _start = new Vector3();
  16751. var _end = new Vector3();
  16752. var _inverseMatrix$1 = new Matrix4();
  16753. var _ray$1 = new Ray();
  16754. var _sphere$2 = new Sphere();
  16755. function Line(geometry, material) {
  16756. if (geometry === void 0) {
  16757. geometry = new BufferGeometry();
  16758. }
  16759. if (material === void 0) {
  16760. material = new LineBasicMaterial();
  16761. }
  16762. Object3D.call(this);
  16763. this.type = 'Line';
  16764. this.geometry = geometry;
  16765. this.material = material;
  16766. this.updateMorphTargets();
  16767. }
  16768. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  16769. constructor: Line,
  16770. isLine: true,
  16771. copy: function copy(source) {
  16772. Object3D.prototype.copy.call(this, source);
  16773. this.material = source.material;
  16774. this.geometry = source.geometry;
  16775. return this;
  16776. },
  16777. computeLineDistances: function computeLineDistances() {
  16778. var geometry = this.geometry;
  16779. if (geometry.isBufferGeometry) {
  16780. // we assume non-indexed geometry
  16781. if (geometry.index === null) {
  16782. var positionAttribute = geometry.attributes.position;
  16783. var lineDistances = [0];
  16784. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  16785. _start.fromBufferAttribute(positionAttribute, i - 1);
  16786. _end.fromBufferAttribute(positionAttribute, i);
  16787. lineDistances[i] = lineDistances[i - 1];
  16788. lineDistances[i] += _start.distanceTo(_end);
  16789. }
  16790. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16791. } else {
  16792. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16793. }
  16794. } else if (geometry.isGeometry) {
  16795. console.error('THREE.Line.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16796. }
  16797. return this;
  16798. },
  16799. raycast: function raycast(raycaster, intersects) {
  16800. var geometry = this.geometry;
  16801. var matrixWorld = this.matrixWorld;
  16802. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  16803. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16804. _sphere$2.copy(geometry.boundingSphere);
  16805. _sphere$2.applyMatrix4(matrixWorld);
  16806. _sphere$2.radius += threshold;
  16807. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  16808. _inverseMatrix$1.copy(matrixWorld).invert();
  16809. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  16810. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16811. var localThresholdSq = localThreshold * localThreshold;
  16812. var vStart = new Vector3();
  16813. var vEnd = new Vector3();
  16814. var interSegment = new Vector3();
  16815. var interRay = new Vector3();
  16816. var step = this.isLineSegments ? 2 : 1;
  16817. if (geometry.isBufferGeometry) {
  16818. var index = geometry.index;
  16819. var attributes = geometry.attributes;
  16820. var positionAttribute = attributes.position;
  16821. if (index !== null) {
  16822. var indices = index.array;
  16823. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  16824. var a = indices[i];
  16825. var b = indices[i + 1];
  16826. vStart.fromBufferAttribute(positionAttribute, a);
  16827. vEnd.fromBufferAttribute(positionAttribute, b);
  16828. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16829. if (distSq > localThresholdSq) continue;
  16830. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16831. var distance = raycaster.ray.origin.distanceTo(interRay);
  16832. if (distance < raycaster.near || distance > raycaster.far) continue;
  16833. intersects.push({
  16834. distance: distance,
  16835. // What do we want? intersection point on the ray or on the segment??
  16836. // point: raycaster.ray.at( distance ),
  16837. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16838. index: i,
  16839. face: null,
  16840. faceIndex: null,
  16841. object: this
  16842. });
  16843. }
  16844. } else {
  16845. for (var _i = 0, _l = positionAttribute.count - 1; _i < _l; _i += step) {
  16846. vStart.fromBufferAttribute(positionAttribute, _i);
  16847. vEnd.fromBufferAttribute(positionAttribute, _i + 1);
  16848. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16849. if (_distSq > localThresholdSq) continue;
  16850. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16851. var _distance = raycaster.ray.origin.distanceTo(interRay);
  16852. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  16853. intersects.push({
  16854. distance: _distance,
  16855. // What do we want? intersection point on the ray or on the segment??
  16856. // point: raycaster.ray.at( distance ),
  16857. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16858. index: _i,
  16859. face: null,
  16860. faceIndex: null,
  16861. object: this
  16862. });
  16863. }
  16864. }
  16865. } else if (geometry.isGeometry) {
  16866. console.error('THREE.Line.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16867. }
  16868. },
  16869. updateMorphTargets: function updateMorphTargets() {
  16870. var geometry = this.geometry;
  16871. if (geometry.isBufferGeometry) {
  16872. var morphAttributes = geometry.morphAttributes;
  16873. var keys = Object.keys(morphAttributes);
  16874. if (keys.length > 0) {
  16875. var morphAttribute = morphAttributes[keys[0]];
  16876. if (morphAttribute !== undefined) {
  16877. this.morphTargetInfluences = [];
  16878. this.morphTargetDictionary = {};
  16879. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16880. var name = morphAttribute[m].name || String(m);
  16881. this.morphTargetInfluences.push(0);
  16882. this.morphTargetDictionary[name] = m;
  16883. }
  16884. }
  16885. }
  16886. } else {
  16887. var morphTargets = geometry.morphTargets;
  16888. if (morphTargets !== undefined && morphTargets.length > 0) {
  16889. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16890. }
  16891. }
  16892. }
  16893. });
  16894. var _start$1 = new Vector3();
  16895. var _end$1 = new Vector3();
  16896. function LineSegments(geometry, material) {
  16897. Line.call(this, geometry, material);
  16898. this.type = 'LineSegments';
  16899. }
  16900. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  16901. constructor: LineSegments,
  16902. isLineSegments: true,
  16903. computeLineDistances: function computeLineDistances() {
  16904. var geometry = this.geometry;
  16905. if (geometry.isBufferGeometry) {
  16906. // we assume non-indexed geometry
  16907. if (geometry.index === null) {
  16908. var positionAttribute = geometry.attributes.position;
  16909. var lineDistances = [];
  16910. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  16911. _start$1.fromBufferAttribute(positionAttribute, i);
  16912. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  16913. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  16914. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  16915. }
  16916. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16917. } else {
  16918. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16919. }
  16920. } else if (geometry.isGeometry) {
  16921. console.error('THREE.LineSegments.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16922. }
  16923. return this;
  16924. }
  16925. });
  16926. function LineLoop(geometry, material) {
  16927. Line.call(this, geometry, material);
  16928. this.type = 'LineLoop';
  16929. }
  16930. LineLoop.prototype = Object.assign(Object.create(Line.prototype), {
  16931. constructor: LineLoop,
  16932. isLineLoop: true
  16933. });
  16934. /**
  16935. * parameters = {
  16936. * color: <hex>,
  16937. * opacity: <float>,
  16938. * map: new THREE.Texture( <Image> ),
  16939. * alphaMap: new THREE.Texture( <Image> ),
  16940. *
  16941. * size: <float>,
  16942. * sizeAttenuation: <bool>
  16943. *
  16944. * morphTargets: <bool>
  16945. * }
  16946. */
  16947. function PointsMaterial(parameters) {
  16948. Material.call(this);
  16949. this.type = 'PointsMaterial';
  16950. this.color = new Color(0xffffff);
  16951. this.map = null;
  16952. this.alphaMap = null;
  16953. this.size = 1;
  16954. this.sizeAttenuation = true;
  16955. this.morphTargets = false;
  16956. this.setValues(parameters);
  16957. }
  16958. PointsMaterial.prototype = Object.create(Material.prototype);
  16959. PointsMaterial.prototype.constructor = PointsMaterial;
  16960. PointsMaterial.prototype.isPointsMaterial = true;
  16961. PointsMaterial.prototype.copy = function (source) {
  16962. Material.prototype.copy.call(this, source);
  16963. this.color.copy(source.color);
  16964. this.map = source.map;
  16965. this.alphaMap = source.alphaMap;
  16966. this.size = source.size;
  16967. this.sizeAttenuation = source.sizeAttenuation;
  16968. this.morphTargets = source.morphTargets;
  16969. return this;
  16970. };
  16971. var _inverseMatrix$2 = new Matrix4();
  16972. var _ray$2 = new Ray();
  16973. var _sphere$3 = new Sphere();
  16974. var _position$1 = new Vector3();
  16975. function Points(geometry, material) {
  16976. if (geometry === void 0) {
  16977. geometry = new BufferGeometry();
  16978. }
  16979. if (material === void 0) {
  16980. material = new PointsMaterial();
  16981. }
  16982. Object3D.call(this);
  16983. this.type = 'Points';
  16984. this.geometry = geometry;
  16985. this.material = material;
  16986. this.updateMorphTargets();
  16987. }
  16988. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  16989. constructor: Points,
  16990. isPoints: true,
  16991. copy: function copy(source) {
  16992. Object3D.prototype.copy.call(this, source);
  16993. this.material = source.material;
  16994. this.geometry = source.geometry;
  16995. return this;
  16996. },
  16997. raycast: function raycast(raycaster, intersects) {
  16998. var geometry = this.geometry;
  16999. var matrixWorld = this.matrixWorld;
  17000. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  17001. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  17002. _sphere$3.copy(geometry.boundingSphere);
  17003. _sphere$3.applyMatrix4(matrixWorld);
  17004. _sphere$3.radius += threshold;
  17005. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  17006. _inverseMatrix$2.copy(matrixWorld).invert();
  17007. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  17008. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  17009. var localThresholdSq = localThreshold * localThreshold;
  17010. if (geometry.isBufferGeometry) {
  17011. var index = geometry.index;
  17012. var attributes = geometry.attributes;
  17013. var positionAttribute = attributes.position;
  17014. if (index !== null) {
  17015. var indices = index.array;
  17016. for (var i = 0, il = indices.length; i < il; i++) {
  17017. var a = indices[i];
  17018. _position$1.fromBufferAttribute(positionAttribute, a);
  17019. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  17020. }
  17021. } else {
  17022. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  17023. _position$1.fromBufferAttribute(positionAttribute, _i);
  17024. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  17025. }
  17026. }
  17027. } else {
  17028. console.error('THREE.Points.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17029. }
  17030. },
  17031. updateMorphTargets: function updateMorphTargets() {
  17032. var geometry = this.geometry;
  17033. if (geometry.isBufferGeometry) {
  17034. var morphAttributes = geometry.morphAttributes;
  17035. var keys = Object.keys(morphAttributes);
  17036. if (keys.length > 0) {
  17037. var morphAttribute = morphAttributes[keys[0]];
  17038. if (morphAttribute !== undefined) {
  17039. this.morphTargetInfluences = [];
  17040. this.morphTargetDictionary = {};
  17041. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  17042. var name = morphAttribute[m].name || String(m);
  17043. this.morphTargetInfluences.push(0);
  17044. this.morphTargetDictionary[name] = m;
  17045. }
  17046. }
  17047. }
  17048. } else {
  17049. var morphTargets = geometry.morphTargets;
  17050. if (morphTargets !== undefined && morphTargets.length > 0) {
  17051. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  17052. }
  17053. }
  17054. }
  17055. });
  17056. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  17057. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  17058. if (rayPointDistanceSq < localThresholdSq) {
  17059. var intersectPoint = new Vector3();
  17060. _ray$2.closestPointToPoint(point, intersectPoint);
  17061. intersectPoint.applyMatrix4(matrixWorld);
  17062. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  17063. if (distance < raycaster.near || distance > raycaster.far) return;
  17064. intersects.push({
  17065. distance: distance,
  17066. distanceToRay: Math.sqrt(rayPointDistanceSq),
  17067. point: intersectPoint,
  17068. index: index,
  17069. face: null,
  17070. object: object
  17071. });
  17072. }
  17073. }
  17074. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  17075. Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17076. this.format = format !== undefined ? format : RGBFormat;
  17077. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  17078. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  17079. this.generateMipmaps = false;
  17080. var scope = this;
  17081. function updateVideo() {
  17082. scope.needsUpdate = true;
  17083. video.requestVideoFrameCallback(updateVideo);
  17084. }
  17085. if ('requestVideoFrameCallback' in video) {
  17086. video.requestVideoFrameCallback(updateVideo);
  17087. }
  17088. }
  17089. VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
  17090. constructor: VideoTexture,
  17091. clone: function clone() {
  17092. return new this.constructor(this.image).copy(this);
  17093. },
  17094. isVideoTexture: true,
  17095. update: function update() {
  17096. var video = this.image;
  17097. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  17098. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  17099. this.needsUpdate = true;
  17100. }
  17101. }
  17102. });
  17103. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  17104. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  17105. this.image = {
  17106. width: width,
  17107. height: height
  17108. };
  17109. this.mipmaps = mipmaps; // no flipping for cube textures
  17110. // (also flipping doesn't work for compressed textures )
  17111. this.flipY = false; // can't generate mipmaps for compressed textures
  17112. // mips must be embedded in DDS files
  17113. this.generateMipmaps = false;
  17114. }
  17115. CompressedTexture.prototype = Object.create(Texture.prototype);
  17116. CompressedTexture.prototype.constructor = CompressedTexture;
  17117. CompressedTexture.prototype.isCompressedTexture = true;
  17118. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  17119. Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17120. this.needsUpdate = true;
  17121. }
  17122. CanvasTexture.prototype = Object.create(Texture.prototype);
  17123. CanvasTexture.prototype.constructor = CanvasTexture;
  17124. CanvasTexture.prototype.isCanvasTexture = true;
  17125. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  17126. format = format !== undefined ? format : DepthFormat;
  17127. if (format !== DepthFormat && format !== DepthStencilFormat) {
  17128. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  17129. }
  17130. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  17131. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  17132. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17133. this.image = {
  17134. width: width,
  17135. height: height
  17136. };
  17137. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  17138. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  17139. this.flipY = false;
  17140. this.generateMipmaps = false;
  17141. }
  17142. DepthTexture.prototype = Object.create(Texture.prototype);
  17143. DepthTexture.prototype.constructor = DepthTexture;
  17144. DepthTexture.prototype.isDepthTexture = true;
  17145. var CircleGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17146. _inheritsLoose(CircleGeometry, _BufferGeometry);
  17147. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  17148. var _this;
  17149. if (radius === void 0) {
  17150. radius = 1;
  17151. }
  17152. if (segments === void 0) {
  17153. segments = 8;
  17154. }
  17155. if (thetaStart === void 0) {
  17156. thetaStart = 0;
  17157. }
  17158. if (thetaLength === void 0) {
  17159. thetaLength = Math.PI * 2;
  17160. }
  17161. _this = _BufferGeometry.call(this) || this;
  17162. _this.type = 'CircleGeometry';
  17163. _this.parameters = {
  17164. radius: radius,
  17165. segments: segments,
  17166. thetaStart: thetaStart,
  17167. thetaLength: thetaLength
  17168. };
  17169. segments = Math.max(3, segments); // buffers
  17170. var indices = [];
  17171. var vertices = [];
  17172. var normals = [];
  17173. var uvs = []; // helper variables
  17174. var vertex = new Vector3();
  17175. var uv = new Vector2(); // center point
  17176. vertices.push(0, 0, 0);
  17177. normals.push(0, 0, 1);
  17178. uvs.push(0.5, 0.5);
  17179. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  17180. var segment = thetaStart + s / segments * thetaLength; // vertex
  17181. vertex.x = radius * Math.cos(segment);
  17182. vertex.y = radius * Math.sin(segment);
  17183. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17184. normals.push(0, 0, 1); // uvs
  17185. uv.x = (vertices[i] / radius + 1) / 2;
  17186. uv.y = (vertices[i + 1] / radius + 1) / 2;
  17187. uvs.push(uv.x, uv.y);
  17188. } // indices
  17189. for (var _i = 1; _i <= segments; _i++) {
  17190. indices.push(_i, _i + 1, 0);
  17191. } // build geometry
  17192. _this.setIndex(indices);
  17193. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17194. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17195. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17196. return _this;
  17197. }
  17198. return CircleGeometry;
  17199. }(BufferGeometry);
  17200. var CylinderGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17201. _inheritsLoose(CylinderGeometry, _BufferGeometry);
  17202. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17203. var _this;
  17204. if (radiusTop === void 0) {
  17205. radiusTop = 1;
  17206. }
  17207. if (radiusBottom === void 0) {
  17208. radiusBottom = 1;
  17209. }
  17210. if (height === void 0) {
  17211. height = 1;
  17212. }
  17213. if (radialSegments === void 0) {
  17214. radialSegments = 8;
  17215. }
  17216. if (heightSegments === void 0) {
  17217. heightSegments = 1;
  17218. }
  17219. if (openEnded === void 0) {
  17220. openEnded = false;
  17221. }
  17222. if (thetaStart === void 0) {
  17223. thetaStart = 0;
  17224. }
  17225. if (thetaLength === void 0) {
  17226. thetaLength = Math.PI * 2;
  17227. }
  17228. _this = _BufferGeometry.call(this) || this;
  17229. _this.type = 'CylinderGeometry';
  17230. _this.parameters = {
  17231. radiusTop: radiusTop,
  17232. radiusBottom: radiusBottom,
  17233. height: height,
  17234. radialSegments: radialSegments,
  17235. heightSegments: heightSegments,
  17236. openEnded: openEnded,
  17237. thetaStart: thetaStart,
  17238. thetaLength: thetaLength
  17239. };
  17240. var scope = _assertThisInitialized(_this);
  17241. radialSegments = Math.floor(radialSegments);
  17242. heightSegments = Math.floor(heightSegments); // buffers
  17243. var indices = [];
  17244. var vertices = [];
  17245. var normals = [];
  17246. var uvs = []; // helper variables
  17247. var index = 0;
  17248. var indexArray = [];
  17249. var halfHeight = height / 2;
  17250. var groupStart = 0; // generate geometry
  17251. generateTorso();
  17252. if (openEnded === false) {
  17253. if (radiusTop > 0) generateCap(true);
  17254. if (radiusBottom > 0) generateCap(false);
  17255. } // build geometry
  17256. _this.setIndex(indices);
  17257. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17258. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17259. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17260. function generateTorso() {
  17261. var normal = new Vector3();
  17262. var vertex = new Vector3();
  17263. var groupCount = 0; // this will be used to calculate the normal
  17264. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  17265. for (var y = 0; y <= heightSegments; y++) {
  17266. var indexRow = [];
  17267. var v = y / heightSegments; // calculate the radius of the current row
  17268. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  17269. for (var x = 0; x <= radialSegments; x++) {
  17270. var u = x / radialSegments;
  17271. var theta = u * thetaLength + thetaStart;
  17272. var sinTheta = Math.sin(theta);
  17273. var cosTheta = Math.cos(theta); // vertex
  17274. vertex.x = radius * sinTheta;
  17275. vertex.y = -v * height + halfHeight;
  17276. vertex.z = radius * cosTheta;
  17277. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17278. normal.set(sinTheta, slope, cosTheta).normalize();
  17279. normals.push(normal.x, normal.y, normal.z); // uv
  17280. uvs.push(u, 1 - v); // save index of vertex in respective row
  17281. indexRow.push(index++);
  17282. } // now save vertices of the row in our index array
  17283. indexArray.push(indexRow);
  17284. } // generate indices
  17285. for (var _x = 0; _x < radialSegments; _x++) {
  17286. for (var _y = 0; _y < heightSegments; _y++) {
  17287. // we use the index array to access the correct indices
  17288. var a = indexArray[_y][_x];
  17289. var b = indexArray[_y + 1][_x];
  17290. var c = indexArray[_y + 1][_x + 1];
  17291. var d = indexArray[_y][_x + 1]; // faces
  17292. indices.push(a, b, d);
  17293. indices.push(b, c, d); // update group counter
  17294. groupCount += 6;
  17295. }
  17296. } // add a group to the geometry. this will ensure multi material support
  17297. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  17298. groupStart += groupCount;
  17299. }
  17300. function generateCap(top) {
  17301. // save the index of the first center vertex
  17302. var centerIndexStart = index;
  17303. var uv = new Vector2();
  17304. var vertex = new Vector3();
  17305. var groupCount = 0;
  17306. var radius = top === true ? radiusTop : radiusBottom;
  17307. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  17308. // because the geometry needs one set of uvs per face,
  17309. // we must generate a center vertex per face/segment
  17310. for (var x = 1; x <= radialSegments; x++) {
  17311. // vertex
  17312. vertices.push(0, halfHeight * sign, 0); // normal
  17313. normals.push(0, sign, 0); // uv
  17314. uvs.push(0.5, 0.5); // increase index
  17315. index++;
  17316. } // save the index of the last center vertex
  17317. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  17318. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  17319. var u = _x2 / radialSegments;
  17320. var theta = u * thetaLength + thetaStart;
  17321. var cosTheta = Math.cos(theta);
  17322. var sinTheta = Math.sin(theta); // vertex
  17323. vertex.x = radius * sinTheta;
  17324. vertex.y = halfHeight * sign;
  17325. vertex.z = radius * cosTheta;
  17326. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17327. normals.push(0, sign, 0); // uv
  17328. uv.x = cosTheta * 0.5 + 0.5;
  17329. uv.y = sinTheta * 0.5 * sign + 0.5;
  17330. uvs.push(uv.x, uv.y); // increase index
  17331. index++;
  17332. } // generate indices
  17333. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  17334. var c = centerIndexStart + _x3;
  17335. var i = centerIndexEnd + _x3;
  17336. if (top === true) {
  17337. // face top
  17338. indices.push(i, i + 1, c);
  17339. } else {
  17340. // face bottom
  17341. indices.push(i + 1, i, c);
  17342. }
  17343. groupCount += 3;
  17344. } // add a group to the geometry. this will ensure multi material support
  17345. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  17346. groupStart += groupCount;
  17347. }
  17348. return _this;
  17349. }
  17350. return CylinderGeometry;
  17351. }(BufferGeometry);
  17352. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  17353. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  17354. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17355. var _this;
  17356. if (radius === void 0) {
  17357. radius = 1;
  17358. }
  17359. if (height === void 0) {
  17360. height = 1;
  17361. }
  17362. if (radialSegments === void 0) {
  17363. radialSegments = 8;
  17364. }
  17365. if (heightSegments === void 0) {
  17366. heightSegments = 1;
  17367. }
  17368. if (openEnded === void 0) {
  17369. openEnded = false;
  17370. }
  17371. if (thetaStart === void 0) {
  17372. thetaStart = 0;
  17373. }
  17374. if (thetaLength === void 0) {
  17375. thetaLength = Math.PI * 2;
  17376. }
  17377. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17378. _this.type = 'ConeGeometry';
  17379. _this.parameters = {
  17380. radius: radius,
  17381. height: height,
  17382. radialSegments: radialSegments,
  17383. heightSegments: heightSegments,
  17384. openEnded: openEnded,
  17385. thetaStart: thetaStart,
  17386. thetaLength: thetaLength
  17387. };
  17388. return _this;
  17389. }
  17390. return ConeGeometry;
  17391. }(CylinderGeometry);
  17392. var PolyhedronGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17393. _inheritsLoose(PolyhedronGeometry, _BufferGeometry);
  17394. function PolyhedronGeometry(vertices, indices, radius, detail) {
  17395. var _this;
  17396. if (radius === void 0) {
  17397. radius = 1;
  17398. }
  17399. if (detail === void 0) {
  17400. detail = 0;
  17401. }
  17402. _this = _BufferGeometry.call(this) || this;
  17403. _this.type = 'PolyhedronGeometry';
  17404. _this.parameters = {
  17405. vertices: vertices,
  17406. indices: indices,
  17407. radius: radius,
  17408. detail: detail
  17409. }; // default buffer data
  17410. var vertexBuffer = [];
  17411. var uvBuffer = []; // the subdivision creates the vertex buffer data
  17412. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  17413. applyRadius(radius); // finally, create the uv data
  17414. generateUVs(); // build non-indexed geometry
  17415. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  17416. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  17417. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  17418. if (detail === 0) {
  17419. _this.computeVertexNormals(); // flat normals
  17420. } else {
  17421. _this.normalizeNormals(); // smooth normals
  17422. } // helper functions
  17423. function subdivide(detail) {
  17424. var a = new Vector3();
  17425. var b = new Vector3();
  17426. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  17427. for (var i = 0; i < indices.length; i += 3) {
  17428. // get the vertices of the face
  17429. getVertexByIndex(indices[i + 0], a);
  17430. getVertexByIndex(indices[i + 1], b);
  17431. getVertexByIndex(indices[i + 2], c); // perform subdivision
  17432. subdivideFace(a, b, c, detail);
  17433. }
  17434. }
  17435. function subdivideFace(a, b, c, detail) {
  17436. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  17437. var v = []; // construct all of the vertices for this subdivision
  17438. for (var i = 0; i <= cols; i++) {
  17439. v[i] = [];
  17440. var aj = a.clone().lerp(c, i / cols);
  17441. var bj = b.clone().lerp(c, i / cols);
  17442. var rows = cols - i;
  17443. for (var j = 0; j <= rows; j++) {
  17444. if (j === 0 && i === cols) {
  17445. v[i][j] = aj;
  17446. } else {
  17447. v[i][j] = aj.clone().lerp(bj, j / rows);
  17448. }
  17449. }
  17450. } // construct all of the faces
  17451. for (var _i = 0; _i < cols; _i++) {
  17452. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  17453. var k = Math.floor(_j / 2);
  17454. if (_j % 2 === 0) {
  17455. pushVertex(v[_i][k + 1]);
  17456. pushVertex(v[_i + 1][k]);
  17457. pushVertex(v[_i][k]);
  17458. } else {
  17459. pushVertex(v[_i][k + 1]);
  17460. pushVertex(v[_i + 1][k + 1]);
  17461. pushVertex(v[_i + 1][k]);
  17462. }
  17463. }
  17464. }
  17465. }
  17466. function applyRadius(radius) {
  17467. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  17468. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17469. vertex.x = vertexBuffer[i + 0];
  17470. vertex.y = vertexBuffer[i + 1];
  17471. vertex.z = vertexBuffer[i + 2];
  17472. vertex.normalize().multiplyScalar(radius);
  17473. vertexBuffer[i + 0] = vertex.x;
  17474. vertexBuffer[i + 1] = vertex.y;
  17475. vertexBuffer[i + 2] = vertex.z;
  17476. }
  17477. }
  17478. function generateUVs() {
  17479. var vertex = new Vector3();
  17480. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17481. vertex.x = vertexBuffer[i + 0];
  17482. vertex.y = vertexBuffer[i + 1];
  17483. vertex.z = vertexBuffer[i + 2];
  17484. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17485. var v = inclination(vertex) / Math.PI + 0.5;
  17486. uvBuffer.push(u, 1 - v);
  17487. }
  17488. correctUVs();
  17489. correctSeam();
  17490. }
  17491. function correctSeam() {
  17492. // handle case when face straddles the seam, see #3269
  17493. for (var i = 0; i < uvBuffer.length; i += 6) {
  17494. // uv data of a single face
  17495. var x0 = uvBuffer[i + 0];
  17496. var x1 = uvBuffer[i + 2];
  17497. var x2 = uvBuffer[i + 4];
  17498. var max = Math.max(x0, x1, x2);
  17499. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17500. if (max > 0.9 && min < 0.1) {
  17501. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17502. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17503. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17504. }
  17505. }
  17506. }
  17507. function pushVertex(vertex) {
  17508. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17509. }
  17510. function getVertexByIndex(index, vertex) {
  17511. var stride = index * 3;
  17512. vertex.x = vertices[stride + 0];
  17513. vertex.y = vertices[stride + 1];
  17514. vertex.z = vertices[stride + 2];
  17515. }
  17516. function correctUVs() {
  17517. var a = new Vector3();
  17518. var b = new Vector3();
  17519. var c = new Vector3();
  17520. var centroid = new Vector3();
  17521. var uvA = new Vector2();
  17522. var uvB = new Vector2();
  17523. var uvC = new Vector2();
  17524. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17525. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17526. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17527. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17528. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17529. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17530. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17531. centroid.copy(a).add(b).add(c).divideScalar(3);
  17532. var azi = azimuth(centroid);
  17533. correctUV(uvA, j + 0, a, azi);
  17534. correctUV(uvB, j + 2, b, azi);
  17535. correctUV(uvC, j + 4, c, azi);
  17536. }
  17537. }
  17538. function correctUV(uv, stride, vector, azimuth) {
  17539. if (azimuth < 0 && uv.x === 1) {
  17540. uvBuffer[stride] = uv.x - 1;
  17541. }
  17542. if (vector.x === 0 && vector.z === 0) {
  17543. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17544. }
  17545. } // Angle around the Y axis, counter-clockwise when looking from above.
  17546. function azimuth(vector) {
  17547. return Math.atan2(vector.z, -vector.x);
  17548. } // Angle above the XZ plane.
  17549. function inclination(vector) {
  17550. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17551. }
  17552. return _this;
  17553. }
  17554. return PolyhedronGeometry;
  17555. }(BufferGeometry);
  17556. var DodecahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  17557. _inheritsLoose(DodecahedronGeometry, _PolyhedronGeometry);
  17558. function DodecahedronGeometry(radius, detail) {
  17559. var _this;
  17560. if (radius === void 0) {
  17561. radius = 1;
  17562. }
  17563. if (detail === void 0) {
  17564. detail = 0;
  17565. }
  17566. var t = (1 + Math.sqrt(5)) / 2;
  17567. var r = 1 / t;
  17568. var vertices = [// (±1, ±1, ±1)
  17569. -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/φ, ±φ)
  17570. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17571. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17572. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17573. 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];
  17574. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  17575. _this.type = 'DodecahedronGeometry';
  17576. _this.parameters = {
  17577. radius: radius,
  17578. detail: detail
  17579. };
  17580. return _this;
  17581. }
  17582. return DodecahedronGeometry;
  17583. }(PolyhedronGeometry);
  17584. var _v0$2 = new Vector3();
  17585. var _v1$5 = new Vector3();
  17586. var _normal$1 = new Vector3();
  17587. var _triangle = new Triangle();
  17588. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17589. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17590. function EdgesGeometry(geometry, thresholdAngle) {
  17591. var _this;
  17592. _this = _BufferGeometry.call(this) || this;
  17593. _this.type = 'EdgesGeometry';
  17594. _this.parameters = {
  17595. thresholdAngle: thresholdAngle
  17596. };
  17597. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  17598. if (geometry.isGeometry === true) {
  17599. console.error('THREE.EdgesGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17600. return _assertThisInitialized(_this);
  17601. }
  17602. var precisionPoints = 4;
  17603. var precision = Math.pow(10, precisionPoints);
  17604. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  17605. var indexAttr = geometry.getIndex();
  17606. var positionAttr = geometry.getAttribute('position');
  17607. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  17608. var indexArr = [0, 0, 0];
  17609. var vertKeys = ['a', 'b', 'c'];
  17610. var hashes = new Array(3);
  17611. var edgeData = {};
  17612. var vertices = [];
  17613. for (var i = 0; i < indexCount; i += 3) {
  17614. if (indexAttr) {
  17615. indexArr[0] = indexAttr.getX(i);
  17616. indexArr[1] = indexAttr.getX(i + 1);
  17617. indexArr[2] = indexAttr.getX(i + 2);
  17618. } else {
  17619. indexArr[0] = i;
  17620. indexArr[1] = i + 1;
  17621. indexArr[2] = i + 2;
  17622. }
  17623. var a = _triangle.a,
  17624. b = _triangle.b,
  17625. c = _triangle.c;
  17626. a.fromBufferAttribute(positionAttr, indexArr[0]);
  17627. b.fromBufferAttribute(positionAttr, indexArr[1]);
  17628. c.fromBufferAttribute(positionAttr, indexArr[2]);
  17629. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  17630. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  17631. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  17632. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  17633. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  17634. continue;
  17635. } // iterate over every edge
  17636. for (var j = 0; j < 3; j++) {
  17637. // get the first and next vertex making up the edge
  17638. var jNext = (j + 1) % 3;
  17639. var vecHash0 = hashes[j];
  17640. var vecHash1 = hashes[jNext];
  17641. var v0 = _triangle[vertKeys[j]];
  17642. var v1 = _triangle[vertKeys[jNext]];
  17643. var hash = vecHash0 + "_" + vecHash1;
  17644. var reverseHash = vecHash1 + "_" + vecHash0;
  17645. if (reverseHash in edgeData && edgeData[reverseHash]) {
  17646. // if we found a sibling edge add it into the vertex array if
  17647. // it meets the angle threshold and delete the edge from the map.
  17648. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  17649. vertices.push(v0.x, v0.y, v0.z);
  17650. vertices.push(v1.x, v1.y, v1.z);
  17651. }
  17652. edgeData[reverseHash] = null;
  17653. } else if (!(hash in edgeData)) {
  17654. // if we've already got an edge here then skip adding a new one
  17655. edgeData[hash] = {
  17656. index0: indexArr[j],
  17657. index1: indexArr[jNext],
  17658. normal: _normal$1.clone()
  17659. };
  17660. }
  17661. }
  17662. } // iterate over all remaining, unmatched edges and add them to the vertex array
  17663. for (var key in edgeData) {
  17664. if (edgeData[key]) {
  17665. var _edgeData$key = edgeData[key],
  17666. index0 = _edgeData$key.index0,
  17667. index1 = _edgeData$key.index1;
  17668. _v0$2.fromBufferAttribute(positionAttr, index0);
  17669. _v1$5.fromBufferAttribute(positionAttr, index1);
  17670. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  17671. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  17672. }
  17673. }
  17674. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17675. return _this;
  17676. }
  17677. return EdgesGeometry;
  17678. }(BufferGeometry);
  17679. /**
  17680. * Port from https://github.com/mapbox/earcut (v2.2.2)
  17681. */
  17682. var Earcut = {
  17683. triangulate: function triangulate(data, holeIndices, dim) {
  17684. dim = dim || 2;
  17685. var hasHoles = holeIndices && holeIndices.length;
  17686. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  17687. var outerNode = linkedList(data, 0, outerLen, dim, true);
  17688. var triangles = [];
  17689. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  17690. var minX, minY, maxX, maxY, x, y, invSize;
  17691. 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
  17692. if (data.length > 80 * dim) {
  17693. minX = maxX = data[0];
  17694. minY = maxY = data[1];
  17695. for (var i = dim; i < outerLen; i += dim) {
  17696. x = data[i];
  17697. y = data[i + 1];
  17698. if (x < minX) minX = x;
  17699. if (y < minY) minY = y;
  17700. if (x > maxX) maxX = x;
  17701. if (y > maxY) maxY = y;
  17702. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17703. invSize = Math.max(maxX - minX, maxY - minY);
  17704. invSize = invSize !== 0 ? 1 / invSize : 0;
  17705. }
  17706. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  17707. return triangles;
  17708. }
  17709. }; // create a circular doubly linked list from polygon points in the specified winding order
  17710. function linkedList(data, start, end, dim, clockwise) {
  17711. var i, last;
  17712. if (clockwise === signedArea(data, start, end, dim) > 0) {
  17713. for (i = start; i < end; i += dim) {
  17714. last = insertNode(i, data[i], data[i + 1], last);
  17715. }
  17716. } else {
  17717. for (i = end - dim; i >= start; i -= dim) {
  17718. last = insertNode(i, data[i], data[i + 1], last);
  17719. }
  17720. }
  17721. if (last && equals(last, last.next)) {
  17722. removeNode(last);
  17723. last = last.next;
  17724. }
  17725. return last;
  17726. } // eliminate colinear or duplicate points
  17727. function filterPoints(start, end) {
  17728. if (!start) return start;
  17729. if (!end) end = start;
  17730. var p = start,
  17731. again;
  17732. do {
  17733. again = false;
  17734. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  17735. removeNode(p);
  17736. p = end = p.prev;
  17737. if (p === p.next) break;
  17738. again = true;
  17739. } else {
  17740. p = p.next;
  17741. }
  17742. } while (again || p !== end);
  17743. return end;
  17744. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  17745. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  17746. if (!ear) return; // interlink polygon nodes in z-order
  17747. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  17748. var stop = ear,
  17749. prev,
  17750. next; // iterate through ears, slicing them one by one
  17751. while (ear.prev !== ear.next) {
  17752. prev = ear.prev;
  17753. next = ear.next;
  17754. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  17755. // cut off the triangle
  17756. triangles.push(prev.i / dim);
  17757. triangles.push(ear.i / dim);
  17758. triangles.push(next.i / dim);
  17759. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  17760. ear = next.next;
  17761. stop = next.next;
  17762. continue;
  17763. }
  17764. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  17765. if (ear === stop) {
  17766. // try filtering points and slicing again
  17767. if (!pass) {
  17768. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  17769. } else if (pass === 1) {
  17770. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  17771. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  17772. } else if (pass === 2) {
  17773. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  17774. }
  17775. break;
  17776. }
  17777. }
  17778. } // check whether a polygon node forms a valid ear with adjacent nodes
  17779. function isEar(ear) {
  17780. var a = ear.prev,
  17781. b = ear,
  17782. c = ear.next;
  17783. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17784. // now make sure we don't have other points inside the potential ear
  17785. var p = ear.next.next;
  17786. while (p !== ear.prev) {
  17787. 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;
  17788. p = p.next;
  17789. }
  17790. return true;
  17791. }
  17792. function isEarHashed(ear, minX, minY, invSize) {
  17793. var a = ear.prev,
  17794. b = ear,
  17795. c = ear.next;
  17796. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17797. // triangle bbox; min & max are calculated like this for speed
  17798. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  17799. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  17800. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  17801. 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;
  17802. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  17803. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  17804. var p = ear.prevZ,
  17805. n = ear.nextZ; // look for points inside the triangle in both directions
  17806. while (p && p.z >= minZ && n && n.z <= maxZ) {
  17807. 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;
  17808. p = p.prevZ;
  17809. 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;
  17810. n = n.nextZ;
  17811. } // look for remaining points in decreasing z-order
  17812. while (p && p.z >= minZ) {
  17813. 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;
  17814. p = p.prevZ;
  17815. } // look for remaining points in increasing z-order
  17816. while (n && n.z <= maxZ) {
  17817. 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;
  17818. n = n.nextZ;
  17819. }
  17820. return true;
  17821. } // go through all polygon nodes and cure small local self-intersections
  17822. function cureLocalIntersections(start, triangles, dim) {
  17823. var p = start;
  17824. do {
  17825. var a = p.prev,
  17826. b = p.next.next;
  17827. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  17828. triangles.push(a.i / dim);
  17829. triangles.push(p.i / dim);
  17830. triangles.push(b.i / dim); // remove two nodes involved
  17831. removeNode(p);
  17832. removeNode(p.next);
  17833. p = start = b;
  17834. }
  17835. p = p.next;
  17836. } while (p !== start);
  17837. return filterPoints(p);
  17838. } // try splitting polygon into two and triangulate them independently
  17839. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  17840. // look for a valid diagonal that divides the polygon into two
  17841. var a = start;
  17842. do {
  17843. var b = a.next.next;
  17844. while (b !== a.prev) {
  17845. if (a.i !== b.i && isValidDiagonal(a, b)) {
  17846. // split the polygon in two by the diagonal
  17847. var c = splitPolygon(a, b); // filter colinear points around the cuts
  17848. a = filterPoints(a, a.next);
  17849. c = filterPoints(c, c.next); // run earcut on each half
  17850. earcutLinked(a, triangles, dim, minX, minY, invSize);
  17851. earcutLinked(c, triangles, dim, minX, minY, invSize);
  17852. return;
  17853. }
  17854. b = b.next;
  17855. }
  17856. a = a.next;
  17857. } while (a !== start);
  17858. } // link every hole into the outer loop, producing a single-ring polygon without holes
  17859. function eliminateHoles(data, holeIndices, outerNode, dim) {
  17860. var queue = [];
  17861. var i, len, start, end, list;
  17862. for (i = 0, len = holeIndices.length; i < len; i++) {
  17863. start = holeIndices[i] * dim;
  17864. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  17865. list = linkedList(data, start, end, dim, false);
  17866. if (list === list.next) list.steiner = true;
  17867. queue.push(getLeftmost(list));
  17868. }
  17869. queue.sort(compareX); // process holes from left to right
  17870. for (i = 0; i < queue.length; i++) {
  17871. eliminateHole(queue[i], outerNode);
  17872. outerNode = filterPoints(outerNode, outerNode.next);
  17873. }
  17874. return outerNode;
  17875. }
  17876. function compareX(a, b) {
  17877. return a.x - b.x;
  17878. } // find a bridge between vertices that connects hole with an outer ring and and link it
  17879. function eliminateHole(hole, outerNode) {
  17880. outerNode = findHoleBridge(hole, outerNode);
  17881. if (outerNode) {
  17882. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  17883. filterPoints(outerNode, outerNode.next);
  17884. filterPoints(b, b.next);
  17885. }
  17886. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17887. function findHoleBridge(hole, outerNode) {
  17888. var p = outerNode;
  17889. var hx = hole.x;
  17890. var hy = hole.y;
  17891. var qx = -Infinity,
  17892. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  17893. // segment's endpoint with lesser x will be potential connection point
  17894. do {
  17895. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  17896. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  17897. if (x <= hx && x > qx) {
  17898. qx = x;
  17899. if (x === hx) {
  17900. if (hy === p.y) return p;
  17901. if (hy === p.next.y) return p.next;
  17902. }
  17903. m = p.x < p.next.x ? p : p.next;
  17904. }
  17905. }
  17906. p = p.next;
  17907. } while (p !== outerNode);
  17908. if (!m) return null;
  17909. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  17910. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17911. // if there are no points found, we have a valid connection;
  17912. // otherwise choose the point of the minimum angle with the ray as connection point
  17913. var stop = m,
  17914. mx = m.x,
  17915. my = m.y;
  17916. var tanMin = Infinity,
  17917. tan;
  17918. p = m;
  17919. do {
  17920. 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)) {
  17921. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  17922. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  17923. m = p;
  17924. tanMin = tan;
  17925. }
  17926. }
  17927. p = p.next;
  17928. } while (p !== stop);
  17929. return m;
  17930. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  17931. function sectorContainsSector(m, p) {
  17932. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  17933. } // interlink polygon nodes in z-order
  17934. function indexCurve(start, minX, minY, invSize) {
  17935. var p = start;
  17936. do {
  17937. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  17938. p.prevZ = p.prev;
  17939. p.nextZ = p.next;
  17940. p = p.next;
  17941. } while (p !== start);
  17942. p.prevZ.nextZ = null;
  17943. p.prevZ = null;
  17944. sortLinked(p);
  17945. } // Simon Tatham's linked list merge sort algorithm
  17946. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17947. function sortLinked(list) {
  17948. var i,
  17949. p,
  17950. q,
  17951. e,
  17952. tail,
  17953. numMerges,
  17954. pSize,
  17955. qSize,
  17956. inSize = 1;
  17957. do {
  17958. p = list;
  17959. list = null;
  17960. tail = null;
  17961. numMerges = 0;
  17962. while (p) {
  17963. numMerges++;
  17964. q = p;
  17965. pSize = 0;
  17966. for (i = 0; i < inSize; i++) {
  17967. pSize++;
  17968. q = q.nextZ;
  17969. if (!q) break;
  17970. }
  17971. qSize = inSize;
  17972. while (pSize > 0 || qSize > 0 && q) {
  17973. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  17974. e = p;
  17975. p = p.nextZ;
  17976. pSize--;
  17977. } else {
  17978. e = q;
  17979. q = q.nextZ;
  17980. qSize--;
  17981. }
  17982. if (tail) tail.nextZ = e;else list = e;
  17983. e.prevZ = tail;
  17984. tail = e;
  17985. }
  17986. p = q;
  17987. }
  17988. tail.nextZ = null;
  17989. inSize *= 2;
  17990. } while (numMerges > 1);
  17991. return list;
  17992. } // z-order of a point given coords and inverse of the longer side of data bbox
  17993. function zOrder(x, y, minX, minY, invSize) {
  17994. // coords are transformed into non-negative 15-bit integer range
  17995. x = 32767 * (x - minX) * invSize;
  17996. y = 32767 * (y - minY) * invSize;
  17997. x = (x | x << 8) & 0x00FF00FF;
  17998. x = (x | x << 4) & 0x0F0F0F0F;
  17999. x = (x | x << 2) & 0x33333333;
  18000. x = (x | x << 1) & 0x55555555;
  18001. y = (y | y << 8) & 0x00FF00FF;
  18002. y = (y | y << 4) & 0x0F0F0F0F;
  18003. y = (y | y << 2) & 0x33333333;
  18004. y = (y | y << 1) & 0x55555555;
  18005. return x | y << 1;
  18006. } // find the leftmost node of a polygon ring
  18007. function getLeftmost(start) {
  18008. var p = start,
  18009. leftmost = start;
  18010. do {
  18011. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  18012. p = p.next;
  18013. } while (p !== start);
  18014. return leftmost;
  18015. } // check if a point lies within a convex triangle
  18016. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  18017. 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;
  18018. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18019. function isValidDiagonal(a, b) {
  18020. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  18021. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  18022. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  18023. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  18024. } // signed area of a triangle
  18025. function area(p, q, r) {
  18026. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  18027. } // check if two points are equal
  18028. function equals(p1, p2) {
  18029. return p1.x === p2.x && p1.y === p2.y;
  18030. } // check if two segments intersect
  18031. function intersects(p1, q1, p2, q2) {
  18032. var o1 = sign(area(p1, q1, p2));
  18033. var o2 = sign(area(p1, q1, q2));
  18034. var o3 = sign(area(p2, q2, p1));
  18035. var o4 = sign(area(p2, q2, q1));
  18036. if (o1 !== o2 && o3 !== o4) return true; // general case
  18037. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18038. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18039. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18040. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18041. return false;
  18042. } // for collinear points p, q, r, check if point q lies on segment pr
  18043. function onSegment(p, q, r) {
  18044. 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);
  18045. }
  18046. function sign(num) {
  18047. return num > 0 ? 1 : num < 0 ? -1 : 0;
  18048. } // check if a polygon diagonal intersects any polygon segments
  18049. function intersectsPolygon(a, b) {
  18050. var p = a;
  18051. do {
  18052. 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;
  18053. p = p.next;
  18054. } while (p !== a);
  18055. return false;
  18056. } // check if a polygon diagonal is locally inside the polygon
  18057. function locallyInside(a, b) {
  18058. 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;
  18059. } // check if the middle point of a polygon diagonal is inside the polygon
  18060. function middleInside(a, b) {
  18061. var p = a,
  18062. inside = false;
  18063. var px = (a.x + b.x) / 2,
  18064. py = (a.y + b.y) / 2;
  18065. do {
  18066. 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;
  18067. p = p.next;
  18068. } while (p !== a);
  18069. return inside;
  18070. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18071. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18072. function splitPolygon(a, b) {
  18073. var a2 = new Node(a.i, a.x, a.y),
  18074. b2 = new Node(b.i, b.x, b.y),
  18075. an = a.next,
  18076. bp = b.prev;
  18077. a.next = b;
  18078. b.prev = a;
  18079. a2.next = an;
  18080. an.prev = a2;
  18081. b2.next = a2;
  18082. a2.prev = b2;
  18083. bp.next = b2;
  18084. b2.prev = bp;
  18085. return b2;
  18086. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  18087. function insertNode(i, x, y, last) {
  18088. var p = new Node(i, x, y);
  18089. if (!last) {
  18090. p.prev = p;
  18091. p.next = p;
  18092. } else {
  18093. p.next = last.next;
  18094. p.prev = last;
  18095. last.next.prev = p;
  18096. last.next = p;
  18097. }
  18098. return p;
  18099. }
  18100. function removeNode(p) {
  18101. p.next.prev = p.prev;
  18102. p.prev.next = p.next;
  18103. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  18104. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  18105. }
  18106. function Node(i, x, y) {
  18107. // vertex index in coordinates array
  18108. this.i = i; // vertex coordinates
  18109. this.x = x;
  18110. this.y = y; // previous and next vertex nodes in a polygon ring
  18111. this.prev = null;
  18112. this.next = null; // z-order curve value
  18113. this.z = null; // previous and next nodes in z-order
  18114. this.prevZ = null;
  18115. this.nextZ = null; // indicates whether this is a steiner point
  18116. this.steiner = false;
  18117. }
  18118. function signedArea(data, start, end, dim) {
  18119. var sum = 0;
  18120. for (var i = start, j = end - dim; i < end; i += dim) {
  18121. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  18122. j = i;
  18123. }
  18124. return sum;
  18125. }
  18126. var ShapeUtils = {
  18127. // calculate area of the contour polygon
  18128. area: function area(contour) {
  18129. var n = contour.length;
  18130. var a = 0.0;
  18131. for (var p = n - 1, q = 0; q < n; p = q++) {
  18132. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  18133. }
  18134. return a * 0.5;
  18135. },
  18136. isClockWise: function isClockWise(pts) {
  18137. return ShapeUtils.area(pts) < 0;
  18138. },
  18139. triangulateShape: function triangulateShape(contour, holes) {
  18140. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18141. var holeIndices = []; // array of hole indices
  18142. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18143. removeDupEndPts(contour);
  18144. addContour(vertices, contour); //
  18145. var holeIndex = contour.length;
  18146. holes.forEach(removeDupEndPts);
  18147. for (var i = 0; i < holes.length; i++) {
  18148. holeIndices.push(holeIndex);
  18149. holeIndex += holes[i].length;
  18150. addContour(vertices, holes[i]);
  18151. } //
  18152. var triangles = Earcut.triangulate(vertices, holeIndices); //
  18153. for (var _i = 0; _i < triangles.length; _i += 3) {
  18154. faces.push(triangles.slice(_i, _i + 3));
  18155. }
  18156. return faces;
  18157. }
  18158. };
  18159. function removeDupEndPts(points) {
  18160. var l = points.length;
  18161. if (l > 2 && points[l - 1].equals(points[0])) {
  18162. points.pop();
  18163. }
  18164. }
  18165. function addContour(vertices, contour) {
  18166. for (var i = 0; i < contour.length; i++) {
  18167. vertices.push(contour[i].x);
  18168. vertices.push(contour[i].y);
  18169. }
  18170. }
  18171. var ExtrudeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18172. _inheritsLoose(ExtrudeGeometry, _BufferGeometry);
  18173. function ExtrudeGeometry(shapes, options) {
  18174. var _this;
  18175. _this = _BufferGeometry.call(this) || this;
  18176. _this.type = 'ExtrudeGeometry';
  18177. _this.parameters = {
  18178. shapes: shapes,
  18179. options: options
  18180. };
  18181. shapes = Array.isArray(shapes) ? shapes : [shapes];
  18182. var scope = _assertThisInitialized(_this);
  18183. var verticesArray = [];
  18184. var uvArray = [];
  18185. for (var i = 0, l = shapes.length; i < l; i++) {
  18186. var shape = shapes[i];
  18187. addShape(shape);
  18188. } // build geometry
  18189. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  18190. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  18191. _this.computeVertexNormals(); // functions
  18192. function addShape(shape) {
  18193. var placeholder = []; // options
  18194. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18195. var steps = options.steps !== undefined ? options.steps : 1;
  18196. var depth = options.depth !== undefined ? options.depth : 100;
  18197. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18198. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18199. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18200. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18201. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18202. var extrudePath = options.extrudePath;
  18203. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  18204. if (options.amount !== undefined) {
  18205. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  18206. depth = options.amount;
  18207. } //
  18208. var extrudePts,
  18209. extrudeByPath = false;
  18210. var splineTube, binormal, normal, position2;
  18211. if (extrudePath) {
  18212. extrudePts = extrudePath.getSpacedPoints(steps);
  18213. extrudeByPath = true;
  18214. bevelEnabled = false; // bevels not supported for path extrusion
  18215. // SETUP TNB variables
  18216. // TODO1 - have a .isClosed in spline?
  18217. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18218. binormal = new Vector3();
  18219. normal = new Vector3();
  18220. position2 = new Vector3();
  18221. } // Safeguards if bevels are not enabled
  18222. if (!bevelEnabled) {
  18223. bevelSegments = 0;
  18224. bevelThickness = 0;
  18225. bevelSize = 0;
  18226. bevelOffset = 0;
  18227. } // Variables initialization
  18228. var shapePoints = shape.extractPoints(curveSegments);
  18229. var vertices = shapePoints.shape;
  18230. var holes = shapePoints.holes;
  18231. var reverse = !ShapeUtils.isClockWise(vertices);
  18232. if (reverse) {
  18233. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18234. for (var h = 0, hl = holes.length; h < hl; h++) {
  18235. var ahole = holes[h];
  18236. if (ShapeUtils.isClockWise(ahole)) {
  18237. holes[h] = ahole.reverse();
  18238. }
  18239. }
  18240. }
  18241. var faces = ShapeUtils.triangulateShape(vertices, holes);
  18242. /* Vertices */
  18243. var contour = vertices; // vertices has all points but contour has only points of circumference
  18244. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  18245. var _ahole = holes[_h];
  18246. vertices = vertices.concat(_ahole);
  18247. }
  18248. function scalePt2(pt, vec, size) {
  18249. if (!vec) console.error('THREE.ExtrudeGeometry: vec does not exist');
  18250. return vec.clone().multiplyScalar(size).add(pt);
  18251. }
  18252. var vlen = vertices.length,
  18253. flen = faces.length; // Find directions for point movement
  18254. function getBevelVec(inPt, inPrev, inNext) {
  18255. // computes for inPt the corresponding point inPt' on a new contour
  18256. // shifted by 1 unit (length of normalized vector) to the left
  18257. // if we walk along contour clockwise, this new contour is outside the old one
  18258. //
  18259. // inPt' is the intersection of the two lines parallel to the two
  18260. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18261. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18262. // good reading for geometry algorithms (here: line-line intersection)
  18263. // http://geomalgorithms.com/a05-_intersect-1.html
  18264. var v_prev_x = inPt.x - inPrev.x,
  18265. v_prev_y = inPt.y - inPrev.y;
  18266. var v_next_x = inNext.x - inPt.x,
  18267. v_next_y = inNext.y - inPt.y;
  18268. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  18269. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  18270. if (Math.abs(collinear0) > Number.EPSILON) {
  18271. // not collinear
  18272. // length of vectors for normalizing
  18273. var v_prev_len = Math.sqrt(v_prev_lensq);
  18274. 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
  18275. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  18276. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  18277. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  18278. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  18279. 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
  18280. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  18281. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  18282. // but prevent crazy spikes
  18283. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  18284. if (v_trans_lensq <= 2) {
  18285. return new Vector2(v_trans_x, v_trans_y);
  18286. } else {
  18287. shrink_by = Math.sqrt(v_trans_lensq / 2);
  18288. }
  18289. } else {
  18290. // handle special case of collinear edges
  18291. var direction_eq = false; // assumes: opposite
  18292. if (v_prev_x > Number.EPSILON) {
  18293. if (v_next_x > Number.EPSILON) {
  18294. direction_eq = true;
  18295. }
  18296. } else {
  18297. if (v_prev_x < -Number.EPSILON) {
  18298. if (v_next_x < -Number.EPSILON) {
  18299. direction_eq = true;
  18300. }
  18301. } else {
  18302. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  18303. direction_eq = true;
  18304. }
  18305. }
  18306. }
  18307. if (direction_eq) {
  18308. // console.log("Warning: lines are a straight sequence");
  18309. v_trans_x = -v_prev_y;
  18310. v_trans_y = v_prev_x;
  18311. shrink_by = Math.sqrt(v_prev_lensq);
  18312. } else {
  18313. // console.log("Warning: lines are a straight spike");
  18314. v_trans_x = v_prev_x;
  18315. v_trans_y = v_prev_y;
  18316. shrink_by = Math.sqrt(v_prev_lensq / 2);
  18317. }
  18318. }
  18319. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  18320. }
  18321. var contourMovements = [];
  18322. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  18323. if (j === il) j = 0;
  18324. if (k === il) k = 0; // (j)---(i)---(k)
  18325. // console.log('i,j,k', i, j , k)
  18326. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  18327. }
  18328. var holesMovements = [];
  18329. var oneHoleMovements,
  18330. verticesMovements = contourMovements.concat();
  18331. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  18332. var _ahole2 = holes[_h2];
  18333. oneHoleMovements = [];
  18334. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  18335. if (_j === _il) _j = 0;
  18336. if (_k === _il) _k = 0; // (j)---(i)---(k)
  18337. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  18338. }
  18339. holesMovements.push(oneHoleMovements);
  18340. verticesMovements = verticesMovements.concat(oneHoleMovements);
  18341. } // Loop bevelSegments, 1 for the front, 1 for the back
  18342. for (var b = 0; b < bevelSegments; b++) {
  18343. //for ( b = bevelSegments; b > 0; b -- ) {
  18344. var t = b / bevelSegments;
  18345. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  18346. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  18347. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  18348. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  18349. v(vert.x, vert.y, -z);
  18350. } // expand holes
  18351. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  18352. var _ahole3 = holes[_h3];
  18353. oneHoleMovements = holesMovements[_h3];
  18354. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  18355. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  18356. v(_vert.x, _vert.y, -z);
  18357. }
  18358. }
  18359. }
  18360. var bs = bevelSize + bevelOffset; // Back facing vertices
  18361. for (var _i5 = 0; _i5 < vlen; _i5++) {
  18362. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  18363. if (!extrudeByPath) {
  18364. v(_vert2.x, _vert2.y, 0);
  18365. } else {
  18366. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18367. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  18368. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  18369. position2.copy(extrudePts[0]).add(normal).add(binormal);
  18370. v(position2.x, position2.y, position2.z);
  18371. }
  18372. } // Add stepped vertices...
  18373. // Including front facing vertices
  18374. for (var s = 1; s <= steps; s++) {
  18375. for (var _i6 = 0; _i6 < vlen; _i6++) {
  18376. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  18377. if (!extrudeByPath) {
  18378. v(_vert3.x, _vert3.y, depth / steps * s);
  18379. } else {
  18380. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18381. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  18382. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  18383. position2.copy(extrudePts[s]).add(normal).add(binormal);
  18384. v(position2.x, position2.y, position2.z);
  18385. }
  18386. }
  18387. } // Add bevel segments planes
  18388. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18389. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  18390. var _t = _b / bevelSegments;
  18391. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  18392. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  18393. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  18394. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  18395. v(_vert4.x, _vert4.y, depth + _z);
  18396. } // expand holes
  18397. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  18398. var _ahole4 = holes[_h4];
  18399. oneHoleMovements = holesMovements[_h4];
  18400. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  18401. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  18402. if (!extrudeByPath) {
  18403. v(_vert5.x, _vert5.y, depth + _z);
  18404. } else {
  18405. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  18406. }
  18407. }
  18408. }
  18409. }
  18410. /* Faces */
  18411. // Top and bottom faces
  18412. buildLidFaces(); // Sides faces
  18413. buildSideFaces(); ///// Internal functions
  18414. function buildLidFaces() {
  18415. var start = verticesArray.length / 3;
  18416. if (bevelEnabled) {
  18417. var layer = 0; // steps + 1
  18418. var offset = vlen * layer; // Bottom faces
  18419. for (var _i9 = 0; _i9 < flen; _i9++) {
  18420. var face = faces[_i9];
  18421. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  18422. }
  18423. layer = steps + bevelSegments * 2;
  18424. offset = vlen * layer; // Top faces
  18425. for (var _i10 = 0; _i10 < flen; _i10++) {
  18426. var _face = faces[_i10];
  18427. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  18428. }
  18429. } else {
  18430. // Bottom faces
  18431. for (var _i11 = 0; _i11 < flen; _i11++) {
  18432. var _face2 = faces[_i11];
  18433. f3(_face2[2], _face2[1], _face2[0]);
  18434. } // Top faces
  18435. for (var _i12 = 0; _i12 < flen; _i12++) {
  18436. var _face3 = faces[_i12];
  18437. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  18438. }
  18439. }
  18440. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  18441. } // Create faces for the z-sides of the shape
  18442. function buildSideFaces() {
  18443. var start = verticesArray.length / 3;
  18444. var layeroffset = 0;
  18445. sidewalls(contour, layeroffset);
  18446. layeroffset += contour.length;
  18447. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  18448. var _ahole5 = holes[_h5];
  18449. sidewalls(_ahole5, layeroffset); //, true
  18450. layeroffset += _ahole5.length;
  18451. }
  18452. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  18453. }
  18454. function sidewalls(contour, layeroffset) {
  18455. var i = contour.length;
  18456. while (--i >= 0) {
  18457. var _j2 = i;
  18458. var _k2 = i - 1;
  18459. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  18460. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  18461. var slen1 = vlen * _s;
  18462. var slen2 = vlen * (_s + 1);
  18463. var a = layeroffset + _j2 + slen1,
  18464. _b2 = layeroffset + _k2 + slen1,
  18465. c = layeroffset + _k2 + slen2,
  18466. d = layeroffset + _j2 + slen2;
  18467. f4(a, _b2, c, d);
  18468. }
  18469. }
  18470. }
  18471. function v(x, y, z) {
  18472. placeholder.push(x);
  18473. placeholder.push(y);
  18474. placeholder.push(z);
  18475. }
  18476. function f3(a, b, c) {
  18477. addVertex(a);
  18478. addVertex(b);
  18479. addVertex(c);
  18480. var nextIndex = verticesArray.length / 3;
  18481. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18482. addUV(uvs[0]);
  18483. addUV(uvs[1]);
  18484. addUV(uvs[2]);
  18485. }
  18486. function f4(a, b, c, d) {
  18487. addVertex(a);
  18488. addVertex(b);
  18489. addVertex(d);
  18490. addVertex(b);
  18491. addVertex(c);
  18492. addVertex(d);
  18493. var nextIndex = verticesArray.length / 3;
  18494. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18495. addUV(uvs[0]);
  18496. addUV(uvs[1]);
  18497. addUV(uvs[3]);
  18498. addUV(uvs[1]);
  18499. addUV(uvs[2]);
  18500. addUV(uvs[3]);
  18501. }
  18502. function addVertex(index) {
  18503. verticesArray.push(placeholder[index * 3 + 0]);
  18504. verticesArray.push(placeholder[index * 3 + 1]);
  18505. verticesArray.push(placeholder[index * 3 + 2]);
  18506. }
  18507. function addUV(vector2) {
  18508. uvArray.push(vector2.x);
  18509. uvArray.push(vector2.y);
  18510. }
  18511. }
  18512. return _this;
  18513. }
  18514. var _proto = ExtrudeGeometry.prototype;
  18515. _proto.toJSON = function toJSON() {
  18516. var data = BufferGeometry.prototype.toJSON.call(this);
  18517. var shapes = this.parameters.shapes;
  18518. var options = this.parameters.options;
  18519. return _toJSON(shapes, options, data);
  18520. };
  18521. return ExtrudeGeometry;
  18522. }(BufferGeometry);
  18523. var WorldUVGenerator = {
  18524. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18525. var a_x = vertices[indexA * 3];
  18526. var a_y = vertices[indexA * 3 + 1];
  18527. var b_x = vertices[indexB * 3];
  18528. var b_y = vertices[indexB * 3 + 1];
  18529. var c_x = vertices[indexC * 3];
  18530. var c_y = vertices[indexC * 3 + 1];
  18531. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18532. },
  18533. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18534. var a_x = vertices[indexA * 3];
  18535. var a_y = vertices[indexA * 3 + 1];
  18536. var a_z = vertices[indexA * 3 + 2];
  18537. var b_x = vertices[indexB * 3];
  18538. var b_y = vertices[indexB * 3 + 1];
  18539. var b_z = vertices[indexB * 3 + 2];
  18540. var c_x = vertices[indexC * 3];
  18541. var c_y = vertices[indexC * 3 + 1];
  18542. var c_z = vertices[indexC * 3 + 2];
  18543. var d_x = vertices[indexD * 3];
  18544. var d_y = vertices[indexD * 3 + 1];
  18545. var d_z = vertices[indexD * 3 + 2];
  18546. if (Math.abs(a_y - b_y) < 0.01) {
  18547. 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)];
  18548. } else {
  18549. 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)];
  18550. }
  18551. }
  18552. };
  18553. function _toJSON(shapes, options, data) {
  18554. data.shapes = [];
  18555. if (Array.isArray(shapes)) {
  18556. for (var i = 0, l = shapes.length; i < l; i++) {
  18557. var shape = shapes[i];
  18558. data.shapes.push(shape.uuid);
  18559. }
  18560. } else {
  18561. data.shapes.push(shapes.uuid);
  18562. }
  18563. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18564. return data;
  18565. }
  18566. var IcosahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18567. _inheritsLoose(IcosahedronGeometry, _PolyhedronGeometry);
  18568. function IcosahedronGeometry(radius, detail) {
  18569. var _this;
  18570. if (radius === void 0) {
  18571. radius = 1;
  18572. }
  18573. if (detail === void 0) {
  18574. detail = 0;
  18575. }
  18576. var t = (1 + Math.sqrt(5)) / 2;
  18577. 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];
  18578. 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];
  18579. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18580. _this.type = 'IcosahedronGeometry';
  18581. _this.parameters = {
  18582. radius: radius,
  18583. detail: detail
  18584. };
  18585. return _this;
  18586. }
  18587. return IcosahedronGeometry;
  18588. }(PolyhedronGeometry);
  18589. var LatheGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18590. _inheritsLoose(LatheGeometry, _BufferGeometry);
  18591. function LatheGeometry(points, segments, phiStart, phiLength) {
  18592. var _this;
  18593. if (segments === void 0) {
  18594. segments = 12;
  18595. }
  18596. if (phiStart === void 0) {
  18597. phiStart = 0;
  18598. }
  18599. if (phiLength === void 0) {
  18600. phiLength = Math.PI * 2;
  18601. }
  18602. _this = _BufferGeometry.call(this) || this;
  18603. _this.type = 'LatheGeometry';
  18604. _this.parameters = {
  18605. points: points,
  18606. segments: segments,
  18607. phiStart: phiStart,
  18608. phiLength: phiLength
  18609. };
  18610. segments = Math.floor(segments); // clamp phiLength so it's in range of [ 0, 2PI ]
  18611. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  18612. var indices = [];
  18613. var vertices = [];
  18614. var uvs = []; // helper variables
  18615. var inverseSegments = 1.0 / segments;
  18616. var vertex = new Vector3();
  18617. var uv = new Vector2(); // generate vertices and uvs
  18618. for (var i = 0; i <= segments; i++) {
  18619. var phi = phiStart + i * inverseSegments * phiLength;
  18620. var sin = Math.sin(phi);
  18621. var cos = Math.cos(phi);
  18622. for (var j = 0; j <= points.length - 1; j++) {
  18623. // vertex
  18624. vertex.x = points[j].x * sin;
  18625. vertex.y = points[j].y;
  18626. vertex.z = points[j].x * cos;
  18627. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  18628. uv.x = i / segments;
  18629. uv.y = j / (points.length - 1);
  18630. uvs.push(uv.x, uv.y);
  18631. }
  18632. } // indices
  18633. for (var _i = 0; _i < segments; _i++) {
  18634. for (var _j = 0; _j < points.length - 1; _j++) {
  18635. var base = _j + _i * points.length;
  18636. var a = base;
  18637. var b = base + points.length;
  18638. var c = base + points.length + 1;
  18639. var d = base + 1; // faces
  18640. indices.push(a, b, d);
  18641. indices.push(b, c, d);
  18642. }
  18643. } // build geometry
  18644. _this.setIndex(indices);
  18645. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18646. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  18647. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  18648. // because the corresponding vertices are identical (but still have different UVs).
  18649. if (phiLength === Math.PI * 2) {
  18650. var normals = _this.attributes.normal.array;
  18651. var n1 = new Vector3();
  18652. var n2 = new Vector3();
  18653. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  18654. var _base = segments * points.length * 3;
  18655. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  18656. // select the normal of the vertex in the first line
  18657. n1.x = normals[_j2 + 0];
  18658. n1.y = normals[_j2 + 1];
  18659. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  18660. n2.x = normals[_base + _j2 + 0];
  18661. n2.y = normals[_base + _j2 + 1];
  18662. n2.z = normals[_base + _j2 + 2]; // average normals
  18663. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  18664. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  18665. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  18666. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  18667. }
  18668. }
  18669. return _this;
  18670. }
  18671. return LatheGeometry;
  18672. }(BufferGeometry);
  18673. var OctahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18674. _inheritsLoose(OctahedronGeometry, _PolyhedronGeometry);
  18675. function OctahedronGeometry(radius, detail) {
  18676. var _this;
  18677. if (radius === void 0) {
  18678. radius = 1;
  18679. }
  18680. if (detail === void 0) {
  18681. detail = 0;
  18682. }
  18683. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  18684. 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];
  18685. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18686. _this.type = 'OctahedronGeometry';
  18687. _this.parameters = {
  18688. radius: radius,
  18689. detail: detail
  18690. };
  18691. return _this;
  18692. }
  18693. return OctahedronGeometry;
  18694. }(PolyhedronGeometry);
  18695. /**
  18696. * Parametric Surfaces Geometry
  18697. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18698. */
  18699. function ParametricGeometry(func, slices, stacks) {
  18700. BufferGeometry.call(this);
  18701. this.type = 'ParametricGeometry';
  18702. this.parameters = {
  18703. func: func,
  18704. slices: slices,
  18705. stacks: stacks
  18706. }; // buffers
  18707. var indices = [];
  18708. var vertices = [];
  18709. var normals = [];
  18710. var uvs = [];
  18711. var EPS = 0.00001;
  18712. var normal = new Vector3();
  18713. var p0 = new Vector3(),
  18714. p1 = new Vector3();
  18715. var pu = new Vector3(),
  18716. pv = new Vector3();
  18717. if (func.length < 3) {
  18718. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  18719. } // generate vertices, normals and uvs
  18720. var sliceCount = slices + 1;
  18721. for (var i = 0; i <= stacks; i++) {
  18722. var v = i / stacks;
  18723. for (var j = 0; j <= slices; j++) {
  18724. var u = j / slices; // vertex
  18725. func(u, v, p0);
  18726. vertices.push(p0.x, p0.y, p0.z); // normal
  18727. // approximate tangent vectors via finite differences
  18728. if (u - EPS >= 0) {
  18729. func(u - EPS, v, p1);
  18730. pu.subVectors(p0, p1);
  18731. } else {
  18732. func(u + EPS, v, p1);
  18733. pu.subVectors(p1, p0);
  18734. }
  18735. if (v - EPS >= 0) {
  18736. func(u, v - EPS, p1);
  18737. pv.subVectors(p0, p1);
  18738. } else {
  18739. func(u, v + EPS, p1);
  18740. pv.subVectors(p1, p0);
  18741. } // cross product of tangent vectors returns surface normal
  18742. normal.crossVectors(pu, pv).normalize();
  18743. normals.push(normal.x, normal.y, normal.z); // uv
  18744. uvs.push(u, v);
  18745. }
  18746. } // generate indices
  18747. for (var _i = 0; _i < stacks; _i++) {
  18748. for (var _j = 0; _j < slices; _j++) {
  18749. var a = _i * sliceCount + _j;
  18750. var b = _i * sliceCount + _j + 1;
  18751. var c = (_i + 1) * sliceCount + _j + 1;
  18752. var d = (_i + 1) * sliceCount + _j; // faces one and two
  18753. indices.push(a, b, d);
  18754. indices.push(b, c, d);
  18755. }
  18756. } // build geometry
  18757. this.setIndex(indices);
  18758. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18759. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18760. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18761. }
  18762. ParametricGeometry.prototype = Object.create(BufferGeometry.prototype);
  18763. ParametricGeometry.prototype.constructor = ParametricGeometry;
  18764. var RingGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18765. _inheritsLoose(RingGeometry, _BufferGeometry);
  18766. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  18767. var _this;
  18768. if (innerRadius === void 0) {
  18769. innerRadius = 0.5;
  18770. }
  18771. if (outerRadius === void 0) {
  18772. outerRadius = 1;
  18773. }
  18774. if (thetaSegments === void 0) {
  18775. thetaSegments = 8;
  18776. }
  18777. if (phiSegments === void 0) {
  18778. phiSegments = 1;
  18779. }
  18780. if (thetaStart === void 0) {
  18781. thetaStart = 0;
  18782. }
  18783. if (thetaLength === void 0) {
  18784. thetaLength = Math.PI * 2;
  18785. }
  18786. _this = _BufferGeometry.call(this) || this;
  18787. _this.type = 'RingGeometry';
  18788. _this.parameters = {
  18789. innerRadius: innerRadius,
  18790. outerRadius: outerRadius,
  18791. thetaSegments: thetaSegments,
  18792. phiSegments: phiSegments,
  18793. thetaStart: thetaStart,
  18794. thetaLength: thetaLength
  18795. };
  18796. thetaSegments = Math.max(3, thetaSegments);
  18797. phiSegments = Math.max(1, phiSegments); // buffers
  18798. var indices = [];
  18799. var vertices = [];
  18800. var normals = [];
  18801. var uvs = []; // some helper variables
  18802. var radius = innerRadius;
  18803. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  18804. var vertex = new Vector3();
  18805. var uv = new Vector2(); // generate vertices, normals and uvs
  18806. for (var j = 0; j <= phiSegments; j++) {
  18807. for (var i = 0; i <= thetaSegments; i++) {
  18808. // values are generate from the inside of the ring to the outside
  18809. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  18810. vertex.x = radius * Math.cos(segment);
  18811. vertex.y = radius * Math.sin(segment);
  18812. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  18813. normals.push(0, 0, 1); // uv
  18814. uv.x = (vertex.x / outerRadius + 1) / 2;
  18815. uv.y = (vertex.y / outerRadius + 1) / 2;
  18816. uvs.push(uv.x, uv.y);
  18817. } // increase the radius for next row of vertices
  18818. radius += radiusStep;
  18819. } // indices
  18820. for (var _j = 0; _j < phiSegments; _j++) {
  18821. var thetaSegmentLevel = _j * (thetaSegments + 1);
  18822. for (var _i = 0; _i < thetaSegments; _i++) {
  18823. var _segment = _i + thetaSegmentLevel;
  18824. var a = _segment;
  18825. var b = _segment + thetaSegments + 1;
  18826. var c = _segment + thetaSegments + 2;
  18827. var d = _segment + 1; // faces
  18828. indices.push(a, b, d);
  18829. indices.push(b, c, d);
  18830. }
  18831. } // build geometry
  18832. _this.setIndex(indices);
  18833. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18834. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18835. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18836. return _this;
  18837. }
  18838. return RingGeometry;
  18839. }(BufferGeometry);
  18840. var ShapeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18841. _inheritsLoose(ShapeGeometry, _BufferGeometry);
  18842. function ShapeGeometry(shapes, curveSegments) {
  18843. var _this;
  18844. if (curveSegments === void 0) {
  18845. curveSegments = 12;
  18846. }
  18847. _this = _BufferGeometry.call(this) || this;
  18848. _this.type = 'ShapeGeometry';
  18849. _this.parameters = {
  18850. shapes: shapes,
  18851. curveSegments: curveSegments
  18852. }; // buffers
  18853. var indices = [];
  18854. var vertices = [];
  18855. var normals = [];
  18856. var uvs = []; // helper variables
  18857. var groupStart = 0;
  18858. var groupCount = 0; // allow single and array values for "shapes" parameter
  18859. if (Array.isArray(shapes) === false) {
  18860. addShape(shapes);
  18861. } else {
  18862. for (var i = 0; i < shapes.length; i++) {
  18863. addShape(shapes[i]);
  18864. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  18865. groupStart += groupCount;
  18866. groupCount = 0;
  18867. }
  18868. } // build geometry
  18869. _this.setIndex(indices);
  18870. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18871. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18872. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  18873. function addShape(shape) {
  18874. var indexOffset = vertices.length / 3;
  18875. var points = shape.extractPoints(curveSegments);
  18876. var shapeVertices = points.shape;
  18877. var shapeHoles = points.holes; // check direction of vertices
  18878. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  18879. shapeVertices = shapeVertices.reverse();
  18880. }
  18881. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  18882. var shapeHole = shapeHoles[_i];
  18883. if (ShapeUtils.isClockWise(shapeHole) === true) {
  18884. shapeHoles[_i] = shapeHole.reverse();
  18885. }
  18886. }
  18887. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  18888. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  18889. var _shapeHole = shapeHoles[_i2];
  18890. shapeVertices = shapeVertices.concat(_shapeHole);
  18891. } // vertices, normals, uvs
  18892. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  18893. var vertex = shapeVertices[_i3];
  18894. vertices.push(vertex.x, vertex.y, 0);
  18895. normals.push(0, 0, 1);
  18896. uvs.push(vertex.x, vertex.y); // world uvs
  18897. } // incides
  18898. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  18899. var face = faces[_i4];
  18900. var a = face[0] + indexOffset;
  18901. var b = face[1] + indexOffset;
  18902. var c = face[2] + indexOffset;
  18903. indices.push(a, b, c);
  18904. groupCount += 3;
  18905. }
  18906. }
  18907. return _this;
  18908. }
  18909. var _proto = ShapeGeometry.prototype;
  18910. _proto.toJSON = function toJSON() {
  18911. var data = BufferGeometry.prototype.toJSON.call(this);
  18912. var shapes = this.parameters.shapes;
  18913. return _toJSON$1(shapes, data);
  18914. };
  18915. return ShapeGeometry;
  18916. }(BufferGeometry);
  18917. function _toJSON$1(shapes, data) {
  18918. data.shapes = [];
  18919. if (Array.isArray(shapes)) {
  18920. for (var i = 0, l = shapes.length; i < l; i++) {
  18921. var shape = shapes[i];
  18922. data.shapes.push(shape.uuid);
  18923. }
  18924. } else {
  18925. data.shapes.push(shapes.uuid);
  18926. }
  18927. return data;
  18928. }
  18929. var SphereGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18930. _inheritsLoose(SphereGeometry, _BufferGeometry);
  18931. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  18932. var _this;
  18933. if (radius === void 0) {
  18934. radius = 1;
  18935. }
  18936. if (widthSegments === void 0) {
  18937. widthSegments = 8;
  18938. }
  18939. if (heightSegments === void 0) {
  18940. heightSegments = 6;
  18941. }
  18942. if (phiStart === void 0) {
  18943. phiStart = 0;
  18944. }
  18945. if (phiLength === void 0) {
  18946. phiLength = Math.PI * 2;
  18947. }
  18948. if (thetaStart === void 0) {
  18949. thetaStart = 0;
  18950. }
  18951. if (thetaLength === void 0) {
  18952. thetaLength = Math.PI;
  18953. }
  18954. _this = _BufferGeometry.call(this) || this;
  18955. _this.type = 'SphereGeometry';
  18956. _this.parameters = {
  18957. radius: radius,
  18958. widthSegments: widthSegments,
  18959. heightSegments: heightSegments,
  18960. phiStart: phiStart,
  18961. phiLength: phiLength,
  18962. thetaStart: thetaStart,
  18963. thetaLength: thetaLength
  18964. };
  18965. widthSegments = Math.max(3, Math.floor(widthSegments));
  18966. heightSegments = Math.max(2, Math.floor(heightSegments));
  18967. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  18968. var index = 0;
  18969. var grid = [];
  18970. var vertex = new Vector3();
  18971. var normal = new Vector3(); // buffers
  18972. var indices = [];
  18973. var vertices = [];
  18974. var normals = [];
  18975. var uvs = []; // generate vertices, normals and uvs
  18976. for (var iy = 0; iy <= heightSegments; iy++) {
  18977. var verticesRow = [];
  18978. var v = iy / heightSegments; // special case for the poles
  18979. var uOffset = 0;
  18980. if (iy == 0 && thetaStart == 0) {
  18981. uOffset = 0.5 / widthSegments;
  18982. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  18983. uOffset = -0.5 / widthSegments;
  18984. }
  18985. for (var ix = 0; ix <= widthSegments; ix++) {
  18986. var u = ix / widthSegments; // vertex
  18987. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  18988. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  18989. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  18990. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  18991. normal.copy(vertex).normalize();
  18992. normals.push(normal.x, normal.y, normal.z); // uv
  18993. uvs.push(u + uOffset, 1 - v);
  18994. verticesRow.push(index++);
  18995. }
  18996. grid.push(verticesRow);
  18997. } // indices
  18998. for (var _iy = 0; _iy < heightSegments; _iy++) {
  18999. for (var _ix = 0; _ix < widthSegments; _ix++) {
  19000. var a = grid[_iy][_ix + 1];
  19001. var b = grid[_iy][_ix];
  19002. var c = grid[_iy + 1][_ix];
  19003. var d = grid[_iy + 1][_ix + 1];
  19004. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  19005. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  19006. }
  19007. } // build geometry
  19008. _this.setIndex(indices);
  19009. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19010. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19011. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19012. return _this;
  19013. }
  19014. return SphereGeometry;
  19015. }(BufferGeometry);
  19016. var TetrahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  19017. _inheritsLoose(TetrahedronGeometry, _PolyhedronGeometry);
  19018. function TetrahedronGeometry(radius, detail) {
  19019. var _this;
  19020. if (radius === void 0) {
  19021. radius = 1;
  19022. }
  19023. if (detail === void 0) {
  19024. detail = 0;
  19025. }
  19026. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  19027. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  19028. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  19029. _this.type = 'TetrahedronGeometry';
  19030. _this.parameters = {
  19031. radius: radius,
  19032. detail: detail
  19033. };
  19034. return _this;
  19035. }
  19036. return TetrahedronGeometry;
  19037. }(PolyhedronGeometry);
  19038. var TextGeometry = /*#__PURE__*/function (_ExtrudeGeometry) {
  19039. _inheritsLoose(TextGeometry, _ExtrudeGeometry);
  19040. function TextGeometry(text, parameters) {
  19041. var _this;
  19042. if (parameters === void 0) {
  19043. parameters = {};
  19044. }
  19045. var font = parameters.font;
  19046. if (!(font && font.isFont)) {
  19047. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  19048. return new BufferGeometry() || _assertThisInitialized(_this);
  19049. }
  19050. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  19051. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  19052. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  19053. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  19054. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  19055. _this = _ExtrudeGeometry.call(this, shapes, parameters) || this;
  19056. _this.type = 'TextGeometry';
  19057. return _this;
  19058. }
  19059. return TextGeometry;
  19060. }(ExtrudeGeometry);
  19061. var TorusGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19062. _inheritsLoose(TorusGeometry, _BufferGeometry);
  19063. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19064. var _this;
  19065. if (radius === void 0) {
  19066. radius = 1;
  19067. }
  19068. if (tube === void 0) {
  19069. tube = 0.4;
  19070. }
  19071. if (radialSegments === void 0) {
  19072. radialSegments = 8;
  19073. }
  19074. if (tubularSegments === void 0) {
  19075. tubularSegments = 6;
  19076. }
  19077. if (arc === void 0) {
  19078. arc = Math.PI * 2;
  19079. }
  19080. _this = _BufferGeometry.call(this) || this;
  19081. _this.type = 'TorusGeometry';
  19082. _this.parameters = {
  19083. radius: radius,
  19084. tube: tube,
  19085. radialSegments: radialSegments,
  19086. tubularSegments: tubularSegments,
  19087. arc: arc
  19088. };
  19089. radialSegments = Math.floor(radialSegments);
  19090. tubularSegments = Math.floor(tubularSegments); // buffers
  19091. var indices = [];
  19092. var vertices = [];
  19093. var normals = [];
  19094. var uvs = []; // helper variables
  19095. var center = new Vector3();
  19096. var vertex = new Vector3();
  19097. var normal = new Vector3(); // generate vertices, normals and uvs
  19098. for (var j = 0; j <= radialSegments; j++) {
  19099. for (var i = 0; i <= tubularSegments; i++) {
  19100. var u = i / tubularSegments * arc;
  19101. var v = j / radialSegments * Math.PI * 2; // vertex
  19102. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  19103. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  19104. vertex.z = tube * Math.sin(v);
  19105. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19106. center.x = radius * Math.cos(u);
  19107. center.y = radius * Math.sin(u);
  19108. normal.subVectors(vertex, center).normalize();
  19109. normals.push(normal.x, normal.y, normal.z); // uv
  19110. uvs.push(i / tubularSegments);
  19111. uvs.push(j / radialSegments);
  19112. }
  19113. } // generate indices
  19114. for (var _j = 1; _j <= radialSegments; _j++) {
  19115. for (var _i = 1; _i <= tubularSegments; _i++) {
  19116. // indices
  19117. var a = (tubularSegments + 1) * _j + _i - 1;
  19118. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  19119. var c = (tubularSegments + 1) * (_j - 1) + _i;
  19120. var d = (tubularSegments + 1) * _j + _i; // faces
  19121. indices.push(a, b, d);
  19122. indices.push(b, c, d);
  19123. }
  19124. } // build geometry
  19125. _this.setIndex(indices);
  19126. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19127. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19128. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19129. return _this;
  19130. }
  19131. return TorusGeometry;
  19132. }(BufferGeometry);
  19133. var TorusKnotGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19134. _inheritsLoose(TorusKnotGeometry, _BufferGeometry);
  19135. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  19136. var _this;
  19137. if (radius === void 0) {
  19138. radius = 1;
  19139. }
  19140. if (tube === void 0) {
  19141. tube = 0.4;
  19142. }
  19143. if (tubularSegments === void 0) {
  19144. tubularSegments = 64;
  19145. }
  19146. if (radialSegments === void 0) {
  19147. radialSegments = 8;
  19148. }
  19149. if (p === void 0) {
  19150. p = 2;
  19151. }
  19152. if (q === void 0) {
  19153. q = 3;
  19154. }
  19155. _this = _BufferGeometry.call(this) || this;
  19156. _this.type = 'TorusKnotGeometry';
  19157. _this.parameters = {
  19158. radius: radius,
  19159. tube: tube,
  19160. tubularSegments: tubularSegments,
  19161. radialSegments: radialSegments,
  19162. p: p,
  19163. q: q
  19164. };
  19165. tubularSegments = Math.floor(tubularSegments);
  19166. radialSegments = Math.floor(radialSegments); // buffers
  19167. var indices = [];
  19168. var vertices = [];
  19169. var normals = [];
  19170. var uvs = []; // helper variables
  19171. var vertex = new Vector3();
  19172. var normal = new Vector3();
  19173. var P1 = new Vector3();
  19174. var P2 = new Vector3();
  19175. var B = new Vector3();
  19176. var T = new Vector3();
  19177. var N = new Vector3(); // generate vertices, normals and uvs
  19178. for (var i = 0; i <= tubularSegments; ++i) {
  19179. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19180. 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.
  19181. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19182. calculatePositionOnCurve(u, p, q, radius, P1);
  19183. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  19184. T.subVectors(P2, P1);
  19185. N.addVectors(P2, P1);
  19186. B.crossVectors(T, N);
  19187. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  19188. B.normalize();
  19189. N.normalize();
  19190. for (var j = 0; j <= radialSegments; ++j) {
  19191. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19192. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19193. var v = j / radialSegments * Math.PI * 2;
  19194. var cx = -tube * Math.cos(v);
  19195. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  19196. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19197. vertex.x = P1.x + (cx * N.x + cy * B.x);
  19198. vertex.y = P1.y + (cx * N.y + cy * B.y);
  19199. vertex.z = P1.z + (cx * N.z + cy * B.z);
  19200. 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)
  19201. normal.subVectors(vertex, P1).normalize();
  19202. normals.push(normal.x, normal.y, normal.z); // uv
  19203. uvs.push(i / tubularSegments);
  19204. uvs.push(j / radialSegments);
  19205. }
  19206. } // generate indices
  19207. for (var _j = 1; _j <= tubularSegments; _j++) {
  19208. for (var _i = 1; _i <= radialSegments; _i++) {
  19209. // indices
  19210. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  19211. var b = (radialSegments + 1) * _j + (_i - 1);
  19212. var c = (radialSegments + 1) * _j + _i;
  19213. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  19214. indices.push(a, b, d);
  19215. indices.push(b, c, d);
  19216. }
  19217. } // build geometry
  19218. _this.setIndex(indices);
  19219. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19220. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19221. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  19222. function calculatePositionOnCurve(u, p, q, radius, position) {
  19223. var cu = Math.cos(u);
  19224. var su = Math.sin(u);
  19225. var quOverP = q / p * u;
  19226. var cs = Math.cos(quOverP);
  19227. position.x = radius * (2 + cs) * 0.5 * cu;
  19228. position.y = radius * (2 + cs) * su * 0.5;
  19229. position.z = radius * Math.sin(quOverP) * 0.5;
  19230. }
  19231. return _this;
  19232. }
  19233. return TorusKnotGeometry;
  19234. }(BufferGeometry);
  19235. var TubeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19236. _inheritsLoose(TubeGeometry, _BufferGeometry);
  19237. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed) {
  19238. var _this;
  19239. if (tubularSegments === void 0) {
  19240. tubularSegments = 64;
  19241. }
  19242. if (radius === void 0) {
  19243. radius = 1;
  19244. }
  19245. if (radialSegments === void 0) {
  19246. radialSegments = 8;
  19247. }
  19248. if (closed === void 0) {
  19249. closed = false;
  19250. }
  19251. _this = _BufferGeometry.call(this) || this;
  19252. _this.type = 'TubeGeometry';
  19253. _this.parameters = {
  19254. path: path,
  19255. tubularSegments: tubularSegments,
  19256. radius: radius,
  19257. radialSegments: radialSegments,
  19258. closed: closed
  19259. };
  19260. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  19261. _this.tangents = frames.tangents;
  19262. _this.normals = frames.normals;
  19263. _this.binormals = frames.binormals; // helper variables
  19264. var vertex = new Vector3();
  19265. var normal = new Vector3();
  19266. var uv = new Vector2();
  19267. var P = new Vector3(); // buffer
  19268. var vertices = [];
  19269. var normals = [];
  19270. var uvs = [];
  19271. var indices = []; // create buffer data
  19272. generateBufferData(); // build geometry
  19273. _this.setIndex(indices);
  19274. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19275. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19276. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  19277. function generateBufferData() {
  19278. for (var i = 0; i < tubularSegments; i++) {
  19279. generateSegment(i);
  19280. } // if the geometry is not closed, generate the last row of vertices and normals
  19281. // at the regular position on the given path
  19282. //
  19283. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19284. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  19285. // this makes it easy compute correct values for closed geometries
  19286. generateUVs(); // finally create faces
  19287. generateIndices();
  19288. }
  19289. function generateSegment(i) {
  19290. // we use getPointAt to sample evenly distributed points from the given path
  19291. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  19292. var N = frames.normals[i];
  19293. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  19294. for (var j = 0; j <= radialSegments; j++) {
  19295. var v = j / radialSegments * Math.PI * 2;
  19296. var sin = Math.sin(v);
  19297. var cos = -Math.cos(v); // normal
  19298. normal.x = cos * N.x + sin * B.x;
  19299. normal.y = cos * N.y + sin * B.y;
  19300. normal.z = cos * N.z + sin * B.z;
  19301. normal.normalize();
  19302. normals.push(normal.x, normal.y, normal.z); // vertex
  19303. vertex.x = P.x + radius * normal.x;
  19304. vertex.y = P.y + radius * normal.y;
  19305. vertex.z = P.z + radius * normal.z;
  19306. vertices.push(vertex.x, vertex.y, vertex.z);
  19307. }
  19308. }
  19309. function generateIndices() {
  19310. for (var j = 1; j <= tubularSegments; j++) {
  19311. for (var i = 1; i <= radialSegments; i++) {
  19312. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  19313. var b = (radialSegments + 1) * j + (i - 1);
  19314. var c = (radialSegments + 1) * j + i;
  19315. var d = (radialSegments + 1) * (j - 1) + i; // faces
  19316. indices.push(a, b, d);
  19317. indices.push(b, c, d);
  19318. }
  19319. }
  19320. }
  19321. function generateUVs() {
  19322. for (var i = 0; i <= tubularSegments; i++) {
  19323. for (var j = 0; j <= radialSegments; j++) {
  19324. uv.x = i / tubularSegments;
  19325. uv.y = j / radialSegments;
  19326. uvs.push(uv.x, uv.y);
  19327. }
  19328. }
  19329. }
  19330. return _this;
  19331. }
  19332. var _proto = TubeGeometry.prototype;
  19333. _proto.toJSON = function toJSON() {
  19334. var data = BufferGeometry.prototype.toJSON.call(this);
  19335. data.path = this.parameters.path.toJSON();
  19336. return data;
  19337. };
  19338. return TubeGeometry;
  19339. }(BufferGeometry);
  19340. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19341. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  19342. function WireframeGeometry(geometry) {
  19343. var _this;
  19344. _this = _BufferGeometry.call(this) || this;
  19345. _this.type = 'WireframeGeometry';
  19346. if (geometry.isGeometry === true) {
  19347. console.error('THREE.WireframeGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  19348. return _assertThisInitialized(_this);
  19349. } // buffer
  19350. var vertices = []; // helper variables
  19351. var edge = [0, 0],
  19352. edges = {};
  19353. var vertex = new Vector3();
  19354. if (geometry.index !== null) {
  19355. // indexed BufferGeometry
  19356. var position = geometry.attributes.position;
  19357. var indices = geometry.index;
  19358. var groups = geometry.groups;
  19359. if (groups.length === 0) {
  19360. groups = [{
  19361. start: 0,
  19362. count: indices.count,
  19363. materialIndex: 0
  19364. }];
  19365. } // create a data structure that contains all eges without duplicates
  19366. for (var o = 0, ol = groups.length; o < ol; ++o) {
  19367. var group = groups[o];
  19368. var start = group.start;
  19369. var count = group.count;
  19370. for (var i = start, l = start + count; i < l; i += 3) {
  19371. for (var j = 0; j < 3; j++) {
  19372. var edge1 = indices.getX(i + j);
  19373. var edge2 = indices.getX(i + (j + 1) % 3);
  19374. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  19375. edge[1] = Math.max(edge1, edge2);
  19376. var key = edge[0] + ',' + edge[1];
  19377. if (edges[key] === undefined) {
  19378. edges[key] = {
  19379. index1: edge[0],
  19380. index2: edge[1]
  19381. };
  19382. }
  19383. }
  19384. }
  19385. } // generate vertices
  19386. for (var _key in edges) {
  19387. var e = edges[_key];
  19388. vertex.fromBufferAttribute(position, e.index1);
  19389. vertices.push(vertex.x, vertex.y, vertex.z);
  19390. vertex.fromBufferAttribute(position, e.index2);
  19391. vertices.push(vertex.x, vertex.y, vertex.z);
  19392. }
  19393. } else {
  19394. // non-indexed BufferGeometry
  19395. var _position = geometry.attributes.position;
  19396. for (var _i = 0, _l = _position.count / 3; _i < _l; _i++) {
  19397. for (var _j = 0; _j < 3; _j++) {
  19398. // three edges per triangle, an edge is represented as (index1, index2)
  19399. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  19400. var index1 = 3 * _i + _j;
  19401. vertex.fromBufferAttribute(_position, index1);
  19402. vertices.push(vertex.x, vertex.y, vertex.z);
  19403. var index2 = 3 * _i + (_j + 1) % 3;
  19404. vertex.fromBufferAttribute(_position, index2);
  19405. vertices.push(vertex.x, vertex.y, vertex.z);
  19406. }
  19407. }
  19408. } // build geometry
  19409. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19410. return _this;
  19411. }
  19412. return WireframeGeometry;
  19413. }(BufferGeometry);
  19414. var Geometries = /*#__PURE__*/Object.freeze({
  19415. __proto__: null,
  19416. BoxGeometry: BoxGeometry,
  19417. BoxBufferGeometry: BoxGeometry,
  19418. CircleGeometry: CircleGeometry,
  19419. CircleBufferGeometry: CircleGeometry,
  19420. ConeGeometry: ConeGeometry,
  19421. ConeBufferGeometry: ConeGeometry,
  19422. CylinderGeometry: CylinderGeometry,
  19423. CylinderBufferGeometry: CylinderGeometry,
  19424. DodecahedronGeometry: DodecahedronGeometry,
  19425. DodecahedronBufferGeometry: DodecahedronGeometry,
  19426. EdgesGeometry: EdgesGeometry,
  19427. ExtrudeGeometry: ExtrudeGeometry,
  19428. ExtrudeBufferGeometry: ExtrudeGeometry,
  19429. IcosahedronGeometry: IcosahedronGeometry,
  19430. IcosahedronBufferGeometry: IcosahedronGeometry,
  19431. LatheGeometry: LatheGeometry,
  19432. LatheBufferGeometry: LatheGeometry,
  19433. OctahedronGeometry: OctahedronGeometry,
  19434. OctahedronBufferGeometry: OctahedronGeometry,
  19435. ParametricGeometry: ParametricGeometry,
  19436. ParametricBufferGeometry: ParametricGeometry,
  19437. PlaneGeometry: PlaneGeometry,
  19438. PlaneBufferGeometry: PlaneGeometry,
  19439. PolyhedronGeometry: PolyhedronGeometry,
  19440. PolyhedronBufferGeometry: PolyhedronGeometry,
  19441. RingGeometry: RingGeometry,
  19442. RingBufferGeometry: RingGeometry,
  19443. ShapeGeometry: ShapeGeometry,
  19444. ShapeBufferGeometry: ShapeGeometry,
  19445. SphereGeometry: SphereGeometry,
  19446. SphereBufferGeometry: SphereGeometry,
  19447. TetrahedronGeometry: TetrahedronGeometry,
  19448. TetrahedronBufferGeometry: TetrahedronGeometry,
  19449. TextGeometry: TextGeometry,
  19450. TextBufferGeometry: TextGeometry,
  19451. TorusGeometry: TorusGeometry,
  19452. TorusBufferGeometry: TorusGeometry,
  19453. TorusKnotGeometry: TorusKnotGeometry,
  19454. TorusKnotBufferGeometry: TorusKnotGeometry,
  19455. TubeGeometry: TubeGeometry,
  19456. TubeBufferGeometry: TubeGeometry,
  19457. WireframeGeometry: WireframeGeometry
  19458. });
  19459. /**
  19460. * parameters = {
  19461. * color: <THREE.Color>
  19462. * }
  19463. */
  19464. function ShadowMaterial(parameters) {
  19465. Material.call(this);
  19466. this.type = 'ShadowMaterial';
  19467. this.color = new Color(0x000000);
  19468. this.transparent = true;
  19469. this.setValues(parameters);
  19470. }
  19471. ShadowMaterial.prototype = Object.create(Material.prototype);
  19472. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19473. ShadowMaterial.prototype.isShadowMaterial = true;
  19474. ShadowMaterial.prototype.copy = function (source) {
  19475. Material.prototype.copy.call(this, source);
  19476. this.color.copy(source.color);
  19477. return this;
  19478. };
  19479. function RawShaderMaterial(parameters) {
  19480. ShaderMaterial.call(this, parameters);
  19481. this.type = 'RawShaderMaterial';
  19482. }
  19483. RawShaderMaterial.prototype = Object.create(ShaderMaterial.prototype);
  19484. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19485. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19486. /**
  19487. * parameters = {
  19488. * color: <hex>,
  19489. * roughness: <float>,
  19490. * metalness: <float>,
  19491. * opacity: <float>,
  19492. *
  19493. * map: new THREE.Texture( <Image> ),
  19494. *
  19495. * lightMap: new THREE.Texture( <Image> ),
  19496. * lightMapIntensity: <float>
  19497. *
  19498. * aoMap: new THREE.Texture( <Image> ),
  19499. * aoMapIntensity: <float>
  19500. *
  19501. * emissive: <hex>,
  19502. * emissiveIntensity: <float>
  19503. * emissiveMap: new THREE.Texture( <Image> ),
  19504. *
  19505. * bumpMap: new THREE.Texture( <Image> ),
  19506. * bumpScale: <float>,
  19507. *
  19508. * normalMap: new THREE.Texture( <Image> ),
  19509. * normalMapType: THREE.TangentSpaceNormalMap,
  19510. * normalScale: <Vector2>,
  19511. *
  19512. * displacementMap: new THREE.Texture( <Image> ),
  19513. * displacementScale: <float>,
  19514. * displacementBias: <float>,
  19515. *
  19516. * roughnessMap: new THREE.Texture( <Image> ),
  19517. *
  19518. * metalnessMap: new THREE.Texture( <Image> ),
  19519. *
  19520. * alphaMap: new THREE.Texture( <Image> ),
  19521. *
  19522. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19523. * envMapIntensity: <float>
  19524. *
  19525. * refractionRatio: <float>,
  19526. *
  19527. * wireframe: <boolean>,
  19528. * wireframeLinewidth: <float>,
  19529. *
  19530. * skinning: <bool>,
  19531. * morphTargets: <bool>,
  19532. * morphNormals: <bool>
  19533. * }
  19534. */
  19535. function MeshStandardMaterial(parameters) {
  19536. Material.call(this);
  19537. this.defines = {
  19538. 'STANDARD': ''
  19539. };
  19540. this.type = 'MeshStandardMaterial';
  19541. this.color = new Color(0xffffff); // diffuse
  19542. this.roughness = 1.0;
  19543. this.metalness = 0.0;
  19544. this.map = null;
  19545. this.lightMap = null;
  19546. this.lightMapIntensity = 1.0;
  19547. this.aoMap = null;
  19548. this.aoMapIntensity = 1.0;
  19549. this.emissive = new Color(0x000000);
  19550. this.emissiveIntensity = 1.0;
  19551. this.emissiveMap = null;
  19552. this.bumpMap = null;
  19553. this.bumpScale = 1;
  19554. this.normalMap = null;
  19555. this.normalMapType = TangentSpaceNormalMap;
  19556. this.normalScale = new Vector2(1, 1);
  19557. this.displacementMap = null;
  19558. this.displacementScale = 1;
  19559. this.displacementBias = 0;
  19560. this.roughnessMap = null;
  19561. this.metalnessMap = null;
  19562. this.alphaMap = null;
  19563. this.envMap = null;
  19564. this.envMapIntensity = 1.0;
  19565. this.refractionRatio = 0.98;
  19566. this.wireframe = false;
  19567. this.wireframeLinewidth = 1;
  19568. this.wireframeLinecap = 'round';
  19569. this.wireframeLinejoin = 'round';
  19570. this.skinning = false;
  19571. this.morphTargets = false;
  19572. this.morphNormals = false;
  19573. this.vertexTangents = false;
  19574. this.setValues(parameters);
  19575. }
  19576. MeshStandardMaterial.prototype = Object.create(Material.prototype);
  19577. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19578. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19579. MeshStandardMaterial.prototype.copy = function (source) {
  19580. Material.prototype.copy.call(this, source);
  19581. this.defines = {
  19582. 'STANDARD': ''
  19583. };
  19584. this.color.copy(source.color);
  19585. this.roughness = source.roughness;
  19586. this.metalness = source.metalness;
  19587. this.map = source.map;
  19588. this.lightMap = source.lightMap;
  19589. this.lightMapIntensity = source.lightMapIntensity;
  19590. this.aoMap = source.aoMap;
  19591. this.aoMapIntensity = source.aoMapIntensity;
  19592. this.emissive.copy(source.emissive);
  19593. this.emissiveMap = source.emissiveMap;
  19594. this.emissiveIntensity = source.emissiveIntensity;
  19595. this.bumpMap = source.bumpMap;
  19596. this.bumpScale = source.bumpScale;
  19597. this.normalMap = source.normalMap;
  19598. this.normalMapType = source.normalMapType;
  19599. this.normalScale.copy(source.normalScale);
  19600. this.displacementMap = source.displacementMap;
  19601. this.displacementScale = source.displacementScale;
  19602. this.displacementBias = source.displacementBias;
  19603. this.roughnessMap = source.roughnessMap;
  19604. this.metalnessMap = source.metalnessMap;
  19605. this.alphaMap = source.alphaMap;
  19606. this.envMap = source.envMap;
  19607. this.envMapIntensity = source.envMapIntensity;
  19608. this.refractionRatio = source.refractionRatio;
  19609. this.wireframe = source.wireframe;
  19610. this.wireframeLinewidth = source.wireframeLinewidth;
  19611. this.wireframeLinecap = source.wireframeLinecap;
  19612. this.wireframeLinejoin = source.wireframeLinejoin;
  19613. this.skinning = source.skinning;
  19614. this.morphTargets = source.morphTargets;
  19615. this.morphNormals = source.morphNormals;
  19616. this.vertexTangents = source.vertexTangents;
  19617. return this;
  19618. };
  19619. /**
  19620. * parameters = {
  19621. * clearcoat: <float>,
  19622. * clearcoatMap: new THREE.Texture( <Image> ),
  19623. * clearcoatRoughness: <float>,
  19624. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  19625. * clearcoatNormalScale: <Vector2>,
  19626. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  19627. *
  19628. * reflectivity: <float>,
  19629. * ior: <float>,
  19630. *
  19631. * sheen: <Color>,
  19632. *
  19633. * transmission: <float>,
  19634. * transmissionMap: new THREE.Texture( <Image> )
  19635. * }
  19636. */
  19637. function MeshPhysicalMaterial(parameters) {
  19638. MeshStandardMaterial.call(this);
  19639. this.defines = {
  19640. 'STANDARD': '',
  19641. 'PHYSICAL': ''
  19642. };
  19643. this.type = 'MeshPhysicalMaterial';
  19644. this.clearcoat = 0.0;
  19645. this.clearcoatMap = null;
  19646. this.clearcoatRoughness = 0.0;
  19647. this.clearcoatRoughnessMap = null;
  19648. this.clearcoatNormalScale = new Vector2(1, 1);
  19649. this.clearcoatNormalMap = null;
  19650. this.reflectivity = 0.5; // maps to F0 = 0.04
  19651. Object.defineProperty(this, 'ior', {
  19652. get: function get() {
  19653. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  19654. },
  19655. set: function set(ior) {
  19656. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  19657. }
  19658. });
  19659. this.sheen = null; // null will disable sheen bsdf
  19660. this.transmission = 0.0;
  19661. this.transmissionMap = null;
  19662. this.setValues(parameters);
  19663. }
  19664. MeshPhysicalMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
  19665. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  19666. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19667. MeshPhysicalMaterial.prototype.copy = function (source) {
  19668. MeshStandardMaterial.prototype.copy.call(this, source);
  19669. this.defines = {
  19670. 'STANDARD': '',
  19671. 'PHYSICAL': ''
  19672. };
  19673. this.clearcoat = source.clearcoat;
  19674. this.clearcoatMap = source.clearcoatMap;
  19675. this.clearcoatRoughness = source.clearcoatRoughness;
  19676. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  19677. this.clearcoatNormalMap = source.clearcoatNormalMap;
  19678. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  19679. this.reflectivity = source.reflectivity;
  19680. if (source.sheen) {
  19681. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  19682. } else {
  19683. this.sheen = null;
  19684. }
  19685. this.transmission = source.transmission;
  19686. this.transmissionMap = source.transmissionMap;
  19687. return this;
  19688. };
  19689. /**
  19690. * parameters = {
  19691. * color: <hex>,
  19692. * specular: <hex>,
  19693. * shininess: <float>,
  19694. * opacity: <float>,
  19695. *
  19696. * map: new THREE.Texture( <Image> ),
  19697. *
  19698. * lightMap: new THREE.Texture( <Image> ),
  19699. * lightMapIntensity: <float>
  19700. *
  19701. * aoMap: new THREE.Texture( <Image> ),
  19702. * aoMapIntensity: <float>
  19703. *
  19704. * emissive: <hex>,
  19705. * emissiveIntensity: <float>
  19706. * emissiveMap: new THREE.Texture( <Image> ),
  19707. *
  19708. * bumpMap: new THREE.Texture( <Image> ),
  19709. * bumpScale: <float>,
  19710. *
  19711. * normalMap: new THREE.Texture( <Image> ),
  19712. * normalMapType: THREE.TangentSpaceNormalMap,
  19713. * normalScale: <Vector2>,
  19714. *
  19715. * displacementMap: new THREE.Texture( <Image> ),
  19716. * displacementScale: <float>,
  19717. * displacementBias: <float>,
  19718. *
  19719. * specularMap: new THREE.Texture( <Image> ),
  19720. *
  19721. * alphaMap: new THREE.Texture( <Image> ),
  19722. *
  19723. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19724. * combine: THREE.MultiplyOperation,
  19725. * reflectivity: <float>,
  19726. * refractionRatio: <float>,
  19727. *
  19728. * wireframe: <boolean>,
  19729. * wireframeLinewidth: <float>,
  19730. *
  19731. * skinning: <bool>,
  19732. * morphTargets: <bool>,
  19733. * morphNormals: <bool>
  19734. * }
  19735. */
  19736. function MeshPhongMaterial(parameters) {
  19737. Material.call(this);
  19738. this.type = 'MeshPhongMaterial';
  19739. this.color = new Color(0xffffff); // diffuse
  19740. this.specular = new Color(0x111111);
  19741. this.shininess = 30;
  19742. this.map = null;
  19743. this.lightMap = null;
  19744. this.lightMapIntensity = 1.0;
  19745. this.aoMap = null;
  19746. this.aoMapIntensity = 1.0;
  19747. this.emissive = new Color(0x000000);
  19748. this.emissiveIntensity = 1.0;
  19749. this.emissiveMap = null;
  19750. this.bumpMap = null;
  19751. this.bumpScale = 1;
  19752. this.normalMap = null;
  19753. this.normalMapType = TangentSpaceNormalMap;
  19754. this.normalScale = new Vector2(1, 1);
  19755. this.displacementMap = null;
  19756. this.displacementScale = 1;
  19757. this.displacementBias = 0;
  19758. this.specularMap = null;
  19759. this.alphaMap = null;
  19760. this.envMap = null;
  19761. this.combine = MultiplyOperation;
  19762. this.reflectivity = 1;
  19763. this.refractionRatio = 0.98;
  19764. this.wireframe = false;
  19765. this.wireframeLinewidth = 1;
  19766. this.wireframeLinecap = 'round';
  19767. this.wireframeLinejoin = 'round';
  19768. this.skinning = false;
  19769. this.morphTargets = false;
  19770. this.morphNormals = false;
  19771. this.setValues(parameters);
  19772. }
  19773. MeshPhongMaterial.prototype = Object.create(Material.prototype);
  19774. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  19775. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  19776. MeshPhongMaterial.prototype.copy = function (source) {
  19777. Material.prototype.copy.call(this, source);
  19778. this.color.copy(source.color);
  19779. this.specular.copy(source.specular);
  19780. this.shininess = source.shininess;
  19781. this.map = source.map;
  19782. this.lightMap = source.lightMap;
  19783. this.lightMapIntensity = source.lightMapIntensity;
  19784. this.aoMap = source.aoMap;
  19785. this.aoMapIntensity = source.aoMapIntensity;
  19786. this.emissive.copy(source.emissive);
  19787. this.emissiveMap = source.emissiveMap;
  19788. this.emissiveIntensity = source.emissiveIntensity;
  19789. this.bumpMap = source.bumpMap;
  19790. this.bumpScale = source.bumpScale;
  19791. this.normalMap = source.normalMap;
  19792. this.normalMapType = source.normalMapType;
  19793. this.normalScale.copy(source.normalScale);
  19794. this.displacementMap = source.displacementMap;
  19795. this.displacementScale = source.displacementScale;
  19796. this.displacementBias = source.displacementBias;
  19797. this.specularMap = source.specularMap;
  19798. this.alphaMap = source.alphaMap;
  19799. this.envMap = source.envMap;
  19800. this.combine = source.combine;
  19801. this.reflectivity = source.reflectivity;
  19802. this.refractionRatio = source.refractionRatio;
  19803. this.wireframe = source.wireframe;
  19804. this.wireframeLinewidth = source.wireframeLinewidth;
  19805. this.wireframeLinecap = source.wireframeLinecap;
  19806. this.wireframeLinejoin = source.wireframeLinejoin;
  19807. this.skinning = source.skinning;
  19808. this.morphTargets = source.morphTargets;
  19809. this.morphNormals = source.morphNormals;
  19810. return this;
  19811. };
  19812. /**
  19813. * parameters = {
  19814. * color: <hex>,
  19815. *
  19816. * map: new THREE.Texture( <Image> ),
  19817. * gradientMap: new THREE.Texture( <Image> ),
  19818. *
  19819. * lightMap: new THREE.Texture( <Image> ),
  19820. * lightMapIntensity: <float>
  19821. *
  19822. * aoMap: new THREE.Texture( <Image> ),
  19823. * aoMapIntensity: <float>
  19824. *
  19825. * emissive: <hex>,
  19826. * emissiveIntensity: <float>
  19827. * emissiveMap: new THREE.Texture( <Image> ),
  19828. *
  19829. * bumpMap: new THREE.Texture( <Image> ),
  19830. * bumpScale: <float>,
  19831. *
  19832. * normalMap: new THREE.Texture( <Image> ),
  19833. * normalMapType: THREE.TangentSpaceNormalMap,
  19834. * normalScale: <Vector2>,
  19835. *
  19836. * displacementMap: new THREE.Texture( <Image> ),
  19837. * displacementScale: <float>,
  19838. * displacementBias: <float>,
  19839. *
  19840. * alphaMap: new THREE.Texture( <Image> ),
  19841. *
  19842. * wireframe: <boolean>,
  19843. * wireframeLinewidth: <float>,
  19844. *
  19845. * skinning: <bool>,
  19846. * morphTargets: <bool>,
  19847. * morphNormals: <bool>
  19848. * }
  19849. */
  19850. function MeshToonMaterial(parameters) {
  19851. Material.call(this);
  19852. this.defines = {
  19853. 'TOON': ''
  19854. };
  19855. this.type = 'MeshToonMaterial';
  19856. this.color = new Color(0xffffff);
  19857. this.map = null;
  19858. this.gradientMap = null;
  19859. this.lightMap = null;
  19860. this.lightMapIntensity = 1.0;
  19861. this.aoMap = null;
  19862. this.aoMapIntensity = 1.0;
  19863. this.emissive = new Color(0x000000);
  19864. this.emissiveIntensity = 1.0;
  19865. this.emissiveMap = null;
  19866. this.bumpMap = null;
  19867. this.bumpScale = 1;
  19868. this.normalMap = null;
  19869. this.normalMapType = TangentSpaceNormalMap;
  19870. this.normalScale = new Vector2(1, 1);
  19871. this.displacementMap = null;
  19872. this.displacementScale = 1;
  19873. this.displacementBias = 0;
  19874. this.alphaMap = null;
  19875. this.wireframe = false;
  19876. this.wireframeLinewidth = 1;
  19877. this.wireframeLinecap = 'round';
  19878. this.wireframeLinejoin = 'round';
  19879. this.skinning = false;
  19880. this.morphTargets = false;
  19881. this.morphNormals = false;
  19882. this.setValues(parameters);
  19883. }
  19884. MeshToonMaterial.prototype = Object.create(Material.prototype);
  19885. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  19886. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  19887. MeshToonMaterial.prototype.copy = function (source) {
  19888. Material.prototype.copy.call(this, source);
  19889. this.color.copy(source.color);
  19890. this.map = source.map;
  19891. this.gradientMap = source.gradientMap;
  19892. this.lightMap = source.lightMap;
  19893. this.lightMapIntensity = source.lightMapIntensity;
  19894. this.aoMap = source.aoMap;
  19895. this.aoMapIntensity = source.aoMapIntensity;
  19896. this.emissive.copy(source.emissive);
  19897. this.emissiveMap = source.emissiveMap;
  19898. this.emissiveIntensity = source.emissiveIntensity;
  19899. this.bumpMap = source.bumpMap;
  19900. this.bumpScale = source.bumpScale;
  19901. this.normalMap = source.normalMap;
  19902. this.normalMapType = source.normalMapType;
  19903. this.normalScale.copy(source.normalScale);
  19904. this.displacementMap = source.displacementMap;
  19905. this.displacementScale = source.displacementScale;
  19906. this.displacementBias = source.displacementBias;
  19907. this.alphaMap = source.alphaMap;
  19908. this.wireframe = source.wireframe;
  19909. this.wireframeLinewidth = source.wireframeLinewidth;
  19910. this.wireframeLinecap = source.wireframeLinecap;
  19911. this.wireframeLinejoin = source.wireframeLinejoin;
  19912. this.skinning = source.skinning;
  19913. this.morphTargets = source.morphTargets;
  19914. this.morphNormals = source.morphNormals;
  19915. return this;
  19916. };
  19917. /**
  19918. * parameters = {
  19919. * opacity: <float>,
  19920. *
  19921. * bumpMap: new THREE.Texture( <Image> ),
  19922. * bumpScale: <float>,
  19923. *
  19924. * normalMap: new THREE.Texture( <Image> ),
  19925. * normalMapType: THREE.TangentSpaceNormalMap,
  19926. * normalScale: <Vector2>,
  19927. *
  19928. * displacementMap: new THREE.Texture( <Image> ),
  19929. * displacementScale: <float>,
  19930. * displacementBias: <float>,
  19931. *
  19932. * wireframe: <boolean>,
  19933. * wireframeLinewidth: <float>
  19934. *
  19935. * skinning: <bool>,
  19936. * morphTargets: <bool>,
  19937. * morphNormals: <bool>
  19938. * }
  19939. */
  19940. function MeshNormalMaterial(parameters) {
  19941. Material.call(this);
  19942. this.type = 'MeshNormalMaterial';
  19943. this.bumpMap = null;
  19944. this.bumpScale = 1;
  19945. this.normalMap = null;
  19946. this.normalMapType = TangentSpaceNormalMap;
  19947. this.normalScale = new Vector2(1, 1);
  19948. this.displacementMap = null;
  19949. this.displacementScale = 1;
  19950. this.displacementBias = 0;
  19951. this.wireframe = false;
  19952. this.wireframeLinewidth = 1;
  19953. this.fog = false;
  19954. this.skinning = false;
  19955. this.morphTargets = false;
  19956. this.morphNormals = false;
  19957. this.setValues(parameters);
  19958. }
  19959. MeshNormalMaterial.prototype = Object.create(Material.prototype);
  19960. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  19961. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  19962. MeshNormalMaterial.prototype.copy = function (source) {
  19963. Material.prototype.copy.call(this, source);
  19964. this.bumpMap = source.bumpMap;
  19965. this.bumpScale = source.bumpScale;
  19966. this.normalMap = source.normalMap;
  19967. this.normalMapType = source.normalMapType;
  19968. this.normalScale.copy(source.normalScale);
  19969. this.displacementMap = source.displacementMap;
  19970. this.displacementScale = source.displacementScale;
  19971. this.displacementBias = source.displacementBias;
  19972. this.wireframe = source.wireframe;
  19973. this.wireframeLinewidth = source.wireframeLinewidth;
  19974. this.skinning = source.skinning;
  19975. this.morphTargets = source.morphTargets;
  19976. this.morphNormals = source.morphNormals;
  19977. return this;
  19978. };
  19979. /**
  19980. * parameters = {
  19981. * color: <hex>,
  19982. * opacity: <float>,
  19983. *
  19984. * map: new THREE.Texture( <Image> ),
  19985. *
  19986. * lightMap: new THREE.Texture( <Image> ),
  19987. * lightMapIntensity: <float>
  19988. *
  19989. * aoMap: new THREE.Texture( <Image> ),
  19990. * aoMapIntensity: <float>
  19991. *
  19992. * emissive: <hex>,
  19993. * emissiveIntensity: <float>
  19994. * emissiveMap: new THREE.Texture( <Image> ),
  19995. *
  19996. * specularMap: new THREE.Texture( <Image> ),
  19997. *
  19998. * alphaMap: new THREE.Texture( <Image> ),
  19999. *
  20000. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20001. * combine: THREE.Multiply,
  20002. * reflectivity: <float>,
  20003. * refractionRatio: <float>,
  20004. *
  20005. * wireframe: <boolean>,
  20006. * wireframeLinewidth: <float>,
  20007. *
  20008. * skinning: <bool>,
  20009. * morphTargets: <bool>,
  20010. * morphNormals: <bool>
  20011. * }
  20012. */
  20013. function MeshLambertMaterial(parameters) {
  20014. Material.call(this);
  20015. this.type = 'MeshLambertMaterial';
  20016. this.color = new Color(0xffffff); // diffuse
  20017. this.map = null;
  20018. this.lightMap = null;
  20019. this.lightMapIntensity = 1.0;
  20020. this.aoMap = null;
  20021. this.aoMapIntensity = 1.0;
  20022. this.emissive = new Color(0x000000);
  20023. this.emissiveIntensity = 1.0;
  20024. this.emissiveMap = null;
  20025. this.specularMap = null;
  20026. this.alphaMap = null;
  20027. this.envMap = null;
  20028. this.combine = MultiplyOperation;
  20029. this.reflectivity = 1;
  20030. this.refractionRatio = 0.98;
  20031. this.wireframe = false;
  20032. this.wireframeLinewidth = 1;
  20033. this.wireframeLinecap = 'round';
  20034. this.wireframeLinejoin = 'round';
  20035. this.skinning = false;
  20036. this.morphTargets = false;
  20037. this.morphNormals = false;
  20038. this.setValues(parameters);
  20039. }
  20040. MeshLambertMaterial.prototype = Object.create(Material.prototype);
  20041. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20042. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20043. MeshLambertMaterial.prototype.copy = function (source) {
  20044. Material.prototype.copy.call(this, source);
  20045. this.color.copy(source.color);
  20046. this.map = source.map;
  20047. this.lightMap = source.lightMap;
  20048. this.lightMapIntensity = source.lightMapIntensity;
  20049. this.aoMap = source.aoMap;
  20050. this.aoMapIntensity = source.aoMapIntensity;
  20051. this.emissive.copy(source.emissive);
  20052. this.emissiveMap = source.emissiveMap;
  20053. this.emissiveIntensity = source.emissiveIntensity;
  20054. this.specularMap = source.specularMap;
  20055. this.alphaMap = source.alphaMap;
  20056. this.envMap = source.envMap;
  20057. this.combine = source.combine;
  20058. this.reflectivity = source.reflectivity;
  20059. this.refractionRatio = source.refractionRatio;
  20060. this.wireframe = source.wireframe;
  20061. this.wireframeLinewidth = source.wireframeLinewidth;
  20062. this.wireframeLinecap = source.wireframeLinecap;
  20063. this.wireframeLinejoin = source.wireframeLinejoin;
  20064. this.skinning = source.skinning;
  20065. this.morphTargets = source.morphTargets;
  20066. this.morphNormals = source.morphNormals;
  20067. return this;
  20068. };
  20069. /**
  20070. * parameters = {
  20071. * color: <hex>,
  20072. * opacity: <float>,
  20073. *
  20074. * matcap: new THREE.Texture( <Image> ),
  20075. *
  20076. * map: new THREE.Texture( <Image> ),
  20077. *
  20078. * bumpMap: new THREE.Texture( <Image> ),
  20079. * bumpScale: <float>,
  20080. *
  20081. * normalMap: new THREE.Texture( <Image> ),
  20082. * normalMapType: THREE.TangentSpaceNormalMap,
  20083. * normalScale: <Vector2>,
  20084. *
  20085. * displacementMap: new THREE.Texture( <Image> ),
  20086. * displacementScale: <float>,
  20087. * displacementBias: <float>,
  20088. *
  20089. * alphaMap: new THREE.Texture( <Image> ),
  20090. *
  20091. * skinning: <bool>,
  20092. * morphTargets: <bool>,
  20093. * morphNormals: <bool>
  20094. * }
  20095. */
  20096. function MeshMatcapMaterial(parameters) {
  20097. Material.call(this);
  20098. this.defines = {
  20099. 'MATCAP': ''
  20100. };
  20101. this.type = 'MeshMatcapMaterial';
  20102. this.color = new Color(0xffffff); // diffuse
  20103. this.matcap = null;
  20104. this.map = null;
  20105. this.bumpMap = null;
  20106. this.bumpScale = 1;
  20107. this.normalMap = null;
  20108. this.normalMapType = TangentSpaceNormalMap;
  20109. this.normalScale = new Vector2(1, 1);
  20110. this.displacementMap = null;
  20111. this.displacementScale = 1;
  20112. this.displacementBias = 0;
  20113. this.alphaMap = null;
  20114. this.skinning = false;
  20115. this.morphTargets = false;
  20116. this.morphNormals = false;
  20117. this.setValues(parameters);
  20118. }
  20119. MeshMatcapMaterial.prototype = Object.create(Material.prototype);
  20120. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20121. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20122. MeshMatcapMaterial.prototype.copy = function (source) {
  20123. Material.prototype.copy.call(this, source);
  20124. this.defines = {
  20125. 'MATCAP': ''
  20126. };
  20127. this.color.copy(source.color);
  20128. this.matcap = source.matcap;
  20129. this.map = source.map;
  20130. this.bumpMap = source.bumpMap;
  20131. this.bumpScale = source.bumpScale;
  20132. this.normalMap = source.normalMap;
  20133. this.normalMapType = source.normalMapType;
  20134. this.normalScale.copy(source.normalScale);
  20135. this.displacementMap = source.displacementMap;
  20136. this.displacementScale = source.displacementScale;
  20137. this.displacementBias = source.displacementBias;
  20138. this.alphaMap = source.alphaMap;
  20139. this.skinning = source.skinning;
  20140. this.morphTargets = source.morphTargets;
  20141. this.morphNormals = source.morphNormals;
  20142. return this;
  20143. };
  20144. /**
  20145. * parameters = {
  20146. * color: <hex>,
  20147. * opacity: <float>,
  20148. *
  20149. * linewidth: <float>,
  20150. *
  20151. * scale: <float>,
  20152. * dashSize: <float>,
  20153. * gapSize: <float>
  20154. * }
  20155. */
  20156. function LineDashedMaterial(parameters) {
  20157. LineBasicMaterial.call(this);
  20158. this.type = 'LineDashedMaterial';
  20159. this.scale = 1;
  20160. this.dashSize = 3;
  20161. this.gapSize = 1;
  20162. this.setValues(parameters);
  20163. }
  20164. LineDashedMaterial.prototype = Object.create(LineBasicMaterial.prototype);
  20165. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20166. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20167. LineDashedMaterial.prototype.copy = function (source) {
  20168. LineBasicMaterial.prototype.copy.call(this, source);
  20169. this.scale = source.scale;
  20170. this.dashSize = source.dashSize;
  20171. this.gapSize = source.gapSize;
  20172. return this;
  20173. };
  20174. var Materials = /*#__PURE__*/Object.freeze({
  20175. __proto__: null,
  20176. ShadowMaterial: ShadowMaterial,
  20177. SpriteMaterial: SpriteMaterial,
  20178. RawShaderMaterial: RawShaderMaterial,
  20179. ShaderMaterial: ShaderMaterial,
  20180. PointsMaterial: PointsMaterial,
  20181. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20182. MeshStandardMaterial: MeshStandardMaterial,
  20183. MeshPhongMaterial: MeshPhongMaterial,
  20184. MeshToonMaterial: MeshToonMaterial,
  20185. MeshNormalMaterial: MeshNormalMaterial,
  20186. MeshLambertMaterial: MeshLambertMaterial,
  20187. MeshDepthMaterial: MeshDepthMaterial,
  20188. MeshDistanceMaterial: MeshDistanceMaterial,
  20189. MeshBasicMaterial: MeshBasicMaterial,
  20190. MeshMatcapMaterial: MeshMatcapMaterial,
  20191. LineDashedMaterial: LineDashedMaterial,
  20192. LineBasicMaterial: LineBasicMaterial,
  20193. Material: Material
  20194. });
  20195. var AnimationUtils = {
  20196. // same as Array.prototype.slice, but also works on typed arrays
  20197. arraySlice: function arraySlice(array, from, to) {
  20198. if (AnimationUtils.isTypedArray(array)) {
  20199. // in ios9 array.subarray(from, undefined) will return empty array
  20200. // but array.subarray(from) or array.subarray(from, len) is correct
  20201. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  20202. }
  20203. return array.slice(from, to);
  20204. },
  20205. // converts an array to a specific type
  20206. convertArray: function convertArray(array, type, forceClone) {
  20207. if (!array || // let 'undefined' and 'null' pass
  20208. !forceClone && array.constructor === type) return array;
  20209. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  20210. return new type(array); // create typed array
  20211. }
  20212. return Array.prototype.slice.call(array); // create Array
  20213. },
  20214. isTypedArray: function isTypedArray(object) {
  20215. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  20216. },
  20217. // returns an array by which times and values can be sorted
  20218. getKeyframeOrder: function getKeyframeOrder(times) {
  20219. function compareTime(i, j) {
  20220. return times[i] - times[j];
  20221. }
  20222. var n = times.length;
  20223. var result = new Array(n);
  20224. for (var i = 0; i !== n; ++i) {
  20225. result[i] = i;
  20226. }
  20227. result.sort(compareTime);
  20228. return result;
  20229. },
  20230. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20231. sortedArray: function sortedArray(values, stride, order) {
  20232. var nValues = values.length;
  20233. var result = new values.constructor(nValues);
  20234. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  20235. var srcOffset = order[i] * stride;
  20236. for (var j = 0; j !== stride; ++j) {
  20237. result[dstOffset++] = values[srcOffset + j];
  20238. }
  20239. }
  20240. return result;
  20241. },
  20242. // function for parsing AOS keyframe formats
  20243. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  20244. var i = 1,
  20245. key = jsonKeys[0];
  20246. while (key !== undefined && key[valuePropertyName] === undefined) {
  20247. key = jsonKeys[i++];
  20248. }
  20249. if (key === undefined) return; // no data
  20250. var value = key[valuePropertyName];
  20251. if (value === undefined) return; // no data
  20252. if (Array.isArray(value)) {
  20253. do {
  20254. value = key[valuePropertyName];
  20255. if (value !== undefined) {
  20256. times.push(key.time);
  20257. values.push.apply(values, value); // push all elements
  20258. }
  20259. key = jsonKeys[i++];
  20260. } while (key !== undefined);
  20261. } else if (value.toArray !== undefined) {
  20262. // ...assume THREE.Math-ish
  20263. do {
  20264. value = key[valuePropertyName];
  20265. if (value !== undefined) {
  20266. times.push(key.time);
  20267. value.toArray(values, values.length);
  20268. }
  20269. key = jsonKeys[i++];
  20270. } while (key !== undefined);
  20271. } else {
  20272. // otherwise push as-is
  20273. do {
  20274. value = key[valuePropertyName];
  20275. if (value !== undefined) {
  20276. times.push(key.time);
  20277. values.push(value);
  20278. }
  20279. key = jsonKeys[i++];
  20280. } while (key !== undefined);
  20281. }
  20282. },
  20283. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  20284. if (fps === void 0) {
  20285. fps = 30;
  20286. }
  20287. var clip = sourceClip.clone();
  20288. clip.name = name;
  20289. var tracks = [];
  20290. for (var i = 0; i < clip.tracks.length; ++i) {
  20291. var track = clip.tracks[i];
  20292. var valueSize = track.getValueSize();
  20293. var times = [];
  20294. var values = [];
  20295. for (var j = 0; j < track.times.length; ++j) {
  20296. var frame = track.times[j] * fps;
  20297. if (frame < startFrame || frame >= endFrame) continue;
  20298. times.push(track.times[j]);
  20299. for (var k = 0; k < valueSize; ++k) {
  20300. values.push(track.values[j * valueSize + k]);
  20301. }
  20302. }
  20303. if (times.length === 0) continue;
  20304. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  20305. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  20306. tracks.push(track);
  20307. }
  20308. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  20309. var minStartTime = Infinity;
  20310. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  20311. if (minStartTime > clip.tracks[_i].times[0]) {
  20312. minStartTime = clip.tracks[_i].times[0];
  20313. }
  20314. } // shift all tracks such that clip begins at t=0
  20315. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  20316. clip.tracks[_i2].shift(-1 * minStartTime);
  20317. }
  20318. clip.resetDuration();
  20319. return clip;
  20320. },
  20321. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  20322. if (referenceFrame === void 0) {
  20323. referenceFrame = 0;
  20324. }
  20325. if (referenceClip === void 0) {
  20326. referenceClip = targetClip;
  20327. }
  20328. if (fps === void 0) {
  20329. fps = 30;
  20330. }
  20331. if (fps <= 0) fps = 30;
  20332. var numTracks = referenceClip.tracks.length;
  20333. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  20334. var _loop = function _loop(i) {
  20335. var referenceTrack = referenceClip.tracks[i];
  20336. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  20337. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  20338. var targetTrack = targetClip.tracks.find(function (track) {
  20339. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  20340. });
  20341. if (targetTrack === undefined) return "continue";
  20342. var referenceOffset = 0;
  20343. var referenceValueSize = referenceTrack.getValueSize();
  20344. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20345. referenceOffset = referenceValueSize / 3;
  20346. }
  20347. var targetOffset = 0;
  20348. var targetValueSize = targetTrack.getValueSize();
  20349. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20350. targetOffset = targetValueSize / 3;
  20351. }
  20352. var lastIndex = referenceTrack.times.length - 1;
  20353. var referenceValue = void 0; // Find the value to subtract out of the track
  20354. if (referenceTime <= referenceTrack.times[0]) {
  20355. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  20356. var startIndex = referenceOffset;
  20357. var endIndex = referenceValueSize - referenceOffset;
  20358. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  20359. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  20360. // Reference frame is after the last keyframe, so just use the last keyframe
  20361. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  20362. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  20363. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  20364. } else {
  20365. // Interpolate to the reference value
  20366. var interpolant = referenceTrack.createInterpolant();
  20367. var _startIndex2 = referenceOffset;
  20368. var _endIndex2 = referenceValueSize - referenceOffset;
  20369. interpolant.evaluate(referenceTime);
  20370. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  20371. } // Conjugate the quaternion
  20372. if (referenceTrackType === 'quaternion') {
  20373. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  20374. referenceQuat.toArray(referenceValue);
  20375. } // Subtract the reference value from all of the track values
  20376. var numTimes = targetTrack.times.length;
  20377. for (var j = 0; j < numTimes; ++j) {
  20378. var valueStart = j * targetValueSize + targetOffset;
  20379. if (referenceTrackType === 'quaternion') {
  20380. // Multiply the conjugate for quaternion track types
  20381. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  20382. } else {
  20383. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  20384. for (var k = 0; k < valueEnd; ++k) {
  20385. targetTrack.values[valueStart + k] -= referenceValue[k];
  20386. }
  20387. }
  20388. }
  20389. };
  20390. for (var i = 0; i < numTracks; ++i) {
  20391. var _ret = _loop(i);
  20392. if (_ret === "continue") continue;
  20393. }
  20394. targetClip.blendMode = AdditiveAnimationBlendMode;
  20395. return targetClip;
  20396. }
  20397. };
  20398. /**
  20399. * Abstract base class of interpolants over parametric samples.
  20400. *
  20401. * The parameter domain is one dimensional, typically the time or a path
  20402. * along a curve defined by the data.
  20403. *
  20404. * The sample values can have any dimensionality and derived classes may
  20405. * apply special interpretations to the data.
  20406. *
  20407. * This class provides the interval seek in a Template Method, deferring
  20408. * the actual interpolation to derived classes.
  20409. *
  20410. * Time complexity is O(1) for linear access crossing at most two points
  20411. * and O(log N) for random access, where N is the number of positions.
  20412. *
  20413. * References:
  20414. *
  20415. * http://www.oodesign.com/template-method-pattern.html
  20416. *
  20417. */
  20418. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20419. this.parameterPositions = parameterPositions;
  20420. this._cachedIndex = 0;
  20421. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  20422. this.sampleValues = sampleValues;
  20423. this.valueSize = sampleSize;
  20424. }
  20425. Object.assign(Interpolant.prototype, {
  20426. evaluate: function evaluate(t) {
  20427. var pp = this.parameterPositions;
  20428. var i1 = this._cachedIndex,
  20429. t1 = pp[i1],
  20430. t0 = pp[i1 - 1];
  20431. validate_interval: {
  20432. seek: {
  20433. var right;
  20434. linear_scan: {
  20435. //- See http://jsperf.com/comparison-to-undefined/3
  20436. //- slower code:
  20437. //-
  20438. //- if ( t >= t1 || t1 === undefined ) {
  20439. forward_scan: if (!(t < t1)) {
  20440. for (var giveUpAt = i1 + 2;;) {
  20441. if (t1 === undefined) {
  20442. if (t < t0) break forward_scan; // after end
  20443. i1 = pp.length;
  20444. this._cachedIndex = i1;
  20445. return this.afterEnd_(i1 - 1, t, t0);
  20446. }
  20447. if (i1 === giveUpAt) break; // this loop
  20448. t0 = t1;
  20449. t1 = pp[++i1];
  20450. if (t < t1) {
  20451. // we have arrived at the sought interval
  20452. break seek;
  20453. }
  20454. } // prepare binary search on the right side of the index
  20455. right = pp.length;
  20456. break linear_scan;
  20457. } //- slower code:
  20458. //- if ( t < t0 || t0 === undefined ) {
  20459. if (!(t >= t0)) {
  20460. // looping?
  20461. var t1global = pp[1];
  20462. if (t < t1global) {
  20463. i1 = 2; // + 1, using the scan for the details
  20464. t0 = t1global;
  20465. } // linear reverse scan
  20466. for (var _giveUpAt = i1 - 2;;) {
  20467. if (t0 === undefined) {
  20468. // before start
  20469. this._cachedIndex = 0;
  20470. return this.beforeStart_(0, t, t1);
  20471. }
  20472. if (i1 === _giveUpAt) break; // this loop
  20473. t1 = t0;
  20474. t0 = pp[--i1 - 1];
  20475. if (t >= t0) {
  20476. // we have arrived at the sought interval
  20477. break seek;
  20478. }
  20479. } // prepare binary search on the left side of the index
  20480. right = i1;
  20481. i1 = 0;
  20482. break linear_scan;
  20483. } // the interval is valid
  20484. break validate_interval;
  20485. } // linear scan
  20486. // binary search
  20487. while (i1 < right) {
  20488. var mid = i1 + right >>> 1;
  20489. if (t < pp[mid]) {
  20490. right = mid;
  20491. } else {
  20492. i1 = mid + 1;
  20493. }
  20494. }
  20495. t1 = pp[i1];
  20496. t0 = pp[i1 - 1]; // check boundary cases, again
  20497. if (t0 === undefined) {
  20498. this._cachedIndex = 0;
  20499. return this.beforeStart_(0, t, t1);
  20500. }
  20501. if (t1 === undefined) {
  20502. i1 = pp.length;
  20503. this._cachedIndex = i1;
  20504. return this.afterEnd_(i1 - 1, t0, t);
  20505. }
  20506. } // seek
  20507. this._cachedIndex = i1;
  20508. this.intervalChanged_(i1, t0, t1);
  20509. } // validate_interval
  20510. return this.interpolate_(i1, t0, t, t1);
  20511. },
  20512. settings: null,
  20513. // optional, subclass-specific settings structure
  20514. // Note: The indirection allows central control of many interpolants.
  20515. // --- Protected interface
  20516. DefaultSettings_: {},
  20517. getSettings_: function getSettings_() {
  20518. return this.settings || this.DefaultSettings_;
  20519. },
  20520. copySampleValue_: function copySampleValue_(index) {
  20521. // copies a sample value to the result buffer
  20522. var result = this.resultBuffer,
  20523. values = this.sampleValues,
  20524. stride = this.valueSize,
  20525. offset = index * stride;
  20526. for (var i = 0; i !== stride; ++i) {
  20527. result[i] = values[offset + i];
  20528. }
  20529. return result;
  20530. },
  20531. // Template methods for derived classes:
  20532. interpolate_: function interpolate_()
  20533. /* i1, t0, t, t1 */
  20534. {
  20535. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  20536. },
  20537. intervalChanged_: function intervalChanged_()
  20538. /* i1, t0, t1 */
  20539. {// empty
  20540. }
  20541. }); // DECLARE ALIAS AFTER assign prototype
  20542. Object.assign(Interpolant.prototype, {
  20543. //( 0, t, t0 ), returns this.resultBuffer
  20544. beforeStart_: Interpolant.prototype.copySampleValue_,
  20545. //( N-1, tN-1, t ), returns this.resultBuffer
  20546. afterEnd_: Interpolant.prototype.copySampleValue_
  20547. });
  20548. /**
  20549. * Fast and simple cubic spline interpolant.
  20550. *
  20551. * It was derived from a Hermitian construction setting the first derivative
  20552. * at each sample position to the linear slope between neighboring positions
  20553. * over their parameter interval.
  20554. */
  20555. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20556. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20557. this._weightPrev = -0;
  20558. this._offsetPrev = -0;
  20559. this._weightNext = -0;
  20560. this._offsetNext = -0;
  20561. }
  20562. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20563. constructor: CubicInterpolant,
  20564. DefaultSettings_: {
  20565. endingStart: ZeroCurvatureEnding,
  20566. endingEnd: ZeroCurvatureEnding
  20567. },
  20568. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  20569. var pp = this.parameterPositions;
  20570. var iPrev = i1 - 2,
  20571. iNext = i1 + 1,
  20572. tPrev = pp[iPrev],
  20573. tNext = pp[iNext];
  20574. if (tPrev === undefined) {
  20575. switch (this.getSettings_().endingStart) {
  20576. case ZeroSlopeEnding:
  20577. // f'(t0) = 0
  20578. iPrev = i1;
  20579. tPrev = 2 * t0 - t1;
  20580. break;
  20581. case WrapAroundEnding:
  20582. // use the other end of the curve
  20583. iPrev = pp.length - 2;
  20584. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  20585. break;
  20586. default:
  20587. // ZeroCurvatureEnding
  20588. // f''(t0) = 0 a.k.a. Natural Spline
  20589. iPrev = i1;
  20590. tPrev = t1;
  20591. }
  20592. }
  20593. if (tNext === undefined) {
  20594. switch (this.getSettings_().endingEnd) {
  20595. case ZeroSlopeEnding:
  20596. // f'(tN) = 0
  20597. iNext = i1;
  20598. tNext = 2 * t1 - t0;
  20599. break;
  20600. case WrapAroundEnding:
  20601. // use the other end of the curve
  20602. iNext = 1;
  20603. tNext = t1 + pp[1] - pp[0];
  20604. break;
  20605. default:
  20606. // ZeroCurvatureEnding
  20607. // f''(tN) = 0, a.k.a. Natural Spline
  20608. iNext = i1 - 1;
  20609. tNext = t0;
  20610. }
  20611. }
  20612. var halfDt = (t1 - t0) * 0.5,
  20613. stride = this.valueSize;
  20614. this._weightPrev = halfDt / (t0 - tPrev);
  20615. this._weightNext = halfDt / (tNext - t1);
  20616. this._offsetPrev = iPrev * stride;
  20617. this._offsetNext = iNext * stride;
  20618. },
  20619. interpolate_: function interpolate_(i1, t0, t, t1) {
  20620. var result = this.resultBuffer,
  20621. values = this.sampleValues,
  20622. stride = this.valueSize,
  20623. o1 = i1 * stride,
  20624. o0 = o1 - stride,
  20625. oP = this._offsetPrev,
  20626. oN = this._offsetNext,
  20627. wP = this._weightPrev,
  20628. wN = this._weightNext,
  20629. p = (t - t0) / (t1 - t0),
  20630. pp = p * p,
  20631. ppp = pp * p; // evaluate polynomials
  20632. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  20633. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  20634. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  20635. var sN = wN * ppp - wN * pp; // combine data linearly
  20636. for (var i = 0; i !== stride; ++i) {
  20637. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  20638. }
  20639. return result;
  20640. }
  20641. });
  20642. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20643. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20644. }
  20645. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20646. constructor: LinearInterpolant,
  20647. interpolate_: function interpolate_(i1, t0, t, t1) {
  20648. var result = this.resultBuffer,
  20649. values = this.sampleValues,
  20650. stride = this.valueSize,
  20651. offset1 = i1 * stride,
  20652. offset0 = offset1 - stride,
  20653. weight1 = (t - t0) / (t1 - t0),
  20654. weight0 = 1 - weight1;
  20655. for (var i = 0; i !== stride; ++i) {
  20656. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  20657. }
  20658. return result;
  20659. }
  20660. });
  20661. /**
  20662. *
  20663. * Interpolant that evaluates to the sample value at the position preceeding
  20664. * the parameter.
  20665. */
  20666. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20667. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20668. }
  20669. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20670. constructor: DiscreteInterpolant,
  20671. interpolate_: function interpolate_(i1
  20672. /*, t0, t, t1 */
  20673. ) {
  20674. return this.copySampleValue_(i1 - 1);
  20675. }
  20676. });
  20677. function KeyframeTrack(name, times, values, interpolation) {
  20678. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  20679. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  20680. this.name = name;
  20681. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  20682. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  20683. this.setInterpolation(interpolation || this.DefaultInterpolation);
  20684. } // Static methods
  20685. Object.assign(KeyframeTrack, {
  20686. // Serialization (in static context, because of constructor invocation
  20687. // and automatic invocation of .toJSON):
  20688. toJSON: function toJSON(track) {
  20689. var trackType = track.constructor;
  20690. var json; // derived classes can define a static toJSON method
  20691. if (trackType.toJSON !== undefined) {
  20692. json = trackType.toJSON(track);
  20693. } else {
  20694. // by default, we assume the data can be serialized as-is
  20695. json = {
  20696. 'name': track.name,
  20697. 'times': AnimationUtils.convertArray(track.times, Array),
  20698. 'values': AnimationUtils.convertArray(track.values, Array)
  20699. };
  20700. var interpolation = track.getInterpolation();
  20701. if (interpolation !== track.DefaultInterpolation) {
  20702. json.interpolation = interpolation;
  20703. }
  20704. }
  20705. json.type = track.ValueTypeName; // mandatory
  20706. return json;
  20707. }
  20708. });
  20709. Object.assign(KeyframeTrack.prototype, {
  20710. constructor: KeyframeTrack,
  20711. TimeBufferType: Float32Array,
  20712. ValueBufferType: Float32Array,
  20713. DefaultInterpolation: InterpolateLinear,
  20714. InterpolantFactoryMethodDiscrete: function InterpolantFactoryMethodDiscrete(result) {
  20715. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  20716. },
  20717. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  20718. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  20719. },
  20720. InterpolantFactoryMethodSmooth: function InterpolantFactoryMethodSmooth(result) {
  20721. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  20722. },
  20723. setInterpolation: function setInterpolation(interpolation) {
  20724. var factoryMethod;
  20725. switch (interpolation) {
  20726. case InterpolateDiscrete:
  20727. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  20728. break;
  20729. case InterpolateLinear:
  20730. factoryMethod = this.InterpolantFactoryMethodLinear;
  20731. break;
  20732. case InterpolateSmooth:
  20733. factoryMethod = this.InterpolantFactoryMethodSmooth;
  20734. break;
  20735. }
  20736. if (factoryMethod === undefined) {
  20737. var message = 'unsupported interpolation for ' + this.ValueTypeName + ' keyframe track named ' + this.name;
  20738. if (this.createInterpolant === undefined) {
  20739. // fall back to default, unless the default itself is messed up
  20740. if (interpolation !== this.DefaultInterpolation) {
  20741. this.setInterpolation(this.DefaultInterpolation);
  20742. } else {
  20743. throw new Error(message); // fatal, in this case
  20744. }
  20745. }
  20746. console.warn('THREE.KeyframeTrack:', message);
  20747. return this;
  20748. }
  20749. this.createInterpolant = factoryMethod;
  20750. return this;
  20751. },
  20752. getInterpolation: function getInterpolation() {
  20753. switch (this.createInterpolant) {
  20754. case this.InterpolantFactoryMethodDiscrete:
  20755. return InterpolateDiscrete;
  20756. case this.InterpolantFactoryMethodLinear:
  20757. return InterpolateLinear;
  20758. case this.InterpolantFactoryMethodSmooth:
  20759. return InterpolateSmooth;
  20760. }
  20761. },
  20762. getValueSize: function getValueSize() {
  20763. return this.values.length / this.times.length;
  20764. },
  20765. // move all keyframes either forwards or backwards in time
  20766. shift: function shift(timeOffset) {
  20767. if (timeOffset !== 0.0) {
  20768. var times = this.times;
  20769. for (var i = 0, n = times.length; i !== n; ++i) {
  20770. times[i] += timeOffset;
  20771. }
  20772. }
  20773. return this;
  20774. },
  20775. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  20776. scale: function scale(timeScale) {
  20777. if (timeScale !== 1.0) {
  20778. var times = this.times;
  20779. for (var i = 0, n = times.length; i !== n; ++i) {
  20780. times[i] *= timeScale;
  20781. }
  20782. }
  20783. return this;
  20784. },
  20785. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  20786. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  20787. trim: function trim(startTime, endTime) {
  20788. var times = this.times,
  20789. nKeys = times.length;
  20790. var from = 0,
  20791. to = nKeys - 1;
  20792. while (from !== nKeys && times[from] < startTime) {
  20793. ++from;
  20794. }
  20795. while (to !== -1 && times[to] > endTime) {
  20796. --to;
  20797. }
  20798. ++to; // inclusive -> exclusive bound
  20799. if (from !== 0 || to !== nKeys) {
  20800. // empty tracks are forbidden, so keep at least one keyframe
  20801. if (from >= to) {
  20802. to = Math.max(to, 1);
  20803. from = to - 1;
  20804. }
  20805. var stride = this.getValueSize();
  20806. this.times = AnimationUtils.arraySlice(times, from, to);
  20807. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  20808. }
  20809. return this;
  20810. },
  20811. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  20812. validate: function validate() {
  20813. var valid = true;
  20814. var valueSize = this.getValueSize();
  20815. if (valueSize - Math.floor(valueSize) !== 0) {
  20816. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  20817. valid = false;
  20818. }
  20819. var times = this.times,
  20820. values = this.values,
  20821. nKeys = times.length;
  20822. if (nKeys === 0) {
  20823. console.error('THREE.KeyframeTrack: Track is empty.', this);
  20824. valid = false;
  20825. }
  20826. var prevTime = null;
  20827. for (var i = 0; i !== nKeys; i++) {
  20828. var currTime = times[i];
  20829. if (typeof currTime === 'number' && isNaN(currTime)) {
  20830. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  20831. valid = false;
  20832. break;
  20833. }
  20834. if (prevTime !== null && prevTime > currTime) {
  20835. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  20836. valid = false;
  20837. break;
  20838. }
  20839. prevTime = currTime;
  20840. }
  20841. if (values !== undefined) {
  20842. if (AnimationUtils.isTypedArray(values)) {
  20843. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  20844. var value = values[_i];
  20845. if (isNaN(value)) {
  20846. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  20847. valid = false;
  20848. break;
  20849. }
  20850. }
  20851. }
  20852. }
  20853. return valid;
  20854. },
  20855. // removes equivalent sequential keys as common in morph target sequences
  20856. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  20857. optimize: function optimize() {
  20858. // times or values may be shared with other tracks, so overwriting is unsafe
  20859. var times = AnimationUtils.arraySlice(this.times),
  20860. values = AnimationUtils.arraySlice(this.values),
  20861. stride = this.getValueSize(),
  20862. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  20863. lastIndex = times.length - 1;
  20864. var writeIndex = 1;
  20865. for (var i = 1; i < lastIndex; ++i) {
  20866. var keep = false;
  20867. var time = times[i];
  20868. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  20869. if (time !== timeNext && (i !== 1 || time !== times[0])) {
  20870. if (!smoothInterpolation) {
  20871. // remove unnecessary keyframes same as their neighbors
  20872. var offset = i * stride,
  20873. offsetP = offset - stride,
  20874. offsetN = offset + stride;
  20875. for (var j = 0; j !== stride; ++j) {
  20876. var value = values[offset + j];
  20877. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  20878. keep = true;
  20879. break;
  20880. }
  20881. }
  20882. } else {
  20883. keep = true;
  20884. }
  20885. } // in-place compaction
  20886. if (keep) {
  20887. if (i !== writeIndex) {
  20888. times[writeIndex] = times[i];
  20889. var readOffset = i * stride,
  20890. writeOffset = writeIndex * stride;
  20891. for (var _j = 0; _j !== stride; ++_j) {
  20892. values[writeOffset + _j] = values[readOffset + _j];
  20893. }
  20894. }
  20895. ++writeIndex;
  20896. }
  20897. } // flush last keyframe (compaction looks ahead)
  20898. if (lastIndex > 0) {
  20899. times[writeIndex] = times[lastIndex];
  20900. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  20901. values[_writeOffset + _j2] = values[_readOffset + _j2];
  20902. }
  20903. ++writeIndex;
  20904. }
  20905. if (writeIndex !== times.length) {
  20906. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  20907. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  20908. } else {
  20909. this.times = times;
  20910. this.values = values;
  20911. }
  20912. return this;
  20913. },
  20914. clone: function clone() {
  20915. var times = AnimationUtils.arraySlice(this.times, 0);
  20916. var values = AnimationUtils.arraySlice(this.values, 0);
  20917. var TypedKeyframeTrack = this.constructor;
  20918. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  20919. track.createInterpolant = this.createInterpolant;
  20920. return track;
  20921. }
  20922. });
  20923. /**
  20924. * A Track of Boolean keyframe values.
  20925. */
  20926. function BooleanKeyframeTrack(name, times, values) {
  20927. KeyframeTrack.call(this, name, times, values);
  20928. }
  20929. BooleanKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  20930. constructor: BooleanKeyframeTrack,
  20931. ValueTypeName: 'bool',
  20932. ValueBufferType: Array,
  20933. DefaultInterpolation: InterpolateDiscrete,
  20934. InterpolantFactoryMethodLinear: undefined,
  20935. InterpolantFactoryMethodSmooth: undefined // Note: Actually this track could have a optimized / compressed
  20936. // representation of a single value and a custom interpolant that
  20937. // computes "firstValue ^ isOdd( index )".
  20938. });
  20939. /**
  20940. * A Track of keyframe values that represent color.
  20941. */
  20942. function ColorKeyframeTrack(name, times, values, interpolation) {
  20943. KeyframeTrack.call(this, name, times, values, interpolation);
  20944. }
  20945. ColorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  20946. constructor: ColorKeyframeTrack,
  20947. ValueTypeName: 'color' // ValueBufferType is inherited
  20948. // DefaultInterpolation is inherited
  20949. // Note: Very basic implementation and nothing special yet.
  20950. // However, this is the place for color space parameterization.
  20951. });
  20952. /**
  20953. * A Track of numeric keyframe values.
  20954. */
  20955. function NumberKeyframeTrack(name, times, values, interpolation) {
  20956. KeyframeTrack.call(this, name, times, values, interpolation);
  20957. }
  20958. NumberKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  20959. constructor: NumberKeyframeTrack,
  20960. ValueTypeName: 'number' // ValueBufferType is inherited
  20961. // DefaultInterpolation is inherited
  20962. });
  20963. /**
  20964. * Spherical linear unit quaternion interpolant.
  20965. */
  20966. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20967. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20968. }
  20969. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20970. constructor: QuaternionLinearInterpolant,
  20971. interpolate_: function interpolate_(i1, t0, t, t1) {
  20972. var result = this.resultBuffer,
  20973. values = this.sampleValues,
  20974. stride = this.valueSize,
  20975. alpha = (t - t0) / (t1 - t0);
  20976. var offset = i1 * stride;
  20977. for (var end = offset + stride; offset !== end; offset += 4) {
  20978. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  20979. }
  20980. return result;
  20981. }
  20982. });
  20983. /**
  20984. * A Track of quaternion keyframe values.
  20985. */
  20986. function QuaternionKeyframeTrack(name, times, values, interpolation) {
  20987. KeyframeTrack.call(this, name, times, values, interpolation);
  20988. }
  20989. QuaternionKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  20990. constructor: QuaternionKeyframeTrack,
  20991. ValueTypeName: 'quaternion',
  20992. // ValueBufferType is inherited
  20993. DefaultInterpolation: InterpolateLinear,
  20994. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  20995. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  20996. },
  20997. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  20998. });
  20999. /**
  21000. * A Track that interpolates Strings
  21001. */
  21002. function StringKeyframeTrack(name, times, values, interpolation) {
  21003. KeyframeTrack.call(this, name, times, values, interpolation);
  21004. }
  21005. StringKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21006. constructor: StringKeyframeTrack,
  21007. ValueTypeName: 'string',
  21008. ValueBufferType: Array,
  21009. DefaultInterpolation: InterpolateDiscrete,
  21010. InterpolantFactoryMethodLinear: undefined,
  21011. InterpolantFactoryMethodSmooth: undefined
  21012. });
  21013. /**
  21014. * A Track of vectored keyframe values.
  21015. */
  21016. function VectorKeyframeTrack(name, times, values, interpolation) {
  21017. KeyframeTrack.call(this, name, times, values, interpolation);
  21018. }
  21019. VectorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21020. constructor: VectorKeyframeTrack,
  21021. ValueTypeName: 'vector' // ValueBufferType is inherited
  21022. // DefaultInterpolation is inherited
  21023. });
  21024. function AnimationClip(name, duration, tracks, blendMode) {
  21025. if (duration === void 0) {
  21026. duration = -1;
  21027. }
  21028. if (blendMode === void 0) {
  21029. blendMode = NormalAnimationBlendMode;
  21030. }
  21031. this.name = name;
  21032. this.tracks = tracks;
  21033. this.duration = duration;
  21034. this.blendMode = blendMode;
  21035. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  21036. if (this.duration < 0) {
  21037. this.resetDuration();
  21038. }
  21039. }
  21040. function getTrackTypeForValueTypeName(typeName) {
  21041. switch (typeName.toLowerCase()) {
  21042. case 'scalar':
  21043. case 'double':
  21044. case 'float':
  21045. case 'number':
  21046. case 'integer':
  21047. return NumberKeyframeTrack;
  21048. case 'vector':
  21049. case 'vector2':
  21050. case 'vector3':
  21051. case 'vector4':
  21052. return VectorKeyframeTrack;
  21053. case 'color':
  21054. return ColorKeyframeTrack;
  21055. case 'quaternion':
  21056. return QuaternionKeyframeTrack;
  21057. case 'bool':
  21058. case 'boolean':
  21059. return BooleanKeyframeTrack;
  21060. case 'string':
  21061. return StringKeyframeTrack;
  21062. }
  21063. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  21064. }
  21065. function parseKeyframeTrack(json) {
  21066. if (json.type === undefined) {
  21067. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  21068. }
  21069. var trackType = getTrackTypeForValueTypeName(json.type);
  21070. if (json.times === undefined) {
  21071. var times = [],
  21072. values = [];
  21073. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  21074. json.times = times;
  21075. json.values = values;
  21076. } // derived classes can define a static parse method
  21077. if (trackType.parse !== undefined) {
  21078. return trackType.parse(json);
  21079. } else {
  21080. // by default, we assume a constructor compatible with the base
  21081. return new trackType(json.name, json.times, json.values, json.interpolation);
  21082. }
  21083. }
  21084. Object.assign(AnimationClip, {
  21085. parse: function parse(json) {
  21086. var tracks = [],
  21087. jsonTracks = json.tracks,
  21088. frameTime = 1.0 / (json.fps || 1.0);
  21089. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  21090. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  21091. }
  21092. var clip = new AnimationClip(json.name, json.duration, tracks, json.blendMode);
  21093. clip.uuid = json.uuid;
  21094. return clip;
  21095. },
  21096. toJSON: function toJSON(clip) {
  21097. var tracks = [],
  21098. clipTracks = clip.tracks;
  21099. var json = {
  21100. 'name': clip.name,
  21101. 'duration': clip.duration,
  21102. 'tracks': tracks,
  21103. 'uuid': clip.uuid,
  21104. 'blendMode': clip.blendMode
  21105. };
  21106. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  21107. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  21108. }
  21109. return json;
  21110. },
  21111. CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  21112. var numMorphTargets = morphTargetSequence.length;
  21113. var tracks = [];
  21114. for (var i = 0; i < numMorphTargets; i++) {
  21115. var times = [];
  21116. var values = [];
  21117. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  21118. values.push(0, 1, 0);
  21119. var order = AnimationUtils.getKeyframeOrder(times);
  21120. times = AnimationUtils.sortedArray(times, 1, order);
  21121. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  21122. // last frame as well for perfect loop.
  21123. if (!noLoop && times[0] === 0) {
  21124. times.push(numMorphTargets);
  21125. values.push(values[0]);
  21126. }
  21127. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  21128. }
  21129. return new AnimationClip(name, -1, tracks);
  21130. },
  21131. findByName: function findByName(objectOrClipArray, name) {
  21132. var clipArray = objectOrClipArray;
  21133. if (!Array.isArray(objectOrClipArray)) {
  21134. var o = objectOrClipArray;
  21135. clipArray = o.geometry && o.geometry.animations || o.animations;
  21136. }
  21137. for (var i = 0; i < clipArray.length; i++) {
  21138. if (clipArray[i].name === name) {
  21139. return clipArray[i];
  21140. }
  21141. }
  21142. return null;
  21143. },
  21144. CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  21145. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  21146. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21147. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  21148. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21149. for (var i = 0, il = morphTargets.length; i < il; i++) {
  21150. var morphTarget = morphTargets[i];
  21151. var parts = morphTarget.name.match(pattern);
  21152. if (parts && parts.length > 1) {
  21153. var name = parts[1];
  21154. var animationMorphTargets = animationToMorphTargets[name];
  21155. if (!animationMorphTargets) {
  21156. animationToMorphTargets[name] = animationMorphTargets = [];
  21157. }
  21158. animationMorphTargets.push(morphTarget);
  21159. }
  21160. }
  21161. var clips = [];
  21162. for (var _name in animationToMorphTargets) {
  21163. clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  21164. }
  21165. return clips;
  21166. },
  21167. // parse the animation.hierarchy format
  21168. parseAnimation: function parseAnimation(animation, bones) {
  21169. if (!animation) {
  21170. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  21171. return null;
  21172. }
  21173. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  21174. // only return track if there are actually keys.
  21175. if (animationKeys.length !== 0) {
  21176. var times = [];
  21177. var values = [];
  21178. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  21179. if (times.length !== 0) {
  21180. destTracks.push(new trackType(trackName, times, values));
  21181. }
  21182. }
  21183. };
  21184. var tracks = [];
  21185. var clipName = animation.name || 'default';
  21186. var fps = animation.fps || 30;
  21187. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  21188. var duration = animation.length || -1;
  21189. var hierarchyTracks = animation.hierarchy || [];
  21190. for (var h = 0; h < hierarchyTracks.length; h++) {
  21191. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  21192. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  21193. if (animationKeys[0].morphTargets) {
  21194. // figure out all morph targets used in this track
  21195. var morphTargetNames = {};
  21196. var k = void 0;
  21197. for (k = 0; k < animationKeys.length; k++) {
  21198. if (animationKeys[k].morphTargets) {
  21199. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  21200. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  21201. }
  21202. }
  21203. } // create a track for each morph target with all zero
  21204. // morphTargetInfluences except for the keys in which
  21205. // the morphTarget is named.
  21206. for (var morphTargetName in morphTargetNames) {
  21207. var times = [];
  21208. var values = [];
  21209. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  21210. var animationKey = animationKeys[k];
  21211. times.push(animationKey.time);
  21212. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  21213. }
  21214. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  21215. }
  21216. duration = morphTargetNames.length * (fps || 1.0);
  21217. } else {
  21218. // ...assume skeletal animation
  21219. var boneName = '.bones[' + bones[h].name + ']';
  21220. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  21221. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  21222. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  21223. }
  21224. }
  21225. if (tracks.length === 0) {
  21226. return null;
  21227. }
  21228. var clip = new AnimationClip(clipName, duration, tracks, blendMode);
  21229. return clip;
  21230. }
  21231. });
  21232. Object.assign(AnimationClip.prototype, {
  21233. resetDuration: function resetDuration() {
  21234. var tracks = this.tracks;
  21235. var duration = 0;
  21236. for (var i = 0, n = tracks.length; i !== n; ++i) {
  21237. var track = this.tracks[i];
  21238. duration = Math.max(duration, track.times[track.times.length - 1]);
  21239. }
  21240. this.duration = duration;
  21241. return this;
  21242. },
  21243. trim: function trim() {
  21244. for (var i = 0; i < this.tracks.length; i++) {
  21245. this.tracks[i].trim(0, this.duration);
  21246. }
  21247. return this;
  21248. },
  21249. validate: function validate() {
  21250. var valid = true;
  21251. for (var i = 0; i < this.tracks.length; i++) {
  21252. valid = valid && this.tracks[i].validate();
  21253. }
  21254. return valid;
  21255. },
  21256. optimize: function optimize() {
  21257. for (var i = 0; i < this.tracks.length; i++) {
  21258. this.tracks[i].optimize();
  21259. }
  21260. return this;
  21261. },
  21262. clone: function clone() {
  21263. var tracks = [];
  21264. for (var i = 0; i < this.tracks.length; i++) {
  21265. tracks.push(this.tracks[i].clone());
  21266. }
  21267. return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
  21268. },
  21269. toJSON: function toJSON() {
  21270. return AnimationClip.toJSON(this);
  21271. }
  21272. });
  21273. var Cache = {
  21274. enabled: false,
  21275. files: {},
  21276. add: function add(key, file) {
  21277. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  21278. this.files[key] = file;
  21279. },
  21280. get: function get(key) {
  21281. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  21282. return this.files[key];
  21283. },
  21284. remove: function remove(key) {
  21285. delete this.files[key];
  21286. },
  21287. clear: function clear() {
  21288. this.files = {};
  21289. }
  21290. };
  21291. function LoadingManager(onLoad, onProgress, onError) {
  21292. var scope = this;
  21293. var isLoading = false;
  21294. var itemsLoaded = 0;
  21295. var itemsTotal = 0;
  21296. var urlModifier = undefined;
  21297. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  21298. // in the constructor
  21299. this.onStart = undefined;
  21300. this.onLoad = onLoad;
  21301. this.onProgress = onProgress;
  21302. this.onError = onError;
  21303. this.itemStart = function (url) {
  21304. itemsTotal++;
  21305. if (isLoading === false) {
  21306. if (scope.onStart !== undefined) {
  21307. scope.onStart(url, itemsLoaded, itemsTotal);
  21308. }
  21309. }
  21310. isLoading = true;
  21311. };
  21312. this.itemEnd = function (url) {
  21313. itemsLoaded++;
  21314. if (scope.onProgress !== undefined) {
  21315. scope.onProgress(url, itemsLoaded, itemsTotal);
  21316. }
  21317. if (itemsLoaded === itemsTotal) {
  21318. isLoading = false;
  21319. if (scope.onLoad !== undefined) {
  21320. scope.onLoad();
  21321. }
  21322. }
  21323. };
  21324. this.itemError = function (url) {
  21325. if (scope.onError !== undefined) {
  21326. scope.onError(url);
  21327. }
  21328. };
  21329. this.resolveURL = function (url) {
  21330. if (urlModifier) {
  21331. return urlModifier(url);
  21332. }
  21333. return url;
  21334. };
  21335. this.setURLModifier = function (transform) {
  21336. urlModifier = transform;
  21337. return this;
  21338. };
  21339. this.addHandler = function (regex, loader) {
  21340. handlers.push(regex, loader);
  21341. return this;
  21342. };
  21343. this.removeHandler = function (regex) {
  21344. var index = handlers.indexOf(regex);
  21345. if (index !== -1) {
  21346. handlers.splice(index, 2);
  21347. }
  21348. return this;
  21349. };
  21350. this.getHandler = function (file) {
  21351. for (var i = 0, l = handlers.length; i < l; i += 2) {
  21352. var regex = handlers[i];
  21353. var loader = handlers[i + 1];
  21354. if (regex.global) regex.lastIndex = 0; // see #17920
  21355. if (regex.test(file)) {
  21356. return loader;
  21357. }
  21358. }
  21359. return null;
  21360. };
  21361. }
  21362. var DefaultLoadingManager = new LoadingManager();
  21363. function Loader(manager) {
  21364. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  21365. this.crossOrigin = 'anonymous';
  21366. this.withCredentials = false;
  21367. this.path = '';
  21368. this.resourcePath = '';
  21369. this.requestHeader = {};
  21370. }
  21371. Object.assign(Loader.prototype, {
  21372. load: function load()
  21373. /* url, onLoad, onProgress, onError */
  21374. {},
  21375. loadAsync: function loadAsync(url, onProgress) {
  21376. var scope = this;
  21377. return new Promise(function (resolve, reject) {
  21378. scope.load(url, resolve, onProgress, reject);
  21379. });
  21380. },
  21381. parse: function parse()
  21382. /* data */
  21383. {},
  21384. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  21385. this.crossOrigin = crossOrigin;
  21386. return this;
  21387. },
  21388. setWithCredentials: function setWithCredentials(value) {
  21389. this.withCredentials = value;
  21390. return this;
  21391. },
  21392. setPath: function setPath(path) {
  21393. this.path = path;
  21394. return this;
  21395. },
  21396. setResourcePath: function setResourcePath(resourcePath) {
  21397. this.resourcePath = resourcePath;
  21398. return this;
  21399. },
  21400. setRequestHeader: function setRequestHeader(requestHeader) {
  21401. this.requestHeader = requestHeader;
  21402. return this;
  21403. }
  21404. });
  21405. var loading = {};
  21406. function FileLoader(manager) {
  21407. Loader.call(this, manager);
  21408. }
  21409. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21410. constructor: FileLoader,
  21411. load: function load(url, onLoad, onProgress, onError) {
  21412. if (url === undefined) url = '';
  21413. if (this.path !== undefined) url = this.path + url;
  21414. url = this.manager.resolveURL(url);
  21415. var scope = this;
  21416. var cached = Cache.get(url);
  21417. if (cached !== undefined) {
  21418. scope.manager.itemStart(url);
  21419. setTimeout(function () {
  21420. if (onLoad) onLoad(cached);
  21421. scope.manager.itemEnd(url);
  21422. }, 0);
  21423. return cached;
  21424. } // Check if request is duplicate
  21425. if (loading[url] !== undefined) {
  21426. loading[url].push({
  21427. onLoad: onLoad,
  21428. onProgress: onProgress,
  21429. onError: onError
  21430. });
  21431. return;
  21432. } // Check for data: URI
  21433. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  21434. var dataUriRegexResult = url.match(dataUriRegex);
  21435. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  21436. if (dataUriRegexResult) {
  21437. var mimeType = dataUriRegexResult[1];
  21438. var isBase64 = !!dataUriRegexResult[2];
  21439. var data = dataUriRegexResult[3];
  21440. data = decodeURIComponent(data);
  21441. if (isBase64) data = atob(data);
  21442. try {
  21443. var response;
  21444. var responseType = (this.responseType || '').toLowerCase();
  21445. switch (responseType) {
  21446. case 'arraybuffer':
  21447. case 'blob':
  21448. var view = new Uint8Array(data.length);
  21449. for (var i = 0; i < data.length; i++) {
  21450. view[i] = data.charCodeAt(i);
  21451. }
  21452. if (responseType === 'blob') {
  21453. response = new Blob([view.buffer], {
  21454. type: mimeType
  21455. });
  21456. } else {
  21457. response = view.buffer;
  21458. }
  21459. break;
  21460. case 'document':
  21461. var parser = new DOMParser();
  21462. response = parser.parseFromString(data, mimeType);
  21463. break;
  21464. case 'json':
  21465. response = JSON.parse(data);
  21466. break;
  21467. default:
  21468. // 'text' or other
  21469. response = data;
  21470. break;
  21471. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21472. setTimeout(function () {
  21473. if (onLoad) onLoad(response);
  21474. scope.manager.itemEnd(url);
  21475. }, 0);
  21476. } catch (error) {
  21477. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21478. setTimeout(function () {
  21479. if (onError) onError(error);
  21480. scope.manager.itemError(url);
  21481. scope.manager.itemEnd(url);
  21482. }, 0);
  21483. }
  21484. } else {
  21485. // Initialise array for duplicate requests
  21486. loading[url] = [];
  21487. loading[url].push({
  21488. onLoad: onLoad,
  21489. onProgress: onProgress,
  21490. onError: onError
  21491. });
  21492. request = new XMLHttpRequest();
  21493. request.open('GET', url, true);
  21494. request.addEventListener('load', function (event) {
  21495. var response = this.response;
  21496. var callbacks = loading[url];
  21497. delete loading[url];
  21498. if (this.status === 200 || this.status === 0) {
  21499. // Some browsers return HTTP Status 0 when using non-http protocol
  21500. // e.g. 'file://' or 'data://'. Handle as success.
  21501. 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
  21502. // error response bodies as proper responses to requests.
  21503. Cache.add(url, response);
  21504. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  21505. var callback = callbacks[_i];
  21506. if (callback.onLoad) callback.onLoad(response);
  21507. }
  21508. scope.manager.itemEnd(url);
  21509. } else {
  21510. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  21511. var _callback = callbacks[_i2];
  21512. if (_callback.onError) _callback.onError(event);
  21513. }
  21514. scope.manager.itemError(url);
  21515. scope.manager.itemEnd(url);
  21516. }
  21517. }, false);
  21518. request.addEventListener('progress', function (event) {
  21519. var callbacks = loading[url];
  21520. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  21521. var callback = callbacks[_i3];
  21522. if (callback.onProgress) callback.onProgress(event);
  21523. }
  21524. }, false);
  21525. request.addEventListener('error', function (event) {
  21526. var callbacks = loading[url];
  21527. delete loading[url];
  21528. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  21529. var callback = callbacks[_i4];
  21530. if (callback.onError) callback.onError(event);
  21531. }
  21532. scope.manager.itemError(url);
  21533. scope.manager.itemEnd(url);
  21534. }, false);
  21535. request.addEventListener('abort', function (event) {
  21536. var callbacks = loading[url];
  21537. delete loading[url];
  21538. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  21539. var callback = callbacks[_i5];
  21540. if (callback.onError) callback.onError(event);
  21541. }
  21542. scope.manager.itemError(url);
  21543. scope.manager.itemEnd(url);
  21544. }, false);
  21545. if (this.responseType !== undefined) request.responseType = this.responseType;
  21546. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  21547. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  21548. for (var header in this.requestHeader) {
  21549. request.setRequestHeader(header, this.requestHeader[header]);
  21550. }
  21551. request.send(null);
  21552. }
  21553. scope.manager.itemStart(url);
  21554. return request;
  21555. },
  21556. setResponseType: function setResponseType(value) {
  21557. this.responseType = value;
  21558. return this;
  21559. },
  21560. setMimeType: function setMimeType(value) {
  21561. this.mimeType = value;
  21562. return this;
  21563. }
  21564. });
  21565. function AnimationLoader(manager) {
  21566. Loader.call(this, manager);
  21567. }
  21568. AnimationLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21569. constructor: AnimationLoader,
  21570. load: function load(url, onLoad, onProgress, onError) {
  21571. var scope = this;
  21572. var loader = new FileLoader(scope.manager);
  21573. loader.setPath(scope.path);
  21574. loader.setRequestHeader(scope.requestHeader);
  21575. loader.setWithCredentials(scope.withCredentials);
  21576. loader.load(url, function (text) {
  21577. try {
  21578. onLoad(scope.parse(JSON.parse(text)));
  21579. } catch (e) {
  21580. if (onError) {
  21581. onError(e);
  21582. } else {
  21583. console.error(e);
  21584. }
  21585. scope.manager.itemError(url);
  21586. }
  21587. }, onProgress, onError);
  21588. },
  21589. parse: function parse(json) {
  21590. var animations = [];
  21591. for (var i = 0; i < json.length; i++) {
  21592. var clip = AnimationClip.parse(json[i]);
  21593. animations.push(clip);
  21594. }
  21595. return animations;
  21596. }
  21597. });
  21598. /**
  21599. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21600. *
  21601. * Sub classes have to implement the parse() method which will be used in load().
  21602. */
  21603. function CompressedTextureLoader(manager) {
  21604. Loader.call(this, manager);
  21605. }
  21606. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21607. constructor: CompressedTextureLoader,
  21608. load: function load(url, onLoad, onProgress, onError) {
  21609. var scope = this;
  21610. var images = [];
  21611. var texture = new CompressedTexture();
  21612. var loader = new FileLoader(this.manager);
  21613. loader.setPath(this.path);
  21614. loader.setResponseType('arraybuffer');
  21615. loader.setRequestHeader(this.requestHeader);
  21616. loader.setWithCredentials(scope.withCredentials);
  21617. var loaded = 0;
  21618. function loadTexture(i) {
  21619. loader.load(url[i], function (buffer) {
  21620. var texDatas = scope.parse(buffer, true);
  21621. images[i] = {
  21622. width: texDatas.width,
  21623. height: texDatas.height,
  21624. format: texDatas.format,
  21625. mipmaps: texDatas.mipmaps
  21626. };
  21627. loaded += 1;
  21628. if (loaded === 6) {
  21629. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  21630. texture.image = images;
  21631. texture.format = texDatas.format;
  21632. texture.needsUpdate = true;
  21633. if (onLoad) onLoad(texture);
  21634. }
  21635. }, onProgress, onError);
  21636. }
  21637. if (Array.isArray(url)) {
  21638. for (var i = 0, il = url.length; i < il; ++i) {
  21639. loadTexture(i);
  21640. }
  21641. } else {
  21642. // compressed cubemap texture stored in a single DDS file
  21643. loader.load(url, function (buffer) {
  21644. var texDatas = scope.parse(buffer, true);
  21645. if (texDatas.isCubemap) {
  21646. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21647. for (var f = 0; f < faces; f++) {
  21648. images[f] = {
  21649. mipmaps: []
  21650. };
  21651. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  21652. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  21653. images[f].format = texDatas.format;
  21654. images[f].width = texDatas.width;
  21655. images[f].height = texDatas.height;
  21656. }
  21657. }
  21658. texture.image = images;
  21659. } else {
  21660. texture.image.width = texDatas.width;
  21661. texture.image.height = texDatas.height;
  21662. texture.mipmaps = texDatas.mipmaps;
  21663. }
  21664. if (texDatas.mipmapCount === 1) {
  21665. texture.minFilter = LinearFilter;
  21666. }
  21667. texture.format = texDatas.format;
  21668. texture.needsUpdate = true;
  21669. if (onLoad) onLoad(texture);
  21670. }, onProgress, onError);
  21671. }
  21672. return texture;
  21673. }
  21674. });
  21675. function ImageLoader(manager) {
  21676. Loader.call(this, manager);
  21677. }
  21678. ImageLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21679. constructor: ImageLoader,
  21680. load: function load(url, onLoad, onProgress, onError) {
  21681. if (this.path !== undefined) url = this.path + url;
  21682. url = this.manager.resolveURL(url);
  21683. var scope = this;
  21684. var cached = Cache.get(url);
  21685. if (cached !== undefined) {
  21686. scope.manager.itemStart(url);
  21687. setTimeout(function () {
  21688. if (onLoad) onLoad(cached);
  21689. scope.manager.itemEnd(url);
  21690. }, 0);
  21691. return cached;
  21692. }
  21693. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  21694. function onImageLoad() {
  21695. image.removeEventListener('load', onImageLoad, false);
  21696. image.removeEventListener('error', onImageError, false);
  21697. Cache.add(url, this);
  21698. if (onLoad) onLoad(this);
  21699. scope.manager.itemEnd(url);
  21700. }
  21701. function onImageError(event) {
  21702. image.removeEventListener('load', onImageLoad, false);
  21703. image.removeEventListener('error', onImageError, false);
  21704. if (onError) onError(event);
  21705. scope.manager.itemError(url);
  21706. scope.manager.itemEnd(url);
  21707. }
  21708. image.addEventListener('load', onImageLoad, false);
  21709. image.addEventListener('error', onImageError, false);
  21710. if (url.substr(0, 5) !== 'data:') {
  21711. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  21712. }
  21713. scope.manager.itemStart(url);
  21714. image.src = url;
  21715. return image;
  21716. }
  21717. });
  21718. function CubeTextureLoader(manager) {
  21719. Loader.call(this, manager);
  21720. }
  21721. CubeTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21722. constructor: CubeTextureLoader,
  21723. load: function load(urls, onLoad, onProgress, onError) {
  21724. var texture = new CubeTexture();
  21725. var loader = new ImageLoader(this.manager);
  21726. loader.setCrossOrigin(this.crossOrigin);
  21727. loader.setPath(this.path);
  21728. var loaded = 0;
  21729. function loadTexture(i) {
  21730. loader.load(urls[i], function (image) {
  21731. texture.images[i] = image;
  21732. loaded++;
  21733. if (loaded === 6) {
  21734. texture.needsUpdate = true;
  21735. if (onLoad) onLoad(texture);
  21736. }
  21737. }, undefined, onError);
  21738. }
  21739. for (var i = 0; i < urls.length; ++i) {
  21740. loadTexture(i);
  21741. }
  21742. return texture;
  21743. }
  21744. });
  21745. /**
  21746. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  21747. *
  21748. * Sub classes have to implement the parse() method which will be used in load().
  21749. */
  21750. function DataTextureLoader(manager) {
  21751. Loader.call(this, manager);
  21752. }
  21753. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21754. constructor: DataTextureLoader,
  21755. load: function load(url, onLoad, onProgress, onError) {
  21756. var scope = this;
  21757. var texture = new DataTexture();
  21758. var loader = new FileLoader(this.manager);
  21759. loader.setResponseType('arraybuffer');
  21760. loader.setRequestHeader(this.requestHeader);
  21761. loader.setPath(this.path);
  21762. loader.setWithCredentials(scope.withCredentials);
  21763. loader.load(url, function (buffer) {
  21764. var texData = scope.parse(buffer);
  21765. if (!texData) return;
  21766. if (texData.image !== undefined) {
  21767. texture.image = texData.image;
  21768. } else if (texData.data !== undefined) {
  21769. texture.image.width = texData.width;
  21770. texture.image.height = texData.height;
  21771. texture.image.data = texData.data;
  21772. }
  21773. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  21774. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  21775. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  21776. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  21777. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  21778. if (texData.format !== undefined) {
  21779. texture.format = texData.format;
  21780. }
  21781. if (texData.type !== undefined) {
  21782. texture.type = texData.type;
  21783. }
  21784. if (texData.mipmaps !== undefined) {
  21785. texture.mipmaps = texData.mipmaps;
  21786. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  21787. }
  21788. if (texData.mipmapCount === 1) {
  21789. texture.minFilter = LinearFilter;
  21790. }
  21791. texture.needsUpdate = true;
  21792. if (onLoad) onLoad(texture, texData);
  21793. }, onProgress, onError);
  21794. return texture;
  21795. }
  21796. });
  21797. function TextureLoader(manager) {
  21798. Loader.call(this, manager);
  21799. }
  21800. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21801. constructor: TextureLoader,
  21802. load: function load(url, onLoad, onProgress, onError) {
  21803. var texture = new Texture();
  21804. var loader = new ImageLoader(this.manager);
  21805. loader.setCrossOrigin(this.crossOrigin);
  21806. loader.setPath(this.path);
  21807. loader.load(url, function (image) {
  21808. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  21809. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  21810. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  21811. texture.needsUpdate = true;
  21812. if (onLoad !== undefined) {
  21813. onLoad(texture);
  21814. }
  21815. }, onProgress, onError);
  21816. return texture;
  21817. }
  21818. });
  21819. /**
  21820. * Extensible curve object.
  21821. *
  21822. * Some common of curve methods:
  21823. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  21824. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  21825. * .getPoints(), .getSpacedPoints()
  21826. * .getLength()
  21827. * .updateArcLengths()
  21828. *
  21829. * This following curves inherit from THREE.Curve:
  21830. *
  21831. * -- 2D curves --
  21832. * THREE.ArcCurve
  21833. * THREE.CubicBezierCurve
  21834. * THREE.EllipseCurve
  21835. * THREE.LineCurve
  21836. * THREE.QuadraticBezierCurve
  21837. * THREE.SplineCurve
  21838. *
  21839. * -- 3D curves --
  21840. * THREE.CatmullRomCurve3
  21841. * THREE.CubicBezierCurve3
  21842. * THREE.LineCurve3
  21843. * THREE.QuadraticBezierCurve3
  21844. *
  21845. * A series of curves can be represented as a THREE.CurvePath.
  21846. *
  21847. **/
  21848. function Curve() {
  21849. this.type = 'Curve';
  21850. this.arcLengthDivisions = 200;
  21851. }
  21852. Object.assign(Curve.prototype, {
  21853. // Virtual base class method to overwrite and implement in subclasses
  21854. // - t [0 .. 1]
  21855. getPoint: function getPoint()
  21856. /* t, optionalTarget */
  21857. {
  21858. console.warn('THREE.Curve: .getPoint() not implemented.');
  21859. return null;
  21860. },
  21861. // Get point at relative position in curve according to arc length
  21862. // - u [0 .. 1]
  21863. getPointAt: function getPointAt(u, optionalTarget) {
  21864. var t = this.getUtoTmapping(u);
  21865. return this.getPoint(t, optionalTarget);
  21866. },
  21867. // Get sequence of points using getPoint( t )
  21868. getPoints: function getPoints(divisions) {
  21869. if (divisions === void 0) {
  21870. divisions = 5;
  21871. }
  21872. var points = [];
  21873. for (var d = 0; d <= divisions; d++) {
  21874. points.push(this.getPoint(d / divisions));
  21875. }
  21876. return points;
  21877. },
  21878. // Get sequence of points using getPointAt( u )
  21879. getSpacedPoints: function getSpacedPoints(divisions) {
  21880. if (divisions === void 0) {
  21881. divisions = 5;
  21882. }
  21883. var points = [];
  21884. for (var d = 0; d <= divisions; d++) {
  21885. points.push(this.getPointAt(d / divisions));
  21886. }
  21887. return points;
  21888. },
  21889. // Get total curve arc length
  21890. getLength: function getLength() {
  21891. var lengths = this.getLengths();
  21892. return lengths[lengths.length - 1];
  21893. },
  21894. // Get list of cumulative segment lengths
  21895. getLengths: function getLengths(divisions) {
  21896. if (divisions === undefined) divisions = this.arcLengthDivisions;
  21897. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  21898. return this.cacheArcLengths;
  21899. }
  21900. this.needsUpdate = false;
  21901. var cache = [];
  21902. var current,
  21903. last = this.getPoint(0);
  21904. var sum = 0;
  21905. cache.push(0);
  21906. for (var p = 1; p <= divisions; p++) {
  21907. current = this.getPoint(p / divisions);
  21908. sum += current.distanceTo(last);
  21909. cache.push(sum);
  21910. last = current;
  21911. }
  21912. this.cacheArcLengths = cache;
  21913. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  21914. },
  21915. updateArcLengths: function updateArcLengths() {
  21916. this.needsUpdate = true;
  21917. this.getLengths();
  21918. },
  21919. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  21920. getUtoTmapping: function getUtoTmapping(u, distance) {
  21921. var arcLengths = this.getLengths();
  21922. var i = 0;
  21923. var il = arcLengths.length;
  21924. var targetArcLength; // The targeted u distance value to get
  21925. if (distance) {
  21926. targetArcLength = distance;
  21927. } else {
  21928. targetArcLength = u * arcLengths[il - 1];
  21929. } // binary search for the index with largest value smaller than target u distance
  21930. var low = 0,
  21931. high = il - 1,
  21932. comparison;
  21933. while (low <= high) {
  21934. 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
  21935. comparison = arcLengths[i] - targetArcLength;
  21936. if (comparison < 0) {
  21937. low = i + 1;
  21938. } else if (comparison > 0) {
  21939. high = i - 1;
  21940. } else {
  21941. high = i;
  21942. break; // DONE
  21943. }
  21944. }
  21945. i = high;
  21946. if (arcLengths[i] === targetArcLength) {
  21947. return i / (il - 1);
  21948. } // we could get finer grain at lengths, or use simple interpolation between two points
  21949. var lengthBefore = arcLengths[i];
  21950. var lengthAfter = arcLengths[i + 1];
  21951. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  21952. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  21953. var t = (i + segmentFraction) / (il - 1);
  21954. return t;
  21955. },
  21956. // Returns a unit vector tangent at t
  21957. // In case any sub curve does not implement its tangent derivation,
  21958. // 2 points a small delta apart will be used to find its gradient
  21959. // which seems to give a reasonable approximation
  21960. getTangent: function getTangent(t, optionalTarget) {
  21961. var delta = 0.0001;
  21962. var t1 = t - delta;
  21963. var t2 = t + delta; // Capping in case of danger
  21964. if (t1 < 0) t1 = 0;
  21965. if (t2 > 1) t2 = 1;
  21966. var pt1 = this.getPoint(t1);
  21967. var pt2 = this.getPoint(t2);
  21968. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  21969. tangent.copy(pt2).sub(pt1).normalize();
  21970. return tangent;
  21971. },
  21972. getTangentAt: function getTangentAt(u, optionalTarget) {
  21973. var t = this.getUtoTmapping(u);
  21974. return this.getTangent(t, optionalTarget);
  21975. },
  21976. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  21977. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  21978. var normal = new Vector3();
  21979. var tangents = [];
  21980. var normals = [];
  21981. var binormals = [];
  21982. var vec = new Vector3();
  21983. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  21984. for (var i = 0; i <= segments; i++) {
  21985. var u = i / segments;
  21986. tangents[i] = this.getTangentAt(u, new Vector3());
  21987. tangents[i].normalize();
  21988. } // select an initial normal vector perpendicular to the first tangent vector,
  21989. // and in the direction of the minimum tangent xyz component
  21990. normals[0] = new Vector3();
  21991. binormals[0] = new Vector3();
  21992. var min = Number.MAX_VALUE;
  21993. var tx = Math.abs(tangents[0].x);
  21994. var ty = Math.abs(tangents[0].y);
  21995. var tz = Math.abs(tangents[0].z);
  21996. if (tx <= min) {
  21997. min = tx;
  21998. normal.set(1, 0, 0);
  21999. }
  22000. if (ty <= min) {
  22001. min = ty;
  22002. normal.set(0, 1, 0);
  22003. }
  22004. if (tz <= min) {
  22005. normal.set(0, 0, 1);
  22006. }
  22007. vec.crossVectors(tangents[0], normal).normalize();
  22008. normals[0].crossVectors(tangents[0], vec);
  22009. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22010. for (var _i = 1; _i <= segments; _i++) {
  22011. normals[_i] = normals[_i - 1].clone();
  22012. binormals[_i] = binormals[_i - 1].clone();
  22013. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  22014. if (vec.length() > Number.EPSILON) {
  22015. vec.normalize();
  22016. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  22017. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  22018. }
  22019. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  22020. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22021. if (closed === true) {
  22022. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  22023. _theta /= segments;
  22024. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  22025. _theta = -_theta;
  22026. }
  22027. for (var _i2 = 1; _i2 <= segments; _i2++) {
  22028. // twist a little...
  22029. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  22030. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  22031. }
  22032. }
  22033. return {
  22034. tangents: tangents,
  22035. normals: normals,
  22036. binormals: binormals
  22037. };
  22038. },
  22039. clone: function clone() {
  22040. return new this.constructor().copy(this);
  22041. },
  22042. copy: function copy(source) {
  22043. this.arcLengthDivisions = source.arcLengthDivisions;
  22044. return this;
  22045. },
  22046. toJSON: function toJSON() {
  22047. var data = {
  22048. metadata: {
  22049. version: 4.5,
  22050. type: 'Curve',
  22051. generator: 'Curve.toJSON'
  22052. }
  22053. };
  22054. data.arcLengthDivisions = this.arcLengthDivisions;
  22055. data.type = this.type;
  22056. return data;
  22057. },
  22058. fromJSON: function fromJSON(json) {
  22059. this.arcLengthDivisions = json.arcLengthDivisions;
  22060. return this;
  22061. }
  22062. });
  22063. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22064. Curve.call(this);
  22065. this.type = 'EllipseCurve';
  22066. this.aX = aX || 0;
  22067. this.aY = aY || 0;
  22068. this.xRadius = xRadius || 1;
  22069. this.yRadius = yRadius || 1;
  22070. this.aStartAngle = aStartAngle || 0;
  22071. this.aEndAngle = aEndAngle || 2 * Math.PI;
  22072. this.aClockwise = aClockwise || false;
  22073. this.aRotation = aRotation || 0;
  22074. }
  22075. EllipseCurve.prototype = Object.create(Curve.prototype);
  22076. EllipseCurve.prototype.constructor = EllipseCurve;
  22077. EllipseCurve.prototype.isEllipseCurve = true;
  22078. EllipseCurve.prototype.getPoint = function (t, optionalTarget) {
  22079. var point = optionalTarget || new Vector2();
  22080. var twoPi = Math.PI * 2;
  22081. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22082. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  22083. while (deltaAngle < 0) {
  22084. deltaAngle += twoPi;
  22085. }
  22086. while (deltaAngle > twoPi) {
  22087. deltaAngle -= twoPi;
  22088. }
  22089. if (deltaAngle < Number.EPSILON) {
  22090. if (samePoints) {
  22091. deltaAngle = 0;
  22092. } else {
  22093. deltaAngle = twoPi;
  22094. }
  22095. }
  22096. if (this.aClockwise === true && !samePoints) {
  22097. if (deltaAngle === twoPi) {
  22098. deltaAngle = -twoPi;
  22099. } else {
  22100. deltaAngle = deltaAngle - twoPi;
  22101. }
  22102. }
  22103. var angle = this.aStartAngle + t * deltaAngle;
  22104. var x = this.aX + this.xRadius * Math.cos(angle);
  22105. var y = this.aY + this.yRadius * Math.sin(angle);
  22106. if (this.aRotation !== 0) {
  22107. var cos = Math.cos(this.aRotation);
  22108. var sin = Math.sin(this.aRotation);
  22109. var tx = x - this.aX;
  22110. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  22111. x = tx * cos - ty * sin + this.aX;
  22112. y = tx * sin + ty * cos + this.aY;
  22113. }
  22114. return point.set(x, y);
  22115. };
  22116. EllipseCurve.prototype.copy = function (source) {
  22117. Curve.prototype.copy.call(this, source);
  22118. this.aX = source.aX;
  22119. this.aY = source.aY;
  22120. this.xRadius = source.xRadius;
  22121. this.yRadius = source.yRadius;
  22122. this.aStartAngle = source.aStartAngle;
  22123. this.aEndAngle = source.aEndAngle;
  22124. this.aClockwise = source.aClockwise;
  22125. this.aRotation = source.aRotation;
  22126. return this;
  22127. };
  22128. EllipseCurve.prototype.toJSON = function () {
  22129. var data = Curve.prototype.toJSON.call(this);
  22130. data.aX = this.aX;
  22131. data.aY = this.aY;
  22132. data.xRadius = this.xRadius;
  22133. data.yRadius = this.yRadius;
  22134. data.aStartAngle = this.aStartAngle;
  22135. data.aEndAngle = this.aEndAngle;
  22136. data.aClockwise = this.aClockwise;
  22137. data.aRotation = this.aRotation;
  22138. return data;
  22139. };
  22140. EllipseCurve.prototype.fromJSON = function (json) {
  22141. Curve.prototype.fromJSON.call(this, json);
  22142. this.aX = json.aX;
  22143. this.aY = json.aY;
  22144. this.xRadius = json.xRadius;
  22145. this.yRadius = json.yRadius;
  22146. this.aStartAngle = json.aStartAngle;
  22147. this.aEndAngle = json.aEndAngle;
  22148. this.aClockwise = json.aClockwise;
  22149. this.aRotation = json.aRotation;
  22150. return this;
  22151. };
  22152. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22153. EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  22154. this.type = 'ArcCurve';
  22155. }
  22156. ArcCurve.prototype = Object.create(EllipseCurve.prototype);
  22157. ArcCurve.prototype.constructor = ArcCurve;
  22158. ArcCurve.prototype.isArcCurve = true;
  22159. /**
  22160. * Centripetal CatmullRom Curve - which is useful for avoiding
  22161. * cusps and self-intersections in non-uniform catmull rom curves.
  22162. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22163. *
  22164. * curve.type accepts centripetal(default), chordal and catmullrom
  22165. * curve.tension is used for catmullrom which defaults to 0.5
  22166. */
  22167. /*
  22168. Based on an optimized c++ solution in
  22169. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22170. - http://ideone.com/NoEbVM
  22171. This CubicPoly class could be used for reusing some variables and calculations,
  22172. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22173. which can be placed in CurveUtils.
  22174. */
  22175. function CubicPoly() {
  22176. var c0 = 0,
  22177. c1 = 0,
  22178. c2 = 0,
  22179. c3 = 0;
  22180. /*
  22181. * Compute coefficients for a cubic polynomial
  22182. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22183. * such that
  22184. * p(0) = x0, p(1) = x1
  22185. * and
  22186. * p'(0) = t0, p'(1) = t1.
  22187. */
  22188. function init(x0, x1, t0, t1) {
  22189. c0 = x0;
  22190. c1 = t0;
  22191. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  22192. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22193. }
  22194. return {
  22195. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  22196. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  22197. },
  22198. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  22199. // compute tangents when parameterized in [t1,t2]
  22200. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  22201. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  22202. t1 *= dt1;
  22203. t2 *= dt1;
  22204. init(x1, x2, t1, t2);
  22205. },
  22206. calc: function calc(t) {
  22207. var t2 = t * t;
  22208. var t3 = t2 * t;
  22209. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22210. }
  22211. };
  22212. } //
  22213. var tmp = new Vector3();
  22214. var px = new CubicPoly(),
  22215. py = new CubicPoly(),
  22216. pz = new CubicPoly();
  22217. function CatmullRomCurve3(points, closed, curveType, tension) {
  22218. if (points === void 0) {
  22219. points = [];
  22220. }
  22221. if (closed === void 0) {
  22222. closed = false;
  22223. }
  22224. if (curveType === void 0) {
  22225. curveType = 'centripetal';
  22226. }
  22227. if (tension === void 0) {
  22228. tension = 0.5;
  22229. }
  22230. Curve.call(this);
  22231. this.type = 'CatmullRomCurve3';
  22232. this.points = points;
  22233. this.closed = closed;
  22234. this.curveType = curveType;
  22235. this.tension = tension;
  22236. }
  22237. CatmullRomCurve3.prototype = Object.create(Curve.prototype);
  22238. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  22239. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22240. CatmullRomCurve3.prototype.getPoint = function (t, optionalTarget) {
  22241. if (optionalTarget === void 0) {
  22242. optionalTarget = new Vector3();
  22243. }
  22244. var point = optionalTarget;
  22245. var points = this.points;
  22246. var l = points.length;
  22247. var p = (l - (this.closed ? 0 : 1)) * t;
  22248. var intPoint = Math.floor(p);
  22249. var weight = p - intPoint;
  22250. if (this.closed) {
  22251. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  22252. } else if (weight === 0 && intPoint === l - 1) {
  22253. intPoint = l - 2;
  22254. weight = 1;
  22255. }
  22256. var p0, p3; // 4 points (p1 & p2 defined below)
  22257. if (this.closed || intPoint > 0) {
  22258. p0 = points[(intPoint - 1) % l];
  22259. } else {
  22260. // extrapolate first point
  22261. tmp.subVectors(points[0], points[1]).add(points[0]);
  22262. p0 = tmp;
  22263. }
  22264. var p1 = points[intPoint % l];
  22265. var p2 = points[(intPoint + 1) % l];
  22266. if (this.closed || intPoint + 2 < l) {
  22267. p3 = points[(intPoint + 2) % l];
  22268. } else {
  22269. // extrapolate last point
  22270. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  22271. p3 = tmp;
  22272. }
  22273. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  22274. // init Centripetal / Chordal Catmull-Rom
  22275. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22276. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  22277. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  22278. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  22279. if (dt1 < 1e-4) dt1 = 1.0;
  22280. if (dt0 < 1e-4) dt0 = dt1;
  22281. if (dt2 < 1e-4) dt2 = dt1;
  22282. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  22283. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  22284. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  22285. } else if (this.curveType === 'catmullrom') {
  22286. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  22287. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  22288. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  22289. }
  22290. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  22291. return point;
  22292. };
  22293. CatmullRomCurve3.prototype.copy = function (source) {
  22294. Curve.prototype.copy.call(this, source);
  22295. this.points = [];
  22296. for (var i = 0, l = source.points.length; i < l; i++) {
  22297. var point = source.points[i];
  22298. this.points.push(point.clone());
  22299. }
  22300. this.closed = source.closed;
  22301. this.curveType = source.curveType;
  22302. this.tension = source.tension;
  22303. return this;
  22304. };
  22305. CatmullRomCurve3.prototype.toJSON = function () {
  22306. var data = Curve.prototype.toJSON.call(this);
  22307. data.points = [];
  22308. for (var i = 0, l = this.points.length; i < l; i++) {
  22309. var point = this.points[i];
  22310. data.points.push(point.toArray());
  22311. }
  22312. data.closed = this.closed;
  22313. data.curveType = this.curveType;
  22314. data.tension = this.tension;
  22315. return data;
  22316. };
  22317. CatmullRomCurve3.prototype.fromJSON = function (json) {
  22318. Curve.prototype.fromJSON.call(this, json);
  22319. this.points = [];
  22320. for (var i = 0, l = json.points.length; i < l; i++) {
  22321. var point = json.points[i];
  22322. this.points.push(new Vector3().fromArray(point));
  22323. }
  22324. this.closed = json.closed;
  22325. this.curveType = json.curveType;
  22326. this.tension = json.tension;
  22327. return this;
  22328. };
  22329. /**
  22330. * Bezier Curves formulas obtained from
  22331. * http://en.wikipedia.org/wiki/Bézier_curve
  22332. */
  22333. function CatmullRom(t, p0, p1, p2, p3) {
  22334. var v0 = (p2 - p0) * 0.5;
  22335. var v1 = (p3 - p1) * 0.5;
  22336. var t2 = t * t;
  22337. var t3 = t * t2;
  22338. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  22339. } //
  22340. function QuadraticBezierP0(t, p) {
  22341. var k = 1 - t;
  22342. return k * k * p;
  22343. }
  22344. function QuadraticBezierP1(t, p) {
  22345. return 2 * (1 - t) * t * p;
  22346. }
  22347. function QuadraticBezierP2(t, p) {
  22348. return t * t * p;
  22349. }
  22350. function QuadraticBezier(t, p0, p1, p2) {
  22351. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  22352. } //
  22353. function CubicBezierP0(t, p) {
  22354. var k = 1 - t;
  22355. return k * k * k * p;
  22356. }
  22357. function CubicBezierP1(t, p) {
  22358. var k = 1 - t;
  22359. return 3 * k * k * t * p;
  22360. }
  22361. function CubicBezierP2(t, p) {
  22362. return 3 * (1 - t) * t * t * p;
  22363. }
  22364. function CubicBezierP3(t, p) {
  22365. return t * t * t * p;
  22366. }
  22367. function CubicBezier(t, p0, p1, p2, p3) {
  22368. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  22369. }
  22370. function CubicBezierCurve(v0, v1, v2, v3) {
  22371. if (v0 === void 0) {
  22372. v0 = new Vector2();
  22373. }
  22374. if (v1 === void 0) {
  22375. v1 = new Vector2();
  22376. }
  22377. if (v2 === void 0) {
  22378. v2 = new Vector2();
  22379. }
  22380. if (v3 === void 0) {
  22381. v3 = new Vector2();
  22382. }
  22383. Curve.call(this);
  22384. this.type = 'CubicBezierCurve';
  22385. this.v0 = v0;
  22386. this.v1 = v1;
  22387. this.v2 = v2;
  22388. this.v3 = v3;
  22389. }
  22390. CubicBezierCurve.prototype = Object.create(Curve.prototype);
  22391. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  22392. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  22393. CubicBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  22394. if (optionalTarget === void 0) {
  22395. optionalTarget = new Vector2();
  22396. }
  22397. var point = optionalTarget;
  22398. var v0 = this.v0,
  22399. v1 = this.v1,
  22400. v2 = this.v2,
  22401. v3 = this.v3;
  22402. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  22403. return point;
  22404. };
  22405. CubicBezierCurve.prototype.copy = function (source) {
  22406. Curve.prototype.copy.call(this, source);
  22407. this.v0.copy(source.v0);
  22408. this.v1.copy(source.v1);
  22409. this.v2.copy(source.v2);
  22410. this.v3.copy(source.v3);
  22411. return this;
  22412. };
  22413. CubicBezierCurve.prototype.toJSON = function () {
  22414. var data = Curve.prototype.toJSON.call(this);
  22415. data.v0 = this.v0.toArray();
  22416. data.v1 = this.v1.toArray();
  22417. data.v2 = this.v2.toArray();
  22418. data.v3 = this.v3.toArray();
  22419. return data;
  22420. };
  22421. CubicBezierCurve.prototype.fromJSON = function (json) {
  22422. Curve.prototype.fromJSON.call(this, json);
  22423. this.v0.fromArray(json.v0);
  22424. this.v1.fromArray(json.v1);
  22425. this.v2.fromArray(json.v2);
  22426. this.v3.fromArray(json.v3);
  22427. return this;
  22428. };
  22429. function CubicBezierCurve3(v0, v1, v2, v3) {
  22430. if (v0 === void 0) {
  22431. v0 = new Vector3();
  22432. }
  22433. if (v1 === void 0) {
  22434. v1 = new Vector3();
  22435. }
  22436. if (v2 === void 0) {
  22437. v2 = new Vector3();
  22438. }
  22439. if (v3 === void 0) {
  22440. v3 = new Vector3();
  22441. }
  22442. Curve.call(this);
  22443. this.type = 'CubicBezierCurve3';
  22444. this.v0 = v0;
  22445. this.v1 = v1;
  22446. this.v2 = v2;
  22447. this.v3 = v3;
  22448. }
  22449. CubicBezierCurve3.prototype = Object.create(Curve.prototype);
  22450. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  22451. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  22452. CubicBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  22453. if (optionalTarget === void 0) {
  22454. optionalTarget = new Vector3();
  22455. }
  22456. var point = optionalTarget;
  22457. var v0 = this.v0,
  22458. v1 = this.v1,
  22459. v2 = this.v2,
  22460. v3 = this.v3;
  22461. 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));
  22462. return point;
  22463. };
  22464. CubicBezierCurve3.prototype.copy = function (source) {
  22465. Curve.prototype.copy.call(this, source);
  22466. this.v0.copy(source.v0);
  22467. this.v1.copy(source.v1);
  22468. this.v2.copy(source.v2);
  22469. this.v3.copy(source.v3);
  22470. return this;
  22471. };
  22472. CubicBezierCurve3.prototype.toJSON = function () {
  22473. var data = Curve.prototype.toJSON.call(this);
  22474. data.v0 = this.v0.toArray();
  22475. data.v1 = this.v1.toArray();
  22476. data.v2 = this.v2.toArray();
  22477. data.v3 = this.v3.toArray();
  22478. return data;
  22479. };
  22480. CubicBezierCurve3.prototype.fromJSON = function (json) {
  22481. Curve.prototype.fromJSON.call(this, json);
  22482. this.v0.fromArray(json.v0);
  22483. this.v1.fromArray(json.v1);
  22484. this.v2.fromArray(json.v2);
  22485. this.v3.fromArray(json.v3);
  22486. return this;
  22487. };
  22488. function LineCurve(v1, v2) {
  22489. if (v1 === void 0) {
  22490. v1 = new Vector2();
  22491. }
  22492. if (v2 === void 0) {
  22493. v2 = new Vector2();
  22494. }
  22495. Curve.call(this);
  22496. this.type = 'LineCurve';
  22497. this.v1 = v1;
  22498. this.v2 = v2;
  22499. }
  22500. LineCurve.prototype = Object.create(Curve.prototype);
  22501. LineCurve.prototype.constructor = LineCurve;
  22502. LineCurve.prototype.isLineCurve = true;
  22503. LineCurve.prototype.getPoint = function (t, optionalTarget) {
  22504. if (optionalTarget === void 0) {
  22505. optionalTarget = new Vector2();
  22506. }
  22507. var point = optionalTarget;
  22508. if (t === 1) {
  22509. point.copy(this.v2);
  22510. } else {
  22511. point.copy(this.v2).sub(this.v1);
  22512. point.multiplyScalar(t).add(this.v1);
  22513. }
  22514. return point;
  22515. }; // Line curve is linear, so we can overwrite default getPointAt
  22516. LineCurve.prototype.getPointAt = function (u, optionalTarget) {
  22517. return this.getPoint(u, optionalTarget);
  22518. };
  22519. LineCurve.prototype.getTangent = function (t, optionalTarget) {
  22520. var tangent = optionalTarget || new Vector2();
  22521. tangent.copy(this.v2).sub(this.v1).normalize();
  22522. return tangent;
  22523. };
  22524. LineCurve.prototype.copy = function (source) {
  22525. Curve.prototype.copy.call(this, source);
  22526. this.v1.copy(source.v1);
  22527. this.v2.copy(source.v2);
  22528. return this;
  22529. };
  22530. LineCurve.prototype.toJSON = function () {
  22531. var data = Curve.prototype.toJSON.call(this);
  22532. data.v1 = this.v1.toArray();
  22533. data.v2 = this.v2.toArray();
  22534. return data;
  22535. };
  22536. LineCurve.prototype.fromJSON = function (json) {
  22537. Curve.prototype.fromJSON.call(this, json);
  22538. this.v1.fromArray(json.v1);
  22539. this.v2.fromArray(json.v2);
  22540. return this;
  22541. };
  22542. function LineCurve3(v1, v2) {
  22543. if (v1 === void 0) {
  22544. v1 = new Vector3();
  22545. }
  22546. if (v2 === void 0) {
  22547. v2 = new Vector3();
  22548. }
  22549. Curve.call(this);
  22550. this.type = 'LineCurve3';
  22551. this.v1 = v1;
  22552. this.v2 = v2;
  22553. }
  22554. LineCurve3.prototype = Object.create(Curve.prototype);
  22555. LineCurve3.prototype.constructor = LineCurve3;
  22556. LineCurve3.prototype.isLineCurve3 = true;
  22557. LineCurve3.prototype.getPoint = function (t, optionalTarget) {
  22558. if (optionalTarget === void 0) {
  22559. optionalTarget = new Vector3();
  22560. }
  22561. var point = optionalTarget;
  22562. if (t === 1) {
  22563. point.copy(this.v2);
  22564. } else {
  22565. point.copy(this.v2).sub(this.v1);
  22566. point.multiplyScalar(t).add(this.v1);
  22567. }
  22568. return point;
  22569. }; // Line curve is linear, so we can overwrite default getPointAt
  22570. LineCurve3.prototype.getPointAt = function (u, optionalTarget) {
  22571. return this.getPoint(u, optionalTarget);
  22572. };
  22573. LineCurve3.prototype.copy = function (source) {
  22574. Curve.prototype.copy.call(this, source);
  22575. this.v1.copy(source.v1);
  22576. this.v2.copy(source.v2);
  22577. return this;
  22578. };
  22579. LineCurve3.prototype.toJSON = function () {
  22580. var data = Curve.prototype.toJSON.call(this);
  22581. data.v1 = this.v1.toArray();
  22582. data.v2 = this.v2.toArray();
  22583. return data;
  22584. };
  22585. LineCurve3.prototype.fromJSON = function (json) {
  22586. Curve.prototype.fromJSON.call(this, json);
  22587. this.v1.fromArray(json.v1);
  22588. this.v2.fromArray(json.v2);
  22589. return this;
  22590. };
  22591. function QuadraticBezierCurve(v0, v1, v2) {
  22592. if (v0 === void 0) {
  22593. v0 = new Vector2();
  22594. }
  22595. if (v1 === void 0) {
  22596. v1 = new Vector2();
  22597. }
  22598. if (v2 === void 0) {
  22599. v2 = new Vector2();
  22600. }
  22601. Curve.call(this);
  22602. this.type = 'QuadraticBezierCurve';
  22603. this.v0 = v0;
  22604. this.v1 = v1;
  22605. this.v2 = v2;
  22606. }
  22607. QuadraticBezierCurve.prototype = Object.create(Curve.prototype);
  22608. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  22609. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  22610. QuadraticBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  22611. if (optionalTarget === void 0) {
  22612. optionalTarget = new Vector2();
  22613. }
  22614. var point = optionalTarget;
  22615. var v0 = this.v0,
  22616. v1 = this.v1,
  22617. v2 = this.v2;
  22618. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  22619. return point;
  22620. };
  22621. QuadraticBezierCurve.prototype.copy = function (source) {
  22622. Curve.prototype.copy.call(this, source);
  22623. this.v0.copy(source.v0);
  22624. this.v1.copy(source.v1);
  22625. this.v2.copy(source.v2);
  22626. return this;
  22627. };
  22628. QuadraticBezierCurve.prototype.toJSON = function () {
  22629. var data = Curve.prototype.toJSON.call(this);
  22630. data.v0 = this.v0.toArray();
  22631. data.v1 = this.v1.toArray();
  22632. data.v2 = this.v2.toArray();
  22633. return data;
  22634. };
  22635. QuadraticBezierCurve.prototype.fromJSON = function (json) {
  22636. Curve.prototype.fromJSON.call(this, json);
  22637. this.v0.fromArray(json.v0);
  22638. this.v1.fromArray(json.v1);
  22639. this.v2.fromArray(json.v2);
  22640. return this;
  22641. };
  22642. function QuadraticBezierCurve3(v0, v1, v2) {
  22643. if (v0 === void 0) {
  22644. v0 = new Vector3();
  22645. }
  22646. if (v1 === void 0) {
  22647. v1 = new Vector3();
  22648. }
  22649. if (v2 === void 0) {
  22650. v2 = new Vector3();
  22651. }
  22652. Curve.call(this);
  22653. this.type = 'QuadraticBezierCurve3';
  22654. this.v0 = v0;
  22655. this.v1 = v1;
  22656. this.v2 = v2;
  22657. }
  22658. QuadraticBezierCurve3.prototype = Object.create(Curve.prototype);
  22659. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  22660. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  22661. QuadraticBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  22662. if (optionalTarget === void 0) {
  22663. optionalTarget = new Vector3();
  22664. }
  22665. var point = optionalTarget;
  22666. var v0 = this.v0,
  22667. v1 = this.v1,
  22668. v2 = this.v2;
  22669. 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));
  22670. return point;
  22671. };
  22672. QuadraticBezierCurve3.prototype.copy = function (source) {
  22673. Curve.prototype.copy.call(this, source);
  22674. this.v0.copy(source.v0);
  22675. this.v1.copy(source.v1);
  22676. this.v2.copy(source.v2);
  22677. return this;
  22678. };
  22679. QuadraticBezierCurve3.prototype.toJSON = function () {
  22680. var data = Curve.prototype.toJSON.call(this);
  22681. data.v0 = this.v0.toArray();
  22682. data.v1 = this.v1.toArray();
  22683. data.v2 = this.v2.toArray();
  22684. return data;
  22685. };
  22686. QuadraticBezierCurve3.prototype.fromJSON = function (json) {
  22687. Curve.prototype.fromJSON.call(this, json);
  22688. this.v0.fromArray(json.v0);
  22689. this.v1.fromArray(json.v1);
  22690. this.v2.fromArray(json.v2);
  22691. return this;
  22692. };
  22693. function SplineCurve(points) {
  22694. if (points === void 0) {
  22695. points = [];
  22696. }
  22697. Curve.call(this);
  22698. this.type = 'SplineCurve';
  22699. this.points = points;
  22700. }
  22701. SplineCurve.prototype = Object.create(Curve.prototype);
  22702. SplineCurve.prototype.constructor = SplineCurve;
  22703. SplineCurve.prototype.isSplineCurve = true;
  22704. SplineCurve.prototype.getPoint = function (t, optionalTarget) {
  22705. if (optionalTarget === void 0) {
  22706. optionalTarget = new Vector2();
  22707. }
  22708. var point = optionalTarget;
  22709. var points = this.points;
  22710. var p = (points.length - 1) * t;
  22711. var intPoint = Math.floor(p);
  22712. var weight = p - intPoint;
  22713. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  22714. var p1 = points[intPoint];
  22715. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  22716. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  22717. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  22718. return point;
  22719. };
  22720. SplineCurve.prototype.copy = function (source) {
  22721. Curve.prototype.copy.call(this, source);
  22722. this.points = [];
  22723. for (var i = 0, l = source.points.length; i < l; i++) {
  22724. var point = source.points[i];
  22725. this.points.push(point.clone());
  22726. }
  22727. return this;
  22728. };
  22729. SplineCurve.prototype.toJSON = function () {
  22730. var data = Curve.prototype.toJSON.call(this);
  22731. data.points = [];
  22732. for (var i = 0, l = this.points.length; i < l; i++) {
  22733. var point = this.points[i];
  22734. data.points.push(point.toArray());
  22735. }
  22736. return data;
  22737. };
  22738. SplineCurve.prototype.fromJSON = function (json) {
  22739. Curve.prototype.fromJSON.call(this, json);
  22740. this.points = [];
  22741. for (var i = 0, l = json.points.length; i < l; i++) {
  22742. var point = json.points[i];
  22743. this.points.push(new Vector2().fromArray(point));
  22744. }
  22745. return this;
  22746. };
  22747. var Curves = /*#__PURE__*/Object.freeze({
  22748. __proto__: null,
  22749. ArcCurve: ArcCurve,
  22750. CatmullRomCurve3: CatmullRomCurve3,
  22751. CubicBezierCurve: CubicBezierCurve,
  22752. CubicBezierCurve3: CubicBezierCurve3,
  22753. EllipseCurve: EllipseCurve,
  22754. LineCurve: LineCurve,
  22755. LineCurve3: LineCurve3,
  22756. QuadraticBezierCurve: QuadraticBezierCurve,
  22757. QuadraticBezierCurve3: QuadraticBezierCurve3,
  22758. SplineCurve: SplineCurve
  22759. });
  22760. /**************************************************************
  22761. * Curved Path - a curve path is simply a array of connected
  22762. * curves, but retains the api of a curve
  22763. **************************************************************/
  22764. function CurvePath() {
  22765. Curve.call(this);
  22766. this.type = 'CurvePath';
  22767. this.curves = [];
  22768. this.autoClose = false; // Automatically closes the path
  22769. }
  22770. CurvePath.prototype = Object.assign(Object.create(Curve.prototype), {
  22771. constructor: CurvePath,
  22772. add: function add(curve) {
  22773. this.curves.push(curve);
  22774. },
  22775. closePath: function closePath() {
  22776. // Add a line curve if start and end of lines are not connected
  22777. var startPoint = this.curves[0].getPoint(0);
  22778. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  22779. if (!startPoint.equals(endPoint)) {
  22780. this.curves.push(new LineCurve(endPoint, startPoint));
  22781. }
  22782. },
  22783. // To get accurate point with reference to
  22784. // entire path distance at time t,
  22785. // following has to be done:
  22786. // 1. Length of each sub path have to be known
  22787. // 2. Locate and identify type of curve
  22788. // 3. Get t for the curve
  22789. // 4. Return curve.getPointAt(t')
  22790. getPoint: function getPoint(t) {
  22791. var d = t * this.getLength();
  22792. var curveLengths = this.getCurveLengths();
  22793. var i = 0; // To think about boundaries points.
  22794. while (i < curveLengths.length) {
  22795. if (curveLengths[i] >= d) {
  22796. var diff = curveLengths[i] - d;
  22797. var curve = this.curves[i];
  22798. var segmentLength = curve.getLength();
  22799. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  22800. return curve.getPointAt(u);
  22801. }
  22802. i++;
  22803. }
  22804. return null; // loop where sum != 0, sum > d , sum+1 <d
  22805. },
  22806. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  22807. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  22808. // getPoint() depends on getLength
  22809. getLength: function getLength() {
  22810. var lens = this.getCurveLengths();
  22811. return lens[lens.length - 1];
  22812. },
  22813. // cacheLengths must be recalculated.
  22814. updateArcLengths: function updateArcLengths() {
  22815. this.needsUpdate = true;
  22816. this.cacheLengths = null;
  22817. this.getCurveLengths();
  22818. },
  22819. // Compute lengths and cache them
  22820. // We cannot overwrite getLengths() because UtoT mapping uses it.
  22821. getCurveLengths: function getCurveLengths() {
  22822. // We use cache values if curves and cache array are same length
  22823. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  22824. return this.cacheLengths;
  22825. } // Get length of sub-curve
  22826. // Push sums into cached array
  22827. var lengths = [];
  22828. var sums = 0;
  22829. for (var i = 0, l = this.curves.length; i < l; i++) {
  22830. sums += this.curves[i].getLength();
  22831. lengths.push(sums);
  22832. }
  22833. this.cacheLengths = lengths;
  22834. return lengths;
  22835. },
  22836. getSpacedPoints: function getSpacedPoints(divisions) {
  22837. if (divisions === void 0) {
  22838. divisions = 40;
  22839. }
  22840. var points = [];
  22841. for (var i = 0; i <= divisions; i++) {
  22842. points.push(this.getPoint(i / divisions));
  22843. }
  22844. if (this.autoClose) {
  22845. points.push(points[0]);
  22846. }
  22847. return points;
  22848. },
  22849. getPoints: function getPoints(divisions) {
  22850. if (divisions === void 0) {
  22851. divisions = 12;
  22852. }
  22853. var points = [];
  22854. var last;
  22855. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  22856. var curve = curves[i];
  22857. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  22858. var pts = curve.getPoints(resolution);
  22859. for (var j = 0; j < pts.length; j++) {
  22860. var point = pts[j];
  22861. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  22862. points.push(point);
  22863. last = point;
  22864. }
  22865. }
  22866. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  22867. points.push(points[0]);
  22868. }
  22869. return points;
  22870. },
  22871. copy: function copy(source) {
  22872. Curve.prototype.copy.call(this, source);
  22873. this.curves = [];
  22874. for (var i = 0, l = source.curves.length; i < l; i++) {
  22875. var curve = source.curves[i];
  22876. this.curves.push(curve.clone());
  22877. }
  22878. this.autoClose = source.autoClose;
  22879. return this;
  22880. },
  22881. toJSON: function toJSON() {
  22882. var data = Curve.prototype.toJSON.call(this);
  22883. data.autoClose = this.autoClose;
  22884. data.curves = [];
  22885. for (var i = 0, l = this.curves.length; i < l; i++) {
  22886. var curve = this.curves[i];
  22887. data.curves.push(curve.toJSON());
  22888. }
  22889. return data;
  22890. },
  22891. fromJSON: function fromJSON(json) {
  22892. Curve.prototype.fromJSON.call(this, json);
  22893. this.autoClose = json.autoClose;
  22894. this.curves = [];
  22895. for (var i = 0, l = json.curves.length; i < l; i++) {
  22896. var curve = json.curves[i];
  22897. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  22898. }
  22899. return this;
  22900. }
  22901. });
  22902. function Path(points) {
  22903. CurvePath.call(this);
  22904. this.type = 'Path';
  22905. this.currentPoint = new Vector2();
  22906. if (points) {
  22907. this.setFromPoints(points);
  22908. }
  22909. }
  22910. Path.prototype = Object.assign(Object.create(CurvePath.prototype), {
  22911. constructor: Path,
  22912. setFromPoints: function setFromPoints(points) {
  22913. this.moveTo(points[0].x, points[0].y);
  22914. for (var i = 1, l = points.length; i < l; i++) {
  22915. this.lineTo(points[i].x, points[i].y);
  22916. }
  22917. return this;
  22918. },
  22919. moveTo: function moveTo(x, y) {
  22920. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  22921. return this;
  22922. },
  22923. lineTo: function lineTo(x, y) {
  22924. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  22925. this.curves.push(curve);
  22926. this.currentPoint.set(x, y);
  22927. return this;
  22928. },
  22929. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  22930. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  22931. this.curves.push(curve);
  22932. this.currentPoint.set(aX, aY);
  22933. return this;
  22934. },
  22935. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  22936. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  22937. this.curves.push(curve);
  22938. this.currentPoint.set(aX, aY);
  22939. return this;
  22940. },
  22941. splineThru: function splineThru(pts
  22942. /*Array of Vector*/
  22943. ) {
  22944. var npts = [this.currentPoint.clone()].concat(pts);
  22945. var curve = new SplineCurve(npts);
  22946. this.curves.push(curve);
  22947. this.currentPoint.copy(pts[pts.length - 1]);
  22948. return this;
  22949. },
  22950. arc: function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22951. var x0 = this.currentPoint.x;
  22952. var y0 = this.currentPoint.y;
  22953. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  22954. return this;
  22955. },
  22956. absarc: function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22957. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  22958. return this;
  22959. },
  22960. ellipse: function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22961. var x0 = this.currentPoint.x;
  22962. var y0 = this.currentPoint.y;
  22963. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  22964. return this;
  22965. },
  22966. absellipse: function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22967. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  22968. if (this.curves.length > 0) {
  22969. // if a previous curve is present, attempt to join
  22970. var firstPoint = curve.getPoint(0);
  22971. if (!firstPoint.equals(this.currentPoint)) {
  22972. this.lineTo(firstPoint.x, firstPoint.y);
  22973. }
  22974. }
  22975. this.curves.push(curve);
  22976. var lastPoint = curve.getPoint(1);
  22977. this.currentPoint.copy(lastPoint);
  22978. return this;
  22979. },
  22980. copy: function copy(source) {
  22981. CurvePath.prototype.copy.call(this, source);
  22982. this.currentPoint.copy(source.currentPoint);
  22983. return this;
  22984. },
  22985. toJSON: function toJSON() {
  22986. var data = CurvePath.prototype.toJSON.call(this);
  22987. data.currentPoint = this.currentPoint.toArray();
  22988. return data;
  22989. },
  22990. fromJSON: function fromJSON(json) {
  22991. CurvePath.prototype.fromJSON.call(this, json);
  22992. this.currentPoint.fromArray(json.currentPoint);
  22993. return this;
  22994. }
  22995. });
  22996. function Shape(points) {
  22997. Path.call(this, points);
  22998. this.uuid = MathUtils.generateUUID();
  22999. this.type = 'Shape';
  23000. this.holes = [];
  23001. }
  23002. Shape.prototype = Object.assign(Object.create(Path.prototype), {
  23003. constructor: Shape,
  23004. getPointsHoles: function getPointsHoles(divisions) {
  23005. var holesPts = [];
  23006. for (var i = 0, l = this.holes.length; i < l; i++) {
  23007. holesPts[i] = this.holes[i].getPoints(divisions);
  23008. }
  23009. return holesPts;
  23010. },
  23011. // get points of shape and holes (keypoints based on segments parameter)
  23012. extractPoints: function extractPoints(divisions) {
  23013. return {
  23014. shape: this.getPoints(divisions),
  23015. holes: this.getPointsHoles(divisions)
  23016. };
  23017. },
  23018. copy: function copy(source) {
  23019. Path.prototype.copy.call(this, source);
  23020. this.holes = [];
  23021. for (var i = 0, l = source.holes.length; i < l; i++) {
  23022. var hole = source.holes[i];
  23023. this.holes.push(hole.clone());
  23024. }
  23025. return this;
  23026. },
  23027. toJSON: function toJSON() {
  23028. var data = Path.prototype.toJSON.call(this);
  23029. data.uuid = this.uuid;
  23030. data.holes = [];
  23031. for (var i = 0, l = this.holes.length; i < l; i++) {
  23032. var hole = this.holes[i];
  23033. data.holes.push(hole.toJSON());
  23034. }
  23035. return data;
  23036. },
  23037. fromJSON: function fromJSON(json) {
  23038. Path.prototype.fromJSON.call(this, json);
  23039. this.uuid = json.uuid;
  23040. this.holes = [];
  23041. for (var i = 0, l = json.holes.length; i < l; i++) {
  23042. var hole = json.holes[i];
  23043. this.holes.push(new Path().fromJSON(hole));
  23044. }
  23045. return this;
  23046. }
  23047. });
  23048. function Light(color, intensity) {
  23049. if (intensity === void 0) {
  23050. intensity = 1;
  23051. }
  23052. Object3D.call(this);
  23053. this.type = 'Light';
  23054. this.color = new Color(color);
  23055. this.intensity = intensity;
  23056. }
  23057. Light.prototype = Object.assign(Object.create(Object3D.prototype), {
  23058. constructor: Light,
  23059. isLight: true,
  23060. copy: function copy(source) {
  23061. Object3D.prototype.copy.call(this, source);
  23062. this.color.copy(source.color);
  23063. this.intensity = source.intensity;
  23064. return this;
  23065. },
  23066. toJSON: function toJSON(meta) {
  23067. var data = Object3D.prototype.toJSON.call(this, meta);
  23068. data.object.color = this.color.getHex();
  23069. data.object.intensity = this.intensity;
  23070. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  23071. if (this.distance !== undefined) data.object.distance = this.distance;
  23072. if (this.angle !== undefined) data.object.angle = this.angle;
  23073. if (this.decay !== undefined) data.object.decay = this.decay;
  23074. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  23075. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  23076. return data;
  23077. }
  23078. });
  23079. function HemisphereLight(skyColor, groundColor, intensity) {
  23080. Light.call(this, skyColor, intensity);
  23081. this.type = 'HemisphereLight';
  23082. this.position.copy(Object3D.DefaultUp);
  23083. this.updateMatrix();
  23084. this.groundColor = new Color(groundColor);
  23085. }
  23086. HemisphereLight.prototype = Object.assign(Object.create(Light.prototype), {
  23087. constructor: HemisphereLight,
  23088. isHemisphereLight: true,
  23089. copy: function copy(source) {
  23090. Light.prototype.copy.call(this, source);
  23091. this.groundColor.copy(source.groundColor);
  23092. return this;
  23093. }
  23094. });
  23095. function LightShadow(camera) {
  23096. this.camera = camera;
  23097. this.bias = 0;
  23098. this.normalBias = 0;
  23099. this.radius = 1;
  23100. this.mapSize = new Vector2(512, 512);
  23101. this.map = null;
  23102. this.mapPass = null;
  23103. this.matrix = new Matrix4();
  23104. this.autoUpdate = true;
  23105. this.needsUpdate = false;
  23106. this._frustum = new Frustum();
  23107. this._frameExtents = new Vector2(1, 1);
  23108. this._viewportCount = 1;
  23109. this._viewports = [new Vector4(0, 0, 1, 1)];
  23110. }
  23111. Object.assign(LightShadow.prototype, {
  23112. _projScreenMatrix: new Matrix4(),
  23113. _lightPositionWorld: new Vector3(),
  23114. _lookTarget: new Vector3(),
  23115. getViewportCount: function getViewportCount() {
  23116. return this._viewportCount;
  23117. },
  23118. getFrustum: function getFrustum() {
  23119. return this._frustum;
  23120. },
  23121. updateMatrices: function updateMatrices(light) {
  23122. var shadowCamera = this.camera,
  23123. shadowMatrix = this.matrix,
  23124. projScreenMatrix = this._projScreenMatrix,
  23125. lookTarget = this._lookTarget,
  23126. lightPositionWorld = this._lightPositionWorld;
  23127. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23128. shadowCamera.position.copy(lightPositionWorld);
  23129. lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  23130. shadowCamera.lookAt(lookTarget);
  23131. shadowCamera.updateMatrixWorld();
  23132. projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  23133. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23134. 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);
  23135. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  23136. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  23137. },
  23138. getViewport: function getViewport(viewportIndex) {
  23139. return this._viewports[viewportIndex];
  23140. },
  23141. getFrameExtents: function getFrameExtents() {
  23142. return this._frameExtents;
  23143. },
  23144. copy: function copy(source) {
  23145. this.camera = source.camera.clone();
  23146. this.bias = source.bias;
  23147. this.radius = source.radius;
  23148. this.mapSize.copy(source.mapSize);
  23149. return this;
  23150. },
  23151. clone: function clone() {
  23152. return new this.constructor().copy(this);
  23153. },
  23154. toJSON: function toJSON() {
  23155. var object = {};
  23156. if (this.bias !== 0) object.bias = this.bias;
  23157. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  23158. if (this.radius !== 1) object.radius = this.radius;
  23159. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  23160. object.camera = this.camera.toJSON(false).object;
  23161. delete object.camera.matrix;
  23162. return object;
  23163. }
  23164. });
  23165. function SpotLightShadow() {
  23166. LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500));
  23167. this.focus = 1;
  23168. }
  23169. SpotLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23170. constructor: SpotLightShadow,
  23171. isSpotLightShadow: true,
  23172. updateMatrices: function updateMatrices(light) {
  23173. var camera = this.camera;
  23174. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23175. var aspect = this.mapSize.width / this.mapSize.height;
  23176. var far = light.distance || camera.far;
  23177. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  23178. camera.fov = fov;
  23179. camera.aspect = aspect;
  23180. camera.far = far;
  23181. camera.updateProjectionMatrix();
  23182. }
  23183. LightShadow.prototype.updateMatrices.call(this, light);
  23184. }
  23185. });
  23186. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  23187. Light.call(this, color, intensity);
  23188. this.type = 'SpotLight';
  23189. this.position.copy(Object3D.DefaultUp);
  23190. this.updateMatrix();
  23191. this.target = new Object3D();
  23192. Object.defineProperty(this, 'power', {
  23193. get: function get() {
  23194. // intensity = power per solid angle.
  23195. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23196. return this.intensity * Math.PI;
  23197. },
  23198. set: function set(power) {
  23199. // intensity = power per solid angle.
  23200. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23201. this.intensity = power / Math.PI;
  23202. }
  23203. });
  23204. this.distance = distance !== undefined ? distance : 0;
  23205. this.angle = angle !== undefined ? angle : Math.PI / 3;
  23206. this.penumbra = penumbra !== undefined ? penumbra : 0;
  23207. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23208. this.shadow = new SpotLightShadow();
  23209. }
  23210. SpotLight.prototype = Object.assign(Object.create(Light.prototype), {
  23211. constructor: SpotLight,
  23212. isSpotLight: true,
  23213. copy: function copy(source) {
  23214. Light.prototype.copy.call(this, source);
  23215. this.distance = source.distance;
  23216. this.angle = source.angle;
  23217. this.penumbra = source.penumbra;
  23218. this.decay = source.decay;
  23219. this.target = source.target.clone();
  23220. this.shadow = source.shadow.clone();
  23221. return this;
  23222. }
  23223. });
  23224. function PointLightShadow() {
  23225. LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500));
  23226. this._frameExtents = new Vector2(4, 2);
  23227. this._viewportCount = 6;
  23228. this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  23229. // following orientation:
  23230. //
  23231. // xzXZ
  23232. // y Y
  23233. //
  23234. // X - Positive x direction
  23235. // x - Negative x direction
  23236. // Y - Positive y direction
  23237. // y - Negative y direction
  23238. // Z - Positive z direction
  23239. // z - Negative z direction
  23240. // positive X
  23241. new Vector4(2, 1, 1, 1), // negative X
  23242. new Vector4(0, 1, 1, 1), // positive Z
  23243. new Vector4(3, 1, 1, 1), // negative Z
  23244. new Vector4(1, 1, 1, 1), // positive Y
  23245. new Vector4(3, 0, 1, 1), // negative Y
  23246. new Vector4(1, 0, 1, 1)];
  23247. 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)];
  23248. 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)];
  23249. }
  23250. PointLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23251. constructor: PointLightShadow,
  23252. isPointLightShadow: true,
  23253. updateMatrices: function updateMatrices(light, viewportIndex) {
  23254. if (viewportIndex === void 0) {
  23255. viewportIndex = 0;
  23256. }
  23257. var camera = this.camera,
  23258. shadowMatrix = this.matrix,
  23259. lightPositionWorld = this._lightPositionWorld,
  23260. lookTarget = this._lookTarget,
  23261. projScreenMatrix = this._projScreenMatrix;
  23262. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23263. camera.position.copy(lightPositionWorld);
  23264. lookTarget.copy(camera.position);
  23265. lookTarget.add(this._cubeDirections[viewportIndex]);
  23266. camera.up.copy(this._cubeUps[viewportIndex]);
  23267. camera.lookAt(lookTarget);
  23268. camera.updateMatrixWorld();
  23269. shadowMatrix.makeTranslation(-lightPositionWorld.x, -lightPositionWorld.y, -lightPositionWorld.z);
  23270. projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  23271. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23272. }
  23273. });
  23274. function PointLight(color, intensity, distance, decay) {
  23275. Light.call(this, color, intensity);
  23276. this.type = 'PointLight';
  23277. Object.defineProperty(this, 'power', {
  23278. get: function get() {
  23279. // intensity = power per solid angle.
  23280. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23281. return this.intensity * 4 * Math.PI;
  23282. },
  23283. set: function set(power) {
  23284. // intensity = power per solid angle.
  23285. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23286. this.intensity = power / (4 * Math.PI);
  23287. }
  23288. });
  23289. this.distance = distance !== undefined ? distance : 0;
  23290. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23291. this.shadow = new PointLightShadow();
  23292. }
  23293. PointLight.prototype = Object.assign(Object.create(Light.prototype), {
  23294. constructor: PointLight,
  23295. isPointLight: true,
  23296. copy: function copy(source) {
  23297. Light.prototype.copy.call(this, source);
  23298. this.distance = source.distance;
  23299. this.decay = source.decay;
  23300. this.shadow = source.shadow.clone();
  23301. return this;
  23302. }
  23303. });
  23304. function OrthographicCamera(left, right, top, bottom, near, far) {
  23305. if (left === void 0) {
  23306. left = -1;
  23307. }
  23308. if (right === void 0) {
  23309. right = 1;
  23310. }
  23311. if (top === void 0) {
  23312. top = 1;
  23313. }
  23314. if (bottom === void 0) {
  23315. bottom = -1;
  23316. }
  23317. if (near === void 0) {
  23318. near = 0.1;
  23319. }
  23320. if (far === void 0) {
  23321. far = 2000;
  23322. }
  23323. Camera.call(this);
  23324. this.type = 'OrthographicCamera';
  23325. this.zoom = 1;
  23326. this.view = null;
  23327. this.left = left;
  23328. this.right = right;
  23329. this.top = top;
  23330. this.bottom = bottom;
  23331. this.near = near;
  23332. this.far = far;
  23333. this.updateProjectionMatrix();
  23334. }
  23335. OrthographicCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  23336. constructor: OrthographicCamera,
  23337. isOrthographicCamera: true,
  23338. copy: function copy(source, recursive) {
  23339. Camera.prototype.copy.call(this, source, recursive);
  23340. this.left = source.left;
  23341. this.right = source.right;
  23342. this.top = source.top;
  23343. this.bottom = source.bottom;
  23344. this.near = source.near;
  23345. this.far = source.far;
  23346. this.zoom = source.zoom;
  23347. this.view = source.view === null ? null : Object.assign({}, source.view);
  23348. return this;
  23349. },
  23350. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  23351. if (this.view === null) {
  23352. this.view = {
  23353. enabled: true,
  23354. fullWidth: 1,
  23355. fullHeight: 1,
  23356. offsetX: 0,
  23357. offsetY: 0,
  23358. width: 1,
  23359. height: 1
  23360. };
  23361. }
  23362. this.view.enabled = true;
  23363. this.view.fullWidth = fullWidth;
  23364. this.view.fullHeight = fullHeight;
  23365. this.view.offsetX = x;
  23366. this.view.offsetY = y;
  23367. this.view.width = width;
  23368. this.view.height = height;
  23369. this.updateProjectionMatrix();
  23370. },
  23371. clearViewOffset: function clearViewOffset() {
  23372. if (this.view !== null) {
  23373. this.view.enabled = false;
  23374. }
  23375. this.updateProjectionMatrix();
  23376. },
  23377. updateProjectionMatrix: function updateProjectionMatrix() {
  23378. var dx = (this.right - this.left) / (2 * this.zoom);
  23379. var dy = (this.top - this.bottom) / (2 * this.zoom);
  23380. var cx = (this.right + this.left) / 2;
  23381. var cy = (this.top + this.bottom) / 2;
  23382. var left = cx - dx;
  23383. var right = cx + dx;
  23384. var top = cy + dy;
  23385. var bottom = cy - dy;
  23386. if (this.view !== null && this.view.enabled) {
  23387. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  23388. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  23389. left += scaleW * this.view.offsetX;
  23390. right = left + scaleW * this.view.width;
  23391. top -= scaleH * this.view.offsetY;
  23392. bottom = top - scaleH * this.view.height;
  23393. }
  23394. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  23395. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  23396. },
  23397. toJSON: function toJSON(meta) {
  23398. var data = Object3D.prototype.toJSON.call(this, meta);
  23399. data.object.zoom = this.zoom;
  23400. data.object.left = this.left;
  23401. data.object.right = this.right;
  23402. data.object.top = this.top;
  23403. data.object.bottom = this.bottom;
  23404. data.object.near = this.near;
  23405. data.object.far = this.far;
  23406. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  23407. return data;
  23408. }
  23409. });
  23410. function DirectionalLightShadow() {
  23411. LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500));
  23412. }
  23413. DirectionalLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23414. constructor: DirectionalLightShadow,
  23415. isDirectionalLightShadow: true,
  23416. updateMatrices: function updateMatrices(light) {
  23417. LightShadow.prototype.updateMatrices.call(this, light);
  23418. }
  23419. });
  23420. function DirectionalLight(color, intensity) {
  23421. Light.call(this, color, intensity);
  23422. this.type = 'DirectionalLight';
  23423. this.position.copy(Object3D.DefaultUp);
  23424. this.updateMatrix();
  23425. this.target = new Object3D();
  23426. this.shadow = new DirectionalLightShadow();
  23427. }
  23428. DirectionalLight.prototype = Object.assign(Object.create(Light.prototype), {
  23429. constructor: DirectionalLight,
  23430. isDirectionalLight: true,
  23431. copy: function copy(source) {
  23432. Light.prototype.copy.call(this, source);
  23433. this.target = source.target.clone();
  23434. this.shadow = source.shadow.clone();
  23435. return this;
  23436. }
  23437. });
  23438. function AmbientLight(color, intensity) {
  23439. Light.call(this, color, intensity);
  23440. this.type = 'AmbientLight';
  23441. }
  23442. AmbientLight.prototype = Object.assign(Object.create(Light.prototype), {
  23443. constructor: AmbientLight,
  23444. isAmbientLight: true
  23445. });
  23446. function RectAreaLight(color, intensity, width, height) {
  23447. Light.call(this, color, intensity);
  23448. this.type = 'RectAreaLight';
  23449. this.width = width !== undefined ? width : 10;
  23450. this.height = height !== undefined ? height : 10;
  23451. }
  23452. RectAreaLight.prototype = Object.assign(Object.create(Light.prototype), {
  23453. constructor: RectAreaLight,
  23454. isRectAreaLight: true,
  23455. copy: function copy(source) {
  23456. Light.prototype.copy.call(this, source);
  23457. this.width = source.width;
  23458. this.height = source.height;
  23459. return this;
  23460. },
  23461. toJSON: function toJSON(meta) {
  23462. var data = Light.prototype.toJSON.call(this, meta);
  23463. data.object.width = this.width;
  23464. data.object.height = this.height;
  23465. return data;
  23466. }
  23467. });
  23468. /**
  23469. * Primary reference:
  23470. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23471. *
  23472. * Secondary reference:
  23473. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23474. */
  23475. // 3-band SH defined by 9 coefficients
  23476. var SphericalHarmonics3 = /*#__PURE__*/function () {
  23477. function SphericalHarmonics3() {
  23478. Object.defineProperty(this, 'isSphericalHarmonics3', {
  23479. value: true
  23480. });
  23481. this.coefficients = [];
  23482. for (var i = 0; i < 9; i++) {
  23483. this.coefficients.push(new Vector3());
  23484. }
  23485. }
  23486. var _proto = SphericalHarmonics3.prototype;
  23487. _proto.set = function set(coefficients) {
  23488. for (var i = 0; i < 9; i++) {
  23489. this.coefficients[i].copy(coefficients[i]);
  23490. }
  23491. return this;
  23492. };
  23493. _proto.zero = function zero() {
  23494. for (var i = 0; i < 9; i++) {
  23495. this.coefficients[i].set(0, 0, 0);
  23496. }
  23497. return this;
  23498. } // get the radiance in the direction of the normal
  23499. // target is a Vector3
  23500. ;
  23501. _proto.getAt = function getAt(normal, target) {
  23502. // normal is assumed to be unit length
  23503. var x = normal.x,
  23504. y = normal.y,
  23505. z = normal.z;
  23506. var coeff = this.coefficients; // band 0
  23507. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  23508. target.addScaledVector(coeff[1], 0.488603 * y);
  23509. target.addScaledVector(coeff[2], 0.488603 * z);
  23510. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  23511. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  23512. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  23513. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  23514. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  23515. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  23516. return target;
  23517. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23518. // target is a Vector3
  23519. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23520. ;
  23521. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  23522. // normal is assumed to be unit length
  23523. var x = normal.x,
  23524. y = normal.y,
  23525. z = normal.z;
  23526. var coeff = this.coefficients; // band 0
  23527. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  23528. // band 1
  23529. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  23530. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  23531. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  23532. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  23533. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  23534. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  23535. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  23536. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  23537. return target;
  23538. };
  23539. _proto.add = function add(sh) {
  23540. for (var i = 0; i < 9; i++) {
  23541. this.coefficients[i].add(sh.coefficients[i]);
  23542. }
  23543. return this;
  23544. };
  23545. _proto.addScaledSH = function addScaledSH(sh, s) {
  23546. for (var i = 0; i < 9; i++) {
  23547. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  23548. }
  23549. return this;
  23550. };
  23551. _proto.scale = function scale(s) {
  23552. for (var i = 0; i < 9; i++) {
  23553. this.coefficients[i].multiplyScalar(s);
  23554. }
  23555. return this;
  23556. };
  23557. _proto.lerp = function lerp(sh, alpha) {
  23558. for (var i = 0; i < 9; i++) {
  23559. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  23560. }
  23561. return this;
  23562. };
  23563. _proto.equals = function equals(sh) {
  23564. for (var i = 0; i < 9; i++) {
  23565. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  23566. return false;
  23567. }
  23568. }
  23569. return true;
  23570. };
  23571. _proto.copy = function copy(sh) {
  23572. return this.set(sh.coefficients);
  23573. };
  23574. _proto.clone = function clone() {
  23575. return new this.constructor().copy(this);
  23576. };
  23577. _proto.fromArray = function fromArray(array, offset) {
  23578. if (offset === void 0) {
  23579. offset = 0;
  23580. }
  23581. var coefficients = this.coefficients;
  23582. for (var i = 0; i < 9; i++) {
  23583. coefficients[i].fromArray(array, offset + i * 3);
  23584. }
  23585. return this;
  23586. };
  23587. _proto.toArray = function toArray(array, offset) {
  23588. if (array === void 0) {
  23589. array = [];
  23590. }
  23591. if (offset === void 0) {
  23592. offset = 0;
  23593. }
  23594. var coefficients = this.coefficients;
  23595. for (var i = 0; i < 9; i++) {
  23596. coefficients[i].toArray(array, offset + i * 3);
  23597. }
  23598. return array;
  23599. } // evaluate the basis functions
  23600. // shBasis is an Array[ 9 ]
  23601. ;
  23602. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  23603. // normal is assumed to be unit length
  23604. var x = normal.x,
  23605. y = normal.y,
  23606. z = normal.z; // band 0
  23607. shBasis[0] = 0.282095; // band 1
  23608. shBasis[1] = 0.488603 * y;
  23609. shBasis[2] = 0.488603 * z;
  23610. shBasis[3] = 0.488603 * x; // band 2
  23611. shBasis[4] = 1.092548 * x * y;
  23612. shBasis[5] = 1.092548 * y * z;
  23613. shBasis[6] = 0.315392 * (3 * z * z - 1);
  23614. shBasis[7] = 1.092548 * x * z;
  23615. shBasis[8] = 0.546274 * (x * x - y * y);
  23616. };
  23617. return SphericalHarmonics3;
  23618. }();
  23619. function LightProbe(sh, intensity) {
  23620. Light.call(this, undefined, intensity);
  23621. this.type = 'LightProbe';
  23622. this.sh = sh !== undefined ? sh : new SphericalHarmonics3();
  23623. }
  23624. LightProbe.prototype = Object.assign(Object.create(Light.prototype), {
  23625. constructor: LightProbe,
  23626. isLightProbe: true,
  23627. copy: function copy(source) {
  23628. Light.prototype.copy.call(this, source);
  23629. this.sh.copy(source.sh);
  23630. return this;
  23631. },
  23632. fromJSON: function fromJSON(json) {
  23633. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  23634. this.sh.fromArray(json.sh);
  23635. return this;
  23636. },
  23637. toJSON: function toJSON(meta) {
  23638. var data = Light.prototype.toJSON.call(this, meta);
  23639. data.object.sh = this.sh.toArray();
  23640. return data;
  23641. }
  23642. });
  23643. function MaterialLoader(manager) {
  23644. Loader.call(this, manager);
  23645. this.textures = {};
  23646. }
  23647. MaterialLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  23648. constructor: MaterialLoader,
  23649. load: function load(url, onLoad, onProgress, onError) {
  23650. var scope = this;
  23651. var loader = new FileLoader(scope.manager);
  23652. loader.setPath(scope.path);
  23653. loader.setRequestHeader(scope.requestHeader);
  23654. loader.setWithCredentials(scope.withCredentials);
  23655. loader.load(url, function (text) {
  23656. try {
  23657. onLoad(scope.parse(JSON.parse(text)));
  23658. } catch (e) {
  23659. if (onError) {
  23660. onError(e);
  23661. } else {
  23662. console.error(e);
  23663. }
  23664. scope.manager.itemError(url);
  23665. }
  23666. }, onProgress, onError);
  23667. },
  23668. parse: function parse(json) {
  23669. var textures = this.textures;
  23670. function getTexture(name) {
  23671. if (textures[name] === undefined) {
  23672. console.warn('THREE.MaterialLoader: Undefined texture', name);
  23673. }
  23674. return textures[name];
  23675. }
  23676. var material = new Materials[json.type]();
  23677. if (json.uuid !== undefined) material.uuid = json.uuid;
  23678. if (json.name !== undefined) material.name = json.name;
  23679. if (json.color !== undefined && material.color !== undefined) material.color.setHex(json.color);
  23680. if (json.roughness !== undefined) material.roughness = json.roughness;
  23681. if (json.metalness !== undefined) material.metalness = json.metalness;
  23682. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  23683. if (json.emissive !== undefined && material.emissive !== undefined) material.emissive.setHex(json.emissive);
  23684. if (json.specular !== undefined && material.specular !== undefined) material.specular.setHex(json.specular);
  23685. if (json.shininess !== undefined) material.shininess = json.shininess;
  23686. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  23687. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  23688. if (json.fog !== undefined) material.fog = json.fog;
  23689. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  23690. if (json.blending !== undefined) material.blending = json.blending;
  23691. if (json.combine !== undefined) material.combine = json.combine;
  23692. if (json.side !== undefined) material.side = json.side;
  23693. if (json.opacity !== undefined) material.opacity = json.opacity;
  23694. if (json.transparent !== undefined) material.transparent = json.transparent;
  23695. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  23696. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  23697. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  23698. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  23699. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  23700. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  23701. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  23702. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  23703. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  23704. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  23705. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  23706. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  23707. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  23708. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  23709. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  23710. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  23711. if (json.rotation !== undefined) material.rotation = json.rotation;
  23712. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  23713. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  23714. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  23715. if (json.scale !== undefined) material.scale = json.scale;
  23716. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  23717. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  23718. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  23719. if (json.skinning !== undefined) material.skinning = json.skinning;
  23720. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  23721. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  23722. if (json.dithering !== undefined) material.dithering = json.dithering;
  23723. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  23724. if (json.visible !== undefined) material.visible = json.visible;
  23725. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  23726. if (json.userData !== undefined) material.userData = json.userData;
  23727. if (json.vertexColors !== undefined) {
  23728. if (typeof json.vertexColors === 'number') {
  23729. material.vertexColors = json.vertexColors > 0 ? true : false;
  23730. } else {
  23731. material.vertexColors = json.vertexColors;
  23732. }
  23733. } // Shader Material
  23734. if (json.uniforms !== undefined) {
  23735. for (var name in json.uniforms) {
  23736. var uniform = json.uniforms[name];
  23737. material.uniforms[name] = {};
  23738. switch (uniform.type) {
  23739. case 't':
  23740. material.uniforms[name].value = getTexture(uniform.value);
  23741. break;
  23742. case 'c':
  23743. material.uniforms[name].value = new Color().setHex(uniform.value);
  23744. break;
  23745. case 'v2':
  23746. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  23747. break;
  23748. case 'v3':
  23749. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  23750. break;
  23751. case 'v4':
  23752. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  23753. break;
  23754. case 'm3':
  23755. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  23756. break;
  23757. case 'm4':
  23758. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  23759. break;
  23760. default:
  23761. material.uniforms[name].value = uniform.value;
  23762. }
  23763. }
  23764. }
  23765. if (json.defines !== undefined) material.defines = json.defines;
  23766. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  23767. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  23768. if (json.extensions !== undefined) {
  23769. for (var key in json.extensions) {
  23770. material.extensions[key] = json.extensions[key];
  23771. }
  23772. } // Deprecated
  23773. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  23774. // for PointsMaterial
  23775. if (json.size !== undefined) material.size = json.size;
  23776. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  23777. if (json.map !== undefined) material.map = getTexture(json.map);
  23778. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  23779. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  23780. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  23781. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  23782. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  23783. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  23784. if (json.normalScale !== undefined) {
  23785. var normalScale = json.normalScale;
  23786. if (Array.isArray(normalScale) === false) {
  23787. // Blender exporter used to export a scalar. See #7459
  23788. normalScale = [normalScale, normalScale];
  23789. }
  23790. material.normalScale = new Vector2().fromArray(normalScale);
  23791. }
  23792. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  23793. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  23794. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  23795. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  23796. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  23797. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  23798. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  23799. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  23800. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  23801. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  23802. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  23803. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  23804. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  23805. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  23806. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  23807. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  23808. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  23809. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  23810. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  23811. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  23812. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  23813. if (json.transmission !== undefined) material.transmission = json.transmission;
  23814. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  23815. return material;
  23816. },
  23817. setTextures: function setTextures(value) {
  23818. this.textures = value;
  23819. return this;
  23820. }
  23821. });
  23822. var LoaderUtils = {
  23823. decodeText: function decodeText(array) {
  23824. if (typeof TextDecoder !== 'undefined') {
  23825. return new TextDecoder().decode(array);
  23826. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  23827. // throws a "maximum call stack size exceeded" error for large arrays.
  23828. var s = '';
  23829. for (var i = 0, il = array.length; i < il; i++) {
  23830. // Implicitly assumes little-endian.
  23831. s += String.fromCharCode(array[i]);
  23832. }
  23833. try {
  23834. // merges multi-byte utf-8 characters.
  23835. return decodeURIComponent(escape(s));
  23836. } catch (e) {
  23837. // see #16358
  23838. return s;
  23839. }
  23840. },
  23841. extractUrlBase: function extractUrlBase(url) {
  23842. var index = url.lastIndexOf('/');
  23843. if (index === -1) return './';
  23844. return url.substr(0, index + 1);
  23845. }
  23846. };
  23847. function InstancedBufferGeometry() {
  23848. BufferGeometry.call(this);
  23849. this.type = 'InstancedBufferGeometry';
  23850. this.instanceCount = Infinity;
  23851. }
  23852. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  23853. constructor: InstancedBufferGeometry,
  23854. isInstancedBufferGeometry: true,
  23855. copy: function copy(source) {
  23856. BufferGeometry.prototype.copy.call(this, source);
  23857. this.instanceCount = source.instanceCount;
  23858. return this;
  23859. },
  23860. clone: function clone() {
  23861. return new this.constructor().copy(this);
  23862. },
  23863. toJSON: function toJSON() {
  23864. var data = BufferGeometry.prototype.toJSON.call(this);
  23865. data.instanceCount = this.instanceCount;
  23866. data.isInstancedBufferGeometry = true;
  23867. return data;
  23868. }
  23869. });
  23870. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  23871. if (typeof normalized === 'number') {
  23872. meshPerAttribute = normalized;
  23873. normalized = false;
  23874. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  23875. }
  23876. BufferAttribute.call(this, array, itemSize, normalized);
  23877. this.meshPerAttribute = meshPerAttribute || 1;
  23878. }
  23879. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  23880. constructor: InstancedBufferAttribute,
  23881. isInstancedBufferAttribute: true,
  23882. copy: function copy(source) {
  23883. BufferAttribute.prototype.copy.call(this, source);
  23884. this.meshPerAttribute = source.meshPerAttribute;
  23885. return this;
  23886. },
  23887. toJSON: function toJSON() {
  23888. var data = BufferAttribute.prototype.toJSON.call(this);
  23889. data.meshPerAttribute = this.meshPerAttribute;
  23890. data.isInstancedBufferAttribute = true;
  23891. return data;
  23892. }
  23893. });
  23894. function BufferGeometryLoader(manager) {
  23895. Loader.call(this, manager);
  23896. }
  23897. BufferGeometryLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  23898. constructor: BufferGeometryLoader,
  23899. load: function load(url, onLoad, onProgress, onError) {
  23900. var scope = this;
  23901. var loader = new FileLoader(scope.manager);
  23902. loader.setPath(scope.path);
  23903. loader.setRequestHeader(scope.requestHeader);
  23904. loader.setWithCredentials(scope.withCredentials);
  23905. loader.load(url, function (text) {
  23906. try {
  23907. onLoad(scope.parse(JSON.parse(text)));
  23908. } catch (e) {
  23909. if (onError) {
  23910. onError(e);
  23911. } else {
  23912. console.error(e);
  23913. }
  23914. scope.manager.itemError(url);
  23915. }
  23916. }, onProgress, onError);
  23917. },
  23918. parse: function parse(json) {
  23919. var interleavedBufferMap = {};
  23920. var arrayBufferMap = {};
  23921. function getInterleavedBuffer(json, uuid) {
  23922. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  23923. var interleavedBuffers = json.interleavedBuffers;
  23924. var interleavedBuffer = interleavedBuffers[uuid];
  23925. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  23926. var array = getTypedArray(interleavedBuffer.type, buffer);
  23927. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  23928. ib.uuid = interleavedBuffer.uuid;
  23929. interleavedBufferMap[uuid] = ib;
  23930. return ib;
  23931. }
  23932. function getArrayBuffer(json, uuid) {
  23933. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  23934. var arrayBuffers = json.arrayBuffers;
  23935. var arrayBuffer = arrayBuffers[uuid];
  23936. var ab = new Uint32Array(arrayBuffer).buffer;
  23937. arrayBufferMap[uuid] = ab;
  23938. return ab;
  23939. }
  23940. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  23941. var index = json.data.index;
  23942. if (index !== undefined) {
  23943. var typedArray = getTypedArray(index.type, index.array);
  23944. geometry.setIndex(new BufferAttribute(typedArray, 1));
  23945. }
  23946. var attributes = json.data.attributes;
  23947. for (var key in attributes) {
  23948. var attribute = attributes[key];
  23949. var bufferAttribute = void 0;
  23950. if (attribute.isInterleavedBufferAttribute) {
  23951. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  23952. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  23953. } else {
  23954. var _typedArray = getTypedArray(attribute.type, attribute.array);
  23955. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  23956. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  23957. }
  23958. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  23959. geometry.setAttribute(key, bufferAttribute);
  23960. }
  23961. var morphAttributes = json.data.morphAttributes;
  23962. if (morphAttributes) {
  23963. for (var _key in morphAttributes) {
  23964. var attributeArray = morphAttributes[_key];
  23965. var array = [];
  23966. for (var i = 0, il = attributeArray.length; i < il; i++) {
  23967. var _attribute = attributeArray[i];
  23968. var _bufferAttribute = void 0;
  23969. if (_attribute.isInterleavedBufferAttribute) {
  23970. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  23971. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  23972. } else {
  23973. var _typedArray2 = getTypedArray(_attribute.type, _attribute.array);
  23974. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  23975. }
  23976. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  23977. array.push(_bufferAttribute);
  23978. }
  23979. geometry.morphAttributes[_key] = array;
  23980. }
  23981. }
  23982. var morphTargetsRelative = json.data.morphTargetsRelative;
  23983. if (morphTargetsRelative) {
  23984. geometry.morphTargetsRelative = true;
  23985. }
  23986. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  23987. if (groups !== undefined) {
  23988. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  23989. var group = groups[_i];
  23990. geometry.addGroup(group.start, group.count, group.materialIndex);
  23991. }
  23992. }
  23993. var boundingSphere = json.data.boundingSphere;
  23994. if (boundingSphere !== undefined) {
  23995. var center = new Vector3();
  23996. if (boundingSphere.center !== undefined) {
  23997. center.fromArray(boundingSphere.center);
  23998. }
  23999. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  24000. }
  24001. if (json.name) geometry.name = json.name;
  24002. if (json.userData) geometry.userData = json.userData;
  24003. return geometry;
  24004. }
  24005. });
  24006. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  24007. _inheritsLoose(ObjectLoader, _Loader);
  24008. function ObjectLoader(manager) {
  24009. return _Loader.call(this, manager) || this;
  24010. }
  24011. var _proto = ObjectLoader.prototype;
  24012. _proto.load = function load(url, onLoad, onProgress, onError) {
  24013. var scope = this;
  24014. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  24015. this.resourcePath = this.resourcePath || path;
  24016. var loader = new FileLoader(this.manager);
  24017. loader.setPath(this.path);
  24018. loader.setRequestHeader(this.requestHeader);
  24019. loader.setWithCredentials(this.withCredentials);
  24020. loader.load(url, function (text) {
  24021. var json = null;
  24022. try {
  24023. json = JSON.parse(text);
  24024. } catch (error) {
  24025. if (onError !== undefined) onError(error);
  24026. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  24027. return;
  24028. }
  24029. var metadata = json.metadata;
  24030. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  24031. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  24032. return;
  24033. }
  24034. scope.parse(json, onLoad);
  24035. }, onProgress, onError);
  24036. };
  24037. _proto.parse = function parse(json, onLoad) {
  24038. var animations = this.parseAnimations(json.animations);
  24039. var shapes = this.parseShapes(json.shapes);
  24040. var geometries = this.parseGeometries(json.geometries, shapes);
  24041. var images = this.parseImages(json.images, function () {
  24042. if (onLoad !== undefined) onLoad(object);
  24043. });
  24044. var textures = this.parseTextures(json.textures, images);
  24045. var materials = this.parseMaterials(json.materials, textures);
  24046. var object = this.parseObject(json.object, geometries, materials, animations);
  24047. var skeletons = this.parseSkeletons(json.skeletons, object);
  24048. this.bindSkeletons(object, skeletons); //
  24049. if (onLoad !== undefined) {
  24050. var hasImages = false;
  24051. for (var uuid in images) {
  24052. if (images[uuid] instanceof HTMLImageElement) {
  24053. hasImages = true;
  24054. break;
  24055. }
  24056. }
  24057. if (hasImages === false) onLoad(object);
  24058. }
  24059. return object;
  24060. };
  24061. _proto.parseShapes = function parseShapes(json) {
  24062. var shapes = {};
  24063. if (json !== undefined) {
  24064. for (var i = 0, l = json.length; i < l; i++) {
  24065. var shape = new Shape().fromJSON(json[i]);
  24066. shapes[shape.uuid] = shape;
  24067. }
  24068. }
  24069. return shapes;
  24070. };
  24071. _proto.parseSkeletons = function parseSkeletons(json, object) {
  24072. var skeletons = {};
  24073. var bones = {}; // generate bone lookup table
  24074. object.traverse(function (child) {
  24075. if (child.isBone) bones[child.uuid] = child;
  24076. }); // create skeletons
  24077. if (json !== undefined) {
  24078. for (var i = 0, l = json.length; i < l; i++) {
  24079. var skeleton = new Skeleton().fromJSON(json[i], bones);
  24080. skeletons[skeleton.uuid] = skeleton;
  24081. }
  24082. }
  24083. return skeletons;
  24084. };
  24085. _proto.parseGeometries = function parseGeometries(json, shapes) {
  24086. var geometries = {};
  24087. var geometryShapes;
  24088. if (json !== undefined) {
  24089. var bufferGeometryLoader = new BufferGeometryLoader();
  24090. for (var i = 0, l = json.length; i < l; i++) {
  24091. var geometry = void 0;
  24092. var data = json[i];
  24093. switch (data.type) {
  24094. case 'PlaneGeometry':
  24095. case 'PlaneBufferGeometry':
  24096. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  24097. break;
  24098. case 'BoxGeometry':
  24099. case 'BoxBufferGeometry':
  24100. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  24101. break;
  24102. case 'CircleGeometry':
  24103. case 'CircleBufferGeometry':
  24104. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  24105. break;
  24106. case 'CylinderGeometry':
  24107. case 'CylinderBufferGeometry':
  24108. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24109. break;
  24110. case 'ConeGeometry':
  24111. case 'ConeBufferGeometry':
  24112. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24113. break;
  24114. case 'SphereGeometry':
  24115. case 'SphereBufferGeometry':
  24116. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  24117. break;
  24118. case 'DodecahedronGeometry':
  24119. case 'DodecahedronBufferGeometry':
  24120. case 'IcosahedronGeometry':
  24121. case 'IcosahedronBufferGeometry':
  24122. case 'OctahedronGeometry':
  24123. case 'OctahedronBufferGeometry':
  24124. case 'TetrahedronGeometry':
  24125. case 'TetrahedronBufferGeometry':
  24126. geometry = new Geometries[data.type](data.radius, data.detail);
  24127. break;
  24128. case 'RingGeometry':
  24129. case 'RingBufferGeometry':
  24130. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  24131. break;
  24132. case 'TorusGeometry':
  24133. case 'TorusBufferGeometry':
  24134. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  24135. break;
  24136. case 'TorusKnotGeometry':
  24137. case 'TorusKnotBufferGeometry':
  24138. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  24139. break;
  24140. case 'TubeGeometry':
  24141. case 'TubeBufferGeometry':
  24142. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24143. // User defined curves or instances of CurvePath will not be deserialized.
  24144. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  24145. break;
  24146. case 'LatheGeometry':
  24147. case 'LatheBufferGeometry':
  24148. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  24149. break;
  24150. case 'PolyhedronGeometry':
  24151. case 'PolyhedronBufferGeometry':
  24152. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  24153. break;
  24154. case 'ShapeGeometry':
  24155. case 'ShapeBufferGeometry':
  24156. geometryShapes = [];
  24157. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  24158. var shape = shapes[data.shapes[j]];
  24159. geometryShapes.push(shape);
  24160. }
  24161. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  24162. break;
  24163. case 'ExtrudeGeometry':
  24164. case 'ExtrudeBufferGeometry':
  24165. geometryShapes = [];
  24166. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  24167. var _shape = shapes[data.shapes[_j]];
  24168. geometryShapes.push(_shape);
  24169. }
  24170. var extrudePath = data.options.extrudePath;
  24171. if (extrudePath !== undefined) {
  24172. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  24173. }
  24174. geometry = new Geometries[data.type](geometryShapes, data.options);
  24175. break;
  24176. case 'BufferGeometry':
  24177. case 'InstancedBufferGeometry':
  24178. geometry = bufferGeometryLoader.parse(data);
  24179. break;
  24180. case 'Geometry':
  24181. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  24182. break;
  24183. default:
  24184. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  24185. continue;
  24186. }
  24187. geometry.uuid = data.uuid;
  24188. if (data.name !== undefined) geometry.name = data.name;
  24189. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  24190. geometries[data.uuid] = geometry;
  24191. }
  24192. }
  24193. return geometries;
  24194. };
  24195. _proto.parseMaterials = function parseMaterials(json, textures) {
  24196. var cache = {}; // MultiMaterial
  24197. var materials = {};
  24198. if (json !== undefined) {
  24199. var loader = new MaterialLoader();
  24200. loader.setTextures(textures);
  24201. for (var i = 0, l = json.length; i < l; i++) {
  24202. var data = json[i];
  24203. if (data.type === 'MultiMaterial') {
  24204. // Deprecated
  24205. var array = [];
  24206. for (var j = 0; j < data.materials.length; j++) {
  24207. var material = data.materials[j];
  24208. if (cache[material.uuid] === undefined) {
  24209. cache[material.uuid] = loader.parse(material);
  24210. }
  24211. array.push(cache[material.uuid]);
  24212. }
  24213. materials[data.uuid] = array;
  24214. } else {
  24215. if (cache[data.uuid] === undefined) {
  24216. cache[data.uuid] = loader.parse(data);
  24217. }
  24218. materials[data.uuid] = cache[data.uuid];
  24219. }
  24220. }
  24221. }
  24222. return materials;
  24223. };
  24224. _proto.parseAnimations = function parseAnimations(json) {
  24225. var animations = {};
  24226. if (json !== undefined) {
  24227. for (var i = 0; i < json.length; i++) {
  24228. var data = json[i];
  24229. var clip = AnimationClip.parse(data);
  24230. animations[clip.uuid] = clip;
  24231. }
  24232. }
  24233. return animations;
  24234. };
  24235. _proto.parseImages = function parseImages(json, onLoad) {
  24236. var scope = this;
  24237. var images = {};
  24238. var loader;
  24239. function loadImage(url) {
  24240. scope.manager.itemStart(url);
  24241. return loader.load(url, function () {
  24242. scope.manager.itemEnd(url);
  24243. }, undefined, function () {
  24244. scope.manager.itemError(url);
  24245. scope.manager.itemEnd(url);
  24246. });
  24247. }
  24248. function deserializeImage(image) {
  24249. if (typeof image === 'string') {
  24250. var url = image;
  24251. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(url) ? url : scope.resourcePath + url;
  24252. return loadImage(path);
  24253. } else {
  24254. if (image.data) {
  24255. return {
  24256. data: getTypedArray(image.type, image.data),
  24257. width: image.width,
  24258. height: image.height
  24259. };
  24260. } else {
  24261. return null;
  24262. }
  24263. }
  24264. }
  24265. if (json !== undefined && json.length > 0) {
  24266. var manager = new LoadingManager(onLoad);
  24267. loader = new ImageLoader(manager);
  24268. loader.setCrossOrigin(this.crossOrigin);
  24269. for (var i = 0, il = json.length; i < il; i++) {
  24270. var image = json[i];
  24271. var url = image.url;
  24272. if (Array.isArray(url)) {
  24273. // load array of images e.g CubeTexture
  24274. images[image.uuid] = [];
  24275. for (var j = 0, jl = url.length; j < jl; j++) {
  24276. var currentUrl = url[j];
  24277. var deserializedImage = deserializeImage(currentUrl);
  24278. if (deserializedImage !== null) {
  24279. if (deserializedImage instanceof HTMLImageElement) {
  24280. images[image.uuid].push(deserializedImage);
  24281. } else {
  24282. // special case: handle array of data textures for cube textures
  24283. images[image.uuid].push(new DataTexture(deserializedImage.data, deserializedImage.width, deserializedImage.height));
  24284. }
  24285. }
  24286. }
  24287. } else {
  24288. // load single image
  24289. var _deserializedImage = deserializeImage(image.url);
  24290. if (_deserializedImage !== null) {
  24291. images[image.uuid] = _deserializedImage;
  24292. }
  24293. }
  24294. }
  24295. }
  24296. return images;
  24297. };
  24298. _proto.parseTextures = function parseTextures(json, images) {
  24299. function parseConstant(value, type) {
  24300. if (typeof value === 'number') return value;
  24301. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  24302. return type[value];
  24303. }
  24304. var textures = {};
  24305. if (json !== undefined) {
  24306. for (var i = 0, l = json.length; i < l; i++) {
  24307. var data = json[i];
  24308. if (data.image === undefined) {
  24309. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  24310. }
  24311. if (images[data.image] === undefined) {
  24312. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  24313. }
  24314. var texture = void 0;
  24315. var image = images[data.image];
  24316. if (Array.isArray(image)) {
  24317. texture = new CubeTexture(image);
  24318. if (image.length === 6) texture.needsUpdate = true;
  24319. } else {
  24320. if (image && image.data) {
  24321. texture = new DataTexture(image.data, image.width, image.height);
  24322. } else {
  24323. texture = new Texture(image);
  24324. }
  24325. if (image) texture.needsUpdate = true; // textures can have undefined image data
  24326. }
  24327. texture.uuid = data.uuid;
  24328. if (data.name !== undefined) texture.name = data.name;
  24329. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  24330. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  24331. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  24332. if (data.center !== undefined) texture.center.fromArray(data.center);
  24333. if (data.rotation !== undefined) texture.rotation = data.rotation;
  24334. if (data.wrap !== undefined) {
  24335. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  24336. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  24337. }
  24338. if (data.format !== undefined) texture.format = data.format;
  24339. if (data.type !== undefined) texture.type = data.type;
  24340. if (data.encoding !== undefined) texture.encoding = data.encoding;
  24341. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  24342. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  24343. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  24344. if (data.flipY !== undefined) texture.flipY = data.flipY;
  24345. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  24346. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  24347. textures[data.uuid] = texture;
  24348. }
  24349. }
  24350. return textures;
  24351. };
  24352. _proto.parseObject = function parseObject(data, geometries, materials, animations) {
  24353. var object;
  24354. function getGeometry(name) {
  24355. if (geometries[name] === undefined) {
  24356. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  24357. }
  24358. return geometries[name];
  24359. }
  24360. function getMaterial(name) {
  24361. if (name === undefined) return undefined;
  24362. if (Array.isArray(name)) {
  24363. var array = [];
  24364. for (var i = 0, l = name.length; i < l; i++) {
  24365. var uuid = name[i];
  24366. if (materials[uuid] === undefined) {
  24367. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  24368. }
  24369. array.push(materials[uuid]);
  24370. }
  24371. return array;
  24372. }
  24373. if (materials[name] === undefined) {
  24374. console.warn('THREE.ObjectLoader: Undefined material', name);
  24375. }
  24376. return materials[name];
  24377. }
  24378. var geometry, material;
  24379. switch (data.type) {
  24380. case 'Scene':
  24381. object = new Scene();
  24382. if (data.background !== undefined) {
  24383. if (Number.isInteger(data.background)) {
  24384. object.background = new Color(data.background);
  24385. }
  24386. }
  24387. if (data.fog !== undefined) {
  24388. if (data.fog.type === 'Fog') {
  24389. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  24390. } else if (data.fog.type === 'FogExp2') {
  24391. object.fog = new FogExp2(data.fog.color, data.fog.density);
  24392. }
  24393. }
  24394. break;
  24395. case 'PerspectiveCamera':
  24396. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  24397. if (data.focus !== undefined) object.focus = data.focus;
  24398. if (data.zoom !== undefined) object.zoom = data.zoom;
  24399. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  24400. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  24401. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24402. break;
  24403. case 'OrthographicCamera':
  24404. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  24405. if (data.zoom !== undefined) object.zoom = data.zoom;
  24406. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24407. break;
  24408. case 'AmbientLight':
  24409. object = new AmbientLight(data.color, data.intensity);
  24410. break;
  24411. case 'DirectionalLight':
  24412. object = new DirectionalLight(data.color, data.intensity);
  24413. break;
  24414. case 'PointLight':
  24415. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  24416. break;
  24417. case 'RectAreaLight':
  24418. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  24419. break;
  24420. case 'SpotLight':
  24421. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  24422. break;
  24423. case 'HemisphereLight':
  24424. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  24425. break;
  24426. case 'LightProbe':
  24427. object = new LightProbe().fromJSON(data);
  24428. break;
  24429. case 'SkinnedMesh':
  24430. geometry = getGeometry(data.geometry);
  24431. material = getMaterial(data.material);
  24432. object = new SkinnedMesh(geometry, material);
  24433. if (data.bindMode !== undefined) object.bindMode = data.bindMode;
  24434. if (data.bindMatrix !== undefined) object.bindMatrix.fromArray(data.bindMatrix);
  24435. if (data.skeleton !== undefined) object.skeleton = data.skeleton;
  24436. break;
  24437. case 'Mesh':
  24438. geometry = getGeometry(data.geometry);
  24439. material = getMaterial(data.material);
  24440. object = new Mesh(geometry, material);
  24441. break;
  24442. case 'InstancedMesh':
  24443. geometry = getGeometry(data.geometry);
  24444. material = getMaterial(data.material);
  24445. var count = data.count;
  24446. var instanceMatrix = data.instanceMatrix;
  24447. object = new InstancedMesh(geometry, material, count);
  24448. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  24449. break;
  24450. case 'LOD':
  24451. object = new LOD();
  24452. break;
  24453. case 'Line':
  24454. object = new Line(getGeometry(data.geometry), getMaterial(data.material));
  24455. break;
  24456. case 'LineLoop':
  24457. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  24458. break;
  24459. case 'LineSegments':
  24460. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  24461. break;
  24462. case 'PointCloud':
  24463. case 'Points':
  24464. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  24465. break;
  24466. case 'Sprite':
  24467. object = new Sprite(getMaterial(data.material));
  24468. break;
  24469. case 'Group':
  24470. object = new Group();
  24471. break;
  24472. case 'Bone':
  24473. object = new Bone();
  24474. break;
  24475. default:
  24476. object = new Object3D();
  24477. }
  24478. object.uuid = data.uuid;
  24479. if (data.name !== undefined) object.name = data.name;
  24480. if (data.matrix !== undefined) {
  24481. object.matrix.fromArray(data.matrix);
  24482. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24483. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  24484. } else {
  24485. if (data.position !== undefined) object.position.fromArray(data.position);
  24486. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  24487. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  24488. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  24489. }
  24490. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  24491. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  24492. if (data.shadow) {
  24493. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  24494. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  24495. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  24496. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  24497. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  24498. }
  24499. if (data.visible !== undefined) object.visible = data.visible;
  24500. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  24501. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  24502. if (data.userData !== undefined) object.userData = data.userData;
  24503. if (data.layers !== undefined) object.layers.mask = data.layers;
  24504. if (data.children !== undefined) {
  24505. var children = data.children;
  24506. for (var i = 0; i < children.length; i++) {
  24507. object.add(this.parseObject(children[i], geometries, materials, animations));
  24508. }
  24509. }
  24510. if (data.animations !== undefined) {
  24511. var objectAnimations = data.animations;
  24512. for (var _i = 0; _i < objectAnimations.length; _i++) {
  24513. var uuid = objectAnimations[_i];
  24514. object.animations.push(animations[uuid]);
  24515. }
  24516. }
  24517. if (data.type === 'LOD') {
  24518. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  24519. var levels = data.levels;
  24520. for (var l = 0; l < levels.length; l++) {
  24521. var level = levels[l];
  24522. var child = object.getObjectByProperty('uuid', level.object);
  24523. if (child !== undefined) {
  24524. object.addLevel(child, level.distance);
  24525. }
  24526. }
  24527. }
  24528. return object;
  24529. };
  24530. _proto.bindSkeletons = function bindSkeletons(object, skeletons) {
  24531. if (Object.keys(skeletons).length === 0) return;
  24532. object.traverse(function (child) {
  24533. if (child.isSkinnedMesh === true && child.skeleton !== undefined) {
  24534. var skeleton = skeletons[child.skeleton];
  24535. if (skeleton === undefined) {
  24536. console.warn('THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton);
  24537. } else {
  24538. child.bind(skeleton, child.bindMatrix);
  24539. }
  24540. }
  24541. });
  24542. }
  24543. /* DEPRECATED */
  24544. ;
  24545. _proto.setTexturePath = function setTexturePath(value) {
  24546. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  24547. return this.setResourcePath(value);
  24548. };
  24549. return ObjectLoader;
  24550. }(Loader);
  24551. var TEXTURE_MAPPING = {
  24552. UVMapping: UVMapping,
  24553. CubeReflectionMapping: CubeReflectionMapping,
  24554. CubeRefractionMapping: CubeRefractionMapping,
  24555. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  24556. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  24557. CubeUVReflectionMapping: CubeUVReflectionMapping,
  24558. CubeUVRefractionMapping: CubeUVRefractionMapping
  24559. };
  24560. var TEXTURE_WRAPPING = {
  24561. RepeatWrapping: RepeatWrapping,
  24562. ClampToEdgeWrapping: ClampToEdgeWrapping,
  24563. MirroredRepeatWrapping: MirroredRepeatWrapping
  24564. };
  24565. var TEXTURE_FILTER = {
  24566. NearestFilter: NearestFilter,
  24567. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  24568. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  24569. LinearFilter: LinearFilter,
  24570. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  24571. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  24572. };
  24573. function ImageBitmapLoader(manager) {
  24574. if (typeof createImageBitmap === 'undefined') {
  24575. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  24576. }
  24577. if (typeof fetch === 'undefined') {
  24578. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  24579. }
  24580. Loader.call(this, manager);
  24581. this.options = {
  24582. premultiplyAlpha: 'none'
  24583. };
  24584. }
  24585. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24586. constructor: ImageBitmapLoader,
  24587. isImageBitmapLoader: true,
  24588. setOptions: function setOptions(options) {
  24589. this.options = options;
  24590. return this;
  24591. },
  24592. load: function load(url, onLoad, onProgress, onError) {
  24593. if (url === undefined) url = '';
  24594. if (this.path !== undefined) url = this.path + url;
  24595. url = this.manager.resolveURL(url);
  24596. var scope = this;
  24597. var cached = Cache.get(url);
  24598. if (cached !== undefined) {
  24599. scope.manager.itemStart(url);
  24600. setTimeout(function () {
  24601. if (onLoad) onLoad(cached);
  24602. scope.manager.itemEnd(url);
  24603. }, 0);
  24604. return cached;
  24605. }
  24606. var fetchOptions = {};
  24607. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  24608. fetch(url, fetchOptions).then(function (res) {
  24609. return res.blob();
  24610. }).then(function (blob) {
  24611. return createImageBitmap(blob, scope.options);
  24612. }).then(function (imageBitmap) {
  24613. Cache.add(url, imageBitmap);
  24614. if (onLoad) onLoad(imageBitmap);
  24615. scope.manager.itemEnd(url);
  24616. }).catch(function (e) {
  24617. if (onError) onError(e);
  24618. scope.manager.itemError(url);
  24619. scope.manager.itemEnd(url);
  24620. });
  24621. scope.manager.itemStart(url);
  24622. }
  24623. });
  24624. function ShapePath() {
  24625. this.type = 'ShapePath';
  24626. this.color = new Color();
  24627. this.subPaths = [];
  24628. this.currentPath = null;
  24629. }
  24630. Object.assign(ShapePath.prototype, {
  24631. moveTo: function moveTo(x, y) {
  24632. this.currentPath = new Path();
  24633. this.subPaths.push(this.currentPath);
  24634. this.currentPath.moveTo(x, y);
  24635. return this;
  24636. },
  24637. lineTo: function lineTo(x, y) {
  24638. this.currentPath.lineTo(x, y);
  24639. return this;
  24640. },
  24641. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  24642. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  24643. return this;
  24644. },
  24645. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  24646. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  24647. return this;
  24648. },
  24649. splineThru: function splineThru(pts) {
  24650. this.currentPath.splineThru(pts);
  24651. return this;
  24652. },
  24653. toShapes: function toShapes(isCCW, noHoles) {
  24654. function toShapesNoHoles(inSubpaths) {
  24655. var shapes = [];
  24656. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  24657. var _tmpPath = inSubpaths[i];
  24658. var _tmpShape = new Shape();
  24659. _tmpShape.curves = _tmpPath.curves;
  24660. shapes.push(_tmpShape);
  24661. }
  24662. return shapes;
  24663. }
  24664. function isPointInsidePolygon(inPt, inPolygon) {
  24665. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  24666. // toggling of inside/outside at every single! intersection point of an edge
  24667. // with the horizontal line through inPt, left of inPt
  24668. // not counting lowerY endpoints of edges and whole edges on that line
  24669. var inside = false;
  24670. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  24671. var edgeLowPt = inPolygon[p];
  24672. var edgeHighPt = inPolygon[q];
  24673. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  24674. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  24675. if (Math.abs(edgeDy) > Number.EPSILON) {
  24676. // not parallel
  24677. if (edgeDy < 0) {
  24678. edgeLowPt = inPolygon[q];
  24679. edgeDx = -edgeDx;
  24680. edgeHighPt = inPolygon[p];
  24681. edgeDy = -edgeDy;
  24682. }
  24683. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  24684. if (inPt.y === edgeLowPt.y) {
  24685. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  24686. // continue; // no intersection or edgeLowPt => doesn't count !!!
  24687. } else {
  24688. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  24689. if (perpEdge === 0) return true; // inPt is on contour ?
  24690. if (perpEdge < 0) continue;
  24691. inside = !inside; // true intersection left of inPt
  24692. }
  24693. } else {
  24694. // parallel or collinear
  24695. if (inPt.y !== edgeLowPt.y) continue; // parallel
  24696. // edge lies on the same horizontal line as inPt
  24697. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  24698. // continue;
  24699. }
  24700. }
  24701. return inside;
  24702. }
  24703. var isClockWise = ShapeUtils.isClockWise;
  24704. var subPaths = this.subPaths;
  24705. if (subPaths.length === 0) return [];
  24706. if (noHoles === true) return toShapesNoHoles(subPaths);
  24707. var solid, tmpPath, tmpShape;
  24708. var shapes = [];
  24709. if (subPaths.length === 1) {
  24710. tmpPath = subPaths[0];
  24711. tmpShape = new Shape();
  24712. tmpShape.curves = tmpPath.curves;
  24713. shapes.push(tmpShape);
  24714. return shapes;
  24715. }
  24716. var holesFirst = !isClockWise(subPaths[0].getPoints());
  24717. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  24718. var betterShapeHoles = [];
  24719. var newShapes = [];
  24720. var newShapeHoles = [];
  24721. var mainIdx = 0;
  24722. var tmpPoints;
  24723. newShapes[mainIdx] = undefined;
  24724. newShapeHoles[mainIdx] = [];
  24725. for (var i = 0, l = subPaths.length; i < l; i++) {
  24726. tmpPath = subPaths[i];
  24727. tmpPoints = tmpPath.getPoints();
  24728. solid = isClockWise(tmpPoints);
  24729. solid = isCCW ? !solid : solid;
  24730. if (solid) {
  24731. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  24732. newShapes[mainIdx] = {
  24733. s: new Shape(),
  24734. p: tmpPoints
  24735. };
  24736. newShapes[mainIdx].s.curves = tmpPath.curves;
  24737. if (holesFirst) mainIdx++;
  24738. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  24739. } else {
  24740. newShapeHoles[mainIdx].push({
  24741. h: tmpPath,
  24742. p: tmpPoints[0]
  24743. }); //console.log('ccw', i);
  24744. }
  24745. } // only Holes? -> probably all Shapes with wrong orientation
  24746. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  24747. if (newShapes.length > 1) {
  24748. var ambiguous = false;
  24749. var toChange = [];
  24750. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  24751. betterShapeHoles[sIdx] = [];
  24752. }
  24753. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  24754. var sho = newShapeHoles[_sIdx];
  24755. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  24756. var ho = sho[hIdx];
  24757. var hole_unassigned = true;
  24758. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  24759. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  24760. if (_sIdx !== s2Idx) toChange.push({
  24761. froms: _sIdx,
  24762. tos: s2Idx,
  24763. hole: hIdx
  24764. });
  24765. if (hole_unassigned) {
  24766. hole_unassigned = false;
  24767. betterShapeHoles[s2Idx].push(ho);
  24768. } else {
  24769. ambiguous = true;
  24770. }
  24771. }
  24772. }
  24773. if (hole_unassigned) {
  24774. betterShapeHoles[_sIdx].push(ho);
  24775. }
  24776. }
  24777. } // console.log("ambiguous: ", ambiguous);
  24778. if (toChange.length > 0) {
  24779. // console.log("to change: ", toChange);
  24780. if (!ambiguous) newShapeHoles = betterShapeHoles;
  24781. }
  24782. }
  24783. var tmpHoles;
  24784. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  24785. tmpShape = newShapes[_i].s;
  24786. shapes.push(tmpShape);
  24787. tmpHoles = newShapeHoles[_i];
  24788. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  24789. tmpShape.holes.push(tmpHoles[j].h);
  24790. }
  24791. } //console.log("shape", shapes);
  24792. return shapes;
  24793. }
  24794. });
  24795. var Font = /*#__PURE__*/function () {
  24796. function Font(data) {
  24797. Object.defineProperty(this, 'isFont', {
  24798. value: true
  24799. });
  24800. this.type = 'Font';
  24801. this.data = data;
  24802. }
  24803. var _proto = Font.prototype;
  24804. _proto.generateShapes = function generateShapes(text, size) {
  24805. if (size === void 0) {
  24806. size = 100;
  24807. }
  24808. var shapes = [];
  24809. var paths = createPaths(text, size, this.data);
  24810. for (var p = 0, pl = paths.length; p < pl; p++) {
  24811. Array.prototype.push.apply(shapes, paths[p].toShapes());
  24812. }
  24813. return shapes;
  24814. };
  24815. return Font;
  24816. }();
  24817. function createPaths(text, size, data) {
  24818. var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
  24819. var scale = size / data.resolution;
  24820. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  24821. var paths = [];
  24822. var offsetX = 0,
  24823. offsetY = 0;
  24824. for (var i = 0; i < chars.length; i++) {
  24825. var char = chars[i];
  24826. if (char === '\n') {
  24827. offsetX = 0;
  24828. offsetY -= line_height;
  24829. } else {
  24830. var ret = createPath(char, scale, offsetX, offsetY, data);
  24831. offsetX += ret.offsetX;
  24832. paths.push(ret.path);
  24833. }
  24834. }
  24835. return paths;
  24836. }
  24837. function createPath(char, scale, offsetX, offsetY, data) {
  24838. var glyph = data.glyphs[char] || data.glyphs['?'];
  24839. if (!glyph) {
  24840. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  24841. return;
  24842. }
  24843. var path = new ShapePath();
  24844. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  24845. if (glyph.o) {
  24846. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  24847. for (var i = 0, l = outline.length; i < l;) {
  24848. var action = outline[i++];
  24849. switch (action) {
  24850. case 'm':
  24851. // moveTo
  24852. x = outline[i++] * scale + offsetX;
  24853. y = outline[i++] * scale + offsetY;
  24854. path.moveTo(x, y);
  24855. break;
  24856. case 'l':
  24857. // lineTo
  24858. x = outline[i++] * scale + offsetX;
  24859. y = outline[i++] * scale + offsetY;
  24860. path.lineTo(x, y);
  24861. break;
  24862. case 'q':
  24863. // quadraticCurveTo
  24864. cpx = outline[i++] * scale + offsetX;
  24865. cpy = outline[i++] * scale + offsetY;
  24866. cpx1 = outline[i++] * scale + offsetX;
  24867. cpy1 = outline[i++] * scale + offsetY;
  24868. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  24869. break;
  24870. case 'b':
  24871. // bezierCurveTo
  24872. cpx = outline[i++] * scale + offsetX;
  24873. cpy = outline[i++] * scale + offsetY;
  24874. cpx1 = outline[i++] * scale + offsetX;
  24875. cpy1 = outline[i++] * scale + offsetY;
  24876. cpx2 = outline[i++] * scale + offsetX;
  24877. cpy2 = outline[i++] * scale + offsetY;
  24878. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  24879. break;
  24880. }
  24881. }
  24882. }
  24883. return {
  24884. offsetX: glyph.ha * scale,
  24885. path: path
  24886. };
  24887. }
  24888. function FontLoader(manager) {
  24889. Loader.call(this, manager);
  24890. }
  24891. FontLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24892. constructor: FontLoader,
  24893. load: function load(url, onLoad, onProgress, onError) {
  24894. var scope = this;
  24895. var loader = new FileLoader(this.manager);
  24896. loader.setPath(this.path);
  24897. loader.setRequestHeader(this.requestHeader);
  24898. loader.setWithCredentials(scope.withCredentials);
  24899. loader.load(url, function (text) {
  24900. var json;
  24901. try {
  24902. json = JSON.parse(text);
  24903. } catch (e) {
  24904. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  24905. json = JSON.parse(text.substring(65, text.length - 2));
  24906. }
  24907. var font = scope.parse(json);
  24908. if (onLoad) onLoad(font);
  24909. }, onProgress, onError);
  24910. },
  24911. parse: function parse(json) {
  24912. return new Font(json);
  24913. }
  24914. });
  24915. var _context;
  24916. var AudioContext = {
  24917. getContext: function getContext() {
  24918. if (_context === undefined) {
  24919. _context = new (window.AudioContext || window.webkitAudioContext)();
  24920. }
  24921. return _context;
  24922. },
  24923. setContext: function setContext(value) {
  24924. _context = value;
  24925. }
  24926. };
  24927. function AudioLoader(manager) {
  24928. Loader.call(this, manager);
  24929. }
  24930. AudioLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24931. constructor: AudioLoader,
  24932. load: function load(url, onLoad, onProgress, onError) {
  24933. var scope = this;
  24934. var loader = new FileLoader(scope.manager);
  24935. loader.setResponseType('arraybuffer');
  24936. loader.setPath(scope.path);
  24937. loader.setRequestHeader(scope.requestHeader);
  24938. loader.setWithCredentials(scope.withCredentials);
  24939. loader.load(url, function (buffer) {
  24940. try {
  24941. // Create a copy of the buffer. The `decodeAudioData` method
  24942. // detaches the buffer when complete, preventing reuse.
  24943. var bufferCopy = buffer.slice(0);
  24944. var context = AudioContext.getContext();
  24945. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  24946. onLoad(audioBuffer);
  24947. });
  24948. } catch (e) {
  24949. if (onError) {
  24950. onError(e);
  24951. } else {
  24952. console.error(e);
  24953. }
  24954. scope.manager.itemError(url);
  24955. }
  24956. }, onProgress, onError);
  24957. }
  24958. });
  24959. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  24960. LightProbe.call(this, undefined, intensity);
  24961. var color1 = new Color().set(skyColor);
  24962. var color2 = new Color().set(groundColor);
  24963. var sky = new Vector3(color1.r, color1.g, color1.b);
  24964. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  24965. var c0 = Math.sqrt(Math.PI);
  24966. var c1 = c0 * Math.sqrt(0.75);
  24967. this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  24968. this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  24969. }
  24970. HemisphereLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  24971. constructor: HemisphereLightProbe,
  24972. isHemisphereLightProbe: true,
  24973. copy: function copy(source) {
  24974. // modifying colors not currently supported
  24975. LightProbe.prototype.copy.call(this, source);
  24976. return this;
  24977. },
  24978. toJSON: function toJSON(meta) {
  24979. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  24980. return data;
  24981. }
  24982. });
  24983. function AmbientLightProbe(color, intensity) {
  24984. LightProbe.call(this, undefined, intensity);
  24985. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  24986. this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  24987. }
  24988. AmbientLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  24989. constructor: AmbientLightProbe,
  24990. isAmbientLightProbe: true,
  24991. copy: function copy(source) {
  24992. // modifying color not currently supported
  24993. LightProbe.prototype.copy.call(this, source);
  24994. return this;
  24995. },
  24996. toJSON: function toJSON(meta) {
  24997. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  24998. return data;
  24999. }
  25000. });
  25001. var _eyeRight = new Matrix4();
  25002. var _eyeLeft = new Matrix4();
  25003. function StereoCamera() {
  25004. this.type = 'StereoCamera';
  25005. this.aspect = 1;
  25006. this.eyeSep = 0.064;
  25007. this.cameraL = new PerspectiveCamera();
  25008. this.cameraL.layers.enable(1);
  25009. this.cameraL.matrixAutoUpdate = false;
  25010. this.cameraR = new PerspectiveCamera();
  25011. this.cameraR.layers.enable(2);
  25012. this.cameraR.matrixAutoUpdate = false;
  25013. this._cache = {
  25014. focus: null,
  25015. fov: null,
  25016. aspect: null,
  25017. near: null,
  25018. far: null,
  25019. zoom: null,
  25020. eyeSep: null
  25021. };
  25022. }
  25023. Object.assign(StereoCamera.prototype, {
  25024. update: function update(camera) {
  25025. var cache = this._cache;
  25026. 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;
  25027. if (needsUpdate) {
  25028. cache.focus = camera.focus;
  25029. cache.fov = camera.fov;
  25030. cache.aspect = camera.aspect * this.aspect;
  25031. cache.near = camera.near;
  25032. cache.far = camera.far;
  25033. cache.zoom = camera.zoom;
  25034. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  25035. // http://paulbourke.net/stereographics/stereorender/
  25036. var projectionMatrix = camera.projectionMatrix.clone();
  25037. var eyeSepHalf = cache.eyeSep / 2;
  25038. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25039. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  25040. var xmin, xmax; // translate xOffset
  25041. _eyeLeft.elements[12] = -eyeSepHalf;
  25042. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  25043. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  25044. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25045. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25046. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25047. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  25048. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  25049. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25050. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25051. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25052. this.cameraR.projectionMatrix.copy(projectionMatrix);
  25053. }
  25054. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  25055. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  25056. }
  25057. });
  25058. var Clock = /*#__PURE__*/function () {
  25059. function Clock(autoStart) {
  25060. this.autoStart = autoStart !== undefined ? autoStart : true;
  25061. this.startTime = 0;
  25062. this.oldTime = 0;
  25063. this.elapsedTime = 0;
  25064. this.running = false;
  25065. }
  25066. var _proto = Clock.prototype;
  25067. _proto.start = function start() {
  25068. this.startTime = now();
  25069. this.oldTime = this.startTime;
  25070. this.elapsedTime = 0;
  25071. this.running = true;
  25072. };
  25073. _proto.stop = function stop() {
  25074. this.getElapsedTime();
  25075. this.running = false;
  25076. this.autoStart = false;
  25077. };
  25078. _proto.getElapsedTime = function getElapsedTime() {
  25079. this.getDelta();
  25080. return this.elapsedTime;
  25081. };
  25082. _proto.getDelta = function getDelta() {
  25083. var diff = 0;
  25084. if (this.autoStart && !this.running) {
  25085. this.start();
  25086. return 0;
  25087. }
  25088. if (this.running) {
  25089. var newTime = now();
  25090. diff = (newTime - this.oldTime) / 1000;
  25091. this.oldTime = newTime;
  25092. this.elapsedTime += diff;
  25093. }
  25094. return diff;
  25095. };
  25096. return Clock;
  25097. }();
  25098. function now() {
  25099. return (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  25100. }
  25101. var _position$2 = /*@__PURE__*/new Vector3();
  25102. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  25103. var _scale$1 = /*@__PURE__*/new Vector3();
  25104. var _orientation = /*@__PURE__*/new Vector3();
  25105. var AudioListener = /*#__PURE__*/function (_Object3D) {
  25106. _inheritsLoose(AudioListener, _Object3D);
  25107. function AudioListener() {
  25108. var _this;
  25109. _this = _Object3D.call(this) || this;
  25110. _this.type = 'AudioListener';
  25111. _this.context = AudioContext.getContext();
  25112. _this.gain = _this.context.createGain();
  25113. _this.gain.connect(_this.context.destination);
  25114. _this.filter = null;
  25115. _this.timeDelta = 0; // private
  25116. _this._clock = new Clock();
  25117. return _this;
  25118. }
  25119. var _proto = AudioListener.prototype;
  25120. _proto.getInput = function getInput() {
  25121. return this.gain;
  25122. };
  25123. _proto.removeFilter = function removeFilter() {
  25124. if (this.filter !== null) {
  25125. this.gain.disconnect(this.filter);
  25126. this.filter.disconnect(this.context.destination);
  25127. this.gain.connect(this.context.destination);
  25128. this.filter = null;
  25129. }
  25130. return this;
  25131. };
  25132. _proto.getFilter = function getFilter() {
  25133. return this.filter;
  25134. };
  25135. _proto.setFilter = function setFilter(value) {
  25136. if (this.filter !== null) {
  25137. this.gain.disconnect(this.filter);
  25138. this.filter.disconnect(this.context.destination);
  25139. } else {
  25140. this.gain.disconnect(this.context.destination);
  25141. }
  25142. this.filter = value;
  25143. this.gain.connect(this.filter);
  25144. this.filter.connect(this.context.destination);
  25145. return this;
  25146. };
  25147. _proto.getMasterVolume = function getMasterVolume() {
  25148. return this.gain.gain.value;
  25149. };
  25150. _proto.setMasterVolume = function setMasterVolume(value) {
  25151. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25152. return this;
  25153. };
  25154. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25155. _Object3D.prototype.updateMatrixWorld.call(this, force);
  25156. var listener = this.context.listener;
  25157. var up = this.up;
  25158. this.timeDelta = this._clock.getDelta();
  25159. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  25160. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  25161. if (listener.positionX) {
  25162. // code path for Chrome (see #14393)
  25163. var endTime = this.context.currentTime + this.timeDelta;
  25164. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  25165. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  25166. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  25167. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  25168. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  25169. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  25170. listener.upX.linearRampToValueAtTime(up.x, endTime);
  25171. listener.upY.linearRampToValueAtTime(up.y, endTime);
  25172. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  25173. } else {
  25174. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  25175. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  25176. }
  25177. };
  25178. return AudioListener;
  25179. }(Object3D);
  25180. var Audio = /*#__PURE__*/function (_Object3D) {
  25181. _inheritsLoose(Audio, _Object3D);
  25182. function Audio(listener) {
  25183. var _this;
  25184. _this = _Object3D.call(this) || this;
  25185. _this.type = 'Audio';
  25186. _this.listener = listener;
  25187. _this.context = listener.context;
  25188. _this.gain = _this.context.createGain();
  25189. _this.gain.connect(listener.getInput());
  25190. _this.autoplay = false;
  25191. _this.buffer = null;
  25192. _this.detune = 0;
  25193. _this.loop = false;
  25194. _this.loopStart = 0;
  25195. _this.loopEnd = 0;
  25196. _this.offset = 0;
  25197. _this.duration = undefined;
  25198. _this.playbackRate = 1;
  25199. _this.isPlaying = false;
  25200. _this.hasPlaybackControl = true;
  25201. _this.source = null;
  25202. _this.sourceType = 'empty';
  25203. _this._startedAt = 0;
  25204. _this._progress = 0;
  25205. _this._connected = false;
  25206. _this.filters = [];
  25207. return _this;
  25208. }
  25209. var _proto = Audio.prototype;
  25210. _proto.getOutput = function getOutput() {
  25211. return this.gain;
  25212. };
  25213. _proto.setNodeSource = function setNodeSource(audioNode) {
  25214. this.hasPlaybackControl = false;
  25215. this.sourceType = 'audioNode';
  25216. this.source = audioNode;
  25217. this.connect();
  25218. return this;
  25219. };
  25220. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  25221. this.hasPlaybackControl = false;
  25222. this.sourceType = 'mediaNode';
  25223. this.source = this.context.createMediaElementSource(mediaElement);
  25224. this.connect();
  25225. return this;
  25226. };
  25227. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  25228. this.hasPlaybackControl = false;
  25229. this.sourceType = 'mediaStreamNode';
  25230. this.source = this.context.createMediaStreamSource(mediaStream);
  25231. this.connect();
  25232. return this;
  25233. };
  25234. _proto.setBuffer = function setBuffer(audioBuffer) {
  25235. this.buffer = audioBuffer;
  25236. this.sourceType = 'buffer';
  25237. if (this.autoplay) this.play();
  25238. return this;
  25239. };
  25240. _proto.play = function play(delay) {
  25241. if (delay === void 0) {
  25242. delay = 0;
  25243. }
  25244. if (this.isPlaying === true) {
  25245. console.warn('THREE.Audio: Audio is already playing.');
  25246. return;
  25247. }
  25248. if (this.hasPlaybackControl === false) {
  25249. console.warn('THREE.Audio: this Audio has no playback control.');
  25250. return;
  25251. }
  25252. this._startedAt = this.context.currentTime + delay;
  25253. var source = this.context.createBufferSource();
  25254. source.buffer = this.buffer;
  25255. source.loop = this.loop;
  25256. source.loopStart = this.loopStart;
  25257. source.loopEnd = this.loopEnd;
  25258. source.onended = this.onEnded.bind(this);
  25259. source.start(this._startedAt, this._progress + this.offset, this.duration);
  25260. this.isPlaying = true;
  25261. this.source = source;
  25262. this.setDetune(this.detune);
  25263. this.setPlaybackRate(this.playbackRate);
  25264. return this.connect();
  25265. };
  25266. _proto.pause = function pause() {
  25267. if (this.hasPlaybackControl === false) {
  25268. console.warn('THREE.Audio: this Audio has no playback control.');
  25269. return;
  25270. }
  25271. if (this.isPlaying === true) {
  25272. // update current progress
  25273. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  25274. if (this.loop === true) {
  25275. // ensure _progress does not exceed duration with looped audios
  25276. this._progress = this._progress % (this.duration || this.buffer.duration);
  25277. }
  25278. this.source.stop();
  25279. this.source.onended = null;
  25280. this.isPlaying = false;
  25281. }
  25282. return this;
  25283. };
  25284. _proto.stop = function stop() {
  25285. if (this.hasPlaybackControl === false) {
  25286. console.warn('THREE.Audio: this Audio has no playback control.');
  25287. return;
  25288. }
  25289. this._progress = 0;
  25290. this.source.stop();
  25291. this.source.onended = null;
  25292. this.isPlaying = false;
  25293. return this;
  25294. };
  25295. _proto.connect = function connect() {
  25296. if (this.filters.length > 0) {
  25297. this.source.connect(this.filters[0]);
  25298. for (var i = 1, l = this.filters.length; i < l; i++) {
  25299. this.filters[i - 1].connect(this.filters[i]);
  25300. }
  25301. this.filters[this.filters.length - 1].connect(this.getOutput());
  25302. } else {
  25303. this.source.connect(this.getOutput());
  25304. }
  25305. this._connected = true;
  25306. return this;
  25307. };
  25308. _proto.disconnect = function disconnect() {
  25309. if (this.filters.length > 0) {
  25310. this.source.disconnect(this.filters[0]);
  25311. for (var i = 1, l = this.filters.length; i < l; i++) {
  25312. this.filters[i - 1].disconnect(this.filters[i]);
  25313. }
  25314. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  25315. } else {
  25316. this.source.disconnect(this.getOutput());
  25317. }
  25318. this._connected = false;
  25319. return this;
  25320. };
  25321. _proto.getFilters = function getFilters() {
  25322. return this.filters;
  25323. };
  25324. _proto.setFilters = function setFilters(value) {
  25325. if (!value) value = [];
  25326. if (this._connected === true) {
  25327. this.disconnect();
  25328. this.filters = value.slice();
  25329. this.connect();
  25330. } else {
  25331. this.filters = value.slice();
  25332. }
  25333. return this;
  25334. };
  25335. _proto.setDetune = function setDetune(value) {
  25336. this.detune = value;
  25337. if (this.source.detune === undefined) return; // only set detune when available
  25338. if (this.isPlaying === true) {
  25339. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  25340. }
  25341. return this;
  25342. };
  25343. _proto.getDetune = function getDetune() {
  25344. return this.detune;
  25345. };
  25346. _proto.getFilter = function getFilter() {
  25347. return this.getFilters()[0];
  25348. };
  25349. _proto.setFilter = function setFilter(filter) {
  25350. return this.setFilters(filter ? [filter] : []);
  25351. };
  25352. _proto.setPlaybackRate = function setPlaybackRate(value) {
  25353. if (this.hasPlaybackControl === false) {
  25354. console.warn('THREE.Audio: this Audio has no playback control.');
  25355. return;
  25356. }
  25357. this.playbackRate = value;
  25358. if (this.isPlaying === true) {
  25359. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  25360. }
  25361. return this;
  25362. };
  25363. _proto.getPlaybackRate = function getPlaybackRate() {
  25364. return this.playbackRate;
  25365. };
  25366. _proto.onEnded = function onEnded() {
  25367. this.isPlaying = false;
  25368. };
  25369. _proto.getLoop = function getLoop() {
  25370. if (this.hasPlaybackControl === false) {
  25371. console.warn('THREE.Audio: this Audio has no playback control.');
  25372. return false;
  25373. }
  25374. return this.loop;
  25375. };
  25376. _proto.setLoop = function setLoop(value) {
  25377. if (this.hasPlaybackControl === false) {
  25378. console.warn('THREE.Audio: this Audio has no playback control.');
  25379. return;
  25380. }
  25381. this.loop = value;
  25382. if (this.isPlaying === true) {
  25383. this.source.loop = this.loop;
  25384. }
  25385. return this;
  25386. };
  25387. _proto.setLoopStart = function setLoopStart(value) {
  25388. this.loopStart = value;
  25389. return this;
  25390. };
  25391. _proto.setLoopEnd = function setLoopEnd(value) {
  25392. this.loopEnd = value;
  25393. return this;
  25394. };
  25395. _proto.getVolume = function getVolume() {
  25396. return this.gain.gain.value;
  25397. };
  25398. _proto.setVolume = function setVolume(value) {
  25399. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25400. return this;
  25401. };
  25402. return Audio;
  25403. }(Object3D);
  25404. var _position$3 = /*@__PURE__*/new Vector3();
  25405. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  25406. var _scale$2 = /*@__PURE__*/new Vector3();
  25407. var _orientation$1 = /*@__PURE__*/new Vector3();
  25408. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  25409. _inheritsLoose(PositionalAudio, _Audio);
  25410. function PositionalAudio(listener) {
  25411. var _this;
  25412. _this = _Audio.call(this, listener) || this;
  25413. _this.panner = _this.context.createPanner();
  25414. _this.panner.panningModel = 'HRTF';
  25415. _this.panner.connect(_this.gain);
  25416. return _this;
  25417. }
  25418. var _proto = PositionalAudio.prototype;
  25419. _proto.getOutput = function getOutput() {
  25420. return this.panner;
  25421. };
  25422. _proto.getRefDistance = function getRefDistance() {
  25423. return this.panner.refDistance;
  25424. };
  25425. _proto.setRefDistance = function setRefDistance(value) {
  25426. this.panner.refDistance = value;
  25427. return this;
  25428. };
  25429. _proto.getRolloffFactor = function getRolloffFactor() {
  25430. return this.panner.rolloffFactor;
  25431. };
  25432. _proto.setRolloffFactor = function setRolloffFactor(value) {
  25433. this.panner.rolloffFactor = value;
  25434. return this;
  25435. };
  25436. _proto.getDistanceModel = function getDistanceModel() {
  25437. return this.panner.distanceModel;
  25438. };
  25439. _proto.setDistanceModel = function setDistanceModel(value) {
  25440. this.panner.distanceModel = value;
  25441. return this;
  25442. };
  25443. _proto.getMaxDistance = function getMaxDistance() {
  25444. return this.panner.maxDistance;
  25445. };
  25446. _proto.setMaxDistance = function setMaxDistance(value) {
  25447. this.panner.maxDistance = value;
  25448. return this;
  25449. };
  25450. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  25451. this.panner.coneInnerAngle = coneInnerAngle;
  25452. this.panner.coneOuterAngle = coneOuterAngle;
  25453. this.panner.coneOuterGain = coneOuterGain;
  25454. return this;
  25455. };
  25456. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25457. _Audio.prototype.updateMatrixWorld.call(this, force);
  25458. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  25459. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  25460. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  25461. var panner = this.panner;
  25462. if (panner.positionX) {
  25463. // code path for Chrome and Firefox (see #14393)
  25464. var endTime = this.context.currentTime + this.listener.timeDelta;
  25465. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  25466. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  25467. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  25468. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  25469. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  25470. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  25471. } else {
  25472. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  25473. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  25474. }
  25475. };
  25476. return PositionalAudio;
  25477. }(Audio);
  25478. var AudioAnalyser = /*#__PURE__*/function () {
  25479. function AudioAnalyser(audio, fftSize) {
  25480. if (fftSize === void 0) {
  25481. fftSize = 2048;
  25482. }
  25483. this.analyser = audio.context.createAnalyser();
  25484. this.analyser.fftSize = fftSize;
  25485. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  25486. audio.getOutput().connect(this.analyser);
  25487. }
  25488. var _proto = AudioAnalyser.prototype;
  25489. _proto.getFrequencyData = function getFrequencyData() {
  25490. this.analyser.getByteFrequencyData(this.data);
  25491. return this.data;
  25492. };
  25493. _proto.getAverageFrequency = function getAverageFrequency() {
  25494. var value = 0;
  25495. var data = this.getFrequencyData();
  25496. for (var i = 0; i < data.length; i++) {
  25497. value += data[i];
  25498. }
  25499. return value / data.length;
  25500. };
  25501. return AudioAnalyser;
  25502. }();
  25503. function PropertyMixer(binding, typeName, valueSize) {
  25504. this.binding = binding;
  25505. this.valueSize = valueSize;
  25506. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  25507. //
  25508. // interpolators can use .buffer as their .result
  25509. // the data then goes to 'incoming'
  25510. //
  25511. // 'accu0' and 'accu1' are used frame-interleaved for
  25512. // the cumulative result and are compared to detect
  25513. // changes
  25514. //
  25515. // 'orig' stores the original state of the property
  25516. //
  25517. // 'add' is used for additive cumulative results
  25518. //
  25519. // 'work' is optional and is only present for quaternion types. It is used
  25520. // to store intermediate quaternion multiplication results
  25521. switch (typeName) {
  25522. case 'quaternion':
  25523. mixFunction = this._slerp;
  25524. mixFunctionAdditive = this._slerpAdditive;
  25525. setIdentity = this._setAdditiveIdentityQuaternion;
  25526. this.buffer = new Float64Array(valueSize * 6);
  25527. this._workIndex = 5;
  25528. break;
  25529. case 'string':
  25530. case 'bool':
  25531. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  25532. // additive is not relevant for non-numeric types
  25533. mixFunctionAdditive = this._select;
  25534. setIdentity = this._setAdditiveIdentityOther;
  25535. this.buffer = new Array(valueSize * 5);
  25536. break;
  25537. default:
  25538. mixFunction = this._lerp;
  25539. mixFunctionAdditive = this._lerpAdditive;
  25540. setIdentity = this._setAdditiveIdentityNumeric;
  25541. this.buffer = new Float64Array(valueSize * 5);
  25542. }
  25543. this._mixBufferRegion = mixFunction;
  25544. this._mixBufferRegionAdditive = mixFunctionAdditive;
  25545. this._setIdentity = setIdentity;
  25546. this._origIndex = 3;
  25547. this._addIndex = 4;
  25548. this.cumulativeWeight = 0;
  25549. this.cumulativeWeightAdditive = 0;
  25550. this.useCount = 0;
  25551. this.referenceCount = 0;
  25552. }
  25553. Object.assign(PropertyMixer.prototype, {
  25554. // accumulate data in the 'incoming' region into 'accu<i>'
  25555. accumulate: function accumulate(accuIndex, weight) {
  25556. // note: happily accumulating nothing when weight = 0, the caller knows
  25557. // the weight and shouldn't have made the call in the first place
  25558. var buffer = this.buffer,
  25559. stride = this.valueSize,
  25560. offset = accuIndex * stride + stride;
  25561. var currentWeight = this.cumulativeWeight;
  25562. if (currentWeight === 0) {
  25563. // accuN := incoming * weight
  25564. for (var i = 0; i !== stride; ++i) {
  25565. buffer[offset + i] = buffer[i];
  25566. }
  25567. currentWeight = weight;
  25568. } else {
  25569. // accuN := accuN + incoming * weight
  25570. currentWeight += weight;
  25571. var mix = weight / currentWeight;
  25572. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  25573. }
  25574. this.cumulativeWeight = currentWeight;
  25575. },
  25576. // accumulate data in the 'incoming' region into 'add'
  25577. accumulateAdditive: function accumulateAdditive(weight) {
  25578. var buffer = this.buffer,
  25579. stride = this.valueSize,
  25580. offset = stride * this._addIndex;
  25581. if (this.cumulativeWeightAdditive === 0) {
  25582. // add = identity
  25583. this._setIdentity();
  25584. } // add := add + incoming * weight
  25585. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  25586. this.cumulativeWeightAdditive += weight;
  25587. },
  25588. // apply the state of 'accu<i>' to the binding when accus differ
  25589. apply: function apply(accuIndex) {
  25590. var stride = this.valueSize,
  25591. buffer = this.buffer,
  25592. offset = accuIndex * stride + stride,
  25593. weight = this.cumulativeWeight,
  25594. weightAdditive = this.cumulativeWeightAdditive,
  25595. binding = this.binding;
  25596. this.cumulativeWeight = 0;
  25597. this.cumulativeWeightAdditive = 0;
  25598. if (weight < 1) {
  25599. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25600. var originalValueOffset = stride * this._origIndex;
  25601. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  25602. }
  25603. if (weightAdditive > 0) {
  25604. // accuN := accuN + additive accuN
  25605. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  25606. }
  25607. for (var i = stride, e = stride + stride; i !== e; ++i) {
  25608. if (buffer[i] !== buffer[i + stride]) {
  25609. // value has changed -> update scene graph
  25610. binding.setValue(buffer, offset);
  25611. break;
  25612. }
  25613. }
  25614. },
  25615. // remember the state of the bound property and copy it to both accus
  25616. saveOriginalState: function saveOriginalState() {
  25617. var binding = this.binding;
  25618. var buffer = this.buffer,
  25619. stride = this.valueSize,
  25620. originalValueOffset = stride * this._origIndex;
  25621. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  25622. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  25623. buffer[i] = buffer[originalValueOffset + i % stride];
  25624. } // Add to identity for additive
  25625. this._setIdentity();
  25626. this.cumulativeWeight = 0;
  25627. this.cumulativeWeightAdditive = 0;
  25628. },
  25629. // apply the state previously taken via 'saveOriginalState' to the binding
  25630. restoreOriginalState: function restoreOriginalState() {
  25631. var originalValueOffset = this.valueSize * 3;
  25632. this.binding.setValue(this.buffer, originalValueOffset);
  25633. },
  25634. _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
  25635. var startIndex = this._addIndex * this.valueSize;
  25636. var endIndex = startIndex + this.valueSize;
  25637. for (var i = startIndex; i < endIndex; i++) {
  25638. this.buffer[i] = 0;
  25639. }
  25640. },
  25641. _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
  25642. this._setAdditiveIdentityNumeric();
  25643. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  25644. },
  25645. _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
  25646. var startIndex = this._origIndex * this.valueSize;
  25647. var targetIndex = this._addIndex * this.valueSize;
  25648. for (var i = 0; i < this.valueSize; i++) {
  25649. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  25650. }
  25651. },
  25652. // mix functions
  25653. _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
  25654. if (t >= 0.5) {
  25655. for (var i = 0; i !== stride; ++i) {
  25656. buffer[dstOffset + i] = buffer[srcOffset + i];
  25657. }
  25658. }
  25659. },
  25660. _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
  25661. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  25662. },
  25663. _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25664. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  25665. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  25666. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  25667. },
  25668. _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  25669. var s = 1 - t;
  25670. for (var i = 0; i !== stride; ++i) {
  25671. var j = dstOffset + i;
  25672. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  25673. }
  25674. },
  25675. _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25676. for (var i = 0; i !== stride; ++i) {
  25677. var j = dstOffset + i;
  25678. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  25679. }
  25680. }
  25681. });
  25682. // Characters [].:/ are reserved for track binding syntax.
  25683. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  25684. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  25685. // only latin characters, and the unicode \p{L} is not yet supported. So
  25686. // instead, we exclude reserved characters and match everything else.
  25687. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  25688. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  25689. // be matched to parse the rest of the track name.
  25690. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  25691. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  25692. // characters. Accessor may contain any character except closing bracket.
  25693. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  25694. // contain any non-bracket characters.
  25695. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  25696. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  25697. var _supportedObjectNames = ['material', 'materials', 'bones'];
  25698. function Composite(targetGroup, path, optionalParsedPath) {
  25699. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  25700. this._targetGroup = targetGroup;
  25701. this._bindings = targetGroup.subscribe_(path, parsedPath);
  25702. }
  25703. Object.assign(Composite.prototype, {
  25704. getValue: function getValue(array, offset) {
  25705. this.bind(); // bind all binding
  25706. var firstValidIndex = this._targetGroup.nCachedObjects_,
  25707. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  25708. if (binding !== undefined) binding.getValue(array, offset);
  25709. },
  25710. setValue: function setValue(array, offset) {
  25711. var bindings = this._bindings;
  25712. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25713. bindings[i].setValue(array, offset);
  25714. }
  25715. },
  25716. bind: function bind() {
  25717. var bindings = this._bindings;
  25718. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25719. bindings[i].bind();
  25720. }
  25721. },
  25722. unbind: function unbind() {
  25723. var bindings = this._bindings;
  25724. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25725. bindings[i].unbind();
  25726. }
  25727. }
  25728. });
  25729. function PropertyBinding(rootNode, path, parsedPath) {
  25730. this.path = path;
  25731. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  25732. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  25733. this.rootNode = rootNode;
  25734. }
  25735. Object.assign(PropertyBinding, {
  25736. Composite: Composite,
  25737. create: function create(root, path, parsedPath) {
  25738. if (!(root && root.isAnimationObjectGroup)) {
  25739. return new PropertyBinding(root, path, parsedPath);
  25740. } else {
  25741. return new PropertyBinding.Composite(root, path, parsedPath);
  25742. }
  25743. },
  25744. /**
  25745. * Replaces spaces with underscores and removes unsupported characters from
  25746. * node names, to ensure compatibility with parseTrackName().
  25747. *
  25748. * @param {string} name Node name to be sanitized.
  25749. * @return {string}
  25750. */
  25751. sanitizeNodeName: function sanitizeNodeName(name) {
  25752. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  25753. },
  25754. parseTrackName: function parseTrackName(trackName) {
  25755. var matches = _trackRe.exec(trackName);
  25756. if (!matches) {
  25757. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  25758. }
  25759. var results = {
  25760. // directoryName: matches[ 1 ], // (tschw) currently unused
  25761. nodeName: matches[2],
  25762. objectName: matches[3],
  25763. objectIndex: matches[4],
  25764. propertyName: matches[5],
  25765. // required
  25766. propertyIndex: matches[6]
  25767. };
  25768. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  25769. if (lastDot !== undefined && lastDot !== -1) {
  25770. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  25771. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  25772. // 'bar' could be the objectName, or part of a nodeName (which can
  25773. // include '.' characters).
  25774. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  25775. results.nodeName = results.nodeName.substring(0, lastDot);
  25776. results.objectName = objectName;
  25777. }
  25778. }
  25779. if (results.propertyName === null || results.propertyName.length === 0) {
  25780. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  25781. }
  25782. return results;
  25783. },
  25784. findNode: function findNode(root, nodeName) {
  25785. if (!nodeName || nodeName === '' || nodeName === '.' || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  25786. return root;
  25787. } // search into skeleton bones.
  25788. if (root.skeleton) {
  25789. var bone = root.skeleton.getBoneByName(nodeName);
  25790. if (bone !== undefined) {
  25791. return bone;
  25792. }
  25793. } // search into node subtree.
  25794. if (root.children) {
  25795. var searchNodeSubtree = function searchNodeSubtree(children) {
  25796. for (var i = 0; i < children.length; i++) {
  25797. var childNode = children[i];
  25798. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  25799. return childNode;
  25800. }
  25801. var result = searchNodeSubtree(childNode.children);
  25802. if (result) return result;
  25803. }
  25804. return null;
  25805. };
  25806. var subTreeNode = searchNodeSubtree(root.children);
  25807. if (subTreeNode) {
  25808. return subTreeNode;
  25809. }
  25810. }
  25811. return null;
  25812. }
  25813. });
  25814. Object.assign(PropertyBinding.prototype, {
  25815. // prototype, continued
  25816. // these are used to "bind" a nonexistent property
  25817. _getValue_unavailable: function _getValue_unavailable() {},
  25818. _setValue_unavailable: function _setValue_unavailable() {},
  25819. BindingType: {
  25820. Direct: 0,
  25821. EntireArray: 1,
  25822. ArrayElement: 2,
  25823. HasFromToArray: 3
  25824. },
  25825. Versioning: {
  25826. None: 0,
  25827. NeedsUpdate: 1,
  25828. MatrixWorldNeedsUpdate: 2
  25829. },
  25830. GetterByBindingType: [function getValue_direct(buffer, offset) {
  25831. buffer[offset] = this.node[this.propertyName];
  25832. }, function getValue_array(buffer, offset) {
  25833. var source = this.resolvedProperty;
  25834. for (var i = 0, n = source.length; i !== n; ++i) {
  25835. buffer[offset++] = source[i];
  25836. }
  25837. }, function getValue_arrayElement(buffer, offset) {
  25838. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  25839. }, function getValue_toArray(buffer, offset) {
  25840. this.resolvedProperty.toArray(buffer, offset);
  25841. }],
  25842. SetterByBindingTypeAndVersioning: [[// Direct
  25843. function setValue_direct(buffer, offset) {
  25844. this.targetObject[this.propertyName] = buffer[offset];
  25845. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  25846. this.targetObject[this.propertyName] = buffer[offset];
  25847. this.targetObject.needsUpdate = true;
  25848. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  25849. this.targetObject[this.propertyName] = buffer[offset];
  25850. this.targetObject.matrixWorldNeedsUpdate = true;
  25851. }], [// EntireArray
  25852. function setValue_array(buffer, offset) {
  25853. var dest = this.resolvedProperty;
  25854. for (var i = 0, n = dest.length; i !== n; ++i) {
  25855. dest[i] = buffer[offset++];
  25856. }
  25857. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  25858. var dest = this.resolvedProperty;
  25859. for (var i = 0, n = dest.length; i !== n; ++i) {
  25860. dest[i] = buffer[offset++];
  25861. }
  25862. this.targetObject.needsUpdate = true;
  25863. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  25864. var dest = this.resolvedProperty;
  25865. for (var i = 0, n = dest.length; i !== n; ++i) {
  25866. dest[i] = buffer[offset++];
  25867. }
  25868. this.targetObject.matrixWorldNeedsUpdate = true;
  25869. }], [// ArrayElement
  25870. function setValue_arrayElement(buffer, offset) {
  25871. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25872. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  25873. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25874. this.targetObject.needsUpdate = true;
  25875. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  25876. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25877. this.targetObject.matrixWorldNeedsUpdate = true;
  25878. }], [// HasToFromArray
  25879. function setValue_fromArray(buffer, offset) {
  25880. this.resolvedProperty.fromArray(buffer, offset);
  25881. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  25882. this.resolvedProperty.fromArray(buffer, offset);
  25883. this.targetObject.needsUpdate = true;
  25884. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  25885. this.resolvedProperty.fromArray(buffer, offset);
  25886. this.targetObject.matrixWorldNeedsUpdate = true;
  25887. }]],
  25888. getValue: function getValue_unbound(targetArray, offset) {
  25889. this.bind();
  25890. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  25891. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  25892. // prototype version of these methods with one that represents
  25893. // the bound state. When the property is not found, the methods
  25894. // become no-ops.
  25895. },
  25896. setValue: function getValue_unbound(sourceArray, offset) {
  25897. this.bind();
  25898. this.setValue(sourceArray, offset);
  25899. },
  25900. // create getter / setter pair for a property in the scene graph
  25901. bind: function bind() {
  25902. var targetObject = this.node;
  25903. var parsedPath = this.parsedPath;
  25904. var objectName = parsedPath.objectName;
  25905. var propertyName = parsedPath.propertyName;
  25906. var propertyIndex = parsedPath.propertyIndex;
  25907. if (!targetObject) {
  25908. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  25909. this.node = targetObject;
  25910. } // set fail state so we can just 'return' on error
  25911. this.getValue = this._getValue_unavailable;
  25912. this.setValue = this._setValue_unavailable; // ensure there is a value node
  25913. if (!targetObject) {
  25914. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  25915. return;
  25916. }
  25917. if (objectName) {
  25918. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  25919. switch (objectName) {
  25920. case 'materials':
  25921. if (!targetObject.material) {
  25922. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  25923. return;
  25924. }
  25925. if (!targetObject.material.materials) {
  25926. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  25927. return;
  25928. }
  25929. targetObject = targetObject.material.materials;
  25930. break;
  25931. case 'bones':
  25932. if (!targetObject.skeleton) {
  25933. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  25934. return;
  25935. } // potential future optimization: skip this if propertyIndex is already an integer
  25936. // and convert the integer string to a true integer.
  25937. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  25938. for (var i = 0; i < targetObject.length; i++) {
  25939. if (targetObject[i].name === objectIndex) {
  25940. objectIndex = i;
  25941. break;
  25942. }
  25943. }
  25944. break;
  25945. default:
  25946. if (targetObject[objectName] === undefined) {
  25947. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  25948. return;
  25949. }
  25950. targetObject = targetObject[objectName];
  25951. }
  25952. if (objectIndex !== undefined) {
  25953. if (targetObject[objectIndex] === undefined) {
  25954. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  25955. return;
  25956. }
  25957. targetObject = targetObject[objectIndex];
  25958. }
  25959. } // resolve property
  25960. var nodeProperty = targetObject[propertyName];
  25961. if (nodeProperty === undefined) {
  25962. var nodeName = parsedPath.nodeName;
  25963. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  25964. return;
  25965. } // determine versioning scheme
  25966. var versioning = this.Versioning.None;
  25967. this.targetObject = targetObject;
  25968. if (targetObject.needsUpdate !== undefined) {
  25969. // material
  25970. versioning = this.Versioning.NeedsUpdate;
  25971. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  25972. // node transform
  25973. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  25974. } // determine how the property gets bound
  25975. var bindingType = this.BindingType.Direct;
  25976. if (propertyIndex !== undefined) {
  25977. // access a sub element of the property array (only primitives are supported right now)
  25978. if (propertyName === 'morphTargetInfluences') {
  25979. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  25980. // support resolving morphTarget names into indices.
  25981. if (!targetObject.geometry) {
  25982. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  25983. return;
  25984. }
  25985. if (targetObject.geometry.isBufferGeometry) {
  25986. if (!targetObject.geometry.morphAttributes) {
  25987. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  25988. return;
  25989. }
  25990. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  25991. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  25992. }
  25993. } else {
  25994. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  25995. return;
  25996. }
  25997. }
  25998. bindingType = this.BindingType.ArrayElement;
  25999. this.resolvedProperty = nodeProperty;
  26000. this.propertyIndex = propertyIndex;
  26001. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  26002. // must use copy for Object3D.Euler/Quaternion
  26003. bindingType = this.BindingType.HasFromToArray;
  26004. this.resolvedProperty = nodeProperty;
  26005. } else if (Array.isArray(nodeProperty)) {
  26006. bindingType = this.BindingType.EntireArray;
  26007. this.resolvedProperty = nodeProperty;
  26008. } else {
  26009. this.propertyName = propertyName;
  26010. } // select getter / setter
  26011. this.getValue = this.GetterByBindingType[bindingType];
  26012. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  26013. },
  26014. unbind: function unbind() {
  26015. this.node = null; // back to the prototype version of getValue / setValue
  26016. // note: avoiding to mutate the shape of 'this' via 'delete'
  26017. this.getValue = this._getValue_unbound;
  26018. this.setValue = this._setValue_unbound;
  26019. }
  26020. }); // DECLARE ALIAS AFTER assign prototype
  26021. Object.assign(PropertyBinding.prototype, {
  26022. // initial state of these methods that calls 'bind'
  26023. _getValue_unbound: PropertyBinding.prototype.getValue,
  26024. _setValue_unbound: PropertyBinding.prototype.setValue
  26025. });
  26026. /**
  26027. *
  26028. * A group of objects that receives a shared animation state.
  26029. *
  26030. * Usage:
  26031. *
  26032. * - Add objects you would otherwise pass as 'root' to the
  26033. * constructor or the .clipAction method of AnimationMixer.
  26034. *
  26035. * - Instead pass this object as 'root'.
  26036. *
  26037. * - You can also add and remove objects later when the mixer
  26038. * is running.
  26039. *
  26040. * Note:
  26041. *
  26042. * Objects of this class appear as one object to the mixer,
  26043. * so cache control of the individual objects must be done
  26044. * on the group.
  26045. *
  26046. * Limitation:
  26047. *
  26048. * - The animated properties must be compatible among the
  26049. * all objects in the group.
  26050. *
  26051. * - A single property can either be controlled through a
  26052. * target group or directly, but not both.
  26053. */
  26054. function AnimationObjectGroup() {
  26055. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  26056. this._objects = Array.prototype.slice.call(arguments);
  26057. this.nCachedObjects_ = 0; // threshold
  26058. // note: read by PropertyBinding.Composite
  26059. var indices = {};
  26060. this._indicesByUUID = indices; // for bookkeeping
  26061. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26062. indices[arguments[i].uuid] = i;
  26063. }
  26064. this._paths = []; // inside: string
  26065. this._parsedPaths = []; // inside: { we don't care, here }
  26066. this._bindings = []; // inside: Array< PropertyBinding >
  26067. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26068. var scope = this;
  26069. this.stats = {
  26070. objects: {
  26071. get total() {
  26072. return scope._objects.length;
  26073. },
  26074. get inUse() {
  26075. return this.total - scope.nCachedObjects_;
  26076. }
  26077. },
  26078. get bindingsPerObject() {
  26079. return scope._bindings.length;
  26080. }
  26081. };
  26082. }
  26083. Object.assign(AnimationObjectGroup.prototype, {
  26084. isAnimationObjectGroup: true,
  26085. add: function add() {
  26086. var objects = this._objects,
  26087. indicesByUUID = this._indicesByUUID,
  26088. paths = this._paths,
  26089. parsedPaths = this._parsedPaths,
  26090. bindings = this._bindings,
  26091. nBindings = bindings.length;
  26092. var knownObject = undefined,
  26093. nObjects = objects.length,
  26094. nCachedObjects = this.nCachedObjects_;
  26095. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26096. var object = arguments[i],
  26097. uuid = object.uuid;
  26098. var index = indicesByUUID[uuid];
  26099. if (index === undefined) {
  26100. // unknown object -> add it to the ACTIVE region
  26101. index = nObjects++;
  26102. indicesByUUID[uuid] = index;
  26103. objects.push(object); // accounting is done, now do the same for all bindings
  26104. for (var j = 0, m = nBindings; j !== m; ++j) {
  26105. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  26106. }
  26107. } else if (index < nCachedObjects) {
  26108. knownObject = objects[index]; // move existing object to the ACTIVE region
  26109. var firstActiveIndex = --nCachedObjects,
  26110. lastCachedObject = objects[firstActiveIndex];
  26111. indicesByUUID[lastCachedObject.uuid] = index;
  26112. objects[index] = lastCachedObject;
  26113. indicesByUUID[uuid] = firstActiveIndex;
  26114. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  26115. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  26116. var bindingsForPath = bindings[_j],
  26117. lastCached = bindingsForPath[firstActiveIndex];
  26118. var binding = bindingsForPath[index];
  26119. bindingsForPath[index] = lastCached;
  26120. if (binding === undefined) {
  26121. // since we do not bother to create new bindings
  26122. // for objects that are cached, the binding may
  26123. // or may not exist
  26124. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  26125. }
  26126. bindingsForPath[firstActiveIndex] = binding;
  26127. }
  26128. } else if (objects[index] !== knownObject) {
  26129. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  26130. } // else the object is already where we want it to be
  26131. } // for arguments
  26132. this.nCachedObjects_ = nCachedObjects;
  26133. },
  26134. remove: function remove() {
  26135. var objects = this._objects,
  26136. indicesByUUID = this._indicesByUUID,
  26137. bindings = this._bindings,
  26138. nBindings = bindings.length;
  26139. var nCachedObjects = this.nCachedObjects_;
  26140. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26141. var object = arguments[i],
  26142. uuid = object.uuid,
  26143. index = indicesByUUID[uuid];
  26144. if (index !== undefined && index >= nCachedObjects) {
  26145. // move existing object into the CACHED region
  26146. var lastCachedIndex = nCachedObjects++,
  26147. firstActiveObject = objects[lastCachedIndex];
  26148. indicesByUUID[firstActiveObject.uuid] = index;
  26149. objects[index] = firstActiveObject;
  26150. indicesByUUID[uuid] = lastCachedIndex;
  26151. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  26152. for (var j = 0, m = nBindings; j !== m; ++j) {
  26153. var bindingsForPath = bindings[j],
  26154. firstActive = bindingsForPath[lastCachedIndex],
  26155. binding = bindingsForPath[index];
  26156. bindingsForPath[index] = firstActive;
  26157. bindingsForPath[lastCachedIndex] = binding;
  26158. }
  26159. }
  26160. } // for arguments
  26161. this.nCachedObjects_ = nCachedObjects;
  26162. },
  26163. // remove & forget
  26164. uncache: function uncache() {
  26165. var objects = this._objects,
  26166. indicesByUUID = this._indicesByUUID,
  26167. bindings = this._bindings,
  26168. nBindings = bindings.length;
  26169. var nCachedObjects = this.nCachedObjects_,
  26170. nObjects = objects.length;
  26171. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26172. var object = arguments[i],
  26173. uuid = object.uuid,
  26174. index = indicesByUUID[uuid];
  26175. if (index !== undefined) {
  26176. delete indicesByUUID[uuid];
  26177. if (index < nCachedObjects) {
  26178. // object is cached, shrink the CACHED region
  26179. var firstActiveIndex = --nCachedObjects,
  26180. lastCachedObject = objects[firstActiveIndex],
  26181. lastIndex = --nObjects,
  26182. lastObject = objects[lastIndex]; // last cached object takes this object's place
  26183. indicesByUUID[lastCachedObject.uuid] = index;
  26184. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  26185. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  26186. objects[firstActiveIndex] = lastObject;
  26187. objects.pop(); // accounting is done, now do the same for all bindings
  26188. for (var j = 0, m = nBindings; j !== m; ++j) {
  26189. var bindingsForPath = bindings[j],
  26190. lastCached = bindingsForPath[firstActiveIndex],
  26191. last = bindingsForPath[lastIndex];
  26192. bindingsForPath[index] = lastCached;
  26193. bindingsForPath[firstActiveIndex] = last;
  26194. bindingsForPath.pop();
  26195. }
  26196. } else {
  26197. // object is active, just swap with the last and pop
  26198. var _lastIndex = --nObjects,
  26199. _lastObject = objects[_lastIndex];
  26200. if (_lastIndex > 0) {
  26201. indicesByUUID[_lastObject.uuid] = index;
  26202. }
  26203. objects[index] = _lastObject;
  26204. objects.pop(); // accounting is done, now do the same for all bindings
  26205. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  26206. var _bindingsForPath = bindings[_j2];
  26207. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  26208. _bindingsForPath.pop();
  26209. }
  26210. } // cached or active
  26211. } // if object is known
  26212. } // for arguments
  26213. this.nCachedObjects_ = nCachedObjects;
  26214. },
  26215. // Internal interface used by befriended PropertyBinding.Composite:
  26216. subscribe_: function subscribe_(path, parsedPath) {
  26217. // returns an array of bindings for the given path that is changed
  26218. // according to the contained objects in the group
  26219. var indicesByPath = this._bindingsIndicesByPath;
  26220. var index = indicesByPath[path];
  26221. var bindings = this._bindings;
  26222. if (index !== undefined) return bindings[index];
  26223. var paths = this._paths,
  26224. parsedPaths = this._parsedPaths,
  26225. objects = this._objects,
  26226. nObjects = objects.length,
  26227. nCachedObjects = this.nCachedObjects_,
  26228. bindingsForPath = new Array(nObjects);
  26229. index = bindings.length;
  26230. indicesByPath[path] = index;
  26231. paths.push(path);
  26232. parsedPaths.push(parsedPath);
  26233. bindings.push(bindingsForPath);
  26234. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  26235. var object = objects[i];
  26236. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  26237. }
  26238. return bindingsForPath;
  26239. },
  26240. unsubscribe_: function unsubscribe_(path) {
  26241. // tells the group to forget about a property path and no longer
  26242. // update the array previously obtained with 'subscribe_'
  26243. var indicesByPath = this._bindingsIndicesByPath,
  26244. index = indicesByPath[path];
  26245. if (index !== undefined) {
  26246. var paths = this._paths,
  26247. parsedPaths = this._parsedPaths,
  26248. bindings = this._bindings,
  26249. lastBindingsIndex = bindings.length - 1,
  26250. lastBindings = bindings[lastBindingsIndex],
  26251. lastBindingsPath = path[lastBindingsIndex];
  26252. indicesByPath[lastBindingsPath] = index;
  26253. bindings[index] = lastBindings;
  26254. bindings.pop();
  26255. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  26256. parsedPaths.pop();
  26257. paths[index] = paths[lastBindingsIndex];
  26258. paths.pop();
  26259. }
  26260. }
  26261. });
  26262. var AnimationAction = /*#__PURE__*/function () {
  26263. function AnimationAction(mixer, clip, localRoot, blendMode) {
  26264. if (localRoot === void 0) {
  26265. localRoot = null;
  26266. }
  26267. if (blendMode === void 0) {
  26268. blendMode = clip.blendMode;
  26269. }
  26270. this._mixer = mixer;
  26271. this._clip = clip;
  26272. this._localRoot = localRoot;
  26273. this.blendMode = blendMode;
  26274. var tracks = clip.tracks,
  26275. nTracks = tracks.length,
  26276. interpolants = new Array(nTracks);
  26277. var interpolantSettings = {
  26278. endingStart: ZeroCurvatureEnding,
  26279. endingEnd: ZeroCurvatureEnding
  26280. };
  26281. for (var i = 0; i !== nTracks; ++i) {
  26282. var interpolant = tracks[i].createInterpolant(null);
  26283. interpolants[i] = interpolant;
  26284. interpolant.settings = interpolantSettings;
  26285. }
  26286. this._interpolantSettings = interpolantSettings;
  26287. this._interpolants = interpolants; // bound by the mixer
  26288. // inside: PropertyMixer (managed by the mixer)
  26289. this._propertyBindings = new Array(nTracks);
  26290. this._cacheIndex = null; // for the memory manager
  26291. this._byClipCacheIndex = null; // for the memory manager
  26292. this._timeScaleInterpolant = null;
  26293. this._weightInterpolant = null;
  26294. this.loop = LoopRepeat;
  26295. this._loopCount = -1; // global mixer time when the action is to be started
  26296. // it's set back to 'null' upon start of the action
  26297. this._startTime = null; // scaled local time of the action
  26298. // gets clamped or wrapped to 0..clip.duration according to loop
  26299. this.time = 0;
  26300. this.timeScale = 1;
  26301. this._effectiveTimeScale = 1;
  26302. this.weight = 1;
  26303. this._effectiveWeight = 1;
  26304. this.repetitions = Infinity; // no. of repetitions when looping
  26305. this.paused = false; // true -> zero effective time scale
  26306. this.enabled = true; // false -> zero effective weight
  26307. this.clampWhenFinished = false; // keep feeding the last frame?
  26308. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  26309. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  26310. } // State & Scheduling
  26311. var _proto = AnimationAction.prototype;
  26312. _proto.play = function play() {
  26313. this._mixer._activateAction(this);
  26314. return this;
  26315. };
  26316. _proto.stop = function stop() {
  26317. this._mixer._deactivateAction(this);
  26318. return this.reset();
  26319. };
  26320. _proto.reset = function reset() {
  26321. this.paused = false;
  26322. this.enabled = true;
  26323. this.time = 0; // restart clip
  26324. this._loopCount = -1; // forget previous loops
  26325. this._startTime = null; // forget scheduling
  26326. return this.stopFading().stopWarping();
  26327. };
  26328. _proto.isRunning = function isRunning() {
  26329. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  26330. } // return true when play has been called
  26331. ;
  26332. _proto.isScheduled = function isScheduled() {
  26333. return this._mixer._isActiveAction(this);
  26334. };
  26335. _proto.startAt = function startAt(time) {
  26336. this._startTime = time;
  26337. return this;
  26338. };
  26339. _proto.setLoop = function setLoop(mode, repetitions) {
  26340. this.loop = mode;
  26341. this.repetitions = repetitions;
  26342. return this;
  26343. } // Weight
  26344. // set the weight stopping any scheduled fading
  26345. // although .enabled = false yields an effective weight of zero, this
  26346. // method does *not* change .enabled, because it would be confusing
  26347. ;
  26348. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  26349. this.weight = weight; // note: same logic as when updated at runtime
  26350. this._effectiveWeight = this.enabled ? weight : 0;
  26351. return this.stopFading();
  26352. } // return the weight considering fading and .enabled
  26353. ;
  26354. _proto.getEffectiveWeight = function getEffectiveWeight() {
  26355. return this._effectiveWeight;
  26356. };
  26357. _proto.fadeIn = function fadeIn(duration) {
  26358. return this._scheduleFading(duration, 0, 1);
  26359. };
  26360. _proto.fadeOut = function fadeOut(duration) {
  26361. return this._scheduleFading(duration, 1, 0);
  26362. };
  26363. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  26364. fadeOutAction.fadeOut(duration);
  26365. this.fadeIn(duration);
  26366. if (warp) {
  26367. var fadeInDuration = this._clip.duration,
  26368. fadeOutDuration = fadeOutAction._clip.duration,
  26369. startEndRatio = fadeOutDuration / fadeInDuration,
  26370. endStartRatio = fadeInDuration / fadeOutDuration;
  26371. fadeOutAction.warp(1.0, startEndRatio, duration);
  26372. this.warp(endStartRatio, 1.0, duration);
  26373. }
  26374. return this;
  26375. };
  26376. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  26377. return fadeInAction.crossFadeFrom(this, duration, warp);
  26378. };
  26379. _proto.stopFading = function stopFading() {
  26380. var weightInterpolant = this._weightInterpolant;
  26381. if (weightInterpolant !== null) {
  26382. this._weightInterpolant = null;
  26383. this._mixer._takeBackControlInterpolant(weightInterpolant);
  26384. }
  26385. return this;
  26386. } // Time Scale Control
  26387. // set the time scale stopping any scheduled warping
  26388. // although .paused = true yields an effective time scale of zero, this
  26389. // method does *not* change .paused, because it would be confusing
  26390. ;
  26391. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  26392. this.timeScale = timeScale;
  26393. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26394. return this.stopWarping();
  26395. } // return the time scale considering warping and .paused
  26396. ;
  26397. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  26398. return this._effectiveTimeScale;
  26399. };
  26400. _proto.setDuration = function setDuration(duration) {
  26401. this.timeScale = this._clip.duration / duration;
  26402. return this.stopWarping();
  26403. };
  26404. _proto.syncWith = function syncWith(action) {
  26405. this.time = action.time;
  26406. this.timeScale = action.timeScale;
  26407. return this.stopWarping();
  26408. };
  26409. _proto.halt = function halt(duration) {
  26410. return this.warp(this._effectiveTimeScale, 0, duration);
  26411. };
  26412. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  26413. var mixer = this._mixer,
  26414. now = mixer.time,
  26415. timeScale = this.timeScale;
  26416. var interpolant = this._timeScaleInterpolant;
  26417. if (interpolant === null) {
  26418. interpolant = mixer._lendControlInterpolant();
  26419. this._timeScaleInterpolant = interpolant;
  26420. }
  26421. var times = interpolant.parameterPositions,
  26422. values = interpolant.sampleValues;
  26423. times[0] = now;
  26424. times[1] = now + duration;
  26425. values[0] = startTimeScale / timeScale;
  26426. values[1] = endTimeScale / timeScale;
  26427. return this;
  26428. };
  26429. _proto.stopWarping = function stopWarping() {
  26430. var timeScaleInterpolant = this._timeScaleInterpolant;
  26431. if (timeScaleInterpolant !== null) {
  26432. this._timeScaleInterpolant = null;
  26433. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  26434. }
  26435. return this;
  26436. } // Object Accessors
  26437. ;
  26438. _proto.getMixer = function getMixer() {
  26439. return this._mixer;
  26440. };
  26441. _proto.getClip = function getClip() {
  26442. return this._clip;
  26443. };
  26444. _proto.getRoot = function getRoot() {
  26445. return this._localRoot || this._mixer._root;
  26446. } // Interna
  26447. ;
  26448. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  26449. // called by the mixer
  26450. if (!this.enabled) {
  26451. // call ._updateWeight() to update ._effectiveWeight
  26452. this._updateWeight(time);
  26453. return;
  26454. }
  26455. var startTime = this._startTime;
  26456. if (startTime !== null) {
  26457. // check for scheduled start of action
  26458. var timeRunning = (time - startTime) * timeDirection;
  26459. if (timeRunning < 0 || timeDirection === 0) {
  26460. return; // yet to come / don't decide when delta = 0
  26461. } // start
  26462. this._startTime = null; // unschedule
  26463. deltaTime = timeDirection * timeRunning;
  26464. } // apply time scale and advance time
  26465. deltaTime *= this._updateTimeScale(time);
  26466. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  26467. // an effective weight of 0
  26468. var weight = this._updateWeight(time);
  26469. if (weight > 0) {
  26470. var _interpolants = this._interpolants;
  26471. var propertyMixers = this._propertyBindings;
  26472. switch (this.blendMode) {
  26473. case AdditiveAnimationBlendMode:
  26474. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  26475. _interpolants[j].evaluate(clipTime);
  26476. propertyMixers[j].accumulateAdditive(weight);
  26477. }
  26478. break;
  26479. case NormalAnimationBlendMode:
  26480. default:
  26481. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  26482. _interpolants[_j].evaluate(clipTime);
  26483. propertyMixers[_j].accumulate(accuIndex, weight);
  26484. }
  26485. }
  26486. }
  26487. };
  26488. _proto._updateWeight = function _updateWeight(time) {
  26489. var weight = 0;
  26490. if (this.enabled) {
  26491. weight = this.weight;
  26492. var interpolant = this._weightInterpolant;
  26493. if (interpolant !== null) {
  26494. var interpolantValue = interpolant.evaluate(time)[0];
  26495. weight *= interpolantValue;
  26496. if (time > interpolant.parameterPositions[1]) {
  26497. this.stopFading();
  26498. if (interpolantValue === 0) {
  26499. // faded out, disable
  26500. this.enabled = false;
  26501. }
  26502. }
  26503. }
  26504. }
  26505. this._effectiveWeight = weight;
  26506. return weight;
  26507. };
  26508. _proto._updateTimeScale = function _updateTimeScale(time) {
  26509. var timeScale = 0;
  26510. if (!this.paused) {
  26511. timeScale = this.timeScale;
  26512. var interpolant = this._timeScaleInterpolant;
  26513. if (interpolant !== null) {
  26514. var interpolantValue = interpolant.evaluate(time)[0];
  26515. timeScale *= interpolantValue;
  26516. if (time > interpolant.parameterPositions[1]) {
  26517. this.stopWarping();
  26518. if (timeScale === 0) {
  26519. // motion has halted, pause
  26520. this.paused = true;
  26521. } else {
  26522. // warp done - apply final time scale
  26523. this.timeScale = timeScale;
  26524. }
  26525. }
  26526. }
  26527. }
  26528. this._effectiveTimeScale = timeScale;
  26529. return timeScale;
  26530. };
  26531. _proto._updateTime = function _updateTime(deltaTime) {
  26532. var duration = this._clip.duration;
  26533. var loop = this.loop;
  26534. var time = this.time + deltaTime;
  26535. var loopCount = this._loopCount;
  26536. var pingPong = loop === LoopPingPong;
  26537. if (deltaTime === 0) {
  26538. if (loopCount === -1) return time;
  26539. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  26540. }
  26541. if (loop === LoopOnce) {
  26542. if (loopCount === -1) {
  26543. // just started
  26544. this._loopCount = 0;
  26545. this._setEndings(true, true, false);
  26546. }
  26547. handle_stop: {
  26548. if (time >= duration) {
  26549. time = duration;
  26550. } else if (time < 0) {
  26551. time = 0;
  26552. } else {
  26553. this.time = time;
  26554. break handle_stop;
  26555. }
  26556. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26557. this.time = time;
  26558. this._mixer.dispatchEvent({
  26559. type: 'finished',
  26560. action: this,
  26561. direction: deltaTime < 0 ? -1 : 1
  26562. });
  26563. }
  26564. } else {
  26565. // repetitive Repeat or PingPong
  26566. if (loopCount === -1) {
  26567. // just started
  26568. if (deltaTime >= 0) {
  26569. loopCount = 0;
  26570. this._setEndings(true, this.repetitions === 0, pingPong);
  26571. } else {
  26572. // when looping in reverse direction, the initial
  26573. // transition through zero counts as a repetition,
  26574. // so leave loopCount at -1
  26575. this._setEndings(this.repetitions === 0, true, pingPong);
  26576. }
  26577. }
  26578. if (time >= duration || time < 0) {
  26579. // wrap around
  26580. var loopDelta = Math.floor(time / duration); // signed
  26581. time -= duration * loopDelta;
  26582. loopCount += Math.abs(loopDelta);
  26583. var pending = this.repetitions - loopCount;
  26584. if (pending <= 0) {
  26585. // have to stop (switch state, clamp time, fire event)
  26586. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26587. time = deltaTime > 0 ? duration : 0;
  26588. this.time = time;
  26589. this._mixer.dispatchEvent({
  26590. type: 'finished',
  26591. action: this,
  26592. direction: deltaTime > 0 ? 1 : -1
  26593. });
  26594. } else {
  26595. // keep running
  26596. if (pending === 1) {
  26597. // entering the last round
  26598. var atStart = deltaTime < 0;
  26599. this._setEndings(atStart, !atStart, pingPong);
  26600. } else {
  26601. this._setEndings(false, false, pingPong);
  26602. }
  26603. this._loopCount = loopCount;
  26604. this.time = time;
  26605. this._mixer.dispatchEvent({
  26606. type: 'loop',
  26607. action: this,
  26608. loopDelta: loopDelta
  26609. });
  26610. }
  26611. } else {
  26612. this.time = time;
  26613. }
  26614. if (pingPong && (loopCount & 1) === 1) {
  26615. // invert time for the "pong round"
  26616. return duration - time;
  26617. }
  26618. }
  26619. return time;
  26620. };
  26621. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  26622. var settings = this._interpolantSettings;
  26623. if (pingPong) {
  26624. settings.endingStart = ZeroSlopeEnding;
  26625. settings.endingEnd = ZeroSlopeEnding;
  26626. } else {
  26627. // assuming for LoopOnce atStart == atEnd == true
  26628. if (atStart) {
  26629. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26630. } else {
  26631. settings.endingStart = WrapAroundEnding;
  26632. }
  26633. if (atEnd) {
  26634. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26635. } else {
  26636. settings.endingEnd = WrapAroundEnding;
  26637. }
  26638. }
  26639. };
  26640. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  26641. var mixer = this._mixer,
  26642. now = mixer.time;
  26643. var interpolant = this._weightInterpolant;
  26644. if (interpolant === null) {
  26645. interpolant = mixer._lendControlInterpolant();
  26646. this._weightInterpolant = interpolant;
  26647. }
  26648. var times = interpolant.parameterPositions,
  26649. values = interpolant.sampleValues;
  26650. times[0] = now;
  26651. values[0] = weightNow;
  26652. times[1] = now + duration;
  26653. values[1] = weightThen;
  26654. return this;
  26655. };
  26656. return AnimationAction;
  26657. }();
  26658. function AnimationMixer(root) {
  26659. this._root = root;
  26660. this._initMemoryManager();
  26661. this._accuIndex = 0;
  26662. this.time = 0;
  26663. this.timeScale = 1.0;
  26664. }
  26665. AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  26666. constructor: AnimationMixer,
  26667. _bindAction: function _bindAction(action, prototypeAction) {
  26668. var root = action._localRoot || this._root,
  26669. tracks = action._clip.tracks,
  26670. nTracks = tracks.length,
  26671. bindings = action._propertyBindings,
  26672. interpolants = action._interpolants,
  26673. rootUuid = root.uuid,
  26674. bindingsByRoot = this._bindingsByRootAndName;
  26675. var bindingsByName = bindingsByRoot[rootUuid];
  26676. if (bindingsByName === undefined) {
  26677. bindingsByName = {};
  26678. bindingsByRoot[rootUuid] = bindingsByName;
  26679. }
  26680. for (var i = 0; i !== nTracks; ++i) {
  26681. var track = tracks[i],
  26682. trackName = track.name;
  26683. var binding = bindingsByName[trackName];
  26684. if (binding !== undefined) {
  26685. bindings[i] = binding;
  26686. } else {
  26687. binding = bindings[i];
  26688. if (binding !== undefined) {
  26689. // existing binding, make sure the cache knows
  26690. if (binding._cacheIndex === null) {
  26691. ++binding.referenceCount;
  26692. this._addInactiveBinding(binding, rootUuid, trackName);
  26693. }
  26694. continue;
  26695. }
  26696. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  26697. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  26698. ++binding.referenceCount;
  26699. this._addInactiveBinding(binding, rootUuid, trackName);
  26700. bindings[i] = binding;
  26701. }
  26702. interpolants[i].resultBuffer = binding.buffer;
  26703. }
  26704. },
  26705. _activateAction: function _activateAction(action) {
  26706. if (!this._isActiveAction(action)) {
  26707. if (action._cacheIndex === null) {
  26708. // this action has been forgotten by the cache, but the user
  26709. // appears to be still using it -> rebind
  26710. var rootUuid = (action._localRoot || this._root).uuid,
  26711. clipUuid = action._clip.uuid,
  26712. actionsForClip = this._actionsByClip[clipUuid];
  26713. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  26714. this._addInactiveAction(action, clipUuid, rootUuid);
  26715. }
  26716. var bindings = action._propertyBindings; // increment reference counts / sort out state
  26717. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26718. var binding = bindings[i];
  26719. if (binding.useCount++ === 0) {
  26720. this._lendBinding(binding);
  26721. binding.saveOriginalState();
  26722. }
  26723. }
  26724. this._lendAction(action);
  26725. }
  26726. },
  26727. _deactivateAction: function _deactivateAction(action) {
  26728. if (this._isActiveAction(action)) {
  26729. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  26730. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26731. var binding = bindings[i];
  26732. if (--binding.useCount === 0) {
  26733. binding.restoreOriginalState();
  26734. this._takeBackBinding(binding);
  26735. }
  26736. }
  26737. this._takeBackAction(action);
  26738. }
  26739. },
  26740. // Memory manager
  26741. _initMemoryManager: function _initMemoryManager() {
  26742. this._actions = []; // 'nActiveActions' followed by inactive ones
  26743. this._nActiveActions = 0;
  26744. this._actionsByClip = {}; // inside:
  26745. // {
  26746. // knownActions: Array< AnimationAction > - used as prototypes
  26747. // actionByRoot: AnimationAction - lookup
  26748. // }
  26749. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  26750. this._nActiveBindings = 0;
  26751. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  26752. this._controlInterpolants = []; // same game as above
  26753. this._nActiveControlInterpolants = 0;
  26754. var scope = this;
  26755. this.stats = {
  26756. actions: {
  26757. get total() {
  26758. return scope._actions.length;
  26759. },
  26760. get inUse() {
  26761. return scope._nActiveActions;
  26762. }
  26763. },
  26764. bindings: {
  26765. get total() {
  26766. return scope._bindings.length;
  26767. },
  26768. get inUse() {
  26769. return scope._nActiveBindings;
  26770. }
  26771. },
  26772. controlInterpolants: {
  26773. get total() {
  26774. return scope._controlInterpolants.length;
  26775. },
  26776. get inUse() {
  26777. return scope._nActiveControlInterpolants;
  26778. }
  26779. }
  26780. };
  26781. },
  26782. // Memory management for AnimationAction objects
  26783. _isActiveAction: function _isActiveAction(action) {
  26784. var index = action._cacheIndex;
  26785. return index !== null && index < this._nActiveActions;
  26786. },
  26787. _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
  26788. var actions = this._actions,
  26789. actionsByClip = this._actionsByClip;
  26790. var actionsForClip = actionsByClip[clipUuid];
  26791. if (actionsForClip === undefined) {
  26792. actionsForClip = {
  26793. knownActions: [action],
  26794. actionByRoot: {}
  26795. };
  26796. action._byClipCacheIndex = 0;
  26797. actionsByClip[clipUuid] = actionsForClip;
  26798. } else {
  26799. var knownActions = actionsForClip.knownActions;
  26800. action._byClipCacheIndex = knownActions.length;
  26801. knownActions.push(action);
  26802. }
  26803. action._cacheIndex = actions.length;
  26804. actions.push(action);
  26805. actionsForClip.actionByRoot[rootUuid] = action;
  26806. },
  26807. _removeInactiveAction: function _removeInactiveAction(action) {
  26808. var actions = this._actions,
  26809. lastInactiveAction = actions[actions.length - 1],
  26810. cacheIndex = action._cacheIndex;
  26811. lastInactiveAction._cacheIndex = cacheIndex;
  26812. actions[cacheIndex] = lastInactiveAction;
  26813. actions.pop();
  26814. action._cacheIndex = null;
  26815. var clipUuid = action._clip.uuid,
  26816. actionsByClip = this._actionsByClip,
  26817. actionsForClip = actionsByClip[clipUuid],
  26818. knownActionsForClip = actionsForClip.knownActions,
  26819. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  26820. byClipCacheIndex = action._byClipCacheIndex;
  26821. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  26822. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  26823. knownActionsForClip.pop();
  26824. action._byClipCacheIndex = null;
  26825. var actionByRoot = actionsForClip.actionByRoot,
  26826. rootUuid = (action._localRoot || this._root).uuid;
  26827. delete actionByRoot[rootUuid];
  26828. if (knownActionsForClip.length === 0) {
  26829. delete actionsByClip[clipUuid];
  26830. }
  26831. this._removeInactiveBindingsForAction(action);
  26832. },
  26833. _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
  26834. var bindings = action._propertyBindings;
  26835. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26836. var binding = bindings[i];
  26837. if (--binding.referenceCount === 0) {
  26838. this._removeInactiveBinding(binding);
  26839. }
  26840. }
  26841. },
  26842. _lendAction: function _lendAction(action) {
  26843. // [ active actions | inactive actions ]
  26844. // [ active actions >| inactive actions ]
  26845. // s a
  26846. // <-swap->
  26847. // a s
  26848. var actions = this._actions,
  26849. prevIndex = action._cacheIndex,
  26850. lastActiveIndex = this._nActiveActions++,
  26851. firstInactiveAction = actions[lastActiveIndex];
  26852. action._cacheIndex = lastActiveIndex;
  26853. actions[lastActiveIndex] = action;
  26854. firstInactiveAction._cacheIndex = prevIndex;
  26855. actions[prevIndex] = firstInactiveAction;
  26856. },
  26857. _takeBackAction: function _takeBackAction(action) {
  26858. // [ active actions | inactive actions ]
  26859. // [ active actions |< inactive actions ]
  26860. // a s
  26861. // <-swap->
  26862. // s a
  26863. var actions = this._actions,
  26864. prevIndex = action._cacheIndex,
  26865. firstInactiveIndex = --this._nActiveActions,
  26866. lastActiveAction = actions[firstInactiveIndex];
  26867. action._cacheIndex = firstInactiveIndex;
  26868. actions[firstInactiveIndex] = action;
  26869. lastActiveAction._cacheIndex = prevIndex;
  26870. actions[prevIndex] = lastActiveAction;
  26871. },
  26872. // Memory management for PropertyMixer objects
  26873. _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
  26874. var bindingsByRoot = this._bindingsByRootAndName,
  26875. bindings = this._bindings;
  26876. var bindingByName = bindingsByRoot[rootUuid];
  26877. if (bindingByName === undefined) {
  26878. bindingByName = {};
  26879. bindingsByRoot[rootUuid] = bindingByName;
  26880. }
  26881. bindingByName[trackName] = binding;
  26882. binding._cacheIndex = bindings.length;
  26883. bindings.push(binding);
  26884. },
  26885. _removeInactiveBinding: function _removeInactiveBinding(binding) {
  26886. var bindings = this._bindings,
  26887. propBinding = binding.binding,
  26888. rootUuid = propBinding.rootNode.uuid,
  26889. trackName = propBinding.path,
  26890. bindingsByRoot = this._bindingsByRootAndName,
  26891. bindingByName = bindingsByRoot[rootUuid],
  26892. lastInactiveBinding = bindings[bindings.length - 1],
  26893. cacheIndex = binding._cacheIndex;
  26894. lastInactiveBinding._cacheIndex = cacheIndex;
  26895. bindings[cacheIndex] = lastInactiveBinding;
  26896. bindings.pop();
  26897. delete bindingByName[trackName];
  26898. if (Object.keys(bindingByName).length === 0) {
  26899. delete bindingsByRoot[rootUuid];
  26900. }
  26901. },
  26902. _lendBinding: function _lendBinding(binding) {
  26903. var bindings = this._bindings,
  26904. prevIndex = binding._cacheIndex,
  26905. lastActiveIndex = this._nActiveBindings++,
  26906. firstInactiveBinding = bindings[lastActiveIndex];
  26907. binding._cacheIndex = lastActiveIndex;
  26908. bindings[lastActiveIndex] = binding;
  26909. firstInactiveBinding._cacheIndex = prevIndex;
  26910. bindings[prevIndex] = firstInactiveBinding;
  26911. },
  26912. _takeBackBinding: function _takeBackBinding(binding) {
  26913. var bindings = this._bindings,
  26914. prevIndex = binding._cacheIndex,
  26915. firstInactiveIndex = --this._nActiveBindings,
  26916. lastActiveBinding = bindings[firstInactiveIndex];
  26917. binding._cacheIndex = firstInactiveIndex;
  26918. bindings[firstInactiveIndex] = binding;
  26919. lastActiveBinding._cacheIndex = prevIndex;
  26920. bindings[prevIndex] = lastActiveBinding;
  26921. },
  26922. // Memory management of Interpolants for weight and time scale
  26923. _lendControlInterpolant: function _lendControlInterpolant() {
  26924. var interpolants = this._controlInterpolants,
  26925. lastActiveIndex = this._nActiveControlInterpolants++;
  26926. var interpolant = interpolants[lastActiveIndex];
  26927. if (interpolant === undefined) {
  26928. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  26929. interpolant.__cacheIndex = lastActiveIndex;
  26930. interpolants[lastActiveIndex] = interpolant;
  26931. }
  26932. return interpolant;
  26933. },
  26934. _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
  26935. var interpolants = this._controlInterpolants,
  26936. prevIndex = interpolant.__cacheIndex,
  26937. firstInactiveIndex = --this._nActiveControlInterpolants,
  26938. lastActiveInterpolant = interpolants[firstInactiveIndex];
  26939. interpolant.__cacheIndex = firstInactiveIndex;
  26940. interpolants[firstInactiveIndex] = interpolant;
  26941. lastActiveInterpolant.__cacheIndex = prevIndex;
  26942. interpolants[prevIndex] = lastActiveInterpolant;
  26943. },
  26944. _controlInterpolantsResultBuffer: new Float32Array(1),
  26945. // return an action for a clip optionally using a custom root target
  26946. // object (this method allocates a lot of dynamic memory in case a
  26947. // previously unknown clip/root combination is specified)
  26948. clipAction: function clipAction(clip, optionalRoot, blendMode) {
  26949. var root = optionalRoot || this._root,
  26950. rootUuid = root.uuid;
  26951. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  26952. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  26953. var actionsForClip = this._actionsByClip[clipUuid];
  26954. var prototypeAction = null;
  26955. if (blendMode === undefined) {
  26956. if (clipObject !== null) {
  26957. blendMode = clipObject.blendMode;
  26958. } else {
  26959. blendMode = NormalAnimationBlendMode;
  26960. }
  26961. }
  26962. if (actionsForClip !== undefined) {
  26963. var existingAction = actionsForClip.actionByRoot[rootUuid];
  26964. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  26965. return existingAction;
  26966. } // we know the clip, so we don't have to parse all
  26967. // the bindings again but can just copy
  26968. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  26969. if (clipObject === null) clipObject = prototypeAction._clip;
  26970. } // clip must be known when specified via string
  26971. if (clipObject === null) return null; // allocate all resources required to run it
  26972. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  26973. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  26974. this._addInactiveAction(newAction, clipUuid, rootUuid);
  26975. return newAction;
  26976. },
  26977. // get an existing action
  26978. existingAction: function existingAction(clip, optionalRoot) {
  26979. var root = optionalRoot || this._root,
  26980. rootUuid = root.uuid,
  26981. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  26982. clipUuid = clipObject ? clipObject.uuid : clip,
  26983. actionsForClip = this._actionsByClip[clipUuid];
  26984. if (actionsForClip !== undefined) {
  26985. return actionsForClip.actionByRoot[rootUuid] || null;
  26986. }
  26987. return null;
  26988. },
  26989. // deactivates all previously scheduled actions
  26990. stopAllAction: function stopAllAction() {
  26991. var actions = this._actions,
  26992. nActions = this._nActiveActions;
  26993. for (var i = nActions - 1; i >= 0; --i) {
  26994. actions[i].stop();
  26995. }
  26996. return this;
  26997. },
  26998. // advance the time and update apply the animation
  26999. update: function update(deltaTime) {
  27000. deltaTime *= this.timeScale;
  27001. var actions = this._actions,
  27002. nActions = this._nActiveActions,
  27003. time = this.time += deltaTime,
  27004. timeDirection = Math.sign(deltaTime),
  27005. accuIndex = this._accuIndex ^= 1; // run active actions
  27006. for (var i = 0; i !== nActions; ++i) {
  27007. var action = actions[i];
  27008. action._update(time, deltaTime, timeDirection, accuIndex);
  27009. } // update scene graph
  27010. var bindings = this._bindings,
  27011. nBindings = this._nActiveBindings;
  27012. for (var _i = 0; _i !== nBindings; ++_i) {
  27013. bindings[_i].apply(accuIndex);
  27014. }
  27015. return this;
  27016. },
  27017. // Allows you to seek to a specific time in an animation.
  27018. setTime: function setTime(timeInSeconds) {
  27019. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27020. for (var i = 0; i < this._actions.length; i++) {
  27021. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27022. }
  27023. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  27024. },
  27025. // return this mixer's root target object
  27026. getRoot: function getRoot() {
  27027. return this._root;
  27028. },
  27029. // free all resources specific to a particular clip
  27030. uncacheClip: function uncacheClip(clip) {
  27031. var actions = this._actions,
  27032. clipUuid = clip.uuid,
  27033. actionsByClip = this._actionsByClip,
  27034. actionsForClip = actionsByClip[clipUuid];
  27035. if (actionsForClip !== undefined) {
  27036. // note: just calling _removeInactiveAction would mess up the
  27037. // iteration state and also require updating the state we can
  27038. // just throw away
  27039. var actionsToRemove = actionsForClip.knownActions;
  27040. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  27041. var action = actionsToRemove[i];
  27042. this._deactivateAction(action);
  27043. var cacheIndex = action._cacheIndex,
  27044. lastInactiveAction = actions[actions.length - 1];
  27045. action._cacheIndex = null;
  27046. action._byClipCacheIndex = null;
  27047. lastInactiveAction._cacheIndex = cacheIndex;
  27048. actions[cacheIndex] = lastInactiveAction;
  27049. actions.pop();
  27050. this._removeInactiveBindingsForAction(action);
  27051. }
  27052. delete actionsByClip[clipUuid];
  27053. }
  27054. },
  27055. // free all resources specific to a particular root target object
  27056. uncacheRoot: function uncacheRoot(root) {
  27057. var rootUuid = root.uuid,
  27058. actionsByClip = this._actionsByClip;
  27059. for (var clipUuid in actionsByClip) {
  27060. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  27061. action = actionByRoot[rootUuid];
  27062. if (action !== undefined) {
  27063. this._deactivateAction(action);
  27064. this._removeInactiveAction(action);
  27065. }
  27066. }
  27067. var bindingsByRoot = this._bindingsByRootAndName,
  27068. bindingByName = bindingsByRoot[rootUuid];
  27069. if (bindingByName !== undefined) {
  27070. for (var trackName in bindingByName) {
  27071. var binding = bindingByName[trackName];
  27072. binding.restoreOriginalState();
  27073. this._removeInactiveBinding(binding);
  27074. }
  27075. }
  27076. },
  27077. // remove a targeted clip from the cache
  27078. uncacheAction: function uncacheAction(clip, optionalRoot) {
  27079. var action = this.existingAction(clip, optionalRoot);
  27080. if (action !== null) {
  27081. this._deactivateAction(action);
  27082. this._removeInactiveAction(action);
  27083. }
  27084. }
  27085. });
  27086. var Uniform = /*#__PURE__*/function () {
  27087. function Uniform(value) {
  27088. if (typeof value === 'string') {
  27089. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  27090. value = arguments[1];
  27091. }
  27092. this.value = value;
  27093. }
  27094. var _proto = Uniform.prototype;
  27095. _proto.clone = function clone() {
  27096. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  27097. };
  27098. return Uniform;
  27099. }();
  27100. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27101. InterleavedBuffer.call(this, array, stride);
  27102. this.meshPerAttribute = meshPerAttribute || 1;
  27103. }
  27104. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27105. constructor: InstancedInterleavedBuffer,
  27106. isInstancedInterleavedBuffer: true,
  27107. copy: function copy(source) {
  27108. InterleavedBuffer.prototype.copy.call(this, source);
  27109. this.meshPerAttribute = source.meshPerAttribute;
  27110. return this;
  27111. },
  27112. clone: function clone(data) {
  27113. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27114. ib.meshPerAttribute = this.meshPerAttribute;
  27115. return ib;
  27116. },
  27117. toJSON: function toJSON(data) {
  27118. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27119. json.isInstancedInterleavedBuffer = true;
  27120. json.meshPerAttribute = this.meshPerAttribute;
  27121. return json;
  27122. }
  27123. });
  27124. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27125. this.buffer = buffer;
  27126. this.type = type;
  27127. this.itemSize = itemSize;
  27128. this.elementSize = elementSize;
  27129. this.count = count;
  27130. this.version = 0;
  27131. }
  27132. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27133. set: function set(value) {
  27134. if (value === true) this.version++;
  27135. }
  27136. });
  27137. Object.assign(GLBufferAttribute.prototype, {
  27138. isGLBufferAttribute: true,
  27139. setBuffer: function setBuffer(buffer) {
  27140. this.buffer = buffer;
  27141. return this;
  27142. },
  27143. setType: function setType(type, elementSize) {
  27144. this.type = type;
  27145. this.elementSize = elementSize;
  27146. return this;
  27147. },
  27148. setItemSize: function setItemSize(itemSize) {
  27149. this.itemSize = itemSize;
  27150. return this;
  27151. },
  27152. setCount: function setCount(count) {
  27153. this.count = count;
  27154. return this;
  27155. }
  27156. });
  27157. function Raycaster(origin, direction, near, far) {
  27158. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27159. this.near = near || 0;
  27160. this.far = far || Infinity;
  27161. this.camera = null;
  27162. this.layers = new Layers();
  27163. this.params = {
  27164. Mesh: {},
  27165. Line: {
  27166. threshold: 1
  27167. },
  27168. LOD: {},
  27169. Points: {
  27170. threshold: 1
  27171. },
  27172. Sprite: {}
  27173. };
  27174. Object.defineProperties(this.params, {
  27175. PointCloud: {
  27176. get: function get() {
  27177. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27178. return this.Points;
  27179. }
  27180. }
  27181. });
  27182. }
  27183. function ascSort(a, b) {
  27184. return a.distance - b.distance;
  27185. }
  27186. function _intersectObject(object, raycaster, intersects, recursive) {
  27187. if (object.layers.test(raycaster.layers)) {
  27188. object.raycast(raycaster, intersects);
  27189. }
  27190. if (recursive === true) {
  27191. var children = object.children;
  27192. for (var i = 0, l = children.length; i < l; i++) {
  27193. _intersectObject(children[i], raycaster, intersects, true);
  27194. }
  27195. }
  27196. }
  27197. Object.assign(Raycaster.prototype, {
  27198. set: function set(origin, direction) {
  27199. // direction is assumed to be normalized (for accurate distance calculations)
  27200. this.ray.set(origin, direction);
  27201. },
  27202. setFromCamera: function setFromCamera(coords, camera) {
  27203. if (camera && camera.isPerspectiveCamera) {
  27204. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27205. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27206. this.camera = camera;
  27207. } else if (camera && camera.isOrthographicCamera) {
  27208. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27209. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27210. this.camera = camera;
  27211. } else {
  27212. console.error('THREE.Raycaster: Unsupported camera type: ' + camera.type);
  27213. }
  27214. },
  27215. intersectObject: function intersectObject(object, recursive, optionalTarget) {
  27216. var intersects = optionalTarget || [];
  27217. _intersectObject(object, this, intersects, recursive);
  27218. intersects.sort(ascSort);
  27219. return intersects;
  27220. },
  27221. intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
  27222. var intersects = optionalTarget || [];
  27223. if (Array.isArray(objects) === false) {
  27224. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  27225. return intersects;
  27226. }
  27227. for (var i = 0, l = objects.length; i < l; i++) {
  27228. _intersectObject(objects[i], this, intersects, recursive);
  27229. }
  27230. intersects.sort(ascSort);
  27231. return intersects;
  27232. }
  27233. });
  27234. /**
  27235. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27236. *
  27237. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27238. * The azimuthal angle (theta) is measured from the positive z-axis.
  27239. */
  27240. var Spherical = /*#__PURE__*/function () {
  27241. function Spherical(radius, phi, theta) {
  27242. if (radius === void 0) {
  27243. radius = 1;
  27244. }
  27245. if (phi === void 0) {
  27246. phi = 0;
  27247. }
  27248. if (theta === void 0) {
  27249. theta = 0;
  27250. }
  27251. this.radius = radius;
  27252. this.phi = phi; // polar angle
  27253. this.theta = theta; // azimuthal angle
  27254. return this;
  27255. }
  27256. var _proto = Spherical.prototype;
  27257. _proto.set = function set(radius, phi, theta) {
  27258. this.radius = radius;
  27259. this.phi = phi;
  27260. this.theta = theta;
  27261. return this;
  27262. };
  27263. _proto.clone = function clone() {
  27264. return new this.constructor().copy(this);
  27265. };
  27266. _proto.copy = function copy(other) {
  27267. this.radius = other.radius;
  27268. this.phi = other.phi;
  27269. this.theta = other.theta;
  27270. return this;
  27271. } // restrict phi to be betwee EPS and PI-EPS
  27272. ;
  27273. _proto.makeSafe = function makeSafe() {
  27274. var EPS = 0.000001;
  27275. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  27276. return this;
  27277. };
  27278. _proto.setFromVector3 = function setFromVector3(v) {
  27279. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27280. };
  27281. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27282. this.radius = Math.sqrt(x * x + y * y + z * z);
  27283. if (this.radius === 0) {
  27284. this.theta = 0;
  27285. this.phi = 0;
  27286. } else {
  27287. this.theta = Math.atan2(x, z);
  27288. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  27289. }
  27290. return this;
  27291. };
  27292. return Spherical;
  27293. }();
  27294. /**
  27295. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27296. */
  27297. var Cylindrical = /*#__PURE__*/function () {
  27298. function Cylindrical(radius, theta, y) {
  27299. this.radius = radius !== undefined ? radius : 1.0; // distance from the origin to a point in the x-z plane
  27300. this.theta = theta !== undefined ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27301. this.y = y !== undefined ? y : 0; // height above the x-z plane
  27302. return this;
  27303. }
  27304. var _proto = Cylindrical.prototype;
  27305. _proto.set = function set(radius, theta, y) {
  27306. this.radius = radius;
  27307. this.theta = theta;
  27308. this.y = y;
  27309. return this;
  27310. };
  27311. _proto.clone = function clone() {
  27312. return new this.constructor().copy(this);
  27313. };
  27314. _proto.copy = function copy(other) {
  27315. this.radius = other.radius;
  27316. this.theta = other.theta;
  27317. this.y = other.y;
  27318. return this;
  27319. };
  27320. _proto.setFromVector3 = function setFromVector3(v) {
  27321. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27322. };
  27323. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27324. this.radius = Math.sqrt(x * x + z * z);
  27325. this.theta = Math.atan2(x, z);
  27326. this.y = y;
  27327. return this;
  27328. };
  27329. return Cylindrical;
  27330. }();
  27331. var _vector$8 = /*@__PURE__*/new Vector2();
  27332. var Box2 = /*#__PURE__*/function () {
  27333. function Box2(min, max) {
  27334. Object.defineProperty(this, 'isBox2', {
  27335. value: true
  27336. });
  27337. this.min = min !== undefined ? min : new Vector2(+Infinity, +Infinity);
  27338. this.max = max !== undefined ? max : new Vector2(-Infinity, -Infinity);
  27339. }
  27340. var _proto = Box2.prototype;
  27341. _proto.set = function set(min, max) {
  27342. this.min.copy(min);
  27343. this.max.copy(max);
  27344. return this;
  27345. };
  27346. _proto.setFromPoints = function setFromPoints(points) {
  27347. this.makeEmpty();
  27348. for (var i = 0, il = points.length; i < il; i++) {
  27349. this.expandByPoint(points[i]);
  27350. }
  27351. return this;
  27352. };
  27353. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  27354. var halfSize = _vector$8.copy(size).multiplyScalar(0.5);
  27355. this.min.copy(center).sub(halfSize);
  27356. this.max.copy(center).add(halfSize);
  27357. return this;
  27358. };
  27359. _proto.clone = function clone() {
  27360. return new this.constructor().copy(this);
  27361. };
  27362. _proto.copy = function copy(box) {
  27363. this.min.copy(box.min);
  27364. this.max.copy(box.max);
  27365. return this;
  27366. };
  27367. _proto.makeEmpty = function makeEmpty() {
  27368. this.min.x = this.min.y = +Infinity;
  27369. this.max.x = this.max.y = -Infinity;
  27370. return this;
  27371. };
  27372. _proto.isEmpty = function isEmpty() {
  27373. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27374. return this.max.x < this.min.x || this.max.y < this.min.y;
  27375. };
  27376. _proto.getCenter = function getCenter(target) {
  27377. if (target === undefined) {
  27378. console.warn('THREE.Box2: .getCenter() target is now required');
  27379. target = new Vector2();
  27380. }
  27381. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  27382. };
  27383. _proto.getSize = function getSize(target) {
  27384. if (target === undefined) {
  27385. console.warn('THREE.Box2: .getSize() target is now required');
  27386. target = new Vector2();
  27387. }
  27388. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  27389. };
  27390. _proto.expandByPoint = function expandByPoint(point) {
  27391. this.min.min(point);
  27392. this.max.max(point);
  27393. return this;
  27394. };
  27395. _proto.expandByVector = function expandByVector(vector) {
  27396. this.min.sub(vector);
  27397. this.max.add(vector);
  27398. return this;
  27399. };
  27400. _proto.expandByScalar = function expandByScalar(scalar) {
  27401. this.min.addScalar(-scalar);
  27402. this.max.addScalar(scalar);
  27403. return this;
  27404. };
  27405. _proto.containsPoint = function containsPoint(point) {
  27406. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  27407. };
  27408. _proto.containsBox = function containsBox(box) {
  27409. 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;
  27410. };
  27411. _proto.getParameter = function getParameter(point, target) {
  27412. // This can potentially have a divide by zero if the box
  27413. // has a size dimension of 0.
  27414. if (target === undefined) {
  27415. console.warn('THREE.Box2: .getParameter() target is now required');
  27416. target = new Vector2();
  27417. }
  27418. 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));
  27419. };
  27420. _proto.intersectsBox = function intersectsBox(box) {
  27421. // using 4 splitting planes to rule out intersections
  27422. 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;
  27423. };
  27424. _proto.clampPoint = function clampPoint(point, target) {
  27425. if (target === undefined) {
  27426. console.warn('THREE.Box2: .clampPoint() target is now required');
  27427. target = new Vector2();
  27428. }
  27429. return target.copy(point).clamp(this.min, this.max);
  27430. };
  27431. _proto.distanceToPoint = function distanceToPoint(point) {
  27432. var clampedPoint = _vector$8.copy(point).clamp(this.min, this.max);
  27433. return clampedPoint.sub(point).length();
  27434. };
  27435. _proto.intersect = function intersect(box) {
  27436. this.min.max(box.min);
  27437. this.max.min(box.max);
  27438. return this;
  27439. };
  27440. _proto.union = function union(box) {
  27441. this.min.min(box.min);
  27442. this.max.max(box.max);
  27443. return this;
  27444. };
  27445. _proto.translate = function translate(offset) {
  27446. this.min.add(offset);
  27447. this.max.add(offset);
  27448. return this;
  27449. };
  27450. _proto.equals = function equals(box) {
  27451. return box.min.equals(this.min) && box.max.equals(this.max);
  27452. };
  27453. return Box2;
  27454. }();
  27455. var _startP = /*@__PURE__*/new Vector3();
  27456. var _startEnd = /*@__PURE__*/new Vector3();
  27457. var Line3 = /*#__PURE__*/function () {
  27458. function Line3(start, end) {
  27459. this.start = start !== undefined ? start : new Vector3();
  27460. this.end = end !== undefined ? end : new Vector3();
  27461. }
  27462. var _proto = Line3.prototype;
  27463. _proto.set = function set(start, end) {
  27464. this.start.copy(start);
  27465. this.end.copy(end);
  27466. return this;
  27467. };
  27468. _proto.clone = function clone() {
  27469. return new this.constructor().copy(this);
  27470. };
  27471. _proto.copy = function copy(line) {
  27472. this.start.copy(line.start);
  27473. this.end.copy(line.end);
  27474. return this;
  27475. };
  27476. _proto.getCenter = function getCenter(target) {
  27477. if (target === undefined) {
  27478. console.warn('THREE.Line3: .getCenter() target is now required');
  27479. target = new Vector3();
  27480. }
  27481. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  27482. };
  27483. _proto.delta = function delta(target) {
  27484. if (target === undefined) {
  27485. console.warn('THREE.Line3: .delta() target is now required');
  27486. target = new Vector3();
  27487. }
  27488. return target.subVectors(this.end, this.start);
  27489. };
  27490. _proto.distanceSq = function distanceSq() {
  27491. return this.start.distanceToSquared(this.end);
  27492. };
  27493. _proto.distance = function distance() {
  27494. return this.start.distanceTo(this.end);
  27495. };
  27496. _proto.at = function at(t, target) {
  27497. if (target === undefined) {
  27498. console.warn('THREE.Line3: .at() target is now required');
  27499. target = new Vector3();
  27500. }
  27501. return this.delta(target).multiplyScalar(t).add(this.start);
  27502. };
  27503. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  27504. _startP.subVectors(point, this.start);
  27505. _startEnd.subVectors(this.end, this.start);
  27506. var startEnd2 = _startEnd.dot(_startEnd);
  27507. var startEnd_startP = _startEnd.dot(_startP);
  27508. var t = startEnd_startP / startEnd2;
  27509. if (clampToLine) {
  27510. t = MathUtils.clamp(t, 0, 1);
  27511. }
  27512. return t;
  27513. };
  27514. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  27515. var t = this.closestPointToPointParameter(point, clampToLine);
  27516. if (target === undefined) {
  27517. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  27518. target = new Vector3();
  27519. }
  27520. return this.delta(target).multiplyScalar(t).add(this.start);
  27521. };
  27522. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  27523. this.start.applyMatrix4(matrix);
  27524. this.end.applyMatrix4(matrix);
  27525. return this;
  27526. };
  27527. _proto.equals = function equals(line) {
  27528. return line.start.equals(this.start) && line.end.equals(this.end);
  27529. };
  27530. return Line3;
  27531. }();
  27532. function ImmediateRenderObject(material) {
  27533. Object3D.call(this);
  27534. this.material = material;
  27535. this.render = function ()
  27536. /* renderCallback */
  27537. {};
  27538. this.hasPositions = false;
  27539. this.hasNormals = false;
  27540. this.hasColors = false;
  27541. this.hasUvs = false;
  27542. this.positionArray = null;
  27543. this.normalArray = null;
  27544. this.colorArray = null;
  27545. this.uvArray = null;
  27546. this.count = 0;
  27547. }
  27548. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  27549. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27550. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27551. var _vector$9 = /*@__PURE__*/new Vector3();
  27552. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  27553. _inheritsLoose(SpotLightHelper, _Object3D);
  27554. function SpotLightHelper(light, color) {
  27555. var _this;
  27556. _this = _Object3D.call(this) || this;
  27557. _this.light = light;
  27558. _this.light.updateMatrixWorld();
  27559. _this.matrix = light.matrixWorld;
  27560. _this.matrixAutoUpdate = false;
  27561. _this.color = color;
  27562. var geometry = new BufferGeometry();
  27563. 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];
  27564. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  27565. var p1 = i / l * Math.PI * 2;
  27566. var p2 = j / l * Math.PI * 2;
  27567. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  27568. }
  27569. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  27570. var material = new LineBasicMaterial({
  27571. fog: false,
  27572. toneMapped: false
  27573. });
  27574. _this.cone = new LineSegments(geometry, material);
  27575. _this.add(_this.cone);
  27576. _this.update();
  27577. return _this;
  27578. }
  27579. var _proto = SpotLightHelper.prototype;
  27580. _proto.dispose = function dispose() {
  27581. this.cone.geometry.dispose();
  27582. this.cone.material.dispose();
  27583. };
  27584. _proto.update = function update() {
  27585. this.light.updateMatrixWorld();
  27586. var coneLength = this.light.distance ? this.light.distance : 1000;
  27587. var coneWidth = coneLength * Math.tan(this.light.angle);
  27588. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  27589. _vector$9.setFromMatrixPosition(this.light.target.matrixWorld);
  27590. this.cone.lookAt(_vector$9);
  27591. if (this.color !== undefined) {
  27592. this.cone.material.color.set(this.color);
  27593. } else {
  27594. this.cone.material.color.copy(this.light.color);
  27595. }
  27596. };
  27597. return SpotLightHelper;
  27598. }(Object3D);
  27599. var _vector$a = /*@__PURE__*/new Vector3();
  27600. var _boneMatrix = /*@__PURE__*/new Matrix4();
  27601. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  27602. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  27603. _inheritsLoose(SkeletonHelper, _LineSegments);
  27604. function SkeletonHelper(object) {
  27605. var _this;
  27606. var bones = getBoneList(object);
  27607. var geometry = new BufferGeometry();
  27608. var vertices = [];
  27609. var colors = [];
  27610. var color1 = new Color(0, 0, 1);
  27611. var color2 = new Color(0, 1, 0);
  27612. for (var i = 0; i < bones.length; i++) {
  27613. var bone = bones[i];
  27614. if (bone.parent && bone.parent.isBone) {
  27615. vertices.push(0, 0, 0);
  27616. vertices.push(0, 0, 0);
  27617. colors.push(color1.r, color1.g, color1.b);
  27618. colors.push(color2.r, color2.g, color2.b);
  27619. }
  27620. }
  27621. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27622. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27623. var material = new LineBasicMaterial({
  27624. vertexColors: true,
  27625. depthTest: false,
  27626. depthWrite: false,
  27627. toneMapped: false,
  27628. transparent: true
  27629. });
  27630. _this = _LineSegments.call(this, geometry, material) || this;
  27631. _this.type = 'SkeletonHelper';
  27632. _this.isSkeletonHelper = true;
  27633. _this.root = object;
  27634. _this.bones = bones;
  27635. _this.matrix = object.matrixWorld;
  27636. _this.matrixAutoUpdate = false;
  27637. return _this;
  27638. }
  27639. var _proto = SkeletonHelper.prototype;
  27640. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  27641. var bones = this.bones;
  27642. var geometry = this.geometry;
  27643. var position = geometry.getAttribute('position');
  27644. _matrixWorldInv.copy(this.root.matrixWorld).invert();
  27645. for (var i = 0, j = 0; i < bones.length; i++) {
  27646. var bone = bones[i];
  27647. if (bone.parent && bone.parent.isBone) {
  27648. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  27649. _vector$a.setFromMatrixPosition(_boneMatrix);
  27650. position.setXYZ(j, _vector$a.x, _vector$a.y, _vector$a.z);
  27651. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  27652. _vector$a.setFromMatrixPosition(_boneMatrix);
  27653. position.setXYZ(j + 1, _vector$a.x, _vector$a.y, _vector$a.z);
  27654. j += 2;
  27655. }
  27656. }
  27657. geometry.getAttribute('position').needsUpdate = true;
  27658. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  27659. };
  27660. return SkeletonHelper;
  27661. }(LineSegments);
  27662. function getBoneList(object) {
  27663. var boneList = [];
  27664. if (object && object.isBone) {
  27665. boneList.push(object);
  27666. }
  27667. for (var i = 0; i < object.children.length; i++) {
  27668. boneList.push.apply(boneList, getBoneList(object.children[i]));
  27669. }
  27670. return boneList;
  27671. }
  27672. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  27673. _inheritsLoose(PointLightHelper, _Mesh);
  27674. function PointLightHelper(light, sphereSize, color) {
  27675. var _this;
  27676. var geometry = new SphereGeometry(sphereSize, 4, 2);
  27677. var material = new MeshBasicMaterial({
  27678. wireframe: true,
  27679. fog: false,
  27680. toneMapped: false
  27681. });
  27682. _this = _Mesh.call(this, geometry, material) || this;
  27683. _this.light = light;
  27684. _this.light.updateMatrixWorld();
  27685. _this.color = color;
  27686. _this.type = 'PointLightHelper';
  27687. _this.matrix = _this.light.matrixWorld;
  27688. _this.matrixAutoUpdate = false;
  27689. _this.update();
  27690. /*
  27691. // TODO: delete this comment?
  27692. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27693. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27694. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27695. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27696. const d = light.distance;
  27697. if ( d === 0.0 ) {
  27698. this.lightDistance.visible = false;
  27699. } else {
  27700. this.lightDistance.scale.set( d, d, d );
  27701. }
  27702. this.add( this.lightDistance );
  27703. */
  27704. return _this;
  27705. }
  27706. var _proto = PointLightHelper.prototype;
  27707. _proto.dispose = function dispose() {
  27708. this.geometry.dispose();
  27709. this.material.dispose();
  27710. };
  27711. _proto.update = function update() {
  27712. if (this.color !== undefined) {
  27713. this.material.color.set(this.color);
  27714. } else {
  27715. this.material.color.copy(this.light.color);
  27716. }
  27717. /*
  27718. const d = this.light.distance;
  27719. if ( d === 0.0 ) {
  27720. this.lightDistance.visible = false;
  27721. } else {
  27722. this.lightDistance.visible = true;
  27723. this.lightDistance.scale.set( d, d, d );
  27724. }
  27725. */
  27726. };
  27727. return PointLightHelper;
  27728. }(Mesh);
  27729. var _vector$b = /*@__PURE__*/new Vector3();
  27730. var _color1 = /*@__PURE__*/new Color();
  27731. var _color2 = /*@__PURE__*/new Color();
  27732. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  27733. _inheritsLoose(HemisphereLightHelper, _Object3D);
  27734. function HemisphereLightHelper(light, size, color) {
  27735. var _this;
  27736. _this = _Object3D.call(this) || this;
  27737. _this.light = light;
  27738. _this.light.updateMatrixWorld();
  27739. _this.matrix = light.matrixWorld;
  27740. _this.matrixAutoUpdate = false;
  27741. _this.color = color;
  27742. var geometry = new OctahedronGeometry(size);
  27743. geometry.rotateY(Math.PI * 0.5);
  27744. _this.material = new MeshBasicMaterial({
  27745. wireframe: true,
  27746. fog: false,
  27747. toneMapped: false
  27748. });
  27749. if (_this.color === undefined) _this.material.vertexColors = true;
  27750. var position = geometry.getAttribute('position');
  27751. var colors = new Float32Array(position.count * 3);
  27752. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  27753. _this.add(new Mesh(geometry, _this.material));
  27754. _this.update();
  27755. return _this;
  27756. }
  27757. var _proto = HemisphereLightHelper.prototype;
  27758. _proto.dispose = function dispose() {
  27759. this.children[0].geometry.dispose();
  27760. this.children[0].material.dispose();
  27761. };
  27762. _proto.update = function update() {
  27763. var mesh = this.children[0];
  27764. if (this.color !== undefined) {
  27765. this.material.color.set(this.color);
  27766. } else {
  27767. var colors = mesh.geometry.getAttribute('color');
  27768. _color1.copy(this.light.color);
  27769. _color2.copy(this.light.groundColor);
  27770. for (var i = 0, l = colors.count; i < l; i++) {
  27771. var color = i < l / 2 ? _color1 : _color2;
  27772. colors.setXYZ(i, color.r, color.g, color.b);
  27773. }
  27774. colors.needsUpdate = true;
  27775. }
  27776. mesh.lookAt(_vector$b.setFromMatrixPosition(this.light.matrixWorld).negate());
  27777. };
  27778. return HemisphereLightHelper;
  27779. }(Object3D);
  27780. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  27781. _inheritsLoose(GridHelper, _LineSegments);
  27782. function GridHelper(size, divisions, color1, color2) {
  27783. var _this;
  27784. if (size === void 0) {
  27785. size = 10;
  27786. }
  27787. if (divisions === void 0) {
  27788. divisions = 10;
  27789. }
  27790. if (color1 === void 0) {
  27791. color1 = 0x444444;
  27792. }
  27793. if (color2 === void 0) {
  27794. color2 = 0x888888;
  27795. }
  27796. color1 = new Color(color1);
  27797. color2 = new Color(color2);
  27798. var center = divisions / 2;
  27799. var step = size / divisions;
  27800. var halfSize = size / 2;
  27801. var vertices = [],
  27802. colors = [];
  27803. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  27804. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  27805. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  27806. var color = i === center ? color1 : color2;
  27807. color.toArray(colors, j);
  27808. j += 3;
  27809. color.toArray(colors, j);
  27810. j += 3;
  27811. color.toArray(colors, j);
  27812. j += 3;
  27813. color.toArray(colors, j);
  27814. j += 3;
  27815. }
  27816. var geometry = new BufferGeometry();
  27817. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27818. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27819. var material = new LineBasicMaterial({
  27820. vertexColors: true,
  27821. toneMapped: false
  27822. });
  27823. _this = _LineSegments.call(this, geometry, material) || this;
  27824. _this.type = 'GridHelper';
  27825. return _this;
  27826. }
  27827. return GridHelper;
  27828. }(LineSegments);
  27829. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  27830. _inheritsLoose(PolarGridHelper, _LineSegments);
  27831. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  27832. var _this;
  27833. if (radius === void 0) {
  27834. radius = 10;
  27835. }
  27836. if (radials === void 0) {
  27837. radials = 16;
  27838. }
  27839. if (circles === void 0) {
  27840. circles = 8;
  27841. }
  27842. if (divisions === void 0) {
  27843. divisions = 64;
  27844. }
  27845. if (color1 === void 0) {
  27846. color1 = 0x444444;
  27847. }
  27848. if (color2 === void 0) {
  27849. color2 = 0x888888;
  27850. }
  27851. color1 = new Color(color1);
  27852. color2 = new Color(color2);
  27853. var vertices = [];
  27854. var colors = []; // create the radials
  27855. for (var i = 0; i <= radials; i++) {
  27856. var v = i / radials * (Math.PI * 2);
  27857. var x = Math.sin(v) * radius;
  27858. var z = Math.cos(v) * radius;
  27859. vertices.push(0, 0, 0);
  27860. vertices.push(x, 0, z);
  27861. var color = i & 1 ? color1 : color2;
  27862. colors.push(color.r, color.g, color.b);
  27863. colors.push(color.r, color.g, color.b);
  27864. } // create the circles
  27865. for (var _i = 0; _i <= circles; _i++) {
  27866. var _color = _i & 1 ? color1 : color2;
  27867. var r = radius - radius / circles * _i;
  27868. for (var j = 0; j < divisions; j++) {
  27869. // first vertex
  27870. var _v = j / divisions * (Math.PI * 2);
  27871. var _x = Math.sin(_v) * r;
  27872. var _z = Math.cos(_v) * r;
  27873. vertices.push(_x, 0, _z);
  27874. colors.push(_color.r, _color.g, _color.b); // second vertex
  27875. _v = (j + 1) / divisions * (Math.PI * 2);
  27876. _x = Math.sin(_v) * r;
  27877. _z = Math.cos(_v) * r;
  27878. vertices.push(_x, 0, _z);
  27879. colors.push(_color.r, _color.g, _color.b);
  27880. }
  27881. }
  27882. var geometry = new BufferGeometry();
  27883. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27884. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27885. var material = new LineBasicMaterial({
  27886. vertexColors: true,
  27887. toneMapped: false
  27888. });
  27889. _this = _LineSegments.call(this, geometry, material) || this;
  27890. _this.type = 'PolarGridHelper';
  27891. return _this;
  27892. }
  27893. return PolarGridHelper;
  27894. }(LineSegments);
  27895. var _v1$6 = /*@__PURE__*/new Vector3();
  27896. var _v2$3 = /*@__PURE__*/new Vector3();
  27897. var _v3$1 = /*@__PURE__*/new Vector3();
  27898. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  27899. _inheritsLoose(DirectionalLightHelper, _Object3D);
  27900. function DirectionalLightHelper(light, size, color) {
  27901. var _this;
  27902. _this = _Object3D.call(this) || this;
  27903. _this.light = light;
  27904. _this.light.updateMatrixWorld();
  27905. _this.matrix = light.matrixWorld;
  27906. _this.matrixAutoUpdate = false;
  27907. _this.color = color;
  27908. if (size === undefined) size = 1;
  27909. var geometry = new BufferGeometry();
  27910. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  27911. var material = new LineBasicMaterial({
  27912. fog: false,
  27913. toneMapped: false
  27914. });
  27915. _this.lightPlane = new Line(geometry, material);
  27916. _this.add(_this.lightPlane);
  27917. geometry = new BufferGeometry();
  27918. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  27919. _this.targetLine = new Line(geometry, material);
  27920. _this.add(_this.targetLine);
  27921. _this.update();
  27922. return _this;
  27923. }
  27924. var _proto = DirectionalLightHelper.prototype;
  27925. _proto.dispose = function dispose() {
  27926. this.lightPlane.geometry.dispose();
  27927. this.lightPlane.material.dispose();
  27928. this.targetLine.geometry.dispose();
  27929. this.targetLine.material.dispose();
  27930. };
  27931. _proto.update = function update() {
  27932. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  27933. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  27934. _v3$1.subVectors(_v2$3, _v1$6);
  27935. this.lightPlane.lookAt(_v2$3);
  27936. if (this.color !== undefined) {
  27937. this.lightPlane.material.color.set(this.color);
  27938. this.targetLine.material.color.set(this.color);
  27939. } else {
  27940. this.lightPlane.material.color.copy(this.light.color);
  27941. this.targetLine.material.color.copy(this.light.color);
  27942. }
  27943. this.targetLine.lookAt(_v2$3);
  27944. this.targetLine.scale.z = _v3$1.length();
  27945. };
  27946. return DirectionalLightHelper;
  27947. }(Object3D);
  27948. var _vector$c = /*@__PURE__*/new Vector3();
  27949. var _camera = /*@__PURE__*/new Camera();
  27950. /**
  27951. * - shows frustum, line of sight and up of the camera
  27952. * - suitable for fast updates
  27953. * - based on frustum visualization in lightgl.js shadowmap example
  27954. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  27955. */
  27956. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  27957. _inheritsLoose(CameraHelper, _LineSegments);
  27958. function CameraHelper(camera) {
  27959. var _this;
  27960. var geometry = new BufferGeometry();
  27961. var material = new LineBasicMaterial({
  27962. color: 0xffffff,
  27963. vertexColors: true,
  27964. toneMapped: false
  27965. });
  27966. var vertices = [];
  27967. var colors = [];
  27968. var pointMap = {}; // colors
  27969. var colorFrustum = new Color(0xffaa00);
  27970. var colorCone = new Color(0xff0000);
  27971. var colorUp = new Color(0x00aaff);
  27972. var colorTarget = new Color(0xffffff);
  27973. var colorCross = new Color(0x333333); // near
  27974. addLine('n1', 'n2', colorFrustum);
  27975. addLine('n2', 'n4', colorFrustum);
  27976. addLine('n4', 'n3', colorFrustum);
  27977. addLine('n3', 'n1', colorFrustum); // far
  27978. addLine('f1', 'f2', colorFrustum);
  27979. addLine('f2', 'f4', colorFrustum);
  27980. addLine('f4', 'f3', colorFrustum);
  27981. addLine('f3', 'f1', colorFrustum); // sides
  27982. addLine('n1', 'f1', colorFrustum);
  27983. addLine('n2', 'f2', colorFrustum);
  27984. addLine('n3', 'f3', colorFrustum);
  27985. addLine('n4', 'f4', colorFrustum); // cone
  27986. addLine('p', 'n1', colorCone);
  27987. addLine('p', 'n2', colorCone);
  27988. addLine('p', 'n3', colorCone);
  27989. addLine('p', 'n4', colorCone); // up
  27990. addLine('u1', 'u2', colorUp);
  27991. addLine('u2', 'u3', colorUp);
  27992. addLine('u3', 'u1', colorUp); // target
  27993. addLine('c', 't', colorTarget);
  27994. addLine('p', 'c', colorCross); // cross
  27995. addLine('cn1', 'cn2', colorCross);
  27996. addLine('cn3', 'cn4', colorCross);
  27997. addLine('cf1', 'cf2', colorCross);
  27998. addLine('cf3', 'cf4', colorCross);
  27999. function addLine(a, b, color) {
  28000. addPoint(a, color);
  28001. addPoint(b, color);
  28002. }
  28003. function addPoint(id, color) {
  28004. vertices.push(0, 0, 0);
  28005. colors.push(color.r, color.g, color.b);
  28006. if (pointMap[id] === undefined) {
  28007. pointMap[id] = [];
  28008. }
  28009. pointMap[id].push(vertices.length / 3 - 1);
  28010. }
  28011. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28012. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28013. _this = _LineSegments.call(this, geometry, material) || this;
  28014. _this.type = 'CameraHelper';
  28015. _this.camera = camera;
  28016. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  28017. _this.matrix = camera.matrixWorld;
  28018. _this.matrixAutoUpdate = false;
  28019. _this.pointMap = pointMap;
  28020. _this.update();
  28021. return _this;
  28022. }
  28023. var _proto = CameraHelper.prototype;
  28024. _proto.update = function update() {
  28025. var geometry = this.geometry;
  28026. var pointMap = this.pointMap;
  28027. var w = 1,
  28028. h = 1; // we need just camera projection matrix inverse
  28029. // world matrix must be identity
  28030. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  28031. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  28032. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  28033. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  28034. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  28035. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  28036. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  28037. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  28038. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  28039. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  28040. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  28041. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  28042. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  28043. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  28044. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  28045. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  28046. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  28047. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  28048. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  28049. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  28050. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  28051. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  28052. geometry.getAttribute('position').needsUpdate = true;
  28053. };
  28054. return CameraHelper;
  28055. }(LineSegments);
  28056. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  28057. _vector$c.set(x, y, z).unproject(camera);
  28058. var points = pointMap[point];
  28059. if (points !== undefined) {
  28060. var position = geometry.getAttribute('position');
  28061. for (var i = 0, l = points.length; i < l; i++) {
  28062. position.setXYZ(points[i], _vector$c.x, _vector$c.y, _vector$c.z);
  28063. }
  28064. }
  28065. }
  28066. var _box$3 = /*@__PURE__*/new Box3();
  28067. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  28068. _inheritsLoose(BoxHelper, _LineSegments);
  28069. function BoxHelper(object, color) {
  28070. var _this;
  28071. if (color === void 0) {
  28072. color = 0xffff00;
  28073. }
  28074. 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]);
  28075. var positions = new Float32Array(8 * 3);
  28076. var geometry = new BufferGeometry();
  28077. geometry.setIndex(new BufferAttribute(indices, 1));
  28078. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28079. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28080. color: color,
  28081. toneMapped: false
  28082. })) || this;
  28083. _this.object = object;
  28084. _this.type = 'BoxHelper';
  28085. _this.matrixAutoUpdate = false;
  28086. _this.update();
  28087. return _this;
  28088. }
  28089. var _proto = BoxHelper.prototype;
  28090. _proto.update = function update(object) {
  28091. if (object !== undefined) {
  28092. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28093. }
  28094. if (this.object !== undefined) {
  28095. _box$3.setFromObject(this.object);
  28096. }
  28097. if (_box$3.isEmpty()) return;
  28098. var min = _box$3.min;
  28099. var max = _box$3.max;
  28100. /*
  28101. 5____4
  28102. 1/___0/|
  28103. | 6__|_7
  28104. 2/___3/
  28105. 0: max.x, max.y, max.z
  28106. 1: min.x, max.y, max.z
  28107. 2: min.x, min.y, max.z
  28108. 3: max.x, min.y, max.z
  28109. 4: max.x, max.y, min.z
  28110. 5: min.x, max.y, min.z
  28111. 6: min.x, min.y, min.z
  28112. 7: max.x, min.y, min.z
  28113. */
  28114. var position = this.geometry.attributes.position;
  28115. var array = position.array;
  28116. array[0] = max.x;
  28117. array[1] = max.y;
  28118. array[2] = max.z;
  28119. array[3] = min.x;
  28120. array[4] = max.y;
  28121. array[5] = max.z;
  28122. array[6] = min.x;
  28123. array[7] = min.y;
  28124. array[8] = max.z;
  28125. array[9] = max.x;
  28126. array[10] = min.y;
  28127. array[11] = max.z;
  28128. array[12] = max.x;
  28129. array[13] = max.y;
  28130. array[14] = min.z;
  28131. array[15] = min.x;
  28132. array[16] = max.y;
  28133. array[17] = min.z;
  28134. array[18] = min.x;
  28135. array[19] = min.y;
  28136. array[20] = min.z;
  28137. array[21] = max.x;
  28138. array[22] = min.y;
  28139. array[23] = min.z;
  28140. position.needsUpdate = true;
  28141. this.geometry.computeBoundingSphere();
  28142. };
  28143. _proto.setFromObject = function setFromObject(object) {
  28144. this.object = object;
  28145. this.update();
  28146. return this;
  28147. };
  28148. _proto.copy = function copy(source) {
  28149. LineSegments.prototype.copy.call(this, source);
  28150. this.object = source.object;
  28151. return this;
  28152. };
  28153. return BoxHelper;
  28154. }(LineSegments);
  28155. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28156. _inheritsLoose(Box3Helper, _LineSegments);
  28157. function Box3Helper(box, color) {
  28158. var _this;
  28159. if (color === void 0) {
  28160. color = 0xffff00;
  28161. }
  28162. 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]);
  28163. 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];
  28164. var geometry = new BufferGeometry();
  28165. geometry.setIndex(new BufferAttribute(indices, 1));
  28166. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28167. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28168. color: color,
  28169. toneMapped: false
  28170. })) || this;
  28171. _this.box = box;
  28172. _this.type = 'Box3Helper';
  28173. _this.geometry.computeBoundingSphere();
  28174. return _this;
  28175. }
  28176. var _proto = Box3Helper.prototype;
  28177. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28178. var box = this.box;
  28179. if (box.isEmpty()) return;
  28180. box.getCenter(this.position);
  28181. box.getSize(this.scale);
  28182. this.scale.multiplyScalar(0.5);
  28183. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28184. };
  28185. return Box3Helper;
  28186. }(LineSegments);
  28187. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28188. _inheritsLoose(PlaneHelper, _Line);
  28189. function PlaneHelper(plane, size, hex) {
  28190. var _this;
  28191. if (size === void 0) {
  28192. size = 1;
  28193. }
  28194. if (hex === void 0) {
  28195. hex = 0xffff00;
  28196. }
  28197. var color = hex;
  28198. 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];
  28199. var geometry = new BufferGeometry();
  28200. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28201. geometry.computeBoundingSphere();
  28202. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28203. color: color,
  28204. toneMapped: false
  28205. })) || this;
  28206. _this.type = 'PlaneHelper';
  28207. _this.plane = plane;
  28208. _this.size = size;
  28209. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28210. var geometry2 = new BufferGeometry();
  28211. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28212. geometry2.computeBoundingSphere();
  28213. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28214. color: color,
  28215. opacity: 0.2,
  28216. transparent: true,
  28217. depthWrite: false,
  28218. toneMapped: false
  28219. })));
  28220. return _this;
  28221. }
  28222. var _proto = PlaneHelper.prototype;
  28223. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28224. var scale = -this.plane.constant;
  28225. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28226. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28227. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28228. this.lookAt(this.plane.normal);
  28229. _Line.prototype.updateMatrixWorld.call(this, force);
  28230. };
  28231. return PlaneHelper;
  28232. }(Line);
  28233. var _axis = /*@__PURE__*/new Vector3();
  28234. var _lineGeometry, _coneGeometry;
  28235. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28236. _inheritsLoose(ArrowHelper, _Object3D);
  28237. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28238. var _this;
  28239. _this = _Object3D.call(this) || this; // dir is assumed to be normalized
  28240. _this.type = 'ArrowHelper';
  28241. if (dir === undefined) dir = new Vector3(0, 0, 1);
  28242. if (origin === undefined) origin = new Vector3(0, 0, 0);
  28243. if (length === undefined) length = 1;
  28244. if (color === undefined) color = 0xffff00;
  28245. if (headLength === undefined) headLength = 0.2 * length;
  28246. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28247. if (_lineGeometry === undefined) {
  28248. _lineGeometry = new BufferGeometry();
  28249. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28250. _coneGeometry = new CylinderGeometry(0, 0.5, 1, 5, 1);
  28251. _coneGeometry.translate(0, -0.5, 0);
  28252. }
  28253. _this.position.copy(origin);
  28254. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28255. color: color,
  28256. toneMapped: false
  28257. }));
  28258. _this.line.matrixAutoUpdate = false;
  28259. _this.add(_this.line);
  28260. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  28261. color: color,
  28262. toneMapped: false
  28263. }));
  28264. _this.cone.matrixAutoUpdate = false;
  28265. _this.add(_this.cone);
  28266. _this.setDirection(dir);
  28267. _this.setLength(length, headLength, headWidth);
  28268. return _this;
  28269. }
  28270. var _proto = ArrowHelper.prototype;
  28271. _proto.setDirection = function setDirection(dir) {
  28272. // dir is assumed to be normalized
  28273. if (dir.y > 0.99999) {
  28274. this.quaternion.set(0, 0, 0, 1);
  28275. } else if (dir.y < -0.99999) {
  28276. this.quaternion.set(1, 0, 0, 0);
  28277. } else {
  28278. _axis.set(dir.z, 0, -dir.x).normalize();
  28279. var radians = Math.acos(dir.y);
  28280. this.quaternion.setFromAxisAngle(_axis, radians);
  28281. }
  28282. };
  28283. _proto.setLength = function setLength(length, headLength, headWidth) {
  28284. if (headLength === undefined) headLength = 0.2 * length;
  28285. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28286. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  28287. this.line.updateMatrix();
  28288. this.cone.scale.set(headWidth, headLength, headWidth);
  28289. this.cone.position.y = length;
  28290. this.cone.updateMatrix();
  28291. };
  28292. _proto.setColor = function setColor(color) {
  28293. this.line.material.color.set(color);
  28294. this.cone.material.color.set(color);
  28295. };
  28296. _proto.copy = function copy(source) {
  28297. _Object3D.prototype.copy.call(this, source, false);
  28298. this.line.copy(source.line);
  28299. this.cone.copy(source.cone);
  28300. return this;
  28301. };
  28302. return ArrowHelper;
  28303. }(Object3D);
  28304. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  28305. _inheritsLoose(AxesHelper, _LineSegments);
  28306. function AxesHelper(size) {
  28307. var _this;
  28308. if (size === void 0) {
  28309. size = 1;
  28310. }
  28311. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  28312. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  28313. var geometry = new BufferGeometry();
  28314. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28315. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28316. var material = new LineBasicMaterial({
  28317. vertexColors: true,
  28318. toneMapped: false
  28319. });
  28320. _this = _LineSegments.call(this, geometry, material) || this;
  28321. _this.type = 'AxesHelper';
  28322. return _this;
  28323. }
  28324. return AxesHelper;
  28325. }(LineSegments);
  28326. var _floatView = new Float32Array(1);
  28327. var _int32View = new Int32Array(_floatView.buffer);
  28328. var DataUtils = {
  28329. // Converts float32 to float16 (stored as uint16 value).
  28330. toHalfFloat: function toHalfFloat(val) {
  28331. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  28332. /* This method is faster than the OpenEXR implementation (very often
  28333. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  28334. * by James Tursa?s half-precision code. */
  28335. _floatView[0] = val;
  28336. var x = _int32View[0];
  28337. var bits = x >> 16 & 0x8000;
  28338. /* Get the sign */
  28339. var m = x >> 12 & 0x07ff;
  28340. /* Keep one extra bit for rounding */
  28341. var e = x >> 23 & 0xff;
  28342. /* Using int is faster here */
  28343. /* If zero, or denormal, or exponent underflows too much for a denormal
  28344. * half, return signed zero. */
  28345. if (e < 103) return bits;
  28346. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  28347. if (e > 142) {
  28348. bits |= 0x7c00;
  28349. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  28350. * not Inf, so make sure we set one mantissa bit too. */
  28351. bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;
  28352. return bits;
  28353. }
  28354. /* If exponent underflows but not too much, return a denormal */
  28355. if (e < 113) {
  28356. m |= 0x0800;
  28357. /* Extra rounding may overflow and set mantissa to 0 and exponent
  28358. * to 1, which is OK. */
  28359. bits |= (m >> 114 - e) + (m >> 113 - e & 1);
  28360. return bits;
  28361. }
  28362. bits |= e - 112 << 10 | m >> 1;
  28363. /* Extra rounding. An overflow will set mantissa to 0 and increment
  28364. * the exponent, which is OK. */
  28365. bits += m & 1;
  28366. return bits;
  28367. }
  28368. };
  28369. var _ENCODINGS;
  28370. var LOD_MIN = 4;
  28371. var LOD_MAX = 8;
  28372. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  28373. // chosen to approximate a Trowbridge-Reitz distribution function times the
  28374. // geometric shadowing function. These sigma values squared must match the
  28375. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  28376. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  28377. 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
  28378. // samples and exit early, but not recompile the shader.
  28379. var MAX_SAMPLES = 20;
  28380. 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);
  28381. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  28382. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  28383. _lodPlanes = _createPlanes2._lodPlanes,
  28384. _sizeLods = _createPlanes2._sizeLods,
  28385. _sigmas = _createPlanes2._sigmas;
  28386. var _clearColor = /*@__PURE__*/new Color();
  28387. var _backgroundColor = /*@__PURE__*/new Color();
  28388. var _oldTarget = null; // Golden Ratio
  28389. var PHI = (1 + Math.sqrt(5)) / 2;
  28390. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  28391. // same axis), used as axis directions evenly spread on a sphere.
  28392. 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)];
  28393. /**
  28394. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28395. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28396. * blur to be quickly accessed based on material roughness. It is packed into a
  28397. * special CubeUV format that allows us to perform custom interpolation so that
  28398. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  28399. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  28400. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  28401. * higher roughness levels. In this way we maintain resolution to smoothly
  28402. * interpolate diffuse lighting while limiting sampling computation.
  28403. */
  28404. function convertLinearToRGBE(color) {
  28405. var maxComponent = Math.max(color.r, color.g, color.b);
  28406. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  28407. color.multiplyScalar(Math.pow(2.0, -fExp));
  28408. var alpha = (fExp + 128.0) / 255.0;
  28409. return alpha;
  28410. }
  28411. var PMREMGenerator = /*#__PURE__*/function () {
  28412. function PMREMGenerator(renderer) {
  28413. this._renderer = renderer;
  28414. this._pingPongRenderTarget = null;
  28415. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  28416. this._equirectShader = null;
  28417. this._cubemapShader = null;
  28418. this._compileMaterial(this._blurMaterial);
  28419. }
  28420. /**
  28421. * Generates a PMREM from a supplied Scene, which can be faster than using an
  28422. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  28423. * in radians to be applied to the scene before PMREM generation. Optional near
  28424. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  28425. * is placed at the origin).
  28426. */
  28427. var _proto = PMREMGenerator.prototype;
  28428. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  28429. if (sigma === void 0) {
  28430. sigma = 0;
  28431. }
  28432. if (near === void 0) {
  28433. near = 0.1;
  28434. }
  28435. if (far === void 0) {
  28436. far = 100;
  28437. }
  28438. _oldTarget = this._renderer.getRenderTarget();
  28439. var cubeUVRenderTarget = this._allocateTargets();
  28440. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  28441. if (sigma > 0) {
  28442. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  28443. }
  28444. this._applyPMREM(cubeUVRenderTarget);
  28445. this._cleanup(cubeUVRenderTarget);
  28446. return cubeUVRenderTarget;
  28447. }
  28448. /**
  28449. * Generates a PMREM from an equirectangular texture, which can be either LDR
  28450. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  28451. * as this matches best with the 256 x 256 cubemap output.
  28452. */
  28453. ;
  28454. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  28455. return this._fromTexture(equirectangular);
  28456. }
  28457. /**
  28458. * Generates a PMREM from an cubemap texture, which can be either LDR
  28459. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  28460. * as this matches best with the 256 x 256 cubemap output.
  28461. */
  28462. ;
  28463. _proto.fromCubemap = function fromCubemap(cubemap) {
  28464. return this._fromTexture(cubemap);
  28465. }
  28466. /**
  28467. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  28468. * your texture's network fetch for increased concurrency.
  28469. */
  28470. ;
  28471. _proto.compileCubemapShader = function compileCubemapShader() {
  28472. if (this._cubemapShader === null) {
  28473. this._cubemapShader = _getCubemapShader();
  28474. this._compileMaterial(this._cubemapShader);
  28475. }
  28476. }
  28477. /**
  28478. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  28479. * your texture's network fetch for increased concurrency.
  28480. */
  28481. ;
  28482. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  28483. if (this._equirectShader === null) {
  28484. this._equirectShader = _getEquirectShader();
  28485. this._compileMaterial(this._equirectShader);
  28486. }
  28487. }
  28488. /**
  28489. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  28490. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  28491. * one of them will cause any others to also become unusable.
  28492. */
  28493. ;
  28494. _proto.dispose = function dispose() {
  28495. this._blurMaterial.dispose();
  28496. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  28497. if (this._equirectShader !== null) this._equirectShader.dispose();
  28498. for (var i = 0; i < _lodPlanes.length; i++) {
  28499. _lodPlanes[i].dispose();
  28500. }
  28501. } // private interface
  28502. ;
  28503. _proto._cleanup = function _cleanup(outputTarget) {
  28504. this._pingPongRenderTarget.dispose();
  28505. this._renderer.setRenderTarget(_oldTarget);
  28506. outputTarget.scissorTest = false;
  28507. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  28508. };
  28509. _proto._fromTexture = function _fromTexture(texture) {
  28510. _oldTarget = this._renderer.getRenderTarget();
  28511. var cubeUVRenderTarget = this._allocateTargets(texture);
  28512. this._textureToCubeUV(texture, cubeUVRenderTarget);
  28513. this._applyPMREM(cubeUVRenderTarget);
  28514. this._cleanup(cubeUVRenderTarget);
  28515. return cubeUVRenderTarget;
  28516. };
  28517. _proto._allocateTargets = function _allocateTargets(texture) {
  28518. // warning: null texture is valid
  28519. var params = {
  28520. magFilter: NearestFilter,
  28521. minFilter: NearestFilter,
  28522. generateMipmaps: false,
  28523. type: UnsignedByteType,
  28524. format: RGBEFormat,
  28525. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  28526. depthBuffer: false
  28527. };
  28528. var cubeUVRenderTarget = _createRenderTarget(params);
  28529. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  28530. this._pingPongRenderTarget = _createRenderTarget(params);
  28531. return cubeUVRenderTarget;
  28532. };
  28533. _proto._compileMaterial = function _compileMaterial(material) {
  28534. var tmpMesh = new Mesh(_lodPlanes[0], material);
  28535. this._renderer.compile(tmpMesh, _flatCamera);
  28536. };
  28537. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  28538. var fov = 90;
  28539. var aspect = 1;
  28540. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  28541. var upSign = [1, -1, 1, 1, 1, 1];
  28542. var forwardSign = [1, 1, 1, -1, -1, -1];
  28543. var renderer = this._renderer;
  28544. var outputEncoding = renderer.outputEncoding;
  28545. var toneMapping = renderer.toneMapping;
  28546. renderer.getClearColor(_clearColor);
  28547. var clearAlpha = renderer.getClearAlpha();
  28548. var originalBackground = scene.background;
  28549. renderer.toneMapping = NoToneMapping;
  28550. renderer.outputEncoding = LinearEncoding;
  28551. var background = scene.background;
  28552. if (background) {
  28553. if (background.isColor) {
  28554. _backgroundColor.copy(background).convertSRGBToLinear();
  28555. scene.background = null;
  28556. var alpha = convertLinearToRGBE(_backgroundColor);
  28557. renderer.setClearColor(_backgroundColor);
  28558. renderer.setClearAlpha(alpha);
  28559. }
  28560. } else {
  28561. _backgroundColor.copy(_clearColor).convertSRGBToLinear();
  28562. var _alpha = convertLinearToRGBE(_backgroundColor);
  28563. renderer.setClearColor(_backgroundColor);
  28564. renderer.setClearAlpha(_alpha);
  28565. }
  28566. for (var i = 0; i < 6; i++) {
  28567. var col = i % 3;
  28568. if (col == 0) {
  28569. cubeCamera.up.set(0, upSign[i], 0);
  28570. cubeCamera.lookAt(forwardSign[i], 0, 0);
  28571. } else if (col == 1) {
  28572. cubeCamera.up.set(0, 0, upSign[i]);
  28573. cubeCamera.lookAt(0, forwardSign[i], 0);
  28574. } else {
  28575. cubeCamera.up.set(0, upSign[i], 0);
  28576. cubeCamera.lookAt(0, 0, forwardSign[i]);
  28577. }
  28578. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  28579. renderer.setRenderTarget(cubeUVRenderTarget);
  28580. renderer.render(scene, cubeCamera);
  28581. }
  28582. renderer.toneMapping = toneMapping;
  28583. renderer.outputEncoding = outputEncoding;
  28584. renderer.setClearColor(_clearColor, clearAlpha);
  28585. scene.background = originalBackground;
  28586. };
  28587. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  28588. var renderer = this._renderer;
  28589. if (texture.isCubeTexture) {
  28590. if (this._cubemapShader == null) {
  28591. this._cubemapShader = _getCubemapShader();
  28592. }
  28593. } else {
  28594. if (this._equirectShader == null) {
  28595. this._equirectShader = _getEquirectShader();
  28596. }
  28597. }
  28598. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  28599. var mesh = new Mesh(_lodPlanes[0], material);
  28600. var uniforms = material.uniforms;
  28601. uniforms['envMap'].value = texture;
  28602. if (!texture.isCubeTexture) {
  28603. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  28604. }
  28605. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  28606. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  28607. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  28608. renderer.setRenderTarget(cubeUVRenderTarget);
  28609. renderer.render(mesh, _flatCamera);
  28610. };
  28611. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  28612. var renderer = this._renderer;
  28613. var autoClear = renderer.autoClear;
  28614. renderer.autoClear = false;
  28615. for (var i = 1; i < TOTAL_LODS; i++) {
  28616. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  28617. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  28618. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  28619. }
  28620. renderer.autoClear = autoClear;
  28621. }
  28622. /**
  28623. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  28624. * vertically and horizontally, but this breaks down on a cube. Here we apply
  28625. * the blur latitudinally (around the poles), and then longitudinally (towards
  28626. * the poles) to approximate the orthogonally-separable blur. It is least
  28627. * accurate at the poles, but still does a decent job.
  28628. */
  28629. ;
  28630. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  28631. var pingPongRenderTarget = this._pingPongRenderTarget;
  28632. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  28633. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  28634. };
  28635. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  28636. var renderer = this._renderer;
  28637. var blurMaterial = this._blurMaterial;
  28638. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  28639. console.error('blur direction must be either latitudinal or longitudinal!');
  28640. } // Number of standard deviations at which to cut off the discrete approximation.
  28641. var STANDARD_DEVIATIONS = 3;
  28642. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  28643. var blurUniforms = blurMaterial.uniforms;
  28644. var pixels = _sizeLods[lodIn] - 1;
  28645. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  28646. var sigmaPixels = sigmaRadians / radiansPerPixel;
  28647. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  28648. if (samples > MAX_SAMPLES) {
  28649. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  28650. }
  28651. var weights = [];
  28652. var sum = 0;
  28653. for (var i = 0; i < MAX_SAMPLES; ++i) {
  28654. var _x = i / sigmaPixels;
  28655. var weight = Math.exp(-_x * _x / 2);
  28656. weights.push(weight);
  28657. if (i == 0) {
  28658. sum += weight;
  28659. } else if (i < samples) {
  28660. sum += 2 * weight;
  28661. }
  28662. }
  28663. for (var _i = 0; _i < weights.length; _i++) {
  28664. weights[_i] = weights[_i] / sum;
  28665. }
  28666. blurUniforms['envMap'].value = targetIn.texture;
  28667. blurUniforms['samples'].value = samples;
  28668. blurUniforms['weights'].value = weights;
  28669. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  28670. if (poleAxis) {
  28671. blurUniforms['poleAxis'].value = poleAxis;
  28672. }
  28673. blurUniforms['dTheta'].value = radiansPerPixel;
  28674. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  28675. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28676. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28677. var outputSize = _sizeLods[lodOut];
  28678. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  28679. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  28680. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  28681. renderer.setRenderTarget(targetOut);
  28682. renderer.render(blurMesh, _flatCamera);
  28683. };
  28684. return PMREMGenerator;
  28685. }();
  28686. function _isLDR(texture) {
  28687. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  28688. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  28689. }
  28690. function _createPlanes() {
  28691. var _lodPlanes = [];
  28692. var _sizeLods = [];
  28693. var _sigmas = [];
  28694. var lod = LOD_MAX;
  28695. for (var i = 0; i < TOTAL_LODS; i++) {
  28696. var sizeLod = Math.pow(2, lod);
  28697. _sizeLods.push(sizeLod);
  28698. var sigma = 1.0 / sizeLod;
  28699. if (i > LOD_MAX - LOD_MIN) {
  28700. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  28701. } else if (i == 0) {
  28702. sigma = 0;
  28703. }
  28704. _sigmas.push(sigma);
  28705. var texelSize = 1.0 / (sizeLod - 1);
  28706. var min = -texelSize / 2;
  28707. var max = 1 + texelSize / 2;
  28708. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  28709. var cubeFaces = 6;
  28710. var vertices = 6;
  28711. var positionSize = 3;
  28712. var uvSize = 2;
  28713. var faceIndexSize = 1;
  28714. var position = new Float32Array(positionSize * vertices * cubeFaces);
  28715. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  28716. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  28717. for (var face = 0; face < cubeFaces; face++) {
  28718. var x = face % 3 * 2 / 3 - 1;
  28719. var y = face > 2 ? 0 : -1;
  28720. 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];
  28721. position.set(coordinates, positionSize * vertices * face);
  28722. uv.set(uv1, uvSize * vertices * face);
  28723. var fill = [face, face, face, face, face, face];
  28724. faceIndex.set(fill, faceIndexSize * vertices * face);
  28725. }
  28726. var planes = new BufferGeometry();
  28727. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  28728. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  28729. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  28730. _lodPlanes.push(planes);
  28731. if (lod > LOD_MIN) {
  28732. lod--;
  28733. }
  28734. }
  28735. return {
  28736. _lodPlanes: _lodPlanes,
  28737. _sizeLods: _sizeLods,
  28738. _sigmas: _sigmas
  28739. };
  28740. }
  28741. function _createRenderTarget(params) {
  28742. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  28743. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  28744. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  28745. cubeUVRenderTarget.scissorTest = true;
  28746. return cubeUVRenderTarget;
  28747. }
  28748. function _setViewport(target, x, y, width, height) {
  28749. target.viewport.set(x, y, width, height);
  28750. target.scissor.set(x, y, width, height);
  28751. }
  28752. function _getBlurShader(maxSamples) {
  28753. var weights = new Float32Array(maxSamples);
  28754. var poleAxis = new Vector3(0, 1, 0);
  28755. var shaderMaterial = new RawShaderMaterial({
  28756. name: 'SphericalGaussianBlur',
  28757. defines: {
  28758. 'n': maxSamples
  28759. },
  28760. uniforms: {
  28761. 'envMap': {
  28762. value: null
  28763. },
  28764. 'samples': {
  28765. value: 1
  28766. },
  28767. 'weights': {
  28768. value: weights
  28769. },
  28770. 'latitudinal': {
  28771. value: false
  28772. },
  28773. 'dTheta': {
  28774. value: 0
  28775. },
  28776. 'mipInt': {
  28777. value: 0
  28778. },
  28779. 'poleAxis': {
  28780. value: poleAxis
  28781. },
  28782. 'inputEncoding': {
  28783. value: ENCODINGS[LinearEncoding]
  28784. },
  28785. 'outputEncoding': {
  28786. value: ENCODINGS[LinearEncoding]
  28787. }
  28788. },
  28789. vertexShader: _getCommonVertexShader(),
  28790. fragmentShader:
  28791. /* glsl */
  28792. "\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",
  28793. blending: NoBlending,
  28794. depthTest: false,
  28795. depthWrite: false
  28796. });
  28797. return shaderMaterial;
  28798. }
  28799. function _getEquirectShader() {
  28800. var texelSize = new Vector2(1, 1);
  28801. var shaderMaterial = new RawShaderMaterial({
  28802. name: 'EquirectangularToCubeUV',
  28803. uniforms: {
  28804. 'envMap': {
  28805. value: null
  28806. },
  28807. 'texelSize': {
  28808. value: texelSize
  28809. },
  28810. 'inputEncoding': {
  28811. value: ENCODINGS[LinearEncoding]
  28812. },
  28813. 'outputEncoding': {
  28814. value: ENCODINGS[LinearEncoding]
  28815. }
  28816. },
  28817. vertexShader: _getCommonVertexShader(),
  28818. fragmentShader:
  28819. /* glsl */
  28820. "\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",
  28821. blending: NoBlending,
  28822. depthTest: false,
  28823. depthWrite: false
  28824. });
  28825. return shaderMaterial;
  28826. }
  28827. function _getCubemapShader() {
  28828. var shaderMaterial = new RawShaderMaterial({
  28829. name: 'CubemapToCubeUV',
  28830. uniforms: {
  28831. 'envMap': {
  28832. value: null
  28833. },
  28834. 'inputEncoding': {
  28835. value: ENCODINGS[LinearEncoding]
  28836. },
  28837. 'outputEncoding': {
  28838. value: ENCODINGS[LinearEncoding]
  28839. }
  28840. },
  28841. vertexShader: _getCommonVertexShader(),
  28842. fragmentShader:
  28843. /* glsl */
  28844. "\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",
  28845. blending: NoBlending,
  28846. depthTest: false,
  28847. depthWrite: false
  28848. });
  28849. return shaderMaterial;
  28850. }
  28851. function _getCommonVertexShader() {
  28852. return (
  28853. /* glsl */
  28854. "\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"
  28855. );
  28856. }
  28857. function _getEncodings() {
  28858. return (
  28859. /* glsl */
  28860. "\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"
  28861. );
  28862. }
  28863. function Face4(a, b, c, d, normal, color, materialIndex) {
  28864. console.warn('THREE.Face4 has been removed. A THREE.Face3 will be created instead.');
  28865. return new Face3(a, b, c, normal, color, materialIndex);
  28866. }
  28867. var LineStrip = 0;
  28868. var LinePieces = 1;
  28869. var NoColors = 0;
  28870. var FaceColors = 1;
  28871. var VertexColors = 2;
  28872. function MeshFaceMaterial(materials) {
  28873. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  28874. return materials;
  28875. }
  28876. function MultiMaterial(materials) {
  28877. if (materials === void 0) {
  28878. materials = [];
  28879. }
  28880. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  28881. materials.isMultiMaterial = true;
  28882. materials.materials = materials;
  28883. materials.clone = function () {
  28884. return materials.slice();
  28885. };
  28886. return materials;
  28887. }
  28888. function PointCloud(geometry, material) {
  28889. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  28890. return new Points(geometry, material);
  28891. }
  28892. function Particle(material) {
  28893. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  28894. return new Sprite(material);
  28895. }
  28896. function ParticleSystem(geometry, material) {
  28897. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  28898. return new Points(geometry, material);
  28899. }
  28900. function PointCloudMaterial(parameters) {
  28901. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  28902. return new PointsMaterial(parameters);
  28903. }
  28904. function ParticleBasicMaterial(parameters) {
  28905. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  28906. return new PointsMaterial(parameters);
  28907. }
  28908. function ParticleSystemMaterial(parameters) {
  28909. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  28910. return new PointsMaterial(parameters);
  28911. }
  28912. function Vertex(x, y, z) {
  28913. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  28914. return new Vector3(x, y, z);
  28915. } //
  28916. function DynamicBufferAttribute(array, itemSize) {
  28917. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  28918. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  28919. }
  28920. function Int8Attribute(array, itemSize) {
  28921. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  28922. return new Int8BufferAttribute(array, itemSize);
  28923. }
  28924. function Uint8Attribute(array, itemSize) {
  28925. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  28926. return new Uint8BufferAttribute(array, itemSize);
  28927. }
  28928. function Uint8ClampedAttribute(array, itemSize) {
  28929. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  28930. return new Uint8ClampedBufferAttribute(array, itemSize);
  28931. }
  28932. function Int16Attribute(array, itemSize) {
  28933. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  28934. return new Int16BufferAttribute(array, itemSize);
  28935. }
  28936. function Uint16Attribute(array, itemSize) {
  28937. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  28938. return new Uint16BufferAttribute(array, itemSize);
  28939. }
  28940. function Int32Attribute(array, itemSize) {
  28941. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  28942. return new Int32BufferAttribute(array, itemSize);
  28943. }
  28944. function Uint32Attribute(array, itemSize) {
  28945. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  28946. return new Uint32BufferAttribute(array, itemSize);
  28947. }
  28948. function Float32Attribute(array, itemSize) {
  28949. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  28950. return new Float32BufferAttribute(array, itemSize);
  28951. }
  28952. function Float64Attribute(array, itemSize) {
  28953. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  28954. return new Float64BufferAttribute(array, itemSize);
  28955. } //
  28956. Curve.create = function (construct, getPoint) {
  28957. console.log('THREE.Curve.create() has been deprecated');
  28958. construct.prototype = Object.create(Curve.prototype);
  28959. construct.prototype.constructor = construct;
  28960. construct.prototype.getPoint = getPoint;
  28961. return construct;
  28962. }; //
  28963. Object.assign(Path.prototype, {
  28964. fromPoints: function fromPoints(points) {
  28965. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  28966. return this.setFromPoints(points);
  28967. }
  28968. }); //
  28969. function ClosedSplineCurve3(points) {
  28970. console.warn('THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  28971. CatmullRomCurve3.call(this, points);
  28972. this.type = 'catmullrom';
  28973. this.closed = true;
  28974. }
  28975. ClosedSplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  28976. function SplineCurve3(points) {
  28977. console.warn('THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  28978. CatmullRomCurve3.call(this, points);
  28979. this.type = 'catmullrom';
  28980. }
  28981. SplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  28982. function Spline(points) {
  28983. console.warn('THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.');
  28984. CatmullRomCurve3.call(this, points);
  28985. this.type = 'catmullrom';
  28986. }
  28987. Spline.prototype = Object.create(CatmullRomCurve3.prototype);
  28988. Object.assign(Spline.prototype, {
  28989. initFromArray: function initFromArray()
  28990. /* a */
  28991. {
  28992. console.error('THREE.Spline: .initFromArray() has been removed.');
  28993. },
  28994. getControlPointsArray: function getControlPointsArray()
  28995. /* optionalTarget */
  28996. {
  28997. console.error('THREE.Spline: .getControlPointsArray() has been removed.');
  28998. },
  28999. reparametrizeByArcLength: function reparametrizeByArcLength()
  29000. /* samplingCoef */
  29001. {
  29002. console.error('THREE.Spline: .reparametrizeByArcLength() has been removed.');
  29003. }
  29004. }); //
  29005. function AxisHelper(size) {
  29006. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  29007. return new AxesHelper(size);
  29008. }
  29009. function BoundingBoxHelper(object, color) {
  29010. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  29011. return new BoxHelper(object, color);
  29012. }
  29013. function EdgesHelper(object, hex) {
  29014. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  29015. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  29016. color: hex !== undefined ? hex : 0xffffff
  29017. }));
  29018. }
  29019. GridHelper.prototype.setColors = function () {
  29020. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  29021. };
  29022. SkeletonHelper.prototype.update = function () {
  29023. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  29024. };
  29025. function WireframeHelper(object, hex) {
  29026. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  29027. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  29028. color: hex !== undefined ? hex : 0xffffff
  29029. }));
  29030. } //
  29031. Object.assign(Loader.prototype, {
  29032. extractUrlBase: function extractUrlBase(url) {
  29033. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  29034. return LoaderUtils.extractUrlBase(url);
  29035. }
  29036. });
  29037. Loader.Handlers = {
  29038. add: function add()
  29039. /* regex, loader */
  29040. {
  29041. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  29042. },
  29043. get: function get()
  29044. /* file */
  29045. {
  29046. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  29047. }
  29048. };
  29049. function XHRLoader(manager) {
  29050. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  29051. return new FileLoader(manager);
  29052. }
  29053. function BinaryTextureLoader(manager) {
  29054. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  29055. return new DataTextureLoader(manager);
  29056. } //
  29057. Object.assign(Box2.prototype, {
  29058. center: function center(optionalTarget) {
  29059. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  29060. return this.getCenter(optionalTarget);
  29061. },
  29062. empty: function empty() {
  29063. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  29064. return this.isEmpty();
  29065. },
  29066. isIntersectionBox: function isIntersectionBox(box) {
  29067. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  29068. return this.intersectsBox(box);
  29069. },
  29070. size: function size(optionalTarget) {
  29071. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  29072. return this.getSize(optionalTarget);
  29073. }
  29074. });
  29075. Object.assign(Box3.prototype, {
  29076. center: function center(optionalTarget) {
  29077. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  29078. return this.getCenter(optionalTarget);
  29079. },
  29080. empty: function empty() {
  29081. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  29082. return this.isEmpty();
  29083. },
  29084. isIntersectionBox: function isIntersectionBox(box) {
  29085. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  29086. return this.intersectsBox(box);
  29087. },
  29088. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29089. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29090. return this.intersectsSphere(sphere);
  29091. },
  29092. size: function size(optionalTarget) {
  29093. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  29094. return this.getSize(optionalTarget);
  29095. }
  29096. });
  29097. Object.assign(Sphere.prototype, {
  29098. empty: function empty() {
  29099. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  29100. return this.isEmpty();
  29101. }
  29102. });
  29103. Frustum.prototype.setFromMatrix = function (m) {
  29104. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  29105. return this.setFromProjectionMatrix(m);
  29106. };
  29107. Line3.prototype.center = function (optionalTarget) {
  29108. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  29109. return this.getCenter(optionalTarget);
  29110. };
  29111. Object.assign(MathUtils, {
  29112. random16: function random16() {
  29113. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  29114. return Math.random();
  29115. },
  29116. nearestPowerOfTwo: function nearestPowerOfTwo(value) {
  29117. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  29118. return MathUtils.floorPowerOfTwo(value);
  29119. },
  29120. nextPowerOfTwo: function nextPowerOfTwo(value) {
  29121. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29122. return MathUtils.ceilPowerOfTwo(value);
  29123. }
  29124. });
  29125. Object.assign(Matrix3.prototype, {
  29126. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29127. console.warn('THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29128. return this.toArray(array, offset);
  29129. },
  29130. multiplyVector3: function multiplyVector3(vector) {
  29131. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29132. return vector.applyMatrix3(this);
  29133. },
  29134. multiplyVector3Array: function multiplyVector3Array()
  29135. /* a */
  29136. {
  29137. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29138. },
  29139. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29140. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29141. return attribute.applyMatrix3(this);
  29142. },
  29143. applyToVector3Array: function applyToVector3Array()
  29144. /* array, offset, length */
  29145. {
  29146. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29147. },
  29148. getInverse: function getInverse(matrix) {
  29149. console.warn('THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29150. return this.copy(matrix).invert();
  29151. }
  29152. });
  29153. Object.assign(Matrix4.prototype, {
  29154. extractPosition: function extractPosition(m) {
  29155. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29156. return this.copyPosition(m);
  29157. },
  29158. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29159. console.warn('THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29160. return this.toArray(array, offset);
  29161. },
  29162. getPosition: function getPosition() {
  29163. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29164. return new Vector3().setFromMatrixColumn(this, 3);
  29165. },
  29166. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  29167. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29168. return this.makeRotationFromQuaternion(q);
  29169. },
  29170. multiplyToArray: function multiplyToArray() {
  29171. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29172. },
  29173. multiplyVector3: function multiplyVector3(vector) {
  29174. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29175. return vector.applyMatrix4(this);
  29176. },
  29177. multiplyVector4: function multiplyVector4(vector) {
  29178. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29179. return vector.applyMatrix4(this);
  29180. },
  29181. multiplyVector3Array: function multiplyVector3Array()
  29182. /* a */
  29183. {
  29184. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29185. },
  29186. rotateAxis: function rotateAxis(v) {
  29187. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29188. v.transformDirection(this);
  29189. },
  29190. crossVector: function crossVector(vector) {
  29191. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29192. return vector.applyMatrix4(this);
  29193. },
  29194. translate: function translate() {
  29195. console.error('THREE.Matrix4: .translate() has been removed.');
  29196. },
  29197. rotateX: function rotateX() {
  29198. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29199. },
  29200. rotateY: function rotateY() {
  29201. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29202. },
  29203. rotateZ: function rotateZ() {
  29204. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29205. },
  29206. rotateByAxis: function rotateByAxis() {
  29207. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29208. },
  29209. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29210. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29211. return attribute.applyMatrix4(this);
  29212. },
  29213. applyToVector3Array: function applyToVector3Array()
  29214. /* array, offset, length */
  29215. {
  29216. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29217. },
  29218. makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
  29219. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29220. return this.makePerspective(left, right, top, bottom, near, far);
  29221. },
  29222. getInverse: function getInverse(matrix) {
  29223. console.warn('THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29224. return this.copy(matrix).invert();
  29225. }
  29226. });
  29227. Plane.prototype.isIntersectionLine = function (line) {
  29228. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29229. return this.intersectsLine(line);
  29230. };
  29231. Object.assign(Quaternion.prototype, {
  29232. multiplyVector3: function multiplyVector3(vector) {
  29233. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29234. return vector.applyQuaternion(this);
  29235. },
  29236. inverse: function inverse() {
  29237. console.warn('THREE.Quaternion: .inverse() has been renamed to invert().');
  29238. return this.invert();
  29239. }
  29240. });
  29241. Object.assign(Ray.prototype, {
  29242. isIntersectionBox: function isIntersectionBox(box) {
  29243. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29244. return this.intersectsBox(box);
  29245. },
  29246. isIntersectionPlane: function isIntersectionPlane(plane) {
  29247. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29248. return this.intersectsPlane(plane);
  29249. },
  29250. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29251. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29252. return this.intersectsSphere(sphere);
  29253. }
  29254. });
  29255. Object.assign(Triangle.prototype, {
  29256. area: function area() {
  29257. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  29258. return this.getArea();
  29259. },
  29260. barycoordFromPoint: function barycoordFromPoint(point, target) {
  29261. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29262. return this.getBarycoord(point, target);
  29263. },
  29264. midpoint: function midpoint(target) {
  29265. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  29266. return this.getMidpoint(target);
  29267. },
  29268. normal: function normal(target) {
  29269. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29270. return this.getNormal(target);
  29271. },
  29272. plane: function plane(target) {
  29273. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  29274. return this.getPlane(target);
  29275. }
  29276. });
  29277. Object.assign(Triangle, {
  29278. barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
  29279. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29280. return Triangle.getBarycoord(point, a, b, c, target);
  29281. },
  29282. normal: function normal(a, b, c, target) {
  29283. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29284. return Triangle.getNormal(a, b, c, target);
  29285. }
  29286. });
  29287. Object.assign(Shape.prototype, {
  29288. extractAllPoints: function extractAllPoints(divisions) {
  29289. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  29290. return this.extractPoints(divisions);
  29291. },
  29292. extrude: function extrude(options) {
  29293. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  29294. return new ExtrudeGeometry(this, options);
  29295. },
  29296. makeGeometry: function makeGeometry(options) {
  29297. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  29298. return new ShapeGeometry(this, options);
  29299. }
  29300. });
  29301. Object.assign(Vector2.prototype, {
  29302. fromAttribute: function fromAttribute(attribute, index, offset) {
  29303. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29304. return this.fromBufferAttribute(attribute, index, offset);
  29305. },
  29306. distanceToManhattan: function distanceToManhattan(v) {
  29307. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29308. return this.manhattanDistanceTo(v);
  29309. },
  29310. lengthManhattan: function lengthManhattan() {
  29311. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  29312. return this.manhattanLength();
  29313. }
  29314. });
  29315. Object.assign(Vector3.prototype, {
  29316. setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
  29317. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  29318. },
  29319. setEulerFromQuaternion: function setEulerFromQuaternion() {
  29320. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  29321. },
  29322. getPositionFromMatrix: function getPositionFromMatrix(m) {
  29323. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  29324. return this.setFromMatrixPosition(m);
  29325. },
  29326. getScaleFromMatrix: function getScaleFromMatrix(m) {
  29327. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  29328. return this.setFromMatrixScale(m);
  29329. },
  29330. getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
  29331. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  29332. return this.setFromMatrixColumn(matrix, index);
  29333. },
  29334. applyProjection: function applyProjection(m) {
  29335. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  29336. return this.applyMatrix4(m);
  29337. },
  29338. fromAttribute: function fromAttribute(attribute, index, offset) {
  29339. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29340. return this.fromBufferAttribute(attribute, index, offset);
  29341. },
  29342. distanceToManhattan: function distanceToManhattan(v) {
  29343. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29344. return this.manhattanDistanceTo(v);
  29345. },
  29346. lengthManhattan: function lengthManhattan() {
  29347. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  29348. return this.manhattanLength();
  29349. }
  29350. });
  29351. Object.assign(Vector4.prototype, {
  29352. fromAttribute: function fromAttribute(attribute, index, offset) {
  29353. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29354. return this.fromBufferAttribute(attribute, index, offset);
  29355. },
  29356. lengthManhattan: function lengthManhattan() {
  29357. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  29358. return this.manhattanLength();
  29359. }
  29360. }); //
  29361. Object.assign(Object3D.prototype, {
  29362. getChildByName: function getChildByName(name) {
  29363. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  29364. return this.getObjectByName(name);
  29365. },
  29366. renderDepth: function renderDepth() {
  29367. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  29368. },
  29369. translate: function translate(distance, axis) {
  29370. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  29371. return this.translateOnAxis(axis, distance);
  29372. },
  29373. getWorldRotation: function getWorldRotation() {
  29374. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  29375. },
  29376. applyMatrix: function applyMatrix(matrix) {
  29377. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  29378. return this.applyMatrix4(matrix);
  29379. }
  29380. });
  29381. Object.defineProperties(Object3D.prototype, {
  29382. eulerOrder: {
  29383. get: function get() {
  29384. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29385. return this.rotation.order;
  29386. },
  29387. set: function set(value) {
  29388. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29389. this.rotation.order = value;
  29390. }
  29391. },
  29392. useQuaternion: {
  29393. get: function get() {
  29394. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29395. },
  29396. set: function set() {
  29397. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29398. }
  29399. }
  29400. });
  29401. Object.assign(Mesh.prototype, {
  29402. setDrawMode: function setDrawMode() {
  29403. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29404. }
  29405. });
  29406. Object.defineProperties(Mesh.prototype, {
  29407. drawMode: {
  29408. get: function get() {
  29409. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  29410. return TrianglesDrawMode;
  29411. },
  29412. set: function set() {
  29413. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29414. }
  29415. }
  29416. });
  29417. Object.defineProperties(LOD.prototype, {
  29418. objects: {
  29419. get: function get() {
  29420. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  29421. return this.levels;
  29422. }
  29423. }
  29424. });
  29425. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  29426. get: function get() {
  29427. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29428. },
  29429. set: function set() {
  29430. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29431. }
  29432. });
  29433. SkinnedMesh.prototype.initBones = function () {
  29434. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  29435. };
  29436. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  29437. get: function get() {
  29438. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29439. return this.arcLengthDivisions;
  29440. },
  29441. set: function set(value) {
  29442. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29443. this.arcLengthDivisions = value;
  29444. }
  29445. }); //
  29446. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  29447. console.warn('THREE.PerspectiveCamera.setLens is deprecated. ' + 'Use .setFocalLength and .filmGauge for a photographic setup.');
  29448. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  29449. this.setFocalLength(focalLength);
  29450. }; //
  29451. Object.defineProperties(Light.prototype, {
  29452. onlyShadow: {
  29453. set: function set() {
  29454. console.warn('THREE.Light: .onlyShadow has been removed.');
  29455. }
  29456. },
  29457. shadowCameraFov: {
  29458. set: function set(value) {
  29459. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  29460. this.shadow.camera.fov = value;
  29461. }
  29462. },
  29463. shadowCameraLeft: {
  29464. set: function set(value) {
  29465. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  29466. this.shadow.camera.left = value;
  29467. }
  29468. },
  29469. shadowCameraRight: {
  29470. set: function set(value) {
  29471. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  29472. this.shadow.camera.right = value;
  29473. }
  29474. },
  29475. shadowCameraTop: {
  29476. set: function set(value) {
  29477. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  29478. this.shadow.camera.top = value;
  29479. }
  29480. },
  29481. shadowCameraBottom: {
  29482. set: function set(value) {
  29483. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  29484. this.shadow.camera.bottom = value;
  29485. }
  29486. },
  29487. shadowCameraNear: {
  29488. set: function set(value) {
  29489. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  29490. this.shadow.camera.near = value;
  29491. }
  29492. },
  29493. shadowCameraFar: {
  29494. set: function set(value) {
  29495. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  29496. this.shadow.camera.far = value;
  29497. }
  29498. },
  29499. shadowCameraVisible: {
  29500. set: function set() {
  29501. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  29502. }
  29503. },
  29504. shadowBias: {
  29505. set: function set(value) {
  29506. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  29507. this.shadow.bias = value;
  29508. }
  29509. },
  29510. shadowDarkness: {
  29511. set: function set() {
  29512. console.warn('THREE.Light: .shadowDarkness has been removed.');
  29513. }
  29514. },
  29515. shadowMapWidth: {
  29516. set: function set(value) {
  29517. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  29518. this.shadow.mapSize.width = value;
  29519. }
  29520. },
  29521. shadowMapHeight: {
  29522. set: function set(value) {
  29523. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  29524. this.shadow.mapSize.height = value;
  29525. }
  29526. }
  29527. }); //
  29528. Object.defineProperties(BufferAttribute.prototype, {
  29529. length: {
  29530. get: function get() {
  29531. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  29532. return this.array.length;
  29533. }
  29534. },
  29535. dynamic: {
  29536. get: function get() {
  29537. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29538. return this.usage === DynamicDrawUsage;
  29539. },
  29540. set: function set()
  29541. /* value */
  29542. {
  29543. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29544. this.setUsage(DynamicDrawUsage);
  29545. }
  29546. }
  29547. });
  29548. Object.assign(BufferAttribute.prototype, {
  29549. setDynamic: function setDynamic(value) {
  29550. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29551. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29552. return this;
  29553. },
  29554. copyIndicesArray: function copyIndicesArray()
  29555. /* indices */
  29556. {
  29557. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  29558. },
  29559. setArray: function setArray()
  29560. /* array */
  29561. {
  29562. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29563. }
  29564. });
  29565. Object.assign(BufferGeometry.prototype, {
  29566. addIndex: function addIndex(index) {
  29567. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  29568. this.setIndex(index);
  29569. },
  29570. addAttribute: function addAttribute(name, attribute) {
  29571. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  29572. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  29573. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  29574. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  29575. }
  29576. if (name === 'index') {
  29577. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  29578. this.setIndex(attribute);
  29579. return this;
  29580. }
  29581. return this.setAttribute(name, attribute);
  29582. },
  29583. addDrawCall: function addDrawCall(start, count, indexOffset) {
  29584. if (indexOffset !== undefined) {
  29585. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  29586. }
  29587. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  29588. this.addGroup(start, count);
  29589. },
  29590. clearDrawCalls: function clearDrawCalls() {
  29591. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  29592. this.clearGroups();
  29593. },
  29594. computeOffsets: function computeOffsets() {
  29595. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  29596. },
  29597. removeAttribute: function removeAttribute(name) {
  29598. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  29599. return this.deleteAttribute(name);
  29600. },
  29601. applyMatrix: function applyMatrix(matrix) {
  29602. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29603. return this.applyMatrix4(matrix);
  29604. }
  29605. });
  29606. Object.defineProperties(BufferGeometry.prototype, {
  29607. drawcalls: {
  29608. get: function get() {
  29609. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  29610. return this.groups;
  29611. }
  29612. },
  29613. offsets: {
  29614. get: function get() {
  29615. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  29616. return this.groups;
  29617. }
  29618. }
  29619. });
  29620. Object.defineProperties(InstancedBufferGeometry.prototype, {
  29621. maxInstancedCount: {
  29622. get: function get() {
  29623. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29624. return this.instanceCount;
  29625. },
  29626. set: function set(value) {
  29627. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29628. this.instanceCount = value;
  29629. }
  29630. }
  29631. });
  29632. Object.defineProperties(Raycaster.prototype, {
  29633. linePrecision: {
  29634. get: function get() {
  29635. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29636. return this.params.Line.threshold;
  29637. },
  29638. set: function set(value) {
  29639. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29640. this.params.Line.threshold = value;
  29641. }
  29642. }
  29643. });
  29644. Object.defineProperties(InterleavedBuffer.prototype, {
  29645. dynamic: {
  29646. get: function get() {
  29647. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29648. return this.usage === DynamicDrawUsage;
  29649. },
  29650. set: function set(value) {
  29651. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29652. this.setUsage(value);
  29653. }
  29654. }
  29655. });
  29656. Object.assign(InterleavedBuffer.prototype, {
  29657. setDynamic: function setDynamic(value) {
  29658. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29659. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29660. return this;
  29661. },
  29662. setArray: function setArray()
  29663. /* array */
  29664. {
  29665. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29666. }
  29667. }); //
  29668. Object.assign(ExtrudeGeometry.prototype, {
  29669. getArrays: function getArrays() {
  29670. console.error('THREE.ExtrudeGeometry: .getArrays() has been removed.');
  29671. },
  29672. addShapeList: function addShapeList() {
  29673. console.error('THREE.ExtrudeGeometry: .addShapeList() has been removed.');
  29674. },
  29675. addShape: function addShape() {
  29676. console.error('THREE.ExtrudeGeometry: .addShape() has been removed.');
  29677. }
  29678. }); //
  29679. Object.assign(Scene.prototype, {
  29680. dispose: function dispose() {
  29681. console.error('THREE.Scene: .dispose() has been removed.');
  29682. }
  29683. }); //
  29684. Object.defineProperties(Uniform.prototype, {
  29685. dynamic: {
  29686. set: function set() {
  29687. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  29688. }
  29689. },
  29690. onUpdate: {
  29691. value: function value() {
  29692. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  29693. return this;
  29694. }
  29695. }
  29696. }); //
  29697. Object.defineProperties(Material.prototype, {
  29698. wrapAround: {
  29699. get: function get() {
  29700. console.warn('THREE.Material: .wrapAround has been removed.');
  29701. },
  29702. set: function set() {
  29703. console.warn('THREE.Material: .wrapAround has been removed.');
  29704. }
  29705. },
  29706. overdraw: {
  29707. get: function get() {
  29708. console.warn('THREE.Material: .overdraw has been removed.');
  29709. },
  29710. set: function set() {
  29711. console.warn('THREE.Material: .overdraw has been removed.');
  29712. }
  29713. },
  29714. wrapRGB: {
  29715. get: function get() {
  29716. console.warn('THREE.Material: .wrapRGB has been removed.');
  29717. return new Color();
  29718. }
  29719. },
  29720. shading: {
  29721. get: function get() {
  29722. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29723. },
  29724. set: function set(value) {
  29725. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29726. this.flatShading = value === FlatShading;
  29727. }
  29728. },
  29729. stencilMask: {
  29730. get: function get() {
  29731. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29732. return this.stencilFuncMask;
  29733. },
  29734. set: function set(value) {
  29735. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29736. this.stencilFuncMask = value;
  29737. }
  29738. }
  29739. });
  29740. Object.defineProperties(MeshPhongMaterial.prototype, {
  29741. metal: {
  29742. get: function get() {
  29743. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  29744. return false;
  29745. },
  29746. set: function set() {
  29747. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  29748. }
  29749. }
  29750. });
  29751. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  29752. transparency: {
  29753. get: function get() {
  29754. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29755. return this.transmission;
  29756. },
  29757. set: function set(value) {
  29758. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29759. this.transmission = value;
  29760. }
  29761. }
  29762. });
  29763. Object.defineProperties(ShaderMaterial.prototype, {
  29764. derivatives: {
  29765. get: function get() {
  29766. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29767. return this.extensions.derivatives;
  29768. },
  29769. set: function set(value) {
  29770. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29771. this.extensions.derivatives = value;
  29772. }
  29773. }
  29774. }); //
  29775. Object.assign(WebGLRenderer.prototype, {
  29776. clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
  29777. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  29778. this.setRenderTarget(renderTarget);
  29779. this.clear(color, depth, stencil);
  29780. },
  29781. animate: function animate(callback) {
  29782. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  29783. this.setAnimationLoop(callback);
  29784. },
  29785. getCurrentRenderTarget: function getCurrentRenderTarget() {
  29786. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  29787. return this.getRenderTarget();
  29788. },
  29789. getMaxAnisotropy: function getMaxAnisotropy() {
  29790. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  29791. return this.capabilities.getMaxAnisotropy();
  29792. },
  29793. getPrecision: function getPrecision() {
  29794. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  29795. return this.capabilities.precision;
  29796. },
  29797. resetGLState: function resetGLState() {
  29798. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  29799. return this.state.reset();
  29800. },
  29801. supportsFloatTextures: function supportsFloatTextures() {
  29802. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  29803. return this.extensions.get('OES_texture_float');
  29804. },
  29805. supportsHalfFloatTextures: function supportsHalfFloatTextures() {
  29806. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  29807. return this.extensions.get('OES_texture_half_float');
  29808. },
  29809. supportsStandardDerivatives: function supportsStandardDerivatives() {
  29810. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  29811. return this.extensions.get('OES_standard_derivatives');
  29812. },
  29813. supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
  29814. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  29815. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  29816. },
  29817. supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
  29818. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  29819. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  29820. },
  29821. supportsBlendMinMax: function supportsBlendMinMax() {
  29822. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  29823. return this.extensions.get('EXT_blend_minmax');
  29824. },
  29825. supportsVertexTextures: function supportsVertexTextures() {
  29826. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  29827. return this.capabilities.vertexTextures;
  29828. },
  29829. supportsInstancedArrays: function supportsInstancedArrays() {
  29830. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  29831. return this.extensions.get('ANGLE_instanced_arrays');
  29832. },
  29833. enableScissorTest: function enableScissorTest(boolean) {
  29834. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  29835. this.setScissorTest(boolean);
  29836. },
  29837. initMaterial: function initMaterial() {
  29838. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  29839. },
  29840. addPrePlugin: function addPrePlugin() {
  29841. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  29842. },
  29843. addPostPlugin: function addPostPlugin() {
  29844. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  29845. },
  29846. updateShadowMap: function updateShadowMap() {
  29847. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  29848. },
  29849. setFaceCulling: function setFaceCulling() {
  29850. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  29851. },
  29852. allocTextureUnit: function allocTextureUnit() {
  29853. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  29854. },
  29855. setTexture: function setTexture() {
  29856. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  29857. },
  29858. setTexture2D: function setTexture2D() {
  29859. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  29860. },
  29861. setTextureCube: function setTextureCube() {
  29862. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  29863. },
  29864. getActiveMipMapLevel: function getActiveMipMapLevel() {
  29865. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  29866. return this.getActiveMipmapLevel();
  29867. }
  29868. });
  29869. Object.defineProperties(WebGLRenderer.prototype, {
  29870. shadowMapEnabled: {
  29871. get: function get() {
  29872. return this.shadowMap.enabled;
  29873. },
  29874. set: function set(value) {
  29875. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  29876. this.shadowMap.enabled = value;
  29877. }
  29878. },
  29879. shadowMapType: {
  29880. get: function get() {
  29881. return this.shadowMap.type;
  29882. },
  29883. set: function set(value) {
  29884. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  29885. this.shadowMap.type = value;
  29886. }
  29887. },
  29888. shadowMapCullFace: {
  29889. get: function get() {
  29890. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  29891. return undefined;
  29892. },
  29893. set: function set()
  29894. /* value */
  29895. {
  29896. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  29897. }
  29898. },
  29899. context: {
  29900. get: function get() {
  29901. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  29902. return this.getContext();
  29903. }
  29904. },
  29905. vr: {
  29906. get: function get() {
  29907. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  29908. return this.xr;
  29909. }
  29910. },
  29911. gammaInput: {
  29912. get: function get() {
  29913. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  29914. return false;
  29915. },
  29916. set: function set() {
  29917. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  29918. }
  29919. },
  29920. gammaOutput: {
  29921. get: function get() {
  29922. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  29923. return false;
  29924. },
  29925. set: function set(value) {
  29926. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  29927. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  29928. }
  29929. },
  29930. toneMappingWhitePoint: {
  29931. get: function get() {
  29932. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  29933. return 1.0;
  29934. },
  29935. set: function set() {
  29936. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  29937. }
  29938. }
  29939. });
  29940. Object.defineProperties(WebGLShadowMap.prototype, {
  29941. cullFace: {
  29942. get: function get() {
  29943. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  29944. return undefined;
  29945. },
  29946. set: function set()
  29947. /* cullFace */
  29948. {
  29949. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  29950. }
  29951. },
  29952. renderReverseSided: {
  29953. get: function get() {
  29954. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  29955. return undefined;
  29956. },
  29957. set: function set() {
  29958. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  29959. }
  29960. },
  29961. renderSingleSided: {
  29962. get: function get() {
  29963. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  29964. return undefined;
  29965. },
  29966. set: function set() {
  29967. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  29968. }
  29969. }
  29970. });
  29971. function WebGLRenderTargetCube(width, height, options) {
  29972. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  29973. return new WebGLCubeRenderTarget(width, options);
  29974. } //
  29975. Object.defineProperties(WebGLRenderTarget.prototype, {
  29976. wrapS: {
  29977. get: function get() {
  29978. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  29979. return this.texture.wrapS;
  29980. },
  29981. set: function set(value) {
  29982. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  29983. this.texture.wrapS = value;
  29984. }
  29985. },
  29986. wrapT: {
  29987. get: function get() {
  29988. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  29989. return this.texture.wrapT;
  29990. },
  29991. set: function set(value) {
  29992. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  29993. this.texture.wrapT = value;
  29994. }
  29995. },
  29996. magFilter: {
  29997. get: function get() {
  29998. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  29999. return this.texture.magFilter;
  30000. },
  30001. set: function set(value) {
  30002. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30003. this.texture.magFilter = value;
  30004. }
  30005. },
  30006. minFilter: {
  30007. get: function get() {
  30008. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30009. return this.texture.minFilter;
  30010. },
  30011. set: function set(value) {
  30012. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30013. this.texture.minFilter = value;
  30014. }
  30015. },
  30016. anisotropy: {
  30017. get: function get() {
  30018. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30019. return this.texture.anisotropy;
  30020. },
  30021. set: function set(value) {
  30022. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30023. this.texture.anisotropy = value;
  30024. }
  30025. },
  30026. offset: {
  30027. get: function get() {
  30028. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30029. return this.texture.offset;
  30030. },
  30031. set: function set(value) {
  30032. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30033. this.texture.offset = value;
  30034. }
  30035. },
  30036. repeat: {
  30037. get: function get() {
  30038. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30039. return this.texture.repeat;
  30040. },
  30041. set: function set(value) {
  30042. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30043. this.texture.repeat = value;
  30044. }
  30045. },
  30046. format: {
  30047. get: function get() {
  30048. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30049. return this.texture.format;
  30050. },
  30051. set: function set(value) {
  30052. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30053. this.texture.format = value;
  30054. }
  30055. },
  30056. type: {
  30057. get: function get() {
  30058. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30059. return this.texture.type;
  30060. },
  30061. set: function set(value) {
  30062. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30063. this.texture.type = value;
  30064. }
  30065. },
  30066. generateMipmaps: {
  30067. get: function get() {
  30068. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30069. return this.texture.generateMipmaps;
  30070. },
  30071. set: function set(value) {
  30072. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30073. this.texture.generateMipmaps = value;
  30074. }
  30075. }
  30076. }); //
  30077. Object.defineProperties(Audio.prototype, {
  30078. load: {
  30079. value: function value(file) {
  30080. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  30081. var scope = this;
  30082. var audioLoader = new AudioLoader();
  30083. audioLoader.load(file, function (buffer) {
  30084. scope.setBuffer(buffer);
  30085. });
  30086. return this;
  30087. }
  30088. },
  30089. startTime: {
  30090. set: function set() {
  30091. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  30092. }
  30093. }
  30094. });
  30095. AudioAnalyser.prototype.getData = function () {
  30096. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  30097. return this.getFrequencyData();
  30098. }; //
  30099. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  30100. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  30101. return this.update(renderer, scene);
  30102. };
  30103. CubeCamera.prototype.clear = function (renderer, color, depth, stencil) {
  30104. console.warn('THREE.CubeCamera: .clear() is now .renderTarget.clear().');
  30105. return this.renderTarget.clear(renderer, color, depth, stencil);
  30106. }; //
  30107. var GeometryUtils = {
  30108. merge: function merge(geometry1, geometry2, materialIndexOffset) {
  30109. console.warn('THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.');
  30110. var matrix;
  30111. if (geometry2.isMesh) {
  30112. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  30113. matrix = geometry2.matrix;
  30114. geometry2 = geometry2.geometry;
  30115. }
  30116. geometry1.merge(geometry2, matrix, materialIndexOffset);
  30117. },
  30118. center: function center(geometry) {
  30119. console.warn('THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.');
  30120. return geometry.center();
  30121. }
  30122. };
  30123. ImageUtils.crossOrigin = undefined;
  30124. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30125. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30126. var loader = new TextureLoader();
  30127. loader.setCrossOrigin(this.crossOrigin);
  30128. var texture = loader.load(url, onLoad, undefined, onError);
  30129. if (mapping) texture.mapping = mapping;
  30130. return texture;
  30131. };
  30132. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30133. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30134. var loader = new CubeTextureLoader();
  30135. loader.setCrossOrigin(this.crossOrigin);
  30136. var texture = loader.load(urls, onLoad, undefined, onError);
  30137. if (mapping) texture.mapping = mapping;
  30138. return texture;
  30139. };
  30140. ImageUtils.loadCompressedTexture = function () {
  30141. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30142. };
  30143. ImageUtils.loadCompressedTextureCube = function () {
  30144. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30145. }; //
  30146. function CanvasRenderer() {
  30147. console.error('THREE.CanvasRenderer has been removed');
  30148. } //
  30149. function JSONLoader() {
  30150. console.error('THREE.JSONLoader has been removed.');
  30151. } //
  30152. var SceneUtils = {
  30153. createMultiMaterialObject: function createMultiMaterialObject()
  30154. /* geometry, materials */
  30155. {
  30156. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30157. },
  30158. detach: function detach()
  30159. /* child, parent, scene */
  30160. {
  30161. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30162. },
  30163. attach: function attach()
  30164. /* child, scene, parent */
  30165. {
  30166. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30167. }
  30168. }; //
  30169. function LensFlare() {
  30170. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30171. }
  30172. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30173. /* eslint-disable no-undef */
  30174. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30175. detail: {
  30176. revision: REVISION
  30177. }
  30178. }));
  30179. /* eslint-enable no-undef */
  30180. }
  30181. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30182. exports.AddEquation = AddEquation;
  30183. exports.AddOperation = AddOperation;
  30184. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30185. exports.AdditiveBlending = AdditiveBlending;
  30186. exports.AlphaFormat = AlphaFormat;
  30187. exports.AlwaysDepth = AlwaysDepth;
  30188. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30189. exports.AmbientLight = AmbientLight;
  30190. exports.AmbientLightProbe = AmbientLightProbe;
  30191. exports.AnimationClip = AnimationClip;
  30192. exports.AnimationLoader = AnimationLoader;
  30193. exports.AnimationMixer = AnimationMixer;
  30194. exports.AnimationObjectGroup = AnimationObjectGroup;
  30195. exports.AnimationUtils = AnimationUtils;
  30196. exports.ArcCurve = ArcCurve;
  30197. exports.ArrayCamera = ArrayCamera;
  30198. exports.ArrowHelper = ArrowHelper;
  30199. exports.Audio = Audio;
  30200. exports.AudioAnalyser = AudioAnalyser;
  30201. exports.AudioContext = AudioContext;
  30202. exports.AudioListener = AudioListener;
  30203. exports.AudioLoader = AudioLoader;
  30204. exports.AxesHelper = AxesHelper;
  30205. exports.AxisHelper = AxisHelper;
  30206. exports.BackSide = BackSide;
  30207. exports.BasicDepthPacking = BasicDepthPacking;
  30208. exports.BasicShadowMap = BasicShadowMap;
  30209. exports.BinaryTextureLoader = BinaryTextureLoader;
  30210. exports.Bone = Bone;
  30211. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30212. exports.BoundingBoxHelper = BoundingBoxHelper;
  30213. exports.Box2 = Box2;
  30214. exports.Box3 = Box3;
  30215. exports.Box3Helper = Box3Helper;
  30216. exports.BoxBufferGeometry = BoxGeometry;
  30217. exports.BoxGeometry = BoxGeometry;
  30218. exports.BoxHelper = BoxHelper;
  30219. exports.BufferAttribute = BufferAttribute;
  30220. exports.BufferGeometry = BufferGeometry;
  30221. exports.BufferGeometryLoader = BufferGeometryLoader;
  30222. exports.ByteType = ByteType;
  30223. exports.Cache = Cache;
  30224. exports.Camera = Camera;
  30225. exports.CameraHelper = CameraHelper;
  30226. exports.CanvasRenderer = CanvasRenderer;
  30227. exports.CanvasTexture = CanvasTexture;
  30228. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30229. exports.CineonToneMapping = CineonToneMapping;
  30230. exports.CircleBufferGeometry = CircleGeometry;
  30231. exports.CircleGeometry = CircleGeometry;
  30232. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30233. exports.Clock = Clock;
  30234. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  30235. exports.Color = Color;
  30236. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30237. exports.CompressedTexture = CompressedTexture;
  30238. exports.CompressedTextureLoader = CompressedTextureLoader;
  30239. exports.ConeBufferGeometry = ConeGeometry;
  30240. exports.ConeGeometry = ConeGeometry;
  30241. exports.CubeCamera = CubeCamera;
  30242. exports.CubeReflectionMapping = CubeReflectionMapping;
  30243. exports.CubeRefractionMapping = CubeRefractionMapping;
  30244. exports.CubeTexture = CubeTexture;
  30245. exports.CubeTextureLoader = CubeTextureLoader;
  30246. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  30247. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  30248. exports.CubicBezierCurve = CubicBezierCurve;
  30249. exports.CubicBezierCurve3 = CubicBezierCurve3;
  30250. exports.CubicInterpolant = CubicInterpolant;
  30251. exports.CullFaceBack = CullFaceBack;
  30252. exports.CullFaceFront = CullFaceFront;
  30253. exports.CullFaceFrontBack = CullFaceFrontBack;
  30254. exports.CullFaceNone = CullFaceNone;
  30255. exports.Curve = Curve;
  30256. exports.CurvePath = CurvePath;
  30257. exports.CustomBlending = CustomBlending;
  30258. exports.CustomToneMapping = CustomToneMapping;
  30259. exports.CylinderBufferGeometry = CylinderGeometry;
  30260. exports.CylinderGeometry = CylinderGeometry;
  30261. exports.Cylindrical = Cylindrical;
  30262. exports.DataTexture = DataTexture;
  30263. exports.DataTexture2DArray = DataTexture2DArray;
  30264. exports.DataTexture3D = DataTexture3D;
  30265. exports.DataTextureLoader = DataTextureLoader;
  30266. exports.DataUtils = DataUtils;
  30267. exports.DecrementStencilOp = DecrementStencilOp;
  30268. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  30269. exports.DefaultLoadingManager = DefaultLoadingManager;
  30270. exports.DepthFormat = DepthFormat;
  30271. exports.DepthStencilFormat = DepthStencilFormat;
  30272. exports.DepthTexture = DepthTexture;
  30273. exports.DirectionalLight = DirectionalLight;
  30274. exports.DirectionalLightHelper = DirectionalLightHelper;
  30275. exports.DiscreteInterpolant = DiscreteInterpolant;
  30276. exports.DodecahedronBufferGeometry = DodecahedronGeometry;
  30277. exports.DodecahedronGeometry = DodecahedronGeometry;
  30278. exports.DoubleSide = DoubleSide;
  30279. exports.DstAlphaFactor = DstAlphaFactor;
  30280. exports.DstColorFactor = DstColorFactor;
  30281. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  30282. exports.DynamicCopyUsage = DynamicCopyUsage;
  30283. exports.DynamicDrawUsage = DynamicDrawUsage;
  30284. exports.DynamicReadUsage = DynamicReadUsage;
  30285. exports.EdgesGeometry = EdgesGeometry;
  30286. exports.EdgesHelper = EdgesHelper;
  30287. exports.EllipseCurve = EllipseCurve;
  30288. exports.EqualDepth = EqualDepth;
  30289. exports.EqualStencilFunc = EqualStencilFunc;
  30290. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  30291. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  30292. exports.Euler = Euler;
  30293. exports.EventDispatcher = EventDispatcher;
  30294. exports.ExtrudeBufferGeometry = ExtrudeGeometry;
  30295. exports.ExtrudeGeometry = ExtrudeGeometry;
  30296. exports.Face3 = Face3;
  30297. exports.Face4 = Face4;
  30298. exports.FaceColors = FaceColors;
  30299. exports.FileLoader = FileLoader;
  30300. exports.FlatShading = FlatShading;
  30301. exports.Float16BufferAttribute = Float16BufferAttribute;
  30302. exports.Float32Attribute = Float32Attribute;
  30303. exports.Float32BufferAttribute = Float32BufferAttribute;
  30304. exports.Float64Attribute = Float64Attribute;
  30305. exports.Float64BufferAttribute = Float64BufferAttribute;
  30306. exports.FloatType = FloatType;
  30307. exports.Fog = Fog;
  30308. exports.FogExp2 = FogExp2;
  30309. exports.Font = Font;
  30310. exports.FontLoader = FontLoader;
  30311. exports.FrontSide = FrontSide;
  30312. exports.Frustum = Frustum;
  30313. exports.GLBufferAttribute = GLBufferAttribute;
  30314. exports.GLSL1 = GLSL1;
  30315. exports.GLSL3 = GLSL3;
  30316. exports.GammaEncoding = GammaEncoding;
  30317. exports.GeometryUtils = GeometryUtils;
  30318. exports.GreaterDepth = GreaterDepth;
  30319. exports.GreaterEqualDepth = GreaterEqualDepth;
  30320. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  30321. exports.GreaterStencilFunc = GreaterStencilFunc;
  30322. exports.GridHelper = GridHelper;
  30323. exports.Group = Group;
  30324. exports.HalfFloatType = HalfFloatType;
  30325. exports.HemisphereLight = HemisphereLight;
  30326. exports.HemisphereLightHelper = HemisphereLightHelper;
  30327. exports.HemisphereLightProbe = HemisphereLightProbe;
  30328. exports.IcosahedronBufferGeometry = IcosahedronGeometry;
  30329. exports.IcosahedronGeometry = IcosahedronGeometry;
  30330. exports.ImageBitmapLoader = ImageBitmapLoader;
  30331. exports.ImageLoader = ImageLoader;
  30332. exports.ImageUtils = ImageUtils;
  30333. exports.ImmediateRenderObject = ImmediateRenderObject;
  30334. exports.IncrementStencilOp = IncrementStencilOp;
  30335. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  30336. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  30337. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  30338. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  30339. exports.InstancedMesh = InstancedMesh;
  30340. exports.Int16Attribute = Int16Attribute;
  30341. exports.Int16BufferAttribute = Int16BufferAttribute;
  30342. exports.Int32Attribute = Int32Attribute;
  30343. exports.Int32BufferAttribute = Int32BufferAttribute;
  30344. exports.Int8Attribute = Int8Attribute;
  30345. exports.Int8BufferAttribute = Int8BufferAttribute;
  30346. exports.IntType = IntType;
  30347. exports.InterleavedBuffer = InterleavedBuffer;
  30348. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  30349. exports.Interpolant = Interpolant;
  30350. exports.InterpolateDiscrete = InterpolateDiscrete;
  30351. exports.InterpolateLinear = InterpolateLinear;
  30352. exports.InterpolateSmooth = InterpolateSmooth;
  30353. exports.InvertStencilOp = InvertStencilOp;
  30354. exports.JSONLoader = JSONLoader;
  30355. exports.KeepStencilOp = KeepStencilOp;
  30356. exports.KeyframeTrack = KeyframeTrack;
  30357. exports.LOD = LOD;
  30358. exports.LatheBufferGeometry = LatheGeometry;
  30359. exports.LatheGeometry = LatheGeometry;
  30360. exports.Layers = Layers;
  30361. exports.LensFlare = LensFlare;
  30362. exports.LessDepth = LessDepth;
  30363. exports.LessEqualDepth = LessEqualDepth;
  30364. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  30365. exports.LessStencilFunc = LessStencilFunc;
  30366. exports.Light = Light;
  30367. exports.LightProbe = LightProbe;
  30368. exports.Line = Line;
  30369. exports.Line3 = Line3;
  30370. exports.LineBasicMaterial = LineBasicMaterial;
  30371. exports.LineCurve = LineCurve;
  30372. exports.LineCurve3 = LineCurve3;
  30373. exports.LineDashedMaterial = LineDashedMaterial;
  30374. exports.LineLoop = LineLoop;
  30375. exports.LinePieces = LinePieces;
  30376. exports.LineSegments = LineSegments;
  30377. exports.LineStrip = LineStrip;
  30378. exports.LinearEncoding = LinearEncoding;
  30379. exports.LinearFilter = LinearFilter;
  30380. exports.LinearInterpolant = LinearInterpolant;
  30381. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  30382. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  30383. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  30384. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  30385. exports.LinearToneMapping = LinearToneMapping;
  30386. exports.Loader = Loader;
  30387. exports.LoaderUtils = LoaderUtils;
  30388. exports.LoadingManager = LoadingManager;
  30389. exports.LogLuvEncoding = LogLuvEncoding;
  30390. exports.LoopOnce = LoopOnce;
  30391. exports.LoopPingPong = LoopPingPong;
  30392. exports.LoopRepeat = LoopRepeat;
  30393. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  30394. exports.LuminanceFormat = LuminanceFormat;
  30395. exports.MOUSE = MOUSE;
  30396. exports.Material = Material;
  30397. exports.MaterialLoader = MaterialLoader;
  30398. exports.Math = MathUtils;
  30399. exports.MathUtils = MathUtils;
  30400. exports.Matrix3 = Matrix3;
  30401. exports.Matrix4 = Matrix4;
  30402. exports.MaxEquation = MaxEquation;
  30403. exports.Mesh = Mesh;
  30404. exports.MeshBasicMaterial = MeshBasicMaterial;
  30405. exports.MeshDepthMaterial = MeshDepthMaterial;
  30406. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  30407. exports.MeshFaceMaterial = MeshFaceMaterial;
  30408. exports.MeshLambertMaterial = MeshLambertMaterial;
  30409. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  30410. exports.MeshNormalMaterial = MeshNormalMaterial;
  30411. exports.MeshPhongMaterial = MeshPhongMaterial;
  30412. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  30413. exports.MeshStandardMaterial = MeshStandardMaterial;
  30414. exports.MeshToonMaterial = MeshToonMaterial;
  30415. exports.MinEquation = MinEquation;
  30416. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  30417. exports.MixOperation = MixOperation;
  30418. exports.MultiMaterial = MultiMaterial;
  30419. exports.MultiplyBlending = MultiplyBlending;
  30420. exports.MultiplyOperation = MultiplyOperation;
  30421. exports.NearestFilter = NearestFilter;
  30422. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  30423. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  30424. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  30425. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  30426. exports.NeverDepth = NeverDepth;
  30427. exports.NeverStencilFunc = NeverStencilFunc;
  30428. exports.NoBlending = NoBlending;
  30429. exports.NoColors = NoColors;
  30430. exports.NoToneMapping = NoToneMapping;
  30431. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  30432. exports.NormalBlending = NormalBlending;
  30433. exports.NotEqualDepth = NotEqualDepth;
  30434. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  30435. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  30436. exports.Object3D = Object3D;
  30437. exports.ObjectLoader = ObjectLoader;
  30438. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  30439. exports.OctahedronBufferGeometry = OctahedronGeometry;
  30440. exports.OctahedronGeometry = OctahedronGeometry;
  30441. exports.OneFactor = OneFactor;
  30442. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  30443. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  30444. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  30445. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  30446. exports.OrthographicCamera = OrthographicCamera;
  30447. exports.PCFShadowMap = PCFShadowMap;
  30448. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  30449. exports.PMREMGenerator = PMREMGenerator;
  30450. exports.ParametricBufferGeometry = ParametricGeometry;
  30451. exports.ParametricGeometry = ParametricGeometry;
  30452. exports.Particle = Particle;
  30453. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  30454. exports.ParticleSystem = ParticleSystem;
  30455. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  30456. exports.Path = Path;
  30457. exports.PerspectiveCamera = PerspectiveCamera;
  30458. exports.Plane = Plane;
  30459. exports.PlaneBufferGeometry = PlaneGeometry;
  30460. exports.PlaneGeometry = PlaneGeometry;
  30461. exports.PlaneHelper = PlaneHelper;
  30462. exports.PointCloud = PointCloud;
  30463. exports.PointCloudMaterial = PointCloudMaterial;
  30464. exports.PointLight = PointLight;
  30465. exports.PointLightHelper = PointLightHelper;
  30466. exports.Points = Points;
  30467. exports.PointsMaterial = PointsMaterial;
  30468. exports.PolarGridHelper = PolarGridHelper;
  30469. exports.PolyhedronBufferGeometry = PolyhedronGeometry;
  30470. exports.PolyhedronGeometry = PolyhedronGeometry;
  30471. exports.PositionalAudio = PositionalAudio;
  30472. exports.PropertyBinding = PropertyBinding;
  30473. exports.PropertyMixer = PropertyMixer;
  30474. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  30475. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  30476. exports.Quaternion = Quaternion;
  30477. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  30478. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  30479. exports.REVISION = REVISION;
  30480. exports.RGBADepthPacking = RGBADepthPacking;
  30481. exports.RGBAFormat = RGBAFormat;
  30482. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  30483. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  30484. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  30485. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  30486. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  30487. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  30488. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  30489. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  30490. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  30491. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  30492. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  30493. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  30494. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  30495. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  30496. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  30497. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  30498. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  30499. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  30500. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  30501. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  30502. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  30503. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  30504. exports.RGBDEncoding = RGBDEncoding;
  30505. exports.RGBEEncoding = RGBEEncoding;
  30506. exports.RGBEFormat = RGBEFormat;
  30507. exports.RGBFormat = RGBFormat;
  30508. exports.RGBIntegerFormat = RGBIntegerFormat;
  30509. exports.RGBM16Encoding = RGBM16Encoding;
  30510. exports.RGBM7Encoding = RGBM7Encoding;
  30511. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  30512. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  30513. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  30514. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  30515. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  30516. exports.RGFormat = RGFormat;
  30517. exports.RGIntegerFormat = RGIntegerFormat;
  30518. exports.RawShaderMaterial = RawShaderMaterial;
  30519. exports.Ray = Ray;
  30520. exports.Raycaster = Raycaster;
  30521. exports.RectAreaLight = RectAreaLight;
  30522. exports.RedFormat = RedFormat;
  30523. exports.RedIntegerFormat = RedIntegerFormat;
  30524. exports.ReinhardToneMapping = ReinhardToneMapping;
  30525. exports.RepeatWrapping = RepeatWrapping;
  30526. exports.ReplaceStencilOp = ReplaceStencilOp;
  30527. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  30528. exports.RingBufferGeometry = RingGeometry;
  30529. exports.RingGeometry = RingGeometry;
  30530. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  30531. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  30532. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  30533. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  30534. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  30535. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  30536. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  30537. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  30538. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  30539. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  30540. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  30541. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  30542. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  30543. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  30544. exports.Scene = Scene;
  30545. exports.SceneUtils = SceneUtils;
  30546. exports.ShaderChunk = ShaderChunk;
  30547. exports.ShaderLib = ShaderLib;
  30548. exports.ShaderMaterial = ShaderMaterial;
  30549. exports.ShadowMaterial = ShadowMaterial;
  30550. exports.Shape = Shape;
  30551. exports.ShapeBufferGeometry = ShapeGeometry;
  30552. exports.ShapeGeometry = ShapeGeometry;
  30553. exports.ShapePath = ShapePath;
  30554. exports.ShapeUtils = ShapeUtils;
  30555. exports.ShortType = ShortType;
  30556. exports.Skeleton = Skeleton;
  30557. exports.SkeletonHelper = SkeletonHelper;
  30558. exports.SkinnedMesh = SkinnedMesh;
  30559. exports.SmoothShading = SmoothShading;
  30560. exports.Sphere = Sphere;
  30561. exports.SphereBufferGeometry = SphereGeometry;
  30562. exports.SphereGeometry = SphereGeometry;
  30563. exports.Spherical = Spherical;
  30564. exports.SphericalHarmonics3 = SphericalHarmonics3;
  30565. exports.Spline = Spline;
  30566. exports.SplineCurve = SplineCurve;
  30567. exports.SplineCurve3 = SplineCurve3;
  30568. exports.SpotLight = SpotLight;
  30569. exports.SpotLightHelper = SpotLightHelper;
  30570. exports.Sprite = Sprite;
  30571. exports.SpriteMaterial = SpriteMaterial;
  30572. exports.SrcAlphaFactor = SrcAlphaFactor;
  30573. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  30574. exports.SrcColorFactor = SrcColorFactor;
  30575. exports.StaticCopyUsage = StaticCopyUsage;
  30576. exports.StaticDrawUsage = StaticDrawUsage;
  30577. exports.StaticReadUsage = StaticReadUsage;
  30578. exports.StereoCamera = StereoCamera;
  30579. exports.StreamCopyUsage = StreamCopyUsage;
  30580. exports.StreamDrawUsage = StreamDrawUsage;
  30581. exports.StreamReadUsage = StreamReadUsage;
  30582. exports.StringKeyframeTrack = StringKeyframeTrack;
  30583. exports.SubtractEquation = SubtractEquation;
  30584. exports.SubtractiveBlending = SubtractiveBlending;
  30585. exports.TOUCH = TOUCH;
  30586. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  30587. exports.TetrahedronBufferGeometry = TetrahedronGeometry;
  30588. exports.TetrahedronGeometry = TetrahedronGeometry;
  30589. exports.TextBufferGeometry = TextGeometry;
  30590. exports.TextGeometry = TextGeometry;
  30591. exports.Texture = Texture;
  30592. exports.TextureLoader = TextureLoader;
  30593. exports.TorusBufferGeometry = TorusGeometry;
  30594. exports.TorusGeometry = TorusGeometry;
  30595. exports.TorusKnotBufferGeometry = TorusKnotGeometry;
  30596. exports.TorusKnotGeometry = TorusKnotGeometry;
  30597. exports.Triangle = Triangle;
  30598. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  30599. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  30600. exports.TrianglesDrawMode = TrianglesDrawMode;
  30601. exports.TubeBufferGeometry = TubeGeometry;
  30602. exports.TubeGeometry = TubeGeometry;
  30603. exports.UVMapping = UVMapping;
  30604. exports.Uint16Attribute = Uint16Attribute;
  30605. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  30606. exports.Uint32Attribute = Uint32Attribute;
  30607. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  30608. exports.Uint8Attribute = Uint8Attribute;
  30609. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  30610. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  30611. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  30612. exports.Uniform = Uniform;
  30613. exports.UniformsLib = UniformsLib;
  30614. exports.UniformsUtils = UniformsUtils;
  30615. exports.UnsignedByteType = UnsignedByteType;
  30616. exports.UnsignedInt248Type = UnsignedInt248Type;
  30617. exports.UnsignedIntType = UnsignedIntType;
  30618. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  30619. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  30620. exports.UnsignedShort565Type = UnsignedShort565Type;
  30621. exports.UnsignedShortType = UnsignedShortType;
  30622. exports.VSMShadowMap = VSMShadowMap;
  30623. exports.Vector2 = Vector2;
  30624. exports.Vector3 = Vector3;
  30625. exports.Vector4 = Vector4;
  30626. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  30627. exports.Vertex = Vertex;
  30628. exports.VertexColors = VertexColors;
  30629. exports.VideoTexture = VideoTexture;
  30630. exports.WebGL1Renderer = WebGL1Renderer;
  30631. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  30632. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  30633. exports.WebGLRenderTarget = WebGLRenderTarget;
  30634. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  30635. exports.WebGLRenderer = WebGLRenderer;
  30636. exports.WebGLUtils = WebGLUtils;
  30637. exports.WireframeGeometry = WireframeGeometry;
  30638. exports.WireframeHelper = WireframeHelper;
  30639. exports.WrapAroundEnding = WrapAroundEnding;
  30640. exports.XHRLoader = XHRLoader;
  30641. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  30642. exports.ZeroFactor = ZeroFactor;
  30643. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  30644. exports.ZeroStencilOp = ZeroStencilOp;
  30645. exports.sRGBEncoding = sRGBEncoding;
  30646. Object.defineProperty(exports, '__esModule', { value: true });
  30647. })));